mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 17:58:26 +02:00
Merge remote branch 'origin/master' into gallium_draw_llvm
This commit is contained in:
commit
880e3fb09b
631 changed files with 17767 additions and 7885 deletions
25
Makefile
25
Makefile
|
|
@ -243,7 +243,6 @@ MAIN_FILES = \
|
|||
$(DIRECTORY)/src/mesa/shader/descrip.mms \
|
||||
$(DIRECTORY)/src/mesa/shader/slang/*.[ch] \
|
||||
$(DIRECTORY)/src/mesa/shader/slang/descrip.mms \
|
||||
$(DIRECTORY)/src/mesa/shader/slang/library/*.[ch] \
|
||||
$(DIRECTORY)/src/mesa/shader/slang/library/*.gc \
|
||||
$(DIRECTORY)/src/mesa/shader/slang/library/Makefile \
|
||||
$(DIRECTORY)/src/mesa/swrast/*.[ch] \
|
||||
|
|
@ -324,6 +323,7 @@ GALLIUM_FILES = \
|
|||
$(DIRECTORY)/src/gallium/*/Makefile \
|
||||
$(DIRECTORY)/src/gallium/*/SConscript \
|
||||
$(DIRECTORY)/src/gallium/*/*/Makefile \
|
||||
$(DIRECTORY)/src/gallium/*/*/Makefile.egl \
|
||||
$(DIRECTORY)/src/gallium/*/*/Makefile.template \
|
||||
$(DIRECTORY)/src/gallium/*/*/SConscript \
|
||||
$(DIRECTORY)/src/gallium/*/*/*.[ch] \
|
||||
|
|
@ -379,15 +379,6 @@ SGI_GLU_FILES = \
|
|||
$(DIRECTORY)/src/glu/sgi/libtess/*.[ch] \
|
||||
$(DIRECTORY)/src/glu/sgi/libutil/*.[ch]
|
||||
|
||||
MESA_GLU_FILES = \
|
||||
$(DIRECTORY)/src/glu/mesa/README[12] \
|
||||
$(DIRECTORY)/src/glu/mesa/Makefile* \
|
||||
$(DIRECTORY)/src/glu/mesa/descrip.mms \
|
||||
$(DIRECTORY)/src/glu/mesa/mms_depend \
|
||||
$(DIRECTORY)/src/glu/mesa/*.def \
|
||||
$(DIRECTORY)/src/glu/mesa/depend \
|
||||
$(DIRECTORY)/src/glu/mesa/*.[ch]
|
||||
|
||||
GLW_FILES = \
|
||||
$(DIRECTORY)/src/glw/*.[ch] \
|
||||
$(DIRECTORY)/src/glw/Makefile* \
|
||||
|
|
@ -416,6 +407,14 @@ DEMO_FILES = \
|
|||
$(DIRECTORY)/progs/demos/*.cxx \
|
||||
$(DIRECTORY)/progs/demos/*.dat \
|
||||
$(DIRECTORY)/progs/demos/README \
|
||||
$(DIRECTORY)/progs/egl/Makefile \
|
||||
$(DIRECTORY)/progs/egl/*.[ch] \
|
||||
$(DIRECTORY)/progs/es1/*/Makefile \
|
||||
$(DIRECTORY)/progs/es1/*/*.[ch] \
|
||||
$(DIRECTORY)/progs/es2/*/Makefile \
|
||||
$(DIRECTORY)/progs/es2/*/*.[ch] \
|
||||
$(DIRECTORY)/progs/openvg/*/Makefile \
|
||||
$(DIRECTORY)/progs/openvg/*/*.[ch] \
|
||||
$(DIRECTORY)/progs/fbdev/Makefile \
|
||||
$(DIRECTORY)/progs/fbdev/glfbdevtest.c \
|
||||
$(DIRECTORY)/progs/objviewer/*.[ch] \
|
||||
|
|
@ -450,11 +449,7 @@ GLUT_FILES = \
|
|||
$(DIRECTORY)/src/glut/glx/*.[ch] \
|
||||
$(DIRECTORY)/src/glut/beos/*.[ch] \
|
||||
$(DIRECTORY)/src/glut/beos/*.cpp \
|
||||
$(DIRECTORY)/src/glut/beos/Makefile \
|
||||
$(DIRECTORY)/src/glut/fbdev/Makefile \
|
||||
$(DIRECTORY)/src/glut/fbdev/*[ch] \
|
||||
$(DIRECTORY)/src/glut/mini/*[ch] \
|
||||
$(DIRECTORY)/src/glut/mini/glut.pc.in \
|
||||
$(DIRECTORY)/src/glut/beos/Makefile
|
||||
|
||||
DEPEND_FILES = \
|
||||
$(TOP)/src/mesa/depend \
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ opts.Add(ListVariable('statetrackers', 'state trackers to build', default_statet
|
|||
opts.Add(ListVariable('drivers', 'pipe drivers to build', default_drivers,
|
||||
['softpipe', 'failover', 'svga', 'i915', 'i965', 'trace', 'r300', 'identity', 'llvmpipe']))
|
||||
opts.Add(ListVariable('winsys', 'winsys drivers to build', default_winsys,
|
||||
['xlib', 'vmware', 'intel', 'i965', 'gdi', 'radeon']))
|
||||
['xlib', 'vmware', 'i915', 'i965', 'gdi', 'radeon', 'graw-xlib']))
|
||||
|
||||
opts.Add(EnumVariable('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ RADEON_CFLAGS = @RADEON_CFLAGS@
|
|||
RADEON_LDFLAGS = @RADEON_LDFLAGS@
|
||||
INTEL_LIBS = @INTEL_LIBS@
|
||||
INTEL_CFLAGS = @INTEL_CFLAGS@
|
||||
X_LIBS = @X_LIBS@
|
||||
X_CFLAGS = @X_CFLAGS@
|
||||
X11_LIBS = @X11_LIBS@
|
||||
X11_CFLAGS = @X11_CFLAGS@
|
||||
|
||||
# Assembler
|
||||
MESA_ASM_SOURCES = @MESA_ASM_SOURCES@
|
||||
|
|
@ -76,7 +76,6 @@ GALLIUM_DIRS = @GALLIUM_DIRS@
|
|||
GALLIUM_DRIVERS_DIRS = @GALLIUM_DRIVERS_DIRS@
|
||||
GALLIUM_WINSYS_DIRS = @GALLIUM_WINSYS_DIRS@
|
||||
GALLIUM_TARGET_DIRS = @GALLIUM_TARGET_DIRS@
|
||||
GALLIUM_WINSYS_DRM_DIRS = @GALLIUM_WINSYS_DRM_DIRS@
|
||||
GALLIUM_STATE_TRACKERS_DIRS = @GALLIUM_STATE_TRACKERS_DIRS@
|
||||
GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
|
||||
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
|
||||
|
|
|
|||
|
|
@ -100,9 +100,8 @@ GALLIUM_DIRS = auxiliary drivers state_trackers
|
|||
GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
|
||||
GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity
|
||||
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
|
||||
GALLIUM_WINSYS_DIRS = null xlib drm
|
||||
GALLIUM_WINSYS_DIRS = sw sw/xlib
|
||||
GALLIUM_TARGET_DIRS = libgl-xlib
|
||||
GALLIUM_WINSYS_DRM_DIRS = swrast
|
||||
GALLIUM_STATE_TRACKERS_DIRS = glx vega
|
||||
|
||||
# native displays EGL should support
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ CONFIG_NAME = linux-cell
|
|||
|
||||
|
||||
# Omiting other gallium drivers:
|
||||
GALLIUM_DRIVERS_DIRS = cell softpipe trace
|
||||
GALLIUM_DRIVERS_DIRS = cell softpipe trace identity
|
||||
|
||||
|
||||
# Compiler and flags
|
||||
|
|
|
|||
|
|
@ -58,9 +58,8 @@ PROGRAM_DIRS := egl $(PROGRAM_DIRS)
|
|||
EGL_DRIVERS_DIRS = glx
|
||||
|
||||
DRIVER_DIRS = dri
|
||||
GALLIUM_WINSYS_DIRS = null xlib drm
|
||||
GALLIUM_TARGET_DIRS =
|
||||
GALLIUM_WINSYS_DRM_DIRS = vmware intel i965
|
||||
GALLIUM_WINSYS_DIRS = sw sw/xlib drm/vmware drm/intel drm/i965
|
||||
GALLIUM_TARGET_DIRS = egl-swrast
|
||||
GALLIUM_STATE_TRACKERS_DIRS = egl
|
||||
|
||||
DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon \
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ CONFIG_NAME = linux-llvm
|
|||
GALLIUM_DRIVERS_DIRS += llvmpipe
|
||||
|
||||
OPT_FLAGS = -O3 -ansi -pedantic
|
||||
ARCH_FLAGS = -m32 -mmmx -msse -msse2 -mstackrealign
|
||||
ARCH_FLAGS = -mmmx -msse -msse2 -mstackrealign
|
||||
|
||||
DEFINES += -DNDEBUG -DGALLIUM_LLVMPIPE -DDRAW_LLVM -DHAVE_UDIS86
|
||||
|
||||
|
|
@ -24,6 +24,8 @@ ifeq ($(LLVM_VERSION),)
|
|||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -24,5 +24,5 @@ GALLIUM_STATE_TRACKERS_DIRS = es
|
|||
# build egl_x11_{swrast,i915}.so
|
||||
GALLIUM_DRIVERS_DIRS += trace i915
|
||||
GALLIUM_STATE_TRACKERS_DIRS += egl
|
||||
GALLIUM_WINSYS_DIRS += drm
|
||||
GALLIUM_WINSYS_DRM_DIRS += intel swrast
|
||||
GALLIUM_WINSYS_DIRS += drm/intel
|
||||
GALLIUM_TARGET_DIRS += egl-swrast egl-i915
|
||||
|
|
|
|||
72
configure.ac
72
configure.ac
|
|
@ -461,21 +461,20 @@ SRC_DIRS="glew"
|
|||
GLU_DIRS="sgi"
|
||||
GALLIUM_DIRS="auxiliary drivers state_trackers"
|
||||
GALLIUM_TARGET_DIRS=""
|
||||
GALLIUM_WINSYS_DIRS=""
|
||||
GALLIUM_WINSYS_DRM_DIRS=""
|
||||
GALLIUM_WINSYS_DIRS="sw"
|
||||
GALLIUM_DRIVERS_DIRS="softpipe failover trace identity"
|
||||
GALLIUM_STATE_TRACKERS_DIRS=""
|
||||
|
||||
case "$mesa_driver" in
|
||||
xlib)
|
||||
DRIVER_DIRS="x11"
|
||||
GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib"
|
||||
GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib"
|
||||
GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS libgl-xlib"
|
||||
;;
|
||||
dri)
|
||||
SRC_DIRS="$SRC_DIRS glx"
|
||||
DRIVER_DIRS="dri"
|
||||
GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib drm"
|
||||
GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/dri sw/drm"
|
||||
;;
|
||||
osmesa)
|
||||
DRIVER_DIRS="osmesa"
|
||||
|
|
@ -487,7 +486,6 @@ AC_SUBST([DRIVER_DIRS])
|
|||
AC_SUBST([GALLIUM_DIRS])
|
||||
AC_SUBST([GALLIUM_TARGET_DIRS])
|
||||
AC_SUBST([GALLIUM_WINSYS_DIRS])
|
||||
AC_SUBST([GALLIUM_WINSYS_DRM_DIRS])
|
||||
AC_SUBST([GALLIUM_DRIVERS_DIRS])
|
||||
AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS])
|
||||
|
||||
|
|
@ -548,9 +546,13 @@ else
|
|||
fi
|
||||
dnl Use the autoconf macro if no pkg-config files
|
||||
if test "$x11_pkgconfig" = yes; then
|
||||
PKG_CHECK_MODULES([X], [x11])
|
||||
PKG_CHECK_MODULES([X11], [x11])
|
||||
else
|
||||
AC_PATH_XTRA
|
||||
test -z "$X11_CFLAGS" && X11_CFLAGS="$X_CFLAGS"
|
||||
test -z "$X11_LIBS" && X11_LIBS="$X_LIBS -lX11"
|
||||
AC_SUBST([X11_CFLAGS])
|
||||
AC_SUBST([X11_LIBS])
|
||||
fi
|
||||
|
||||
dnl Try to tell the user that the --x-* options are only used when
|
||||
|
|
@ -1178,7 +1180,7 @@ AC_ARG_ENABLE([gallium],
|
|||
[enable_gallium="$enableval"],
|
||||
[enable_gallium=yes])
|
||||
if test "x$enable_gallium" = xyes; then
|
||||
SRC_DIRS="$SRC_DIRS gallium gallium/winsys"
|
||||
SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets"
|
||||
fi
|
||||
|
||||
dnl
|
||||
|
|
@ -1203,13 +1205,15 @@ yes)
|
|||
;;
|
||||
dri)
|
||||
GALLIUM_STATE_TRACKERS_DIRS="dri"
|
||||
HAVE_ST_DRI="yes"
|
||||
if test "x$enable_egl" = xyes; then
|
||||
GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl"
|
||||
HAVE_ST_EGL="yes"
|
||||
fi
|
||||
# Have only tested st/xorg on 1.6.0 servers
|
||||
PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED],
|
||||
HAVE_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg",
|
||||
HAVE_XORG="no")
|
||||
HAVE_ST_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg",
|
||||
HAVE_ST_XORG="no")
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
|
@ -1221,15 +1225,22 @@ yes)
|
|||
AC_MSG_ERROR([state tracker '$tracker' doesn't exist])
|
||||
|
||||
case "$tracker" in
|
||||
dri)
|
||||
if test "x$mesa_driver" != xdri; then
|
||||
AC_MSG_ERROR([cannot build dri state tracker without mesa driver set to dri])
|
||||
fi
|
||||
HAVE_ST_DRI="yes"
|
||||
;;
|
||||
egl)
|
||||
if test "x$enable_egl" != xyes; then
|
||||
AC_MSG_ERROR([cannot build egl state tracker without EGL library])
|
||||
fi
|
||||
HAVE_ST_EGL="yes"
|
||||
;;
|
||||
xorg)
|
||||
PKG_CHECK_MODULES([LIBDRM_XORG], [libdrm >= $LIBDRM_XORG_REQUIRED])
|
||||
PKG_CHECK_MODULES([LIBKMS_XORG], [libkms >= $LIBKMS_XORG_REQUIRED])
|
||||
HAVE_XORG="yes"
|
||||
HAVE_ST_XORG="yes"
|
||||
;;
|
||||
es)
|
||||
# mesa/es is required to build es state tracker
|
||||
|
|
@ -1241,7 +1252,7 @@ yes)
|
|||
;;
|
||||
esac
|
||||
|
||||
if test "x$HAVE_XORG" = xyes; then
|
||||
if test "x$HAVE_ST_XORG" = xyes; then
|
||||
PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1],
|
||||
HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71",
|
||||
HAVE_XEXTPROTO_71="no")
|
||||
|
|
@ -1305,6 +1316,25 @@ AC_ARG_WITH([max-height],
|
|||
[AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])]
|
||||
)
|
||||
|
||||
dnl
|
||||
dnl Gallium helper functions
|
||||
dnl
|
||||
gallium_check_st() {
|
||||
if test "x$HAVE_ST_DRI" = xyes || test "x$HAVE_ST_EGL" = xyes || test "x$HAVE_ST_XORG" = xyes; then
|
||||
GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS $1"
|
||||
fi
|
||||
if test "x$HAVE_ST_DRI" = xyes && test "x$2" != x; then
|
||||
GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $2"
|
||||
fi
|
||||
if test "x$HAVE_ST_EGL" = xyes && test "x$3" != x; then
|
||||
GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $3"
|
||||
fi
|
||||
if test "x$HAVE_ST_XORG" = xyes && test "x$4" != x; then
|
||||
GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $4"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
dnl
|
||||
dnl Gallium SVGA configuration
|
||||
dnl
|
||||
|
|
@ -1314,8 +1344,8 @@ AC_ARG_ENABLE([gallium-svga],
|
|||
[enable_gallium_svga="$enableval"],
|
||||
[enable_gallium_svga=auto])
|
||||
if test "x$enable_gallium_svga" = xyes; then
|
||||
GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS vmware"
|
||||
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
|
||||
gallium_check_st "svga/drm" "dri-vmwgfx" "egl-vmwgfx" "xorg-vmwgfx"
|
||||
elif test "x$enable_gallium_svga" = xauto; then
|
||||
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
|
||||
fi
|
||||
|
|
@ -1329,8 +1359,8 @@ AC_ARG_ENABLE([gallium-intel],
|
|||
[enable_gallium_intel="$enableval"],
|
||||
[enable_gallium_intel=auto])
|
||||
if test "x$enable_gallium_intel" = xyes; then
|
||||
GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS intel i965"
|
||||
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965"
|
||||
gallium_check_st "i915/drm i965/drm" "dri-i915 dri-i965" "egl-i915 egl-i965" "xorg-i915 xorg-i965"
|
||||
elif test "x$enable_gallium_intel" = xauto; then
|
||||
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965"
|
||||
fi
|
||||
|
|
@ -1344,8 +1374,8 @@ AC_ARG_ENABLE([gallium-radeon],
|
|||
[enable_gallium_radeon="$enableval"],
|
||||
[enable_gallium_radeon=auto])
|
||||
if test "x$enable_gallium_radeon" = xyes; then
|
||||
GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS radeon"
|
||||
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
|
||||
gallium_check_st "radeon/drm" "dri-radeong" "egl-radeon" "xorg-radeon"
|
||||
elif test "x$enable_gallium_radeon" = xauto; then
|
||||
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
|
||||
fi
|
||||
|
|
@ -1359,8 +1389,8 @@ AC_ARG_ENABLE([gallium-nouveau],
|
|||
[enable_gallium_nouveau="$enableval"],
|
||||
[enable_gallium_nouveau=no])
|
||||
if test "x$enable_gallium_nouveau" = xyes; then
|
||||
GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS nouveau"
|
||||
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50"
|
||||
gallium_check_st "nouveau/drm" "dri-nouveau" "egl-nouveau" "xorg-nouveau"
|
||||
fi
|
||||
|
||||
dnl
|
||||
|
|
@ -1368,11 +1398,16 @@ dnl Gallium swrast configuration
|
|||
dnl
|
||||
AC_ARG_ENABLE([gallium-swrast],
|
||||
[AS_HELP_STRING([--enable-gallium-swrast],
|
||||
[build gallium swrast @<:@default=disabled@:>@])],
|
||||
[build gallium swrast @<:@default=auto@:>@])],
|
||||
[enable_gallium_swrast="$enableval"],
|
||||
[enable_gallium_swrast=auto])
|
||||
if test "x$enable_gallium_swrast" = xyes; then
|
||||
GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS swrast"
|
||||
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
|
||||
if test "x$HAVE_ST_EGL" = xyes; then
|
||||
GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast"
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl prepend CORE_DIRS to SRC_DIRS
|
||||
|
|
@ -1430,7 +1465,6 @@ if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then
|
|||
echo " Gallium dirs: $GALLIUM_DIRS"
|
||||
echo " Target dirs: $GALLIUM_TARGET_DIRS"
|
||||
echo " Winsys dirs: $GALLIUM_WINSYS_DIRS"
|
||||
echo " Winsys drm dirs:$GALLIUM_WINSYS_DRM_DIRS"
|
||||
echo " Driver dirs: $GALLIUM_DRIVERS_DIRS"
|
||||
echo " Trackers dirs: $GALLIUM_STATE_TRACKERS_DIRS"
|
||||
else
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ GLSL changes (GL_EXT_gpu_shader4, etc) not started
|
|||
Conditional rendering (GL_NV_conditional_render) DONE (swrast & softpipe)
|
||||
Map buffer subranges (GL_APPLE_flush_buffer_range) not started
|
||||
Float textures, renderbuffers some infrastructure done
|
||||
(incl. GL_EXT_packed_float, GL_EXT_shared_exponent)
|
||||
Framebuffer objects (GL_EXT_framebuffer_object) DONE
|
||||
Half-float some infrastructure done
|
||||
Multisample blit DONE
|
||||
|
|
|
|||
|
|
@ -106,11 +106,11 @@ noted that the classic <code>libGL</code> is not a state tracker and cannot be
|
|||
used with EGL (unless the EGL driver in use is <code>egl_glx</code>). To build
|
||||
the OpenGL state tracker, one may append <code>glx</code> to
|
||||
<code>--with-state-trackers</code> and manually build
|
||||
<code>src/gallium/winsys/xlib/</code>.</p>
|
||||
<code>src/gallium/targets/libgl-xlib/</code>.</p>
|
||||
|
||||
<h2>Use EGL</h2>
|
||||
|
||||
<p> The demos for OpenGL ES and OpenVG can be found in <code>progs/es1/</code>,
|
||||
<p>The demos for OpenGL ES and OpenVG can be found in <code>progs/es1/</code>,
|
||||
<code>progs/es2/</code> and <code>progs/openvg/</code>. You can use them to
|
||||
test your build. For example,</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,19 @@
|
|||
|
||||
<H1>News</H1>
|
||||
|
||||
|
||||
<h2>March 28, 2010</h2>
|
||||
<p>
|
||||
<a href="relnotes-7.7.1.html">Mesa 7.7.1</a> is released. This is a bug-fix
|
||||
release fixing issues found in the 7.7 release.
|
||||
</p>
|
||||
<p>
|
||||
Also, <a href="relnotes-7.8.html">Mesa 7.8</a> is released. This is a new
|
||||
development release.
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
<h2>December 21, 2009</h2>
|
||||
<p>
|
||||
<a href="relnotes-7.6.1.html">Mesa 7.6.1</a> is released. This is a bug-fix
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<body bgcolor="#eeeeee">
|
||||
|
||||
<H1>Mesa 7.7.1 Release Notes / date tbd</H1>
|
||||
<H1>Mesa 7.7.1 Release Notes / March 28, 2010</H1>
|
||||
|
||||
<p>
|
||||
Mesa 7.7.1 is a bug-fix release.
|
||||
|
|
@ -26,16 +26,18 @@ for DRI hardware acceleration.
|
|||
|
||||
<h2>MD5 checksums</h2>
|
||||
<pre>
|
||||
tbd
|
||||
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
|
||||
</pre>
|
||||
|
||||
|
||||
<h2>New features</h2>
|
||||
<ul>
|
||||
<li>tbd
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Bug fixes</h2>
|
||||
<ul>
|
||||
<li>Assorted fixes to VMware SVGA gallium driver.
|
||||
|
|
@ -45,6 +47,12 @@ tbd
|
|||
<li>Gallium SSE codegen for XPD didn't always work.
|
||||
<li>Fixed Windows build.
|
||||
<li>Fixed broken glMultiDrawElements().
|
||||
<li>Silence bogus GL errors generated in glxinfo.
|
||||
<li>Fixed several render to texture bugs.
|
||||
<li>Assorted bug fixes in Mesa/Gallium state tracker including
|
||||
glCopy/DrawPixels() to FBOs.
|
||||
<li>Assorted fixes to Gallium drivers.
|
||||
<li>Fixed broken glPush/PopClientAttrib() for vertex arrays in GLX code.
|
||||
</ul>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<body bgcolor="#eeeeee">
|
||||
|
||||
<H1>Mesa 7.8 Release Notes / date TBD</H1>
|
||||
<H1>Mesa 7.8 Release Notes / March 28, 2010</H1>
|
||||
|
||||
<p>
|
||||
Mesa 7.8 is a new development release.
|
||||
|
|
@ -28,7 +28,15 @@ for DRI hardware acceleration.
|
|||
|
||||
<h2>MD5 checksums</h2>
|
||||
<pre>
|
||||
tbd
|
||||
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
|
||||
</pre>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,10 +14,6 @@ This page describes the features and status of Mesa's support for the
|
|||
OpenGL Shading Language</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Last updated on 15 December 2008.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Contents
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -393,6 +393,8 @@
|
|||
#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)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,13 @@
|
|||
#define DRI_INTERFACE_H
|
||||
|
||||
/* For archs with no drm.h */
|
||||
#if !defined(__APPLE__) && !defined(__CYGWIN__) && !defined(__GNU__)
|
||||
#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 <drm.h>
|
||||
#else
|
||||
typedef unsigned int drm_context_t;
|
||||
|
|
@ -410,15 +416,15 @@ struct __DRIswrastLoaderExtensionRec {
|
|||
* Put image to drawable
|
||||
*/
|
||||
void (*putImage)(__DRIdrawable *drawable, int op,
|
||||
int x, int y, int width, int height, char *data,
|
||||
void *loaderPrivate);
|
||||
int x, int y, int width, int height,
|
||||
char *data, void *loaderPrivate);
|
||||
|
||||
/**
|
||||
* Get image from drawable
|
||||
* Get image from readable
|
||||
*/
|
||||
void (*getImage)(__DRIdrawable *drawable,
|
||||
int x, int y, int width, int height, char *data,
|
||||
void *loaderPrivate);
|
||||
void (*getImage)(__DRIdrawable *readable,
|
||||
int x, int y, int width, int height,
|
||||
char *data, void *loaderPrivate);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -56,4 +56,5 @@ SConscript([
|
|||
'wgl/SConscript',
|
||||
'perf/SConscript',
|
||||
'gallium/unit/SConscript',
|
||||
# 'gallium/raw/SConscript',
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Dissolve between two images using randomized stencil buffer
|
||||
* Dissolve between two images using randomized/patterned stencil buffer
|
||||
* and varying stencil ref.
|
||||
*
|
||||
* Brian Paul
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <GL/glut.h>
|
||||
#include "readtex.h"
|
||||
|
|
@ -28,6 +29,8 @@ static GLfloat ScaleX[2], ScaleY[2];
|
|||
|
||||
static GLubyte StencilRef = 0;
|
||||
|
||||
static int Mode = 0;
|
||||
|
||||
|
||||
static void
|
||||
Idle(void)
|
||||
|
|
@ -38,13 +41,114 @@ Idle(void)
|
|||
|
||||
|
||||
static void
|
||||
RandomizeStencilBuffer(void)
|
||||
FillRandomPixels(GLubyte *b)
|
||||
{
|
||||
GLubyte *b = malloc(WinWidth * WinHeight);
|
||||
int i;
|
||||
for (i = 0; i < WinWidth * WinHeight; i++) {
|
||||
b[i] = rand() & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
FillRandomRects(GLubyte *b)
|
||||
{
|
||||
int i;
|
||||
|
||||
memset(b, 0, WinWidth * WinHeight);
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
int x = rand() % WinWidth;
|
||||
int y = rand() % WinHeight;
|
||||
int w = rand() % 60;
|
||||
int h = rand() % 60;
|
||||
int ix, iy;
|
||||
|
||||
if (x + w > WinWidth)
|
||||
w = WinWidth - x;
|
||||
if (y + h > WinHeight)
|
||||
h = WinHeight - y;
|
||||
|
||||
for (iy = 0; iy < h; iy++) {
|
||||
for (ix = 0; ix < w; ix++) {
|
||||
int p = (y + iy) * WinWidth + x + ix;
|
||||
b[p] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
FillWipe(GLubyte *b)
|
||||
{
|
||||
int iy, ix;
|
||||
|
||||
memset(b, 0, WinWidth * WinHeight);
|
||||
|
||||
for (iy = 0; iy < WinHeight; iy++) {
|
||||
for (ix = 0; ix < WinWidth; ix++) {
|
||||
int p = iy * WinWidth + ix;
|
||||
b[p] = 2 * ix + iy / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
FillMoire(GLubyte *b)
|
||||
{
|
||||
int iy, ix;
|
||||
|
||||
memset(b, 0, WinWidth * WinHeight);
|
||||
|
||||
for (iy = 0; iy < WinHeight; iy++) {
|
||||
for (ix = 0; ix < WinWidth; ix++) {
|
||||
int p = iy * WinWidth + ix;
|
||||
b[p] = (ix / 2) * (ix / 2) - (iy / 2) * (iy / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
FillWaves(GLubyte *b)
|
||||
{
|
||||
int iy, ix;
|
||||
|
||||
memset(b, 0, WinWidth * WinHeight);
|
||||
|
||||
for (iy = 0; iy < WinHeight; iy++) {
|
||||
for (ix = 0; ix < WinWidth; ix++) {
|
||||
int p = iy * WinWidth + ix;
|
||||
float x = 8.0 * 3.1415 * ix / (float) WinWidth;
|
||||
b[p] = (int) (25.0 * sin(x) ) - iy*2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef void (*FillFunc)(GLubyte *b);
|
||||
|
||||
|
||||
static FillFunc Funcs[] = {
|
||||
FillRandomPixels,
|
||||
FillRandomRects,
|
||||
FillWipe,
|
||||
FillMoire,
|
||||
FillWaves
|
||||
};
|
||||
|
||||
#define NUM_MODES (sizeof(Funcs) / sizeof(Funcs[0]))
|
||||
|
||||
|
||||
|
||||
static void
|
||||
InitStencilBuffer(void)
|
||||
{
|
||||
GLubyte *b = malloc(WinWidth * WinHeight);
|
||||
|
||||
Funcs[Mode](b);
|
||||
|
||||
glStencilFunc(GL_ALWAYS, 0, ~0);
|
||||
glPixelZoom(1.0, 1.0);
|
||||
|
|
@ -54,7 +158,6 @@ RandomizeStencilBuffer(void)
|
|||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
Draw(void)
|
||||
{
|
||||
|
|
@ -85,7 +188,7 @@ Reshape(int width, int height)
|
|||
glLoadIdentity();
|
||||
glTranslatef(0.0, 0.0, -15.0);
|
||||
|
||||
RandomizeStencilBuffer();
|
||||
InitStencilBuffer();
|
||||
|
||||
ScaleX[0] = (float) width / ImgWidth[0];
|
||||
ScaleY[0] = (float) height / ImgHeight[0];
|
||||
|
|
@ -102,12 +205,26 @@ Key(unsigned char key, int x, int y)
|
|||
(void) y;
|
||||
switch (key) {
|
||||
case 'a':
|
||||
case ' ':
|
||||
Anim = !Anim;
|
||||
if (Anim)
|
||||
glutIdleFunc(Idle);
|
||||
else
|
||||
glutIdleFunc(NULL);
|
||||
break;
|
||||
case 'i':
|
||||
InitStencilBuffer();
|
||||
break;
|
||||
case '-':
|
||||
StencilRef--;
|
||||
break;
|
||||
case '+':
|
||||
StencilRef++;
|
||||
break;
|
||||
case 'm':
|
||||
Mode = (Mode + 1) % NUM_MODES;
|
||||
InitStencilBuffer();
|
||||
break;
|
||||
case 27:
|
||||
glutDestroyWindow(Win);
|
||||
exit(0);
|
||||
|
|
@ -143,8 +260,8 @@ Init(void)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitWindowSize(WinWidth, WinHeight);
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
|
||||
Win = glutCreateWindow(argv[0]);
|
||||
glutReshapeFunc(Reshape);
|
||||
|
|
@ -153,6 +270,14 @@ main(int argc, char *argv[])
|
|||
if (Anim)
|
||||
glutIdleFunc(Idle);
|
||||
Init();
|
||||
|
||||
printf("Keys:\n");
|
||||
printf(" a/SPACE toggle animation\n");
|
||||
printf(" +/- single step\n");
|
||||
printf(" i re-init pattern\n");
|
||||
printf(" m change pattern/dissolve mode\n");
|
||||
printf(" ESC exit\n");
|
||||
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,13 +57,13 @@ peglgears: peglgears.o $(HEADERS) $(LIB_DEP)
|
|||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm
|
||||
|
||||
xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS)
|
||||
|
||||
xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS)
|
||||
|
||||
xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS)
|
||||
|
||||
clean:
|
||||
-rm -f *.o *~
|
||||
|
|
|
|||
|
|
@ -30,19 +30,19 @@
|
|||
from gallium import *
|
||||
|
||||
|
||||
def make_image(surface):
|
||||
data = surface.get_tile_rgba8(0, 0, surface.width, surface.height)
|
||||
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(filename, surface):
|
||||
outimage = make_image(surface)
|
||||
def save_image(ctx, surface, filename):
|
||||
outimage = make_image(ctx, surface)
|
||||
outimage.save(filename, "PNG")
|
||||
|
||||
def show_image(surface):
|
||||
outimage = make_image(surface)
|
||||
def show_image(ctx, surface):
|
||||
outimage = make_image(ctx, surface)
|
||||
|
||||
import Tkinter as tk
|
||||
from PIL import Image, ImageTk
|
||||
|
|
@ -216,10 +216,10 @@ def test(dev):
|
|||
|
||||
ctx.flush()
|
||||
|
||||
show_image(cbuf)
|
||||
#show_image(zbuf)
|
||||
#save_image('cbuf.png', cbuf)
|
||||
#save_image('zbuf.png', zbuf)
|
||||
show_image(ctx, cbuf)
|
||||
show_image(ctx, zbuf)
|
||||
save_image(ctx, cbuf, 'cbuf.png')
|
||||
save_image(ctx, zbuf, 'zbuf.png')
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
17
progs/gallium/raw/SConscript
Normal file
17
progs/gallium/raw/SConscript
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Import('*')
|
||||
|
||||
env = env.Clone()
|
||||
|
||||
env.Prepend(LIBPATH = [graw.dir])
|
||||
env.Prepend(LIBS = [graw.name])
|
||||
|
||||
progs = [
|
||||
'clear'
|
||||
]
|
||||
|
||||
for prog in progs:
|
||||
env.Program(
|
||||
target = prog,
|
||||
source = prog + '.c',
|
||||
)
|
||||
|
||||
95
progs/gallium/raw/clear.c
Normal file
95
progs/gallium/raw/clear.c
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/* 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 <unistd.h> /* for sleep() */
|
||||
|
||||
#include "util/u_debug.h" /* debug_dump_surface_bmp() */
|
||||
|
||||
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;
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
struct pipe_screen *screen;
|
||||
struct pipe_context *pipe;
|
||||
struct pipe_surface *surf;
|
||||
struct pipe_framebuffer_state fb;
|
||||
struct pipe_texture *tex, templat;
|
||||
void *window = NULL;
|
||||
float clear_color[4] = {1,0,1,1};
|
||||
int i;
|
||||
|
||||
screen = graw_init();
|
||||
if (screen == NULL)
|
||||
exit(1);
|
||||
|
||||
for (i = 0;
|
||||
window == NULL && formats[i] != PIPE_FORMAT_NONE;
|
||||
i++) {
|
||||
|
||||
window = graw_create_window(0,0,300,300, formats[i]);
|
||||
}
|
||||
|
||||
if (window == NULL)
|
||||
exit(2);
|
||||
|
||||
pipe = screen->context_create(screen, NULL);
|
||||
if (pipe == 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.tex_usage = (PIPE_TEXTURE_USAGE_RENDER_TARGET |
|
||||
PIPE_TEXTURE_USAGE_DISPLAY_TARGET);
|
||||
|
||||
tex = screen->texture_create(screen,
|
||||
&templat);
|
||||
if (tex == NULL)
|
||||
exit(4);
|
||||
|
||||
surf = screen->get_tex_surface(screen, tex, 0, 0, 0,
|
||||
PIPE_TEXTURE_USAGE_RENDER_TARGET |
|
||||
PIPE_TEXTURE_USAGE_DISPLAY_TARGET);
|
||||
if (surf == NULL)
|
||||
exit(5);
|
||||
|
||||
memset(&fb, 0, sizeof fb);
|
||||
fb.nr_cbufs = 1;
|
||||
fb.width = WIDTH;
|
||||
fb.height = HEIGHT;
|
||||
fb.cbufs[0] = surf;
|
||||
|
||||
pipe->set_framebuffer_state(pipe, &fb);
|
||||
pipe->clear(pipe, PIPE_CLEAR_COLOR, clear_color, 0, 0);
|
||||
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
|
||||
|
||||
/* At the moment, libgraw includes/makes available all the symbols
|
||||
* from gallium/auxiliary, including these debug helpers. Will
|
||||
* eventually want to bless some of these paths, and lock the
|
||||
* others down so they aren't accessible from test programs.
|
||||
*/
|
||||
if (0)
|
||||
debug_dump_surface_bmp(pipe, "result.bmp", surf);
|
||||
|
||||
screen->flush_frontbuffer(screen, surf, window);
|
||||
|
||||
sleep(100);
|
||||
return 0;
|
||||
}
|
||||
3
progs/gallium/trivial/.gitignore
vendored
Normal file
3
progs/gallium/trivial/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
tri
|
||||
quad-tex
|
||||
result.bmp
|
||||
44
progs/gallium/trivial/Makefile
Normal file
44
progs/gallium/trivial/Makefile
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# 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 = \
|
||||
tri.c \
|
||||
quad-tex.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 -o $@
|
||||
346
progs/gallium/trivial/quad-tex.c
Normal file
346
progs/gallium/trivial/quad-tex.c
Normal file
|
|
@ -0,0 +1,346 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
* 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"
|
||||
|
||||
/* softpipe software driver */
|
||||
#include "softpipe/sp_public.h"
|
||||
|
||||
/* null software winsys */
|
||||
#include "sw/null/null_sw_winsys.h"
|
||||
|
||||
/* traceing support see src/gallium/drivers/trace/README for more info. */
|
||||
#if USE_TRACE
|
||||
#include "trace/tr_screen.h"
|
||||
#include "trace/tr_context.h"
|
||||
#endif
|
||||
|
||||
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_buffer *vbuf;
|
||||
struct pipe_texture *target;
|
||||
struct pipe_texture *tex;
|
||||
struct pipe_sampler_view *view;
|
||||
};
|
||||
|
||||
static void init_prog(struct program *p)
|
||||
{
|
||||
/* create the software rasterizer */
|
||||
p->screen = softpipe_create_screen(null_sw_create());
|
||||
#if USE_TRACE
|
||||
p->screen = trace_screen_create(p->screen);
|
||||
#endif
|
||||
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, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices));
|
||||
pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices);
|
||||
}
|
||||
|
||||
/* render target texture */
|
||||
{
|
||||
struct pipe_texture 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.last_level = 0;
|
||||
tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
|
||||
|
||||
p->target = p->screen->texture_create(p->screen, &tmplt);
|
||||
}
|
||||
|
||||
/* sampler texture */
|
||||
{
|
||||
uint32_t *ptr;
|
||||
struct pipe_transfer *t;
|
||||
struct pipe_texture t_tmplt;
|
||||
struct pipe_sampler_view v_tmplt;
|
||||
|
||||
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.last_level = 0;
|
||||
t_tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
|
||||
|
||||
p->tex = p->screen->texture_create(p->screen, &t_tmplt);
|
||||
|
||||
t = p->pipe->get_tex_transfer(p->pipe, p->tex,
|
||||
0, 0, 0, /* face, level, zslice */
|
||||
PIPE_TRANSFER_WRITE,
|
||||
0, 0, 2, 2); /* x, y, width, height */
|
||||
|
||||
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->tex_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.front_winding = PIPE_WINDING_CW;
|
||||
p->rasterizer.cull_mode = PIPE_WINDING_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;
|
||||
|
||||
/* 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->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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_texture_reference(&p->target, NULL);
|
||||
pipe_texture_reference(&p->tex, NULL);
|
||||
pipe_buffer_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;
|
||||
}
|
||||
278
progs/gallium/trivial/tri.c
Normal file
278
progs/gallium/trivial/tri.c
Normal file
|
|
@ -0,0 +1,278 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
* 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"
|
||||
|
||||
/* softpipe software driver */
|
||||
#include "softpipe/sp_public.h"
|
||||
|
||||
/* null software winsys */
|
||||
#include "sw/null/null_sw_winsys.h"
|
||||
|
||||
/* traceing support see src/gallium/drivers/trace/README for more info. */
|
||||
#if USE_TRACE
|
||||
#include "trace/tr_screen.h"
|
||||
#include "trace/tr_context.h"
|
||||
#endif
|
||||
|
||||
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_buffer *vbuf;
|
||||
struct pipe_texture *target;
|
||||
};
|
||||
|
||||
static void init_prog(struct program *p)
|
||||
{
|
||||
/* create the software rasterizer */
|
||||
p->screen = softpipe_create_screen(null_sw_create());
|
||||
#if USE_TRACE
|
||||
p->screen = trace_screen_create(p->screen);
|
||||
#endif
|
||||
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, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices));
|
||||
pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices);
|
||||
}
|
||||
|
||||
/* render target texture */
|
||||
{
|
||||
struct pipe_texture 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.last_level = 0;
|
||||
tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
|
||||
|
||||
p->target = p->screen->texture_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.front_winding = PIPE_WINDING_CW;
|
||||
p->rasterizer.cull_mode = PIPE_WINDING_NONE;
|
||||
p->rasterizer.gl_rasterization_rules = 1;
|
||||
|
||||
/* 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->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
|
||||
|
||||
/* 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_texture_reference(&p->target, NULL);
|
||||
pipe_buffer_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;
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ PROG_SOURCES = \
|
|||
convolutions.c \
|
||||
deriv.c \
|
||||
fragcoord.c \
|
||||
fsraytrace.c \
|
||||
identity.c \
|
||||
linktest.c \
|
||||
mandelbrot.c \
|
||||
|
|
@ -46,7 +47,8 @@ PROG_SOURCES = \
|
|||
trirast.c \
|
||||
twoside.c \
|
||||
vert-or-frag-only.c \
|
||||
vert-tex.c
|
||||
vert-tex.c \
|
||||
vsraytrace.c
|
||||
|
||||
UTIL_HEADERS = \
|
||||
extfuncs.h \
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ progs = [
|
|||
'convolutions',
|
||||
'deriv',
|
||||
'fragcoord',
|
||||
'fsraytrace',
|
||||
'identity',
|
||||
'linktest',
|
||||
'mandelbrot',
|
||||
|
|
@ -27,6 +28,7 @@ progs = [
|
|||
'twoside',
|
||||
'vert-or-frag-only',
|
||||
'vert-tex',
|
||||
'vsraytrace',
|
||||
]
|
||||
|
||||
for prog in progs:
|
||||
|
|
|
|||
412
progs/glsl/fsraytrace.c
Normal file
412
progs/glsl/fsraytrace.c
Normal file
|
|
@ -0,0 +1,412 @@
|
|||
/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */
|
||||
/*
|
||||
Copyright (c) 2010 Kristóf Ralovich
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/glew.h>
|
||||
#include <GL/glut.h>
|
||||
#include "shaderutil.h"
|
||||
#include <math.h>
|
||||
|
||||
static int Win;
|
||||
static int WinWidth = 512, WinHeight = 512;
|
||||
static int mouseGrabbed = 0;
|
||||
static GLuint vertShader;
|
||||
static GLuint fragShader;
|
||||
static GLuint program;
|
||||
static float rot[9] = {1,0,0, 0,1,0, 0,0,1};
|
||||
|
||||
static const char* vsSource =
|
||||
"varying vec2 rayDir; \n"
|
||||
" \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" rayDir = gl_MultiTexCoord0.xy - vec2(0.5,0.5); \n"
|
||||
" gl_Position = gl_ProjectionMatrix * gl_Vertex; \n"
|
||||
"}\n";
|
||||
|
||||
static const char* fsSource =
|
||||
"const float INF = 9999.9; \n"
|
||||
"const float EPSILON = 0.00001; \n"
|
||||
"const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n"
|
||||
"const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n"
|
||||
" \n"
|
||||
"varying vec2 rayDir; \n"
|
||||
" \n"
|
||||
"uniform mat3 rot; \n"
|
||||
" \n"
|
||||
"struct Ray \n"
|
||||
"{ \n"
|
||||
"vec3 orig; \n"
|
||||
"vec3 dir; \n"
|
||||
"}; \n"
|
||||
" \n"
|
||||
"struct Sphere \n"
|
||||
"{ \n"
|
||||
" vec3 c; \n"
|
||||
" float r; \n"
|
||||
"}; \n"
|
||||
" \n"
|
||||
"struct Isec \n"
|
||||
"{ \n"
|
||||
" float t; \n"
|
||||
" int idx; \n"
|
||||
" vec3 hit; \n"
|
||||
" vec3 n; \n"
|
||||
"}; \n"
|
||||
" \n"
|
||||
#ifdef __APPLE__
|
||||
"Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
|
||||
"Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
|
||||
"Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
|
||||
"Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
|
||||
#else
|
||||
"const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
|
||||
"const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
|
||||
"const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
|
||||
"const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
|
||||
#endif
|
||||
" \n"
|
||||
"// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n"
|
||||
"// sqrt, let's work around. \n"
|
||||
"float \n"
|
||||
"sqrt_hack(float f2) \n"
|
||||
"{ \n"
|
||||
" vec3 v = vec3(f2,0.0,0.0); \n"
|
||||
" return length(v); \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void \n"
|
||||
"intersect(const in Ray ray, \n"
|
||||
" const in Sphere sph, \n"
|
||||
" const in int idx, \n"
|
||||
" inout Isec isec) \n"
|
||||
"{ \n"
|
||||
" // Project both o and the sphere to the plane perpendicular to d \n"
|
||||
" // and containing c. Let x be the point where the ray intersects \n"
|
||||
" // the plane. If |x-c| < r, the ray intersects the sphere. \n"
|
||||
" vec3 o = ray.orig; \n"
|
||||
" vec3 d = ray.dir; \n"
|
||||
" vec3 n = -d; \n"
|
||||
" vec3 c = sph.c; \n"
|
||||
" float r = sph.r; \n"
|
||||
" float t = dot(c-o,n)/dot(n,d); \n"
|
||||
" vec3 x = o+d*t; \n"
|
||||
" float e = length(x-c); \n"
|
||||
" if(e > r) \n"
|
||||
" { \n"
|
||||
" // no intersection \n"
|
||||
" return; \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" // Apply Pythagorean theorem on the (intersection,x,c) triangle \n"
|
||||
" // to get the distance between c and the intersection. \n"
|
||||
"#ifndef BUGGY_INTEL_GEN4_GLSL \n"
|
||||
" float f = sqrt(r*r - e*e); \n"
|
||||
"#else \n"
|
||||
" float f = sqrt_hack(r*r - e*e); \n"
|
||||
"#endif \n"
|
||||
" float dist = t - f; \n"
|
||||
" if(dist < 0.0) \n"
|
||||
" { \n"
|
||||
" // inside the sphere \n"
|
||||
" return; \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" if(dist < EPSILON) \n"
|
||||
" return; \n"
|
||||
" \n"
|
||||
" if(dist > isec.t) \n"
|
||||
" return; \n"
|
||||
" \n"
|
||||
" isec.t = dist; \n"
|
||||
" isec.idx = idx; \n"
|
||||
" \n"
|
||||
" isec.hit = ray.orig + ray.dir * isec.t; \n"
|
||||
" isec.n = (isec.hit - c) / r; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"Isec \n"
|
||||
"intersect(const in Ray ray, \n"
|
||||
" const in float max_t /*= INF*/) \n"
|
||||
"{ \n"
|
||||
" Isec nearest; \n"
|
||||
" nearest.t = max_t; \n"
|
||||
" nearest.idx = -1; \n"
|
||||
" \n"
|
||||
" intersect(ray, spheres0, 0, nearest); \n"
|
||||
" intersect(ray, spheres1, 1, nearest); \n"
|
||||
" intersect(ray, spheres2, 2, nearest); \n"
|
||||
" intersect(ray, spheres3, 3, nearest); \n"
|
||||
" \n"
|
||||
" return nearest; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"vec4 \n"
|
||||
"idx2color(const in int idx) \n"
|
||||
"{ \n"
|
||||
" vec4 diff; \n"
|
||||
" if(idx == 0) \n"
|
||||
" diff = vec4(1.0, 0.0, 0.0, 0.0); \n"
|
||||
" else if(idx == 1) \n"
|
||||
" diff = vec4(0.0, 1.0, 0.0, 0.0); \n"
|
||||
" else if(idx == 2) \n"
|
||||
" diff = vec4(0.0, 0.0, 1.0, 0.0); \n"
|
||||
" else if(idx == 3) \n"
|
||||
" diff = vec4(1.0, 1.0, 0.0, 0.0); \n"
|
||||
" return diff; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"vec4 \n"
|
||||
"trace0(const in Ray ray) \n"
|
||||
"{ \n"
|
||||
" Isec isec = intersect(ray, INF); \n"
|
||||
" \n"
|
||||
" if(isec.idx == -1) \n"
|
||||
" { \n"
|
||||
" return backgroundColor; \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" vec4 diff = idx2color(isec.idx); \n"
|
||||
" \n"
|
||||
" vec3 N = isec.n; \n"
|
||||
" vec3 L = normalize(lightPos-isec.hit); \n"
|
||||
" vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
|
||||
" return dot(N,L)*diff + pow( \n"
|
||||
" clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"vec4 \n"
|
||||
"trace1(const in Ray ray) \n"
|
||||
"{ \n"
|
||||
" Isec isec = intersect(ray, INF); \n"
|
||||
" \n"
|
||||
" if(isec.idx == -1) \n"
|
||||
" { \n"
|
||||
" return backgroundColor; \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n"
|
||||
" \n"
|
||||
" vec4 reflCol = trace0(reflRay); \n"
|
||||
" \n"
|
||||
" vec4 diff = idx2color(isec.idx) + reflCol; \n"
|
||||
" \n"
|
||||
" vec3 N = isec.n; \n"
|
||||
" vec3 L = normalize(lightPos-isec.hit); \n"
|
||||
" vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
|
||||
" return dot(N,L)*diff + pow( \n"
|
||||
" clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" const float z = -0.5; \n"
|
||||
" const vec3 cameraPos = vec3(0,0,3); \n"
|
||||
" Ray r = Ray(cameraPos, normalize(vec3(rayDir, z) * rot)); \n"
|
||||
" gl_FragColor = trace1(r); \n"
|
||||
"}\n";
|
||||
|
||||
static
|
||||
float
|
||||
deg2rad(const float degree)
|
||||
{
|
||||
return( degree * 0.017453292519943295769236907684886F);
|
||||
}
|
||||
|
||||
static void
|
||||
rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY)
|
||||
{
|
||||
const float rad1 = deg2rad(degreesAroundX);
|
||||
const float c1 = cosf(rad1);
|
||||
const float s1 = sinf(rad1);
|
||||
const float rad2 = deg2rad(degreesAroundY);
|
||||
const float c2 = cosf(rad2);
|
||||
const float s2 = sinf(rad2);
|
||||
mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2;
|
||||
mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2;
|
||||
mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2;
|
||||
}
|
||||
|
||||
static void
|
||||
identity(float* mat3)
|
||||
{
|
||||
mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F;
|
||||
mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F;
|
||||
mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F;
|
||||
}
|
||||
|
||||
static void
|
||||
Draw(void)
|
||||
{
|
||||
GLint location = glGetUniformLocation(program, "rot");
|
||||
static const float m = -10.F;
|
||||
static const float p = 10.F;
|
||||
static const float d = -0.5F;
|
||||
|
||||
glUseProgram(program);
|
||||
glUniformMatrix3fv(location, 1, 0, rot);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
{
|
||||
glTexCoord2f(0.0F, 0.0F); glVertex3f(m, m, d);
|
||||
glTexCoord2f(1.0F, 0.0F); glVertex3f(p, m, d);
|
||||
glTexCoord2f(1.0F, 1.0F); glVertex3f(p, p, d);
|
||||
glTexCoord2f(0.0F, 1.0F); glVertex3f(m, p, d);
|
||||
}
|
||||
glEnd();
|
||||
glUseProgram(0);
|
||||
|
||||
glutSwapBuffers();
|
||||
|
||||
{
|
||||
static int frames = 0;
|
||||
static int t0 = 0;
|
||||
static int t1 = 0;
|
||||
float dt;
|
||||
frames++;
|
||||
t1 = glutGet(GLUT_ELAPSED_TIME);
|
||||
dt = (float)(t1-t0)/1000.0F;
|
||||
if(dt >= 5.0F)
|
||||
{
|
||||
float fps = (float)frames / dt;
|
||||
printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt);
|
||||
frames = 0;
|
||||
t0 = t1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
Reshape(int width, int height)
|
||||
{
|
||||
WinWidth = width;
|
||||
WinHeight = height;
|
||||
glViewport(0, 0, width, height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-10, 10, -10, 10, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
Key(unsigned char key, int x, int y)
|
||||
{
|
||||
(void) x;
|
||||
(void) y;
|
||||
switch (key) {
|
||||
case 27:
|
||||
glutDestroyWindow(Win);
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
drag(int x, int y)
|
||||
{
|
||||
float scale = 1.5F;
|
||||
if(mouseGrabbed)
|
||||
{
|
||||
static GLfloat xRot = 0, yRot = 0;
|
||||
xRot = (float)(x - WinWidth/2) / scale;
|
||||
yRot = (float)(y - WinHeight/2) / scale;
|
||||
identity(rot);
|
||||
rotate_xy(rot, yRot, xRot);
|
||||
glutPostRedisplay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
mouse(int button, int state, int x, int y)
|
||||
{
|
||||
mouseGrabbed = (state == GLUT_DOWN);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
Init(void)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
if(!ShadersSupported())
|
||||
{
|
||||
fprintf(stderr, "Shaders are not supported!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource);
|
||||
fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fsSource);
|
||||
program = LinkShaders(vertShader, fragShader);
|
||||
glUseProgram(0);
|
||||
|
||||
if(glGetError() != 0)
|
||||
{
|
||||
fprintf(stderr, "Shaders were not loaded!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(!glIsShader(vertShader))
|
||||
{
|
||||
fprintf(stderr, "Vertex shader failed!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(!glIsProgram(program))
|
||||
{
|
||||
fprintf(stderr, "Shader program failed!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
glutInitWindowSize(WinWidth, WinHeight);
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
Win = glutCreateWindow(argv[0]);
|
||||
glewInit();
|
||||
glutReshapeFunc(Reshape);
|
||||
glutKeyboardFunc(Key);
|
||||
glutDisplayFunc(Draw);
|
||||
glutMouseFunc(mouse);
|
||||
glutMotionFunc(drag);
|
||||
glutIdleFunc(Draw);
|
||||
Init();
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
401
progs/glsl/vsraytrace.c
Normal file
401
progs/glsl/vsraytrace.c
Normal file
|
|
@ -0,0 +1,401 @@
|
|||
/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */
|
||||
/*
|
||||
Copyright (c) 2010 Kristóf Ralovich
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/glew.h>
|
||||
#include <GL/glut.h>
|
||||
#include "shaderutil.h"
|
||||
#include <math.h>
|
||||
|
||||
static int Win;
|
||||
static int WinWidth = 256, WinHeight = 256;
|
||||
static GLboolean mouseGrabbed = GL_FALSE;
|
||||
static GLuint vertShader;
|
||||
static GLuint program;
|
||||
float rot[9] = {1,0,0, 0,1,0, 0,0,1};
|
||||
|
||||
static const char* vsSource =
|
||||
"const float INF = 9999.9; \n"
|
||||
"const float EPSILON = 0.00001; \n"
|
||||
"const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n"
|
||||
"const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n"
|
||||
" \n"
|
||||
"uniform mat3 rot; \n"
|
||||
" \n"
|
||||
"struct Ray \n"
|
||||
"{ \n"
|
||||
"vec3 orig; \n"
|
||||
"vec3 dir; \n"
|
||||
"}; \n"
|
||||
" \n"
|
||||
"struct Sphere \n"
|
||||
"{ \n"
|
||||
" vec3 c; \n"
|
||||
" float r; \n"
|
||||
"}; \n"
|
||||
" \n"
|
||||
"struct Isec \n"
|
||||
"{ \n"
|
||||
" float t; \n"
|
||||
" int idx; \n"
|
||||
" vec3 hit; \n"
|
||||
" vec3 n; \n"
|
||||
"}; \n"
|
||||
" \n"
|
||||
#ifdef __APPLE__
|
||||
"Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
|
||||
"Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
|
||||
"Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
|
||||
"Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
|
||||
#else
|
||||
"const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
|
||||
"const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
|
||||
"const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
|
||||
"const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
|
||||
#endif
|
||||
" \n"
|
||||
"// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n"
|
||||
"// sqrt, let's work around. \n"
|
||||
"float \n"
|
||||
"sqrt_hack(float f2) \n"
|
||||
"{ \n"
|
||||
" vec3 v = vec3(f2,0.0,0.0); \n"
|
||||
" return length(v); \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void \n"
|
||||
"intersect(const in Ray ray, \n"
|
||||
" const in Sphere sph, \n"
|
||||
" const in int idx, \n"
|
||||
" inout Isec isec) \n"
|
||||
"{ \n"
|
||||
" // Project both o and the sphere to the plane perpendicular to d \n"
|
||||
" // and containing c. Let x be the point where the ray intersects \n"
|
||||
" // the plane. If |x-c| < r, the ray intersects the sphere. \n"
|
||||
" vec3 o = ray.orig; \n"
|
||||
" vec3 d = ray.dir; \n"
|
||||
" vec3 n = -d; \n"
|
||||
" vec3 c = sph.c; \n"
|
||||
" float r = sph.r; \n"
|
||||
" float t = dot(c-o,n)/dot(n,d); \n"
|
||||
" vec3 x = o+d*t; \n"
|
||||
" float e = length(x-c); \n"
|
||||
" if(e > r) \n"
|
||||
" { \n"
|
||||
" // no intersection \n"
|
||||
" return; \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" // Apply Pythagorean theorem on the (intersection,x,c) triangle \n"
|
||||
" // to get the distance between c and the intersection. \n"
|
||||
"#define BUGGY_INTEL_GEN4_GLSL 1 \n"
|
||||
"#ifndef BUGGY_INTEL_GEN4_GLSL \n"
|
||||
" float f = sqrt(r*r - e*e); \n"
|
||||
"#else \n"
|
||||
" float f = sqrt_hack(r*r - e*e); \n"
|
||||
"#endif \n"
|
||||
" float dist = t - f; \n"
|
||||
" if(dist < 0.0) \n"
|
||||
" { \n"
|
||||
" // inside the sphere \n"
|
||||
" return; \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" if(dist < EPSILON) \n"
|
||||
" return; \n"
|
||||
" \n"
|
||||
" if(dist > isec.t) \n"
|
||||
" return; \n"
|
||||
" \n"
|
||||
" isec.t = dist; \n"
|
||||
" isec.idx = idx; \n"
|
||||
" \n"
|
||||
" isec.hit = ray.orig + ray.dir * isec.t; \n"
|
||||
" isec.n = (isec.hit - c) / r; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"Isec \n"
|
||||
"intersect(const in Ray ray, \n"
|
||||
" const in float max_t /*= INF*/) \n"
|
||||
"{ \n"
|
||||
" Isec nearest; \n"
|
||||
" nearest.t = max_t; \n"
|
||||
" nearest.idx = -1; \n"
|
||||
" \n"
|
||||
" intersect(ray, spheres0, 0, nearest); \n"
|
||||
" intersect(ray, spheres1, 1, nearest); \n"
|
||||
" intersect(ray, spheres2, 2, nearest); \n"
|
||||
" intersect(ray, spheres3, 3, nearest); \n"
|
||||
" \n"
|
||||
" return nearest; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"vec4 \n"
|
||||
"idx2color(const in int idx) \n"
|
||||
"{ \n"
|
||||
" vec4 diff; \n"
|
||||
" if(idx == 0) \n"
|
||||
" diff = vec4(1.0, 0.0, 0.0, 0.0); \n"
|
||||
" else if(idx == 1) \n"
|
||||
" diff = vec4(0.0, 1.0, 0.0, 0.0); \n"
|
||||
" else if(idx == 2) \n"
|
||||
" diff = vec4(0.0, 0.0, 1.0, 0.0); \n"
|
||||
" else if(idx == 3) \n"
|
||||
" diff = vec4(1.0, 1.0, 0.0, 0.0); \n"
|
||||
" return diff; \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"vec4 \n"
|
||||
"trace0(const in Ray ray) \n"
|
||||
"{ \n"
|
||||
" Isec isec = intersect(ray, INF); \n"
|
||||
" \n"
|
||||
" if(isec.idx == -1) \n"
|
||||
" { \n"
|
||||
" return backgroundColor; \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" vec4 diff = idx2color(isec.idx); \n"
|
||||
" \n"
|
||||
" vec3 N = isec.n; \n"
|
||||
" vec3 L = normalize(lightPos-isec.hit); \n"
|
||||
" vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
|
||||
" return dot(N,L)*diff + pow( \n"
|
||||
" clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"vec4 \n"
|
||||
"trace1(const in Ray ray) \n"
|
||||
"{ \n"
|
||||
" Isec isec = intersect(ray, INF); \n"
|
||||
" \n"
|
||||
" if(isec.idx == -1) \n"
|
||||
" { \n"
|
||||
" return backgroundColor; \n"
|
||||
" } \n"
|
||||
" \n"
|
||||
" Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n"
|
||||
" \n"
|
||||
" vec4 reflCol = trace0(reflRay); \n"
|
||||
" \n"
|
||||
" vec4 diff = idx2color(isec.idx) + reflCol; \n"
|
||||
" \n"
|
||||
" vec3 N = isec.n; \n"
|
||||
" vec3 L = normalize(lightPos-isec.hit); \n"
|
||||
" vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
|
||||
" return dot(N,L)*diff + pow( \n"
|
||||
" clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
|
||||
"} \n"
|
||||
" \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" const vec3 cameraPos = vec3(0,0,3); \n"
|
||||
" vec3 rayDir = normalize(vec3(gl_Vertex.x, gl_Vertex.y, -1.0) * rot);\n"
|
||||
" Ray ray = Ray(cameraPos, rayDir); \n"
|
||||
" gl_Position = gl_Vertex; \n"
|
||||
" gl_FrontColor = trace1(ray); \n"
|
||||
"}\n";
|
||||
|
||||
|
||||
static
|
||||
float
|
||||
deg2rad(const float degree)
|
||||
{
|
||||
return( degree * 0.017453292519943295769236907684886F);
|
||||
}
|
||||
|
||||
static void
|
||||
rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY)
|
||||
{
|
||||
const float rad1 = deg2rad(degreesAroundX);
|
||||
const float c1 = cosf(rad1);
|
||||
const float s1 = sinf(rad1);
|
||||
const float rad2 = deg2rad(degreesAroundY);
|
||||
const float c2 = cosf(rad2);
|
||||
const float s2 = sinf(rad2);
|
||||
mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2;
|
||||
mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2;
|
||||
mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2;
|
||||
}
|
||||
|
||||
static void
|
||||
identity(float* mat3)
|
||||
{
|
||||
mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F;
|
||||
mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F;
|
||||
mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F;
|
||||
}
|
||||
|
||||
static void
|
||||
Draw(void)
|
||||
{
|
||||
const float w = 0.5F * WinWidth;
|
||||
const float h = 0.5F * WinHeight;
|
||||
int x,y;
|
||||
|
||||
GLint location = glGetUniformLocation(program, "rot");
|
||||
|
||||
glUseProgram(program);
|
||||
glUniformMatrix3fv(location, 1, 0, rot);
|
||||
glBegin(GL_POINTS);
|
||||
for(y = 0; y < WinHeight; y++)
|
||||
{
|
||||
for(x = 0; x < WinWidth; x++)
|
||||
{
|
||||
const float posx = x / w - 1.0F;
|
||||
const float posy = y / h - 1.0F;
|
||||
glVertex2f(posx, posy);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
glUseProgram(0);
|
||||
|
||||
glutSwapBuffers();
|
||||
|
||||
{
|
||||
static int frames = 0;
|
||||
static int t0 = 0;
|
||||
static int t1 = 0;
|
||||
float dt;
|
||||
frames++;
|
||||
t1 = glutGet(GLUT_ELAPSED_TIME);
|
||||
dt = (float)(t1-t0)/1000.0F;
|
||||
if (dt >= 5.0F)
|
||||
{
|
||||
float fps = (float)frames / dt;
|
||||
printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt);
|
||||
frames = 0;
|
||||
t0 = t1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
Reshape(int width, int height)
|
||||
{
|
||||
WinWidth = width;
|
||||
WinHeight = height;
|
||||
glViewport(0, 0, width, height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
Key(unsigned char key, int x, int y)
|
||||
{
|
||||
if(key == 27)
|
||||
{
|
||||
glutDestroyWindow(Win);
|
||||
exit(0);
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
drag(int x, int y)
|
||||
{
|
||||
float scale = 1.5F;
|
||||
if(mouseGrabbed)
|
||||
{
|
||||
static GLfloat xRot = 0, yRot = 0;
|
||||
xRot = (float)(x - WinWidth/2) / scale;
|
||||
yRot = (float)(y - WinHeight/2) / scale;
|
||||
identity(rot);
|
||||
rotate_xy(rot, yRot, xRot);
|
||||
glutPostRedisplay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
mouse(int button, int state, int x, int y)
|
||||
{
|
||||
mouseGrabbed = (state == GLUT_DOWN);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
Init(void)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
if(!ShadersSupported())
|
||||
{
|
||||
fprintf(stderr, "Shaders are not supported!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource);
|
||||
program = LinkShaders(vertShader, 0);
|
||||
glUseProgram(0);
|
||||
|
||||
if(glGetError() != 0)
|
||||
{
|
||||
fprintf(stderr, "Shaders were not loaded!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(!glIsShader(vertShader))
|
||||
{
|
||||
fprintf(stderr, "Vertex shader failed!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(!glIsProgram(program))
|
||||
{
|
||||
fprintf(stderr, "Shader program failed!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
glutInitWindowSize(WinWidth, WinHeight);
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
Win = glutCreateWindow(argv[0]);
|
||||
glewInit();
|
||||
glutReshapeFunc(Reshape);
|
||||
glutKeyboardFunc(Key);
|
||||
glutDisplayFunc(Draw);
|
||||
glutIdleFunc(Draw);
|
||||
glutMouseFunc(mouse);
|
||||
glutMotionFunc(drag);
|
||||
Init();
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/glew.h>
|
||||
#include <GL/glut.h>
|
||||
|
||||
|
||||
|
|
@ -35,7 +36,6 @@ GLint windW, windH;
|
|||
|
||||
char *fileName = 0;
|
||||
PPMImage *image;
|
||||
float point[3];
|
||||
float zoom;
|
||||
GLint x, y;
|
||||
|
||||
|
|
@ -97,27 +97,27 @@ static void Mouse(int button, int state, int mouseX, int mouseY)
|
|||
|
||||
static void Draw(void)
|
||||
{
|
||||
GLint src[3], dst[3];
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
point[0] = (windW / 2) - (image->sizeX / 2);
|
||||
point[1] = (windH / 2) - (image->sizeY / 2);
|
||||
point[2] = 0;
|
||||
glRasterPos3fv(point);
|
||||
src[0] = (int) ((windW / 2.0) - (image->sizeX / 2.0));
|
||||
src[1] = (int) ((windH / 2.0) - (image->sizeY / 2.0));
|
||||
src[2] = 0;
|
||||
glWindowPos3ivARB(src);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glPixelZoom(1.0, 1.0);
|
||||
glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE,
|
||||
image->data);
|
||||
|
||||
point[0] = (float)x;
|
||||
point[1] = windH - (float)y;
|
||||
point[2] = 0.0;
|
||||
glRasterPos3fv(point);
|
||||
dst[0] = x;
|
||||
dst[1] = windH - y;
|
||||
dst[2] = 0;
|
||||
glWindowPos3ivARB(dst);
|
||||
|
||||
glPixelZoom(zoom, zoom);
|
||||
glCopyPixels((windW/2)-(image->sizeX/2),
|
||||
(windH/2)-(image->sizeY/2),
|
||||
glCopyPixels(src[0], src[1],
|
||||
image->sizeX, image->sizeY, GL_COLOR);
|
||||
|
||||
glFlush();
|
||||
|
|
@ -170,8 +170,8 @@ int main(int argc, char **argv)
|
|||
|
||||
image = LoadPPM(fileName);
|
||||
|
||||
windW = 300;
|
||||
windH = 300;
|
||||
windW = 2*300;
|
||||
windH = 2*300;
|
||||
glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH);
|
||||
|
||||
type = GLUT_RGB;
|
||||
|
|
@ -182,6 +182,7 @@ int main(int argc, char **argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
glewInit();
|
||||
Init();
|
||||
|
||||
glutReshapeFunc(Reshape);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ static PPMImage *LoadPPM(const char *filename)
|
|||
char buff[16];
|
||||
PPMImage *result;
|
||||
FILE *fp;
|
||||
int maxval;
|
||||
int maxval, w, h;
|
||||
|
||||
fp = fopen(filename, "rb");
|
||||
if (!fp)
|
||||
|
|
@ -37,11 +37,13 @@ static PPMImage *LoadPPM(const char *filename)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if (fscanf(fp, "%lu %lu", &result->sizeX, &result->sizeY) != 2)
|
||||
if (fscanf(fp, "%d %d", &w, &h) != 2)
|
||||
{
|
||||
fprintf(stderr, "Error loading image `%s'\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
result->sizeX = w;
|
||||
result->sizeY = h;
|
||||
|
||||
if (fscanf(fp, "%d", &maxval) != 1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ SOURCES = \
|
|||
copypixrate.c \
|
||||
crossbar.c \
|
||||
cva.c \
|
||||
cva_huge.c \
|
||||
cylwrap.c \
|
||||
drawbuffers.c \
|
||||
drawbuffers2.c \
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ glx_progs = [
|
|||
'getprocaddress',
|
||||
'jkrahntest',
|
||||
'sharedtex',
|
||||
'texcompress2',
|
||||
'texobjshare',
|
||||
]
|
||||
|
||||
|
|
@ -45,6 +44,7 @@ progs = [
|
|||
'copypixrate',
|
||||
'crossbar',
|
||||
'cva',
|
||||
'cva_huge',
|
||||
'cylwrap',
|
||||
'drawbuffers',
|
||||
'drawbuffers2',
|
||||
|
|
|
|||
232
progs/tests/cva_huge.c
Normal file
232
progs/tests/cva_huge.c
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
* Copyright © 2010 Pauli Nieminen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION 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 huge cva arrays. Mesa code has to split this to multiple VBOs
|
||||
* which had memory access error.
|
||||
* This test case doesn't render incorrectly but valgrind showed the memory
|
||||
* access error.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#define GL_GLEXT_LEGACY
|
||||
#include <GL/glut.h>
|
||||
|
||||
GLfloat *verts;
|
||||
|
||||
GLubyte *color;
|
||||
|
||||
GLuint *indices;
|
||||
|
||||
#define rows 1000 /* Create 1000x1000 vertex grid */
|
||||
#define row_width 5000.0
|
||||
#define grid_depth -50.0
|
||||
GLuint nr_verts_in_row = rows;
|
||||
GLuint nr_indices_in_strip = rows * 2;
|
||||
|
||||
GLboolean double_buffer;
|
||||
GLboolean compiled = GL_TRUE;
|
||||
|
||||
static void generate_verts( void )
|
||||
{
|
||||
unsigned x, y;
|
||||
GLfloat step = row_width /(GLfloat)(nr_verts_in_row - 1);
|
||||
verts = malloc(sizeof(verts[0]) * 4 * nr_verts_in_row * nr_verts_in_row);
|
||||
|
||||
for (y = 0; y < nr_verts_in_row; ++y) {
|
||||
for (x = 0; x < nr_verts_in_row; ++x) {
|
||||
unsigned idx = 4*(x + y * nr_verts_in_row);
|
||||
verts[idx + 0] = step * x - row_width/2.0;
|
||||
verts[idx + 1] = step * y - row_width/2.0;
|
||||
/* deep enough not to be vissible */
|
||||
verts[idx + 2] = grid_depth;
|
||||
verts[idx + 3] = 0.0;
|
||||
}
|
||||
}
|
||||
glVertexPointer( 3, GL_FLOAT, sizeof(verts[0])*4, verts );
|
||||
}
|
||||
|
||||
static void generate_colors( void )
|
||||
{
|
||||
unsigned x, y;
|
||||
GLfloat step = 255.0/(GLfloat)(nr_verts_in_row - 1);
|
||||
color = malloc(sizeof(color[0]) * 4 * nr_verts_in_row * nr_verts_in_row);
|
||||
|
||||
for (y = 0; y < nr_verts_in_row; ++y) {
|
||||
for (x = 0; x < nr_verts_in_row; ++x) {
|
||||
unsigned idx = 4*(x + y * nr_verts_in_row);
|
||||
color[idx + 0] = (GLubyte)(step * x);
|
||||
color[idx + 1] = 0x00;
|
||||
color[idx + 2] = (GLubyte)(step * y);
|
||||
color[idx + 3] = 0x00;
|
||||
}
|
||||
}
|
||||
glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
|
||||
}
|
||||
|
||||
static void generate_indices( void )
|
||||
{
|
||||
unsigned strip, i;
|
||||
|
||||
/* indice size * number of strips * number of indices in strip */
|
||||
indices = malloc(sizeof(indices[0]) * (nr_verts_in_row - 1) *
|
||||
(nr_indices_in_strip));
|
||||
|
||||
for (strip = 0; strip < nr_verts_in_row - 1; strip += 2) {
|
||||
for (i = 0; i < nr_indices_in_strip; i+=2) {
|
||||
unsigned idx = i + strip * nr_indices_in_strip;
|
||||
unsigned idx2 = (nr_indices_in_strip - i - 2) + (strip +
|
||||
1) * (nr_indices_in_strip);
|
||||
indices[idx + 1] = i/2 + strip*nr_verts_in_row;
|
||||
indices[idx] = i/2 + (strip + 1)*nr_verts_in_row;
|
||||
if (strip + 1 < nr_verts_in_row - 1) {
|
||||
indices[idx2] = i/2 + (strip + 1)*nr_verts_in_row;
|
||||
indices[idx2 + 1] = i/2 + (strip + 2)*nr_verts_in_row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void init( void )
|
||||
{
|
||||
|
||||
|
||||
generate_verts();
|
||||
generate_colors();
|
||||
generate_indices();
|
||||
|
||||
glClearColor( 0.0, 0.0, 0.0, 0.0 );
|
||||
glShadeModel( GL_SMOOTH );
|
||||
|
||||
glEnableClientState( GL_VERTEX_ARRAY );
|
||||
glEnableClientState( GL_COLOR_ARRAY );
|
||||
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
glFrustum( -100.0, 100.0, -100.0, 100.0, 1.0, 100.0 );
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
|
||||
#ifdef GL_EXT_compiled_vertex_array
|
||||
if ( compiled ) {
|
||||
glLockArraysEXT( 0, rows * rows );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void display( void )
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
glDrawElements( GL_TRIANGLE_STRIP, nr_indices_in_strip * (nr_verts_in_row - 1) , GL_UNSIGNED_INT, indices );
|
||||
|
||||
if ( double_buffer )
|
||||
glutSwapBuffers();
|
||||
else
|
||||
glFlush();
|
||||
}
|
||||
|
||||
static void keyboard( unsigned char key, int x, int y )
|
||||
{
|
||||
switch ( key ) {
|
||||
case 27:
|
||||
exit( 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
static GLboolean args( int argc, char **argv )
|
||||
{
|
||||
GLint i;
|
||||
|
||||
double_buffer = GL_TRUE;
|
||||
|
||||
for ( i = 1 ; i < argc ; i++ ) {
|
||||
if ( strcmp( argv[i], "-sb" ) == 0 ) {
|
||||
double_buffer = GL_FALSE;
|
||||
} else if ( strcmp( argv[i], "-db" ) == 0 ) {
|
||||
double_buffer = GL_TRUE;
|
||||
} else {
|
||||
fprintf( stderr, "%s (Bad option).\n", argv[i] );
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
GLenum type;
|
||||
char *string;
|
||||
double version;
|
||||
|
||||
glutInit( &argc, argv );
|
||||
|
||||
if ( args( argc, argv ) == GL_FALSE ) {
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
type = GLUT_RGB | GLUT_DEPTH;
|
||||
type |= ( double_buffer ) ? GLUT_DOUBLE : GLUT_SINGLE;
|
||||
|
||||
glutInitDisplayMode( type );
|
||||
glutInitWindowSize( 250, 250 );
|
||||
glutInitWindowPosition( 100, 100 );
|
||||
glutCreateWindow( "CVA Test" );
|
||||
|
||||
/* Make sure the server supports GL 1.2 vertex arrays.
|
||||
*/
|
||||
string = (char *) glGetString( GL_VERSION );
|
||||
|
||||
version = atof(string);
|
||||
if ( version < 1.2 ) {
|
||||
fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
/* See if the server supports compiled vertex arrays.
|
||||
*/
|
||||
string = (char *) glGetString( GL_EXTENSIONS );
|
||||
|
||||
if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) {
|
||||
fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
|
||||
compiled = GL_FALSE;
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
glutDisplayFunc( display );
|
||||
glutKeyboardFunc( keyboard );
|
||||
glutMainLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
* \file stencil_twoside.c
|
||||
*
|
||||
* Simple test of GL_ATI_separate_stencil (or the OGL 2.0 equivalent) functionality.
|
||||
* Four squares are drawn
|
||||
* Five squares (or six if stencil wrap is available) are drawn
|
||||
* with different stencil modes, but all should be rendered with the same
|
||||
* final color.
|
||||
*/
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
#include <GL/glut.h>
|
||||
|
||||
static int use20syntax = 1;
|
||||
static int Width = 550;
|
||||
static int Width = 650;
|
||||
static int Height = 200;
|
||||
static const GLfloat Near = 5.0, Far = 25.0;
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ static void Display( void )
|
|||
*/
|
||||
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glTranslatef(-6.0, 0, 0);
|
||||
glTranslatef(-7.0, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.5, 0.5, 0.5 );
|
||||
glVertex2f(-1, -1);
|
||||
|
|
@ -85,6 +85,9 @@ static void Display( void )
|
|||
/* Draw the first two squares using incr for the affected face
|
||||
*/
|
||||
|
||||
/*************************************************************************
|
||||
* 2nd square
|
||||
*/
|
||||
if (use20syntax) {
|
||||
stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0);
|
||||
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
|
||||
|
|
@ -98,8 +101,8 @@ static void Display( void )
|
|||
glTranslatef(3.0, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.9, 0.9, 0.9 );
|
||||
/* this should be front facing */
|
||||
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
|
||||
/* this should be front facing */
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f( 1, -1);
|
||||
glVertex2f( 1, 1);
|
||||
|
|
@ -107,6 +110,7 @@ static void Display( void )
|
|||
}
|
||||
glEnd();
|
||||
|
||||
/* stencil vals should be equal to max_stencil */
|
||||
glStencilFunc(GL_EQUAL, max_stencil, ~0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.5, 0.5, 0.5 );
|
||||
|
|
@ -116,6 +120,9 @@ static void Display( void )
|
|||
glVertex2f(-1, 1);
|
||||
glEnd();
|
||||
|
||||
/*************************************************************************
|
||||
* 3rd square
|
||||
*/
|
||||
if (use20syntax) {
|
||||
stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0);
|
||||
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
|
||||
|
|
@ -129,9 +136,8 @@ static void Display( void )
|
|||
glTranslatef(3.0, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.9, 0.9, 0.9 );
|
||||
|
||||
/* this should be back facing */
|
||||
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
|
||||
/* this should be back facing */
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f(-1, 1);
|
||||
glVertex2f( 1, 1);
|
||||
|
|
@ -139,6 +145,7 @@ static void Display( void )
|
|||
}
|
||||
glEnd();
|
||||
|
||||
/* stencil vals should be equal to max_stencil */
|
||||
glStencilFunc(GL_EQUAL, max_stencil, ~0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.5, 0.5, 0.5 );
|
||||
|
|
@ -148,6 +155,9 @@ static void Display( void )
|
|||
glVertex2f(-1, 1);
|
||||
glEnd();
|
||||
|
||||
/*************************************************************************
|
||||
* 4th square
|
||||
*/
|
||||
if (use20syntax) {
|
||||
stencil_func_separate(GL_FRONT, GL_NEVER, 0, ~0);
|
||||
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
|
||||
|
|
@ -161,15 +171,13 @@ static void Display( void )
|
|||
glTranslatef(3.0, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.9, 0.9, 0.9 );
|
||||
|
||||
/* this should be back facing */
|
||||
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
|
||||
/* this should be back facing */
|
||||
/* this should be back facing */
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f(-1, 1);
|
||||
glVertex2f( 1, 1);
|
||||
glVertex2f( 1, -1);
|
||||
/* this should be front facing */
|
||||
/* this should be front facing */
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f( 1, -1);
|
||||
glVertex2f( 1, 1);
|
||||
|
|
@ -177,6 +185,7 @@ static void Display( void )
|
|||
}
|
||||
glEnd();
|
||||
|
||||
/* stencil vals should be equal to max_stencil */
|
||||
glStencilFunc(GL_EQUAL, max_stencil, ~0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.5, 0.5, 0.5 );
|
||||
|
|
@ -186,6 +195,9 @@ static void Display( void )
|
|||
glVertex2f(-1, 1);
|
||||
glEnd();
|
||||
|
||||
/*************************************************************************
|
||||
* 5th square
|
||||
*/
|
||||
if (use20syntax) {
|
||||
stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0);
|
||||
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
|
||||
|
|
@ -193,21 +205,19 @@ static void Display( void )
|
|||
else {
|
||||
stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0);
|
||||
}
|
||||
stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR);
|
||||
stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR);
|
||||
stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR);
|
||||
stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR);
|
||||
|
||||
glTranslatef(3.0, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.9, 0.9, 0.9 );
|
||||
|
||||
/* this should be back facing */
|
||||
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
|
||||
/* this should be back facing */
|
||||
/* this should be back facing */
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f(-1, 1);
|
||||
glVertex2f( 1, 1);
|
||||
glVertex2f( 1, -1);
|
||||
/* this should be front facing */
|
||||
/* this should be front facing */
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f( 1, -1);
|
||||
glVertex2f( 1, 1);
|
||||
|
|
@ -224,6 +234,47 @@ static void Display( void )
|
|||
glVertex2f(-1, 1);
|
||||
glEnd();
|
||||
|
||||
/*************************************************************************
|
||||
* 6th square
|
||||
*/
|
||||
if (glutExtensionSupported("GL_EXT_stencil_wrap")) {
|
||||
if (use20syntax) {
|
||||
stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0);
|
||||
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
|
||||
}
|
||||
else {
|
||||
stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0);
|
||||
}
|
||||
stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
|
||||
|
||||
glTranslatef(3.0, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.9, 0.9, 0.9 );
|
||||
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
|
||||
/* this should be back facing */
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f(-1, 1);
|
||||
glVertex2f( 1, 1);
|
||||
glVertex2f( 1, -1);
|
||||
/* this should be front facing */
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f( 1, -1);
|
||||
glVertex2f( 1, 1);
|
||||
glVertex2f(-1, 1);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glStencilFunc(GL_EQUAL, 260 - 255, ~0);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f( 0.5, 0.5, 0.5 );
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f( 1, -1);
|
||||
glVertex2f( 1, 1);
|
||||
glVertex2f(-1, 1);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glutSwapBuffers();
|
||||
|
|
@ -278,7 +329,7 @@ static void Init( void )
|
|||
stencil_func_separate_ati = (PFNGLSTENCILFUNCSEPARATEATIPROC) glutGetProcAddress( "glStencilFuncSeparateATI" );
|
||||
stencil_op_separate = (PFNGLSTENCILOPSEPARATEPROC) glutGetProcAddress( "glStencilOpSeparate" );
|
||||
|
||||
printf("\nAll 5 squares should be the same color.\n");
|
||||
printf("\nAll 5 (or 6) squares should be the same color.\n");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ static void Draw(void)
|
|||
glStencilFunc(GL_ALWAYS, 1, 1);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||
|
||||
/* red triangle (setting stencil to 1) */
|
||||
glColor3ub(200, 0, 0);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3i(-4, -4, 0);
|
||||
|
|
@ -88,6 +89,7 @@ static void Draw(void)
|
|||
glStencilFunc(GL_EQUAL, 1, 1);
|
||||
glStencilOp(GL_INCR, GL_KEEP, GL_DECR);
|
||||
|
||||
/* green quad (if over red, decr stencil to 0, else incr to 1) */
|
||||
glColor3ub(0, 200, 0);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3i(3, 3, 0);
|
||||
|
|
@ -101,6 +103,7 @@ static void Draw(void)
|
|||
glStencilFunc(GL_EQUAL, 1, 1);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
/* blue quad (where stencil == 1) */
|
||||
glColor3ub(0, 0, 200);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3f(2.5, 2.5, 0);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ INCDIR = $(TOP)/include
|
|||
LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
|
||||
|
||||
# Add X11 and pthread libs to satisfy GNU gold.
|
||||
APP_LIB_DEPS += $(X_LIBS) -lpthread
|
||||
APP_LIB_DEPS += $(X11_LIBS) -lpthread
|
||||
|
||||
LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(APP_LIB_DEPS)
|
||||
|
||||
|
|
|
|||
|
|
@ -212,21 +212,35 @@ _eglBindContextToSurfaces(_EGLContext *ctx,
|
|||
_EGLSurface **draw, _EGLSurface **read)
|
||||
{
|
||||
_EGLSurface *newDraw = *draw, *newRead = *read;
|
||||
_EGLContext *oldCtx;
|
||||
|
||||
if (newDraw->CurrentContext)
|
||||
newDraw->CurrentContext->DrawSurface = NULL;
|
||||
newDraw->CurrentContext = ctx;
|
||||
oldCtx = newDraw->CurrentContext;
|
||||
if (ctx != oldCtx) {
|
||||
if (oldCtx) {
|
||||
assert(*draw == oldCtx->DrawSurface);
|
||||
oldCtx->DrawSurface = NULL;
|
||||
}
|
||||
if (ctx) {
|
||||
*draw = ctx->DrawSurface;
|
||||
ctx->DrawSurface = newDraw;
|
||||
}
|
||||
|
||||
if (newRead->CurrentContext)
|
||||
newRead->CurrentContext->ReadSurface = NULL;
|
||||
newRead->CurrentContext = ctx;
|
||||
newDraw->CurrentContext = ctx;
|
||||
}
|
||||
|
||||
if (ctx) {
|
||||
*draw = ctx->DrawSurface;
|
||||
ctx->DrawSurface = newDraw;
|
||||
if (newRead != newDraw)
|
||||
oldCtx = newRead->CurrentContext;
|
||||
if (ctx != oldCtx) {
|
||||
if (oldCtx) {
|
||||
assert(*read == oldCtx->ReadSurface);
|
||||
oldCtx->ReadSurface = NULL;
|
||||
}
|
||||
if (ctx) {
|
||||
*read = ctx->ReadSurface;
|
||||
ctx->ReadSurface = newRead;
|
||||
}
|
||||
|
||||
*read = ctx->ReadSurface;
|
||||
ctx->ReadSurface = newRead;
|
||||
newRead->CurrentContext = ctx;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -246,15 +260,14 @@ _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t)
|
|||
_eglConvertApiToIndex(ctx->ClientAPI) : t->CurrentAPIIndex;
|
||||
|
||||
oldCtx = t->CurrentContexts[apiIndex];
|
||||
if (ctx == oldCtx)
|
||||
return NULL;
|
||||
if (ctx != oldCtx) {
|
||||
if (oldCtx)
|
||||
oldCtx->Binding = NULL;
|
||||
if (ctx)
|
||||
ctx->Binding = t;
|
||||
|
||||
if (oldCtx)
|
||||
oldCtx->Binding = NULL;
|
||||
if (ctx)
|
||||
ctx->Binding = t;
|
||||
|
||||
t->CurrentContexts[apiIndex] = ctx;
|
||||
t->CurrentContexts[apiIndex] = ctx;
|
||||
}
|
||||
|
||||
return oldCtx;
|
||||
}
|
||||
|
|
@ -352,7 +365,7 @@ _eglBindContext(_EGLContext **ctx, _EGLSurface **draw, _EGLSurface **read)
|
|||
_eglBindContextToSurfaces(newCtx, draw, read);
|
||||
|
||||
/* unbind the old context from its binding surfaces */
|
||||
if (oldCtx) {
|
||||
if (oldCtx && oldCtx != newCtx) {
|
||||
/*
|
||||
* If the new context replaces some old context, the new one should not
|
||||
* be current before the replacement and it should not be bound to any
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ INCLUDES = \
|
|||
|
||||
##### TARGETS #####
|
||||
|
||||
default: depend lib$(LIBNAME).a
|
||||
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)
|
||||
|
|
@ -36,13 +36,16 @@ depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURC
|
|||
touch depend
|
||||
$(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null
|
||||
|
||||
$(PROGS): % : %.o
|
||||
$(LD) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS) -Wl,--end-group
|
||||
|
||||
# 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) lib$(LIBNAME).a depend depend.bak
|
||||
rm -f $(OBJECTS) $(GENERATED_SOURCES) $(PROGS) lib$(LIBNAME).a depend depend.bak
|
||||
|
||||
# Dummy target
|
||||
install:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ for driver in env['drivers']:
|
|||
SConscript(os.path.join('drivers', driver, 'SConscript'))
|
||||
|
||||
# Needed by some state trackers
|
||||
SConscript('winsys/null/SConscript')
|
||||
SConscript('winsys/sw/null/SConscript')
|
||||
|
||||
SConscript('state_trackers/python/SConscript')
|
||||
if platform != 'embedded':
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ C_SOURCES = \
|
|||
util/u_mm.c \
|
||||
util/u_rect.c \
|
||||
util/u_ringbuffer.c \
|
||||
util/u_sampler.c \
|
||||
util/u_simple_shaders.c \
|
||||
util/u_snprintf.c \
|
||||
util/u_surface.c \
|
||||
|
|
@ -127,13 +128,15 @@ C_SOURCES = \
|
|||
util/u_timed_winsys.c \
|
||||
util/u_upload_mgr.c \
|
||||
util/u_simple_screen.c \
|
||||
vl/vl_bitstream_parser.c \
|
||||
vl/vl_mpeg12_mc_renderer.c \
|
||||
vl/vl_compositor.c \
|
||||
vl/vl_csc.c \
|
||||
vl/vl_shader_build.c \
|
||||
target-helpers/wrap_screen.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_alpha.c \
|
||||
gallivm/lp_bld_arit.c \
|
||||
|
|
@ -152,6 +155,7 @@ GALLIVM_SOURCES = \
|
|||
gallivm/lp_bld_intr.c \
|
||||
gallivm/lp_bld_logic.c \
|
||||
gallivm/lp_bld_pack.c \
|
||||
gallivm/lp_bld_printf.c \
|
||||
gallivm/lp_bld_sample.c \
|
||||
gallivm/lp_bld_sample_soa.c \
|
||||
gallivm/lp_bld_struct.c \
|
||||
|
|
|
|||
|
|
@ -162,6 +162,7 @@ source = [
|
|||
'util/u_mm.c',
|
||||
'util/u_rect.c',
|
||||
'util/u_ringbuffer.c',
|
||||
'util/u_sampler.c',
|
||||
'util/u_simple_shaders.c',
|
||||
'util/u_snprintf.c',
|
||||
'util/u_surface.c',
|
||||
|
|
@ -170,11 +171,12 @@ source = [
|
|||
'util/u_timed_winsys.c',
|
||||
'util/u_upload_mgr.c',
|
||||
'util/u_simple_screen.c',
|
||||
'vl/vl_bitstream_parser.c',
|
||||
'vl/vl_mpeg12_mc_renderer.c',
|
||||
'vl/vl_compositor.c',
|
||||
'vl/vl_csc.c',
|
||||
'vl/vl_shader_build.c',
|
||||
# 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',
|
||||
'target-helpers/wrap_screen.c',
|
||||
]
|
||||
|
||||
|
|
@ -198,6 +200,7 @@ if drawllvm:
|
|||
'gallivm/lp_bld_logic.c',
|
||||
'gallivm/lp_bld_init.cpp',
|
||||
'gallivm/lp_bld_pack.c',
|
||||
'gallivm/lp_bld_printf.c',
|
||||
'gallivm/lp_bld_sample.c',
|
||||
'gallivm/lp_bld_sample_soa.c',
|
||||
'gallivm/lp_bld_struct.c',
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include "pipe/p_state.h"
|
||||
#include "util/u_inlines.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "tgsi/tgsi_parse.h"
|
||||
|
||||
|
|
@ -69,17 +70,17 @@ struct cso_context {
|
|||
unsigned nr_vertex_samplers_saved;
|
||||
void *vertex_samplers_saved[PIPE_MAX_VERTEX_SAMPLERS];
|
||||
|
||||
struct pipe_texture *textures[PIPE_MAX_SAMPLERS];
|
||||
uint nr_textures;
|
||||
uint nr_fragment_sampler_views;
|
||||
struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
|
||||
|
||||
struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS];
|
||||
uint nr_vertex_textures;
|
||||
uint nr_vertex_sampler_views;
|
||||
struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
|
||||
|
||||
uint nr_textures_saved;
|
||||
struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS];
|
||||
uint nr_fragment_sampler_views_saved;
|
||||
struct pipe_sampler_view *fragment_sampler_views_saved[PIPE_MAX_SAMPLERS];
|
||||
|
||||
uint nr_vertex_textures_saved;
|
||||
struct pipe_texture *vertex_textures_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.
|
||||
|
|
@ -293,13 +294,13 @@ void cso_release_all( struct cso_context *ctx )
|
|||
}
|
||||
|
||||
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
|
||||
pipe_texture_reference(&ctx->textures[i], NULL);
|
||||
pipe_texture_reference(&ctx->textures_saved[i], NULL);
|
||||
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_texture_reference(&ctx->vertex_textures[i], NULL);
|
||||
pipe_texture_reference(&ctx->vertex_textures_saved[i], NULL);
|
||||
pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL);
|
||||
pipe_sampler_view_reference(&ctx->vertex_sampler_views_saved[i], NULL);
|
||||
}
|
||||
|
||||
free_framebuffer_state(&ctx->fb);
|
||||
|
|
@ -616,114 +617,6 @@ cso_restore_vertex_samplers(struct cso_context *ctx)
|
|||
}
|
||||
|
||||
|
||||
enum pipe_error cso_set_sampler_textures( struct cso_context *ctx,
|
||||
uint count,
|
||||
struct pipe_texture **textures )
|
||||
{
|
||||
uint i;
|
||||
|
||||
ctx->nr_textures = count;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
pipe_texture_reference(&ctx->textures[i], textures[i]);
|
||||
for ( ; i < PIPE_MAX_SAMPLERS; i++)
|
||||
pipe_texture_reference(&ctx->textures[i], NULL);
|
||||
|
||||
ctx->pipe->set_fragment_sampler_textures(ctx->pipe, count, textures);
|
||||
|
||||
return PIPE_OK;
|
||||
}
|
||||
|
||||
void cso_save_sampler_textures( struct cso_context *ctx )
|
||||
{
|
||||
uint i;
|
||||
|
||||
ctx->nr_textures_saved = ctx->nr_textures;
|
||||
for (i = 0; i < ctx->nr_textures; i++) {
|
||||
assert(!ctx->textures_saved[i]);
|
||||
pipe_texture_reference(&ctx->textures_saved[i], ctx->textures[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void cso_restore_sampler_textures( struct cso_context *ctx )
|
||||
{
|
||||
uint i;
|
||||
|
||||
ctx->nr_textures = ctx->nr_textures_saved;
|
||||
|
||||
for (i = 0; i < ctx->nr_textures; i++) {
|
||||
pipe_texture_reference(&ctx->textures[i], NULL);
|
||||
ctx->textures[i] = ctx->textures_saved[i];
|
||||
ctx->textures_saved[i] = NULL;
|
||||
}
|
||||
for ( ; i < PIPE_MAX_SAMPLERS; i++)
|
||||
pipe_texture_reference(&ctx->textures[i], NULL);
|
||||
|
||||
ctx->pipe->set_fragment_sampler_textures(ctx->pipe, ctx->nr_textures, ctx->textures);
|
||||
|
||||
ctx->nr_textures_saved = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum pipe_error
|
||||
cso_set_vertex_sampler_textures(struct cso_context *ctx,
|
||||
uint count,
|
||||
struct pipe_texture **textures)
|
||||
{
|
||||
uint i;
|
||||
|
||||
ctx->nr_vertex_textures = count;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
pipe_texture_reference(&ctx->vertex_textures[i], textures[i]);
|
||||
}
|
||||
for ( ; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
|
||||
pipe_texture_reference(&ctx->vertex_textures[i], NULL);
|
||||
}
|
||||
|
||||
ctx->pipe->set_vertex_sampler_textures(ctx->pipe, count, textures);
|
||||
|
||||
return PIPE_OK;
|
||||
}
|
||||
|
||||
void
|
||||
cso_save_vertex_sampler_textures(struct cso_context *ctx)
|
||||
{
|
||||
uint i;
|
||||
|
||||
ctx->nr_vertex_textures_saved = ctx->nr_vertex_textures;
|
||||
for (i = 0; i < ctx->nr_vertex_textures; i++) {
|
||||
assert(!ctx->vertex_textures_saved[i]);
|
||||
pipe_texture_reference(&ctx->vertex_textures_saved[i], ctx->vertex_textures[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cso_restore_vertex_sampler_textures(struct cso_context *ctx)
|
||||
{
|
||||
uint i;
|
||||
|
||||
ctx->nr_vertex_textures = ctx->nr_vertex_textures_saved;
|
||||
|
||||
for (i = 0; i < ctx->nr_vertex_textures; i++) {
|
||||
pipe_texture_reference(&ctx->vertex_textures[i], NULL);
|
||||
ctx->vertex_textures[i] = ctx->vertex_textures_saved[i];
|
||||
ctx->vertex_textures_saved[i] = NULL;
|
||||
}
|
||||
for ( ; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
|
||||
pipe_texture_reference(&ctx->vertex_textures[i], NULL);
|
||||
}
|
||||
|
||||
ctx->pipe->set_vertex_sampler_textures(ctx->pipe,
|
||||
ctx->nr_vertex_textures,
|
||||
ctx->vertex_textures);
|
||||
|
||||
ctx->nr_vertex_textures_saved = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum pipe_error cso_set_depth_stencil_alpha(struct cso_context *ctx,
|
||||
const struct pipe_depth_stencil_alpha_state *templ)
|
||||
{
|
||||
|
|
@ -1261,3 +1154,122 @@ void cso_restore_vertex_elements(struct cso_context *ctx)
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,25 +103,6 @@ void
|
|||
cso_single_vertex_sampler_done(struct cso_context *cso);
|
||||
|
||||
|
||||
|
||||
enum pipe_error cso_set_sampler_textures( struct cso_context *cso,
|
||||
uint count,
|
||||
struct pipe_texture **textures );
|
||||
void cso_save_sampler_textures( struct cso_context *cso );
|
||||
void cso_restore_sampler_textures( struct cso_context *cso );
|
||||
|
||||
|
||||
|
||||
enum pipe_error
|
||||
cso_set_vertex_sampler_textures(struct cso_context *cso,
|
||||
uint count,
|
||||
struct pipe_texture **textures);
|
||||
void
|
||||
cso_save_vertex_sampler_textures(struct cso_context *cso);
|
||||
void
|
||||
cso_restore_vertex_sampler_textures(struct cso_context *cso);
|
||||
|
||||
|
||||
enum pipe_error cso_set_vertex_elements(struct cso_context *ctx,
|
||||
unsigned count,
|
||||
const struct pipe_vertex_element *states);
|
||||
|
|
@ -198,6 +179,34 @@ 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
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#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"
|
||||
|
|
@ -88,8 +89,9 @@ struct aaline_stage
|
|||
|
||||
void *sampler_cso;
|
||||
struct pipe_texture *texture;
|
||||
struct pipe_sampler_view *sampler_view;
|
||||
uint num_samplers;
|
||||
uint num_textures;
|
||||
uint num_sampler_views;
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -98,7 +100,7 @@ struct aaline_stage
|
|||
struct aaline_fragment_shader *fs;
|
||||
struct {
|
||||
void *sampler[PIPE_MAX_SAMPLERS];
|
||||
struct pipe_texture *texture[PIPE_MAX_SAMPLERS];
|
||||
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
|
||||
} state;
|
||||
|
||||
/*
|
||||
|
|
@ -111,8 +113,9 @@ struct aaline_stage
|
|||
|
||||
void (*driver_bind_sampler_states)(struct pipe_context *, unsigned,
|
||||
void **);
|
||||
void (*driver_set_sampler_textures)(struct pipe_context *, unsigned,
|
||||
struct pipe_texture **);
|
||||
void (*driver_set_sampler_views)(struct pipe_context *,
|
||||
unsigned,
|
||||
struct pipe_sampler_view **);
|
||||
|
||||
struct pipe_context *pipe;
|
||||
};
|
||||
|
|
@ -394,6 +397,7 @@ aaline_create_texture(struct aaline_stage *aaline)
|
|||
struct pipe_context *pipe = aaline->pipe;
|
||||
struct pipe_screen *screen = pipe->screen;
|
||||
struct pipe_texture texTemp;
|
||||
struct pipe_sampler_view viewTempl;
|
||||
uint level;
|
||||
|
||||
memset(&texTemp, 0, sizeof(texTemp));
|
||||
|
|
@ -408,6 +412,16 @@ aaline_create_texture(struct aaline_stage *aaline)
|
|||
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.
|
||||
|
|
@ -669,16 +683,16 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header)
|
|||
|
||||
/* how many samplers? */
|
||||
/* we'll use sampler/texture[pstip->sampler_unit] for the stipple */
|
||||
num_samplers = MAX2(aaline->num_textures, aaline->num_samplers);
|
||||
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_texture_reference(&aaline->state.texture[aaline->fs->sampler_unit],
|
||||
aaline->texture);
|
||||
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_textures(pipe, num_samplers, aaline->state.texture);
|
||||
aaline->driver_set_sampler_views(pipe, num_samplers, aaline->state.sampler_views);
|
||||
draw->suspend_flushing = FALSE;
|
||||
|
||||
/* now really draw first line */
|
||||
|
|
@ -702,8 +716,9 @@ aaline_flush(struct draw_stage *stage, unsigned flags)
|
|||
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_textures(pipe, aaline->num_textures,
|
||||
aaline->state.texture);
|
||||
aaline->driver_set_sampler_views(pipe,
|
||||
aaline->num_sampler_views,
|
||||
aaline->state.sampler_views);
|
||||
draw->suspend_flushing = FALSE;
|
||||
|
||||
draw->extra_shader_outputs.slot = 0;
|
||||
|
|
@ -724,7 +739,7 @@ aaline_destroy(struct draw_stage *stage)
|
|||
uint i;
|
||||
|
||||
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
|
||||
pipe_texture_reference(&aaline->state.texture[i], NULL);
|
||||
pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL);
|
||||
}
|
||||
|
||||
if (aaline->sampler_cso)
|
||||
|
|
@ -733,6 +748,10 @@ aaline_destroy(struct draw_stage *stage)
|
|||
if (aaline->texture)
|
||||
pipe_texture_reference(&aaline->texture, NULL);
|
||||
|
||||
if (aaline->sampler_view) {
|
||||
pipe_sampler_view_reference(&aaline->sampler_view, NULL);
|
||||
}
|
||||
|
||||
draw_free_temp_verts( stage );
|
||||
|
||||
FREE( stage );
|
||||
|
|
@ -844,23 +863,24 @@ aaline_bind_sampler_states(struct pipe_context *pipe,
|
|||
|
||||
|
||||
static void
|
||||
aaline_set_sampler_textures(struct pipe_context *pipe,
|
||||
unsigned num, struct pipe_texture **texture)
|
||||
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_texture_reference(&aaline->state.texture[i], texture[i]);
|
||||
pipe_sampler_view_reference(&aaline->state.sampler_views[i], views[i]);
|
||||
}
|
||||
for ( ; i < PIPE_MAX_SAMPLERS; i++) {
|
||||
pipe_texture_reference(&aaline->state.texture[i], NULL);
|
||||
pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL);
|
||||
}
|
||||
aaline->num_textures = num;
|
||||
aaline->num_sampler_views = num;
|
||||
|
||||
/* pass-through */
|
||||
aaline->driver_set_sampler_textures(aaline->pipe, num, texture);
|
||||
aaline->driver_set_sampler_views(aaline->pipe, num, views);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -898,7 +918,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe)
|
|||
aaline->driver_delete_fs_state = pipe->delete_fs_state;
|
||||
|
||||
aaline->driver_bind_sampler_states = pipe->bind_fragment_sampler_states;
|
||||
aaline->driver_set_sampler_textures = pipe->set_fragment_sampler_textures;
|
||||
aaline->driver_set_sampler_views = pipe->set_fragment_sampler_views;
|
||||
|
||||
/* override the driver's functions */
|
||||
pipe->create_fs_state = aaline_create_fs_state;
|
||||
|
|
@ -906,7 +926,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe)
|
|||
pipe->delete_fs_state = aaline_delete_fs_state;
|
||||
|
||||
pipe->bind_fragment_sampler_states = aaline_bind_sampler_states;
|
||||
pipe->set_fragment_sampler_textures = aaline_set_sampler_textures;
|
||||
pipe->set_fragment_sampler_views = aaline_set_sampler_views;
|
||||
|
||||
/* Install once everything is known to be OK:
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
#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"
|
||||
|
|
@ -75,8 +76,9 @@ struct pstip_stage
|
|||
|
||||
void *sampler_cso;
|
||||
struct pipe_texture *texture;
|
||||
struct pipe_sampler_view *sampler_view;
|
||||
uint num_samplers;
|
||||
uint num_textures;
|
||||
uint num_sampler_views;
|
||||
|
||||
/*
|
||||
* Currently bound state
|
||||
|
|
@ -84,7 +86,7 @@ struct pstip_stage
|
|||
struct pstip_fragment_shader *fs;
|
||||
struct {
|
||||
void *samplers[PIPE_MAX_SAMPLERS];
|
||||
struct pipe_texture *textures[PIPE_MAX_SAMPLERS];
|
||||
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
|
||||
const struct pipe_poly_stipple *stipple;
|
||||
} state;
|
||||
|
||||
|
|
@ -98,8 +100,9 @@ struct pstip_stage
|
|||
|
||||
void (*driver_bind_sampler_states)(struct pipe_context *, unsigned, void **);
|
||||
|
||||
void (*driver_set_sampler_textures)(struct pipe_context *, unsigned,
|
||||
struct pipe_texture **);
|
||||
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 *);
|
||||
|
|
@ -424,6 +427,7 @@ pstip_create_texture(struct pstip_stage *pstip)
|
|||
struct pipe_context *pipe = pstip->pipe;
|
||||
struct pipe_screen *screen = pipe->screen;
|
||||
struct pipe_texture texTemp;
|
||||
struct pipe_sampler_view viewTempl;
|
||||
|
||||
memset(&texTemp, 0, sizeof(texTemp));
|
||||
texTemp.target = PIPE_TEXTURE_2D;
|
||||
|
|
@ -437,6 +441,16 @@ pstip_create_texture(struct pstip_stage *pstip)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
@ -515,19 +529,19 @@ pstip_first_tri(struct draw_stage *stage, struct prim_header *header)
|
|||
|
||||
/* how many samplers? */
|
||||
/* we'll use sampler/texture[pstip->sampler_unit] for the stipple */
|
||||
num_samplers = MAX2(pstip->num_textures, pstip->num_samplers);
|
||||
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_texture_reference(&pstip->state.textures[pstip->fs->sampler_unit],
|
||||
pstip->texture);
|
||||
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_textures(pipe, num_samplers, pstip->state.textures);
|
||||
pstip->driver_set_sampler_views(pipe, num_samplers, pstip->state.sampler_views);
|
||||
draw->suspend_flushing = FALSE;
|
||||
|
||||
/* now really draw first triangle */
|
||||
|
|
@ -551,8 +565,9 @@ pstip_flush(struct draw_stage *stage, unsigned flags)
|
|||
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_textures(pipe, pstip->num_textures,
|
||||
pstip->state.textures);
|
||||
pstip->driver_set_sampler_views(pipe,
|
||||
pstip->num_sampler_views,
|
||||
pstip->state.sampler_views);
|
||||
draw->suspend_flushing = FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -571,13 +586,17 @@ pstip_destroy(struct draw_stage *stage)
|
|||
uint i;
|
||||
|
||||
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
|
||||
pipe_texture_reference(&pstip->state.textures[i], NULL);
|
||||
pipe_sampler_view_reference(&pstip->state.sampler_views[i], NULL);
|
||||
}
|
||||
|
||||
pstip->pipe->delete_sampler_state(pstip->pipe, pstip->sampler_cso);
|
||||
|
||||
pipe_texture_reference(&pstip->texture, NULL);
|
||||
|
||||
if (pstip->sampler_view) {
|
||||
pipe_sampler_view_reference(&pstip->sampler_view, NULL);
|
||||
}
|
||||
|
||||
draw_free_temp_verts( stage );
|
||||
FREE( stage );
|
||||
}
|
||||
|
|
@ -682,24 +701,25 @@ pstip_bind_sampler_states(struct pipe_context *pipe,
|
|||
|
||||
|
||||
static void
|
||||
pstip_set_sampler_textures(struct pipe_context *pipe,
|
||||
unsigned num, struct pipe_texture **texture)
|
||||
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_texture_reference(&pstip->state.textures[i], texture[i]);
|
||||
pipe_sampler_view_reference(&pstip->state.sampler_views[i], views[i]);
|
||||
}
|
||||
for (; i < PIPE_MAX_SAMPLERS; i++) {
|
||||
pipe_texture_reference(&pstip->state.textures[i], NULL);
|
||||
pipe_sampler_view_reference(&pstip->state.sampler_views[i], NULL);
|
||||
}
|
||||
|
||||
pstip->num_textures = num;
|
||||
pstip->num_sampler_views = num;
|
||||
|
||||
/* pass-through */
|
||||
pstip->driver_set_sampler_textures(pstip->pipe, num, texture);
|
||||
pstip->driver_set_sampler_views(pstip->pipe, num, views);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -756,7 +776,7 @@ draw_install_pstipple_stage(struct draw_context *draw,
|
|||
pstip->driver_delete_fs_state = pipe->delete_fs_state;
|
||||
|
||||
pstip->driver_bind_sampler_states = pipe->bind_fragment_sampler_states;
|
||||
pstip->driver_set_sampler_textures = pipe->set_fragment_sampler_textures;
|
||||
pstip->driver_set_sampler_views = pipe->set_fragment_sampler_views;
|
||||
pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple;
|
||||
|
||||
/* override the driver's functions */
|
||||
|
|
@ -765,7 +785,7 @@ draw_install_pstipple_stage(struct draw_context *draw,
|
|||
pipe->delete_fs_state = pstip_delete_fs_state;
|
||||
|
||||
pipe->bind_fragment_sampler_states = pstip_bind_sampler_states;
|
||||
pipe->set_fragment_sampler_textures = pstip_set_sampler_textures;
|
||||
pipe->set_fragment_sampler_views = pstip_set_sampler_views;
|
||||
pipe->set_polygon_stipple = pstip_set_polygon_stipple;
|
||||
|
||||
return TRUE;
|
||||
|
|
|
|||
|
|
@ -238,38 +238,15 @@ vbuf_start_prim( struct vbuf_stage *vbuf, uint prim )
|
|||
unsigned output_format;
|
||||
unsigned src_offset = (vbuf->vinfo->attrib[i].src_index * 4 * sizeof(float) );
|
||||
|
||||
switch (vbuf->vinfo->attrib[i].emit) {
|
||||
case EMIT_4F:
|
||||
output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
|
||||
emit_sz = 4 * sizeof(float);
|
||||
break;
|
||||
case EMIT_3F:
|
||||
output_format = PIPE_FORMAT_R32G32B32_FLOAT;
|
||||
emit_sz = 3 * sizeof(float);
|
||||
break;
|
||||
case EMIT_2F:
|
||||
output_format = PIPE_FORMAT_R32G32_FLOAT;
|
||||
emit_sz = 2 * sizeof(float);
|
||||
break;
|
||||
case EMIT_1F:
|
||||
output_format = PIPE_FORMAT_R32_FLOAT;
|
||||
emit_sz = 1 * sizeof(float);
|
||||
break;
|
||||
case EMIT_1F_PSIZE:
|
||||
output_format = PIPE_FORMAT_R32_FLOAT;
|
||||
emit_sz = 1 * 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;
|
||||
break;
|
||||
case EMIT_4UB:
|
||||
output_format = PIPE_FORMAT_A8R8G8B8_UNORM;
|
||||
emit_sz = 4 * sizeof(ubyte);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
output_format = PIPE_FORMAT_NONE;
|
||||
emit_sz = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL;
|
||||
|
|
|
|||
|
|
@ -86,40 +86,15 @@ void draw_pt_emit_prepare( struct pt_emit *emit,
|
|||
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);
|
||||
|
||||
|
||||
switch (vinfo->attrib[i].emit) {
|
||||
case EMIT_4F:
|
||||
output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
|
||||
emit_sz = 4 * sizeof(float);
|
||||
break;
|
||||
case EMIT_3F:
|
||||
output_format = PIPE_FORMAT_R32G32B32_FLOAT;
|
||||
emit_sz = 3 * sizeof(float);
|
||||
break;
|
||||
case EMIT_2F:
|
||||
output_format = PIPE_FORMAT_R32G32_FLOAT;
|
||||
emit_sz = 2 * sizeof(float);
|
||||
break;
|
||||
case EMIT_1F:
|
||||
output_format = PIPE_FORMAT_R32_FLOAT;
|
||||
emit_sz = 1 * sizeof(float);
|
||||
break;
|
||||
case EMIT_1F_PSIZE:
|
||||
output_format = PIPE_FORMAT_R32_FLOAT;
|
||||
emit_sz = 1 * sizeof(float);
|
||||
/* doesn't handle EMIT_OMIT */
|
||||
assert(emit_sz != 0);
|
||||
|
||||
if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) {
|
||||
src_buffer = 1;
|
||||
src_offset = 0;
|
||||
break;
|
||||
case EMIT_4UB:
|
||||
output_format = PIPE_FORMAT_A8R8G8B8_UNORM;
|
||||
emit_sz = 4 * sizeof(ubyte);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
output_format = PIPE_FORMAT_NONE;
|
||||
emit_sz = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL;
|
||||
|
|
|
|||
|
|
@ -129,41 +129,16 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle,
|
|||
unsigned input_offset = src->src_offset;
|
||||
unsigned output_format;
|
||||
|
||||
switch (vinfo->attrib[i].emit) {
|
||||
case EMIT_4UB:
|
||||
output_format = PIPE_FORMAT_R8G8B8A8_UNORM;
|
||||
emit_sz = 4 * sizeof(unsigned char);
|
||||
break;
|
||||
case EMIT_4F:
|
||||
output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
|
||||
emit_sz = 4 * sizeof(float);
|
||||
break;
|
||||
case EMIT_3F:
|
||||
output_format = PIPE_FORMAT_R32G32B32_FLOAT;
|
||||
emit_sz = 3 * sizeof(float);
|
||||
break;
|
||||
case EMIT_2F:
|
||||
output_format = PIPE_FORMAT_R32G32_FLOAT;
|
||||
emit_sz = 2 * sizeof(float);
|
||||
break;
|
||||
case EMIT_1F:
|
||||
output_format = PIPE_FORMAT_R32_FLOAT;
|
||||
emit_sz = 1 * sizeof(float);
|
||||
break;
|
||||
case EMIT_1F_PSIZE:
|
||||
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;
|
||||
output_format = PIPE_FORMAT_R32_FLOAT;
|
||||
emit_sz = 1 * sizeof(float);
|
||||
break;
|
||||
case EMIT_OMIT:
|
||||
continue;
|
||||
default:
|
||||
assert(0);
|
||||
output_format = PIPE_FORMAT_NONE;
|
||||
emit_sz = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
key.element[i].type = TRANSLATE_ELEMENT_NORMAL;
|
||||
|
|
|
|||
|
|
@ -130,31 +130,10 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
|
|||
unsigned dst_offset = 0;
|
||||
|
||||
for (i = 0; i < vinfo->num_attribs; i++) {
|
||||
unsigned emit_sz = 0;
|
||||
unsigned emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit);
|
||||
|
||||
switch (vinfo->attrib[i].emit) {
|
||||
case EMIT_4F:
|
||||
emit_sz = 4 * sizeof(float);
|
||||
break;
|
||||
case EMIT_3F:
|
||||
emit_sz = 3 * sizeof(float);
|
||||
break;
|
||||
case EMIT_2F:
|
||||
emit_sz = 2 * sizeof(float);
|
||||
break;
|
||||
case EMIT_1F:
|
||||
emit_sz = 1 * sizeof(float);
|
||||
break;
|
||||
case EMIT_1F_PSIZE:
|
||||
emit_sz = 1 * sizeof(float);
|
||||
break;
|
||||
case EMIT_4UB:
|
||||
emit_sz = 4 * sizeof(ubyte);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
/* 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 --
|
||||
|
|
|
|||
|
|
@ -48,30 +48,12 @@ draw_compute_vertex_size(struct vertex_info *vinfo)
|
|||
uint i;
|
||||
|
||||
vinfo->size = 0;
|
||||
for (i = 0; i < vinfo->num_attribs; i++) {
|
||||
switch (vinfo->attrib[i].emit) {
|
||||
case EMIT_OMIT:
|
||||
break;
|
||||
case EMIT_4UB:
|
||||
/* fall-through */
|
||||
case EMIT_1F_PSIZE:
|
||||
/* fall-through */
|
||||
case EMIT_1F:
|
||||
vinfo->size += 1;
|
||||
break;
|
||||
case EMIT_2F:
|
||||
vinfo->size += 2;
|
||||
break;
|
||||
case EMIT_3F:
|
||||
vinfo->size += 3;
|
||||
break;
|
||||
case EMIT_4F:
|
||||
vinfo->size += 4;
|
||||
break;
|
||||
default:
|
||||
assert(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;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -120,6 +102,13 @@ draw_dump_emitted_vertex(const struct vertex_info *vinfo, const uint8_t *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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@ enum attrib_emit {
|
|||
EMIT_2F,
|
||||
EMIT_3F,
|
||||
EMIT_4F,
|
||||
EMIT_4UB /**< XXX may need variations for RGBA vs BGRA, etc */
|
||||
EMIT_4UB, /**< is RGBA like the rest */
|
||||
EMIT_4UB_BGRA
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -141,9 +142,11 @@ void draw_dump_emitted_vertex(const struct vertex_info *vinfo,
|
|||
const uint8_t *data);
|
||||
|
||||
|
||||
static INLINE unsigned draw_translate_vinfo_format(unsigned format )
|
||||
static INLINE unsigned draw_translate_vinfo_format(enum attrib_emit emit)
|
||||
{
|
||||
switch (format) {
|
||||
switch (emit) {
|
||||
case EMIT_OMIT:
|
||||
return PIPE_FORMAT_NONE;
|
||||
case EMIT_1F:
|
||||
case EMIT_1F_PSIZE:
|
||||
return PIPE_FORMAT_R32_FLOAT;
|
||||
|
|
@ -155,10 +158,36 @@ static INLINE unsigned draw_translate_vinfo_format(unsigned format )
|
|||
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 */
|
||||
|
|
|
|||
|
|
@ -401,13 +401,11 @@ static boolean emit_output( struct aos_compilation *cp,
|
|||
emit_store_R32G32B32A32(cp, ptr, dataXMM);
|
||||
break;
|
||||
case EMIT_4UB:
|
||||
if (1) {
|
||||
emit_swizzle(cp, dataXMM, dataXMM, SHUF(Z,Y,X,W));
|
||||
emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM);
|
||||
}
|
||||
else {
|
||||
emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM);
|
||||
}
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef OS_LLVM_H
|
||||
#define OS_LLVM_H
|
||||
#ifndef LP_BLD_H
|
||||
#define LP_BLD_H
|
||||
|
||||
|
||||
#include <llvm-c/Core.h>
|
||||
|
|
@ -40,8 +40,8 @@
|
|||
|
||||
/** Set version to 0 if missing to avoid #ifdef HAVE_LLVM everywhere */
|
||||
#ifndef HAVE_LLVM
|
||||
#define HAVE_LLVM 0x0
|
||||
#define HAVE_LLVM 0x0207
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* OS_LLVM_H */
|
||||
#endif /* LP_BLD_H */
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
#define LP_BLD_ALPHA_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
struct pipe_alpha_state;
|
||||
struct lp_type;
|
||||
|
|
|
|||
|
|
@ -361,12 +361,12 @@ lp_build_mul_u8n(LLVMBuilderRef builder,
|
|||
LLVMValueRef c8;
|
||||
LLVMValueRef ab;
|
||||
|
||||
c8 = lp_build_int_const_scalar(i16_type, 8);
|
||||
c8 = lp_build_const_int_vec(i16_type, 8);
|
||||
|
||||
#if 0
|
||||
|
||||
/* a*b/255 ~= (a*(b + 1)) >> 256 */
|
||||
b = LLVMBuildAdd(builder, b, lp_build_int_const_scalar(i16_type, 1), "");
|
||||
b = LLVMBuildAdd(builder, b, lp_build_const_int_vec(i16_type, 1), "");
|
||||
ab = LLVMBuildMul(builder, a, b, "");
|
||||
|
||||
#else
|
||||
|
|
@ -374,7 +374,7 @@ lp_build_mul_u8n(LLVMBuilderRef builder,
|
|||
/* 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_int_const_scalar(i16_type, 0x80), "");
|
||||
ab = LLVMBuildAdd(builder, ab, lp_build_const_int_vec(i16_type, 0x80), "");
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -429,7 +429,7 @@ lp_build_mul(struct lp_build_context *bld,
|
|||
}
|
||||
|
||||
if(type.fixed)
|
||||
shift = lp_build_int_const_scalar(type, type.width/2);
|
||||
shift = lp_build_const_int_vec(type, type.width/2);
|
||||
else
|
||||
shift = NULL;
|
||||
|
||||
|
|
@ -491,7 +491,7 @@ lp_build_mul_imm(struct lp_build_context *bld,
|
|||
* for Inf and NaN.
|
||||
*/
|
||||
unsigned mantissa = lp_mantissa(bld->type);
|
||||
factor = lp_build_int_const_scalar(bld->type, (unsigned long long)shift << mantissa);
|
||||
factor = lp_build_const_int_vec(bld->type, (unsigned long long)shift << mantissa);
|
||||
a = LLVMBuildBitCast(bld->builder, a, lp_build_int_vec_type(bld->type), "");
|
||||
a = LLVMBuildAdd(bld->builder, a, factor, "");
|
||||
a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(bld->type), "");
|
||||
|
|
@ -499,12 +499,12 @@ lp_build_mul_imm(struct lp_build_context *bld,
|
|||
#endif
|
||||
}
|
||||
else {
|
||||
factor = lp_build_const_scalar(bld->type, shift);
|
||||
factor = lp_build_const_vec(bld->type, shift);
|
||||
return LLVMBuildShl(bld->builder, a, factor, "");
|
||||
}
|
||||
}
|
||||
|
||||
factor = lp_build_const_scalar(bld->type, (double)b);
|
||||
factor = lp_build_const_vec(bld->type, (double)b);
|
||||
return lp_build_mul(bld, a, factor);
|
||||
}
|
||||
|
||||
|
|
@ -567,7 +567,7 @@ lp_build_lerp(struct lp_build_context *bld,
|
|||
* 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(bld->builder, res, lp_build_int_const_scalar(bld->type, (1 << bld->type.width/2) - 1), "");
|
||||
res = LLVMBuildAnd(bld->builder, res, lp_build_const_int_vec(bld->type, (1 << bld->type.width/2) - 1), "");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -689,7 +689,7 @@ lp_build_abs(struct lp_build_context *bld,
|
|||
/* vector of floats */
|
||||
LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
|
||||
unsigned long long absMask = ~(1ULL << (type.width - 1));
|
||||
LLVMValueRef mask = lp_build_int_const_scalar(type, ((unsigned long long) absMask));
|
||||
LLVMValueRef mask = lp_build_const_int_vec(type, ((unsigned long long) absMask));
|
||||
a = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
|
||||
a = LLVMBuildAnd(bld->builder, a, mask, "");
|
||||
a = LLVMBuildBitCast(bld->builder, a, vec_type, "");
|
||||
|
|
@ -751,7 +751,7 @@ lp_build_sgn(struct lp_build_context *bld,
|
|||
/* vector */
|
||||
int_type = lp_build_int_vec_type(type);
|
||||
vec_type = lp_build_vec_type(type);
|
||||
mask = lp_build_int_const_scalar(type, maskBit);
|
||||
mask = lp_build_const_int_vec(type, maskBit);
|
||||
}
|
||||
|
||||
/* Take the sign bit and add it to 1 constant */
|
||||
|
|
@ -763,7 +763,7 @@ lp_build_sgn(struct lp_build_context *bld,
|
|||
}
|
||||
else
|
||||
{
|
||||
LLVMValueRef minus_one = lp_build_const_scalar(type, -1.0);
|
||||
LLVMValueRef minus_one = lp_build_const_vec(type, -1.0);
|
||||
cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, bld->zero);
|
||||
res = lp_build_select(bld, cond, bld->one, minus_one);
|
||||
}
|
||||
|
|
@ -789,8 +789,8 @@ lp_build_set_sign(struct lp_build_context *bld,
|
|||
const struct lp_type type = bld->type;
|
||||
LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
|
||||
LLVMTypeRef vec_type = lp_build_vec_type(type);
|
||||
LLVMValueRef shift = lp_build_int_const_scalar(type, type.width - 1);
|
||||
LLVMValueRef mask = lp_build_int_const_scalar(type,
|
||||
LLVMValueRef shift = lp_build_const_int_vec(type, type.width - 1);
|
||||
LLVMValueRef mask = lp_build_const_int_vec(type,
|
||||
~((unsigned long long) 1 << (type.width - 1)));
|
||||
LLVMValueRef val, res;
|
||||
|
||||
|
|
@ -1034,7 +1034,7 @@ lp_build_iround(struct lp_build_context *bld,
|
|||
}
|
||||
else {
|
||||
LLVMTypeRef vec_type = lp_build_vec_type(type);
|
||||
LLVMValueRef mask = lp_build_int_const_scalar(type, (unsigned long long)1 << (type.width - 1));
|
||||
LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
|
||||
LLVMValueRef sign;
|
||||
LLVMValueRef half;
|
||||
|
||||
|
|
@ -1043,7 +1043,7 @@ lp_build_iround(struct lp_build_context *bld,
|
|||
sign = LLVMBuildAnd(bld->builder, sign, mask, "");
|
||||
|
||||
/* sign * 0.5 */
|
||||
half = lp_build_const_scalar(type, 0.5);
|
||||
half = lp_build_const_vec(type, 0.5);
|
||||
half = LLVMBuildBitCast(bld->builder, half, int_vec_type, "");
|
||||
half = LLVMBuildOr(bld->builder, sign, half, "");
|
||||
half = LLVMBuildBitCast(bld->builder, half, vec_type, "");
|
||||
|
|
@ -1086,18 +1086,18 @@ lp_build_ifloor(struct lp_build_context *bld,
|
|||
/* Take the sign bit and add it to 1 constant */
|
||||
LLVMTypeRef vec_type = lp_build_vec_type(type);
|
||||
unsigned mantissa = lp_mantissa(type);
|
||||
LLVMValueRef mask = lp_build_int_const_scalar(type, (unsigned long long)1 << (type.width - 1));
|
||||
LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
|
||||
LLVMValueRef sign;
|
||||
LLVMValueRef offset;
|
||||
|
||||
/* sign = a < 0 ? ~0 : 0 */
|
||||
sign = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
|
||||
sign = LLVMBuildAnd(bld->builder, sign, mask, "");
|
||||
sign = LLVMBuildAShr(bld->builder, sign, lp_build_int_const_scalar(type, type.width - 1), "");
|
||||
sign = LLVMBuildAShr(bld->builder, sign, lp_build_const_int_vec(type, type.width - 1), "");
|
||||
lp_build_name(sign, "floor.sign");
|
||||
|
||||
/* offset = -0.99999(9)f */
|
||||
offset = lp_build_const_scalar(type, -(double)(((unsigned long long)1 << mantissa) - 1)/((unsigned long long)1 << mantissa));
|
||||
offset = lp_build_const_vec(type, -(double)(((unsigned long long)1 << mantissa) - 1)/((unsigned long long)1 << mantissa));
|
||||
offset = LLVMConstBitCast(offset, int_vec_type);
|
||||
|
||||
/* offset = a < 0 ? -0.99999(9)f : 0.0f */
|
||||
|
|
@ -1268,7 +1268,7 @@ lp_build_exp(struct lp_build_context *bld,
|
|||
LLVMValueRef x)
|
||||
{
|
||||
/* log2(e) = 1/log(2) */
|
||||
LLVMValueRef log2e = lp_build_const_scalar(bld->type, 1.4426950408889634);
|
||||
LLVMValueRef log2e = lp_build_const_vec(bld->type, 1.4426950408889634);
|
||||
|
||||
return lp_build_mul(bld, log2e, lp_build_exp2(bld, x));
|
||||
}
|
||||
|
|
@ -1282,7 +1282,7 @@ lp_build_log(struct lp_build_context *bld,
|
|||
LLVMValueRef x)
|
||||
{
|
||||
/* log(2) */
|
||||
LLVMValueRef log2 = lp_build_const_scalar(bld->type, 0.69314718055994529);
|
||||
LLVMValueRef log2 = lp_build_const_vec(bld->type, 0.69314718055994529);
|
||||
|
||||
return lp_build_mul(bld, log2, lp_build_exp2(bld, x));
|
||||
}
|
||||
|
|
@ -1318,7 +1318,7 @@ lp_build_polynomial(struct lp_build_context *bld,
|
|||
if (type.length == 1)
|
||||
coeff = LLVMConstReal(float_type, coeffs[i]);
|
||||
else
|
||||
coeff = lp_build_const_scalar(type, coeffs[i]);
|
||||
coeff = lp_build_const_vec(type, coeffs[i]);
|
||||
|
||||
if(res)
|
||||
res = lp_build_add(bld, coeff, lp_build_mul(bld, x, res));
|
||||
|
|
@ -1375,11 +1375,11 @@ lp_build_exp2_approx(struct lp_build_context *bld,
|
|||
|
||||
assert(type.floating && type.width == 32);
|
||||
|
||||
x = lp_build_min(bld, x, lp_build_const_scalar(type, 129.0));
|
||||
x = lp_build_max(bld, x, lp_build_const_scalar(type, -126.99999));
|
||||
x = lp_build_min(bld, x, lp_build_const_vec(type, 129.0));
|
||||
x = lp_build_max(bld, x, lp_build_const_vec(type, -126.99999));
|
||||
|
||||
/* ipart = int(x - 0.5) */
|
||||
ipart = LLVMBuildSub(bld->builder, x, lp_build_const_scalar(type, 0.5f), "");
|
||||
ipart = LLVMBuildSub(bld->builder, x, lp_build_const_vec(type, 0.5f), "");
|
||||
ipart = LLVMBuildFPToSI(bld->builder, ipart, int_vec_type, "");
|
||||
|
||||
/* fpart = x - ipart */
|
||||
|
|
@ -1389,8 +1389,8 @@ lp_build_exp2_approx(struct lp_build_context *bld,
|
|||
|
||||
if(p_exp2_int_part || p_exp2) {
|
||||
/* expipart = (float) (1 << ipart) */
|
||||
expipart = LLVMBuildAdd(bld->builder, ipart, lp_build_int_const_scalar(type, 127), "");
|
||||
expipart = LLVMBuildShl(bld->builder, expipart, lp_build_int_const_scalar(type, 23), "");
|
||||
expipart = LLVMBuildAdd(bld->builder, ipart, lp_build_const_int_vec(type, 127), "");
|
||||
expipart = LLVMBuildShl(bld->builder, expipart, lp_build_const_int_vec(type, 23), "");
|
||||
expipart = LLVMBuildBitCast(bld->builder, expipart, vec_type, "");
|
||||
}
|
||||
|
||||
|
|
@ -1456,8 +1456,8 @@ lp_build_log2_approx(struct lp_build_context *bld,
|
|||
LLVMTypeRef vec_type = lp_build_vec_type(type);
|
||||
LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
|
||||
|
||||
LLVMValueRef expmask = lp_build_int_const_scalar(type, 0x7f800000);
|
||||
LLVMValueRef mantmask = lp_build_int_const_scalar(type, 0x007fffff);
|
||||
LLVMValueRef expmask = lp_build_const_int_vec(type, 0x7f800000);
|
||||
LLVMValueRef mantmask = lp_build_const_int_vec(type, 0x007fffff);
|
||||
LLVMValueRef one = LLVMConstBitCast(bld->one, int_vec_type);
|
||||
|
||||
LLVMValueRef i = NULL;
|
||||
|
|
@ -1482,8 +1482,8 @@ lp_build_log2_approx(struct lp_build_context *bld,
|
|||
}
|
||||
|
||||
if(p_floor_log2 || p_log2) {
|
||||
logexp = LLVMBuildLShr(bld->builder, exp, lp_build_int_const_scalar(type, 23), "");
|
||||
logexp = LLVMBuildSub(bld->builder, logexp, lp_build_int_const_scalar(type, 127), "");
|
||||
logexp = LLVMBuildLShr(bld->builder, exp, lp_build_const_int_vec(type, 23), "");
|
||||
logexp = LLVMBuildSub(bld->builder, logexp, lp_build_const_int_vec(type, 127), "");
|
||||
logexp = LLVMBuildSIToFP(bld->builder, logexp, vec_type, "");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#define LP_BLD_ARIT_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
struct lp_type;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
* for a standalone example.
|
||||
*/
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
#include "pipe/p_format.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ lp_build_one(struct lp_type type)
|
|||
if(type.sign)
|
||||
/* TODO: Unfortunately this caused "Tried to create a shift operation
|
||||
* on a non-integer type!" */
|
||||
vec = LLVMConstLShr(vec, lp_build_int_const_scalar(type, 1));
|
||||
vec = LLVMConstLShr(vec, lp_build_const_int_vec(type, 1));
|
||||
#endif
|
||||
|
||||
return vec;
|
||||
|
|
@ -283,8 +283,8 @@ lp_build_one(struct lp_type type)
|
|||
* Build constant-valued vector from a scalar value.
|
||||
*/
|
||||
LLVMValueRef
|
||||
lp_build_const_scalar(struct lp_type type,
|
||||
double val)
|
||||
lp_build_const_vec(struct lp_type type,
|
||||
double val)
|
||||
{
|
||||
LLVMTypeRef elem_type = lp_build_elem_type(type);
|
||||
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
|
||||
|
|
@ -309,7 +309,7 @@ lp_build_const_scalar(struct lp_type type,
|
|||
|
||||
|
||||
LLVMValueRef
|
||||
lp_build_int_const_scalar(struct lp_type type,
|
||||
lp_build_const_int_vec(struct lp_type type,
|
||||
long long val)
|
||||
{
|
||||
LLVMTypeRef elem_type = lp_build_int_elem_type(type);
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@
|
|||
#define LP_BLD_CONST_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "pipe/p_compiler.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
#include <pipe/p_compiler.h>
|
||||
|
||||
|
||||
struct lp_type;
|
||||
|
|
@ -85,13 +85,11 @@ lp_build_one(struct lp_type type);
|
|||
|
||||
|
||||
LLVMValueRef
|
||||
lp_build_const_scalar(struct lp_type type,
|
||||
double val);
|
||||
lp_build_const_vec(struct lp_type type, double val);
|
||||
|
||||
|
||||
LLVMValueRef
|
||||
lp_build_int_const_scalar(struct lp_type type,
|
||||
long long val);
|
||||
lp_build_const_int_vec(struct lp_type type, long long val);
|
||||
|
||||
|
||||
LLVMValueRef
|
||||
|
|
|
|||
|
|
@ -114,13 +114,13 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
|
|||
scale = (double)mask/ubound;
|
||||
bias = (double)((unsigned long long)1 << (mantissa - n));
|
||||
|
||||
res = LLVMBuildMul(builder, src, lp_build_const_scalar(src_type, scale), "");
|
||||
res = LLVMBuildAdd(builder, res, lp_build_const_scalar(src_type, bias), "");
|
||||
res = LLVMBuildMul(builder, src, lp_build_const_vec(src_type, scale), "");
|
||||
res = LLVMBuildAdd(builder, res, lp_build_const_vec(src_type, bias), "");
|
||||
res = LLVMBuildBitCast(builder, res, int_vec_type, "");
|
||||
|
||||
if(dst_width > n) {
|
||||
int shift = dst_width - n;
|
||||
res = LLVMBuildShl(builder, res, lp_build_int_const_scalar(src_type, shift), "");
|
||||
res = LLVMBuildShl(builder, res, lp_build_const_int_vec(src_type, shift), "");
|
||||
|
||||
/* TODO: Fill in the empty lower bits for additional precision? */
|
||||
/* YES: this fixes progs/trivial/tri-z-eq.c.
|
||||
|
|
@ -130,21 +130,21 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
|
|||
#if 0
|
||||
{
|
||||
LLVMValueRef msb;
|
||||
msb = LLVMBuildLShr(builder, res, lp_build_int_const_scalar(src_type, dst_width - 1), "");
|
||||
msb = LLVMBuildShl(builder, msb, lp_build_int_const_scalar(src_type, shift), "");
|
||||
msb = LLVMBuildSub(builder, msb, lp_build_int_const_scalar(src_type, 1), "");
|
||||
msb = LLVMBuildLShr(builder, res, lp_build_const_int_vec(src_type, dst_width - 1), "");
|
||||
msb = LLVMBuildShl(builder, msb, lp_build_const_int_vec(src_type, shift), "");
|
||||
msb = LLVMBuildSub(builder, msb, lp_build_const_int_vec(src_type, 1), "");
|
||||
res = LLVMBuildOr(builder, res, msb, "");
|
||||
}
|
||||
#elif 0
|
||||
while(shift > 0) {
|
||||
res = LLVMBuildOr(builder, res, LLVMBuildLShr(builder, res, lp_build_int_const_scalar(src_type, n), ""), "");
|
||||
res = LLVMBuildOr(builder, res, LLVMBuildLShr(builder, res, lp_build_const_int_vec(src_type, n), ""), "");
|
||||
shift -= n;
|
||||
n *= 2;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
res = LLVMBuildAnd(builder, res, lp_build_int_const_scalar(src_type, mask), "");
|
||||
res = LLVMBuildAnd(builder, res, lp_build_const_int_vec(src_type, mask), "");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -183,10 +183,10 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
|
|||
|
||||
if(src_width > mantissa) {
|
||||
int shift = src_width - mantissa;
|
||||
res = LLVMBuildLShr(builder, res, lp_build_int_const_scalar(dst_type, shift), "");
|
||||
res = LLVMBuildLShr(builder, res, lp_build_const_int_vec(dst_type, shift), "");
|
||||
}
|
||||
|
||||
bias_ = lp_build_const_scalar(dst_type, bias);
|
||||
bias_ = lp_build_const_vec(dst_type, bias);
|
||||
|
||||
res = LLVMBuildOr(builder,
|
||||
res,
|
||||
|
|
@ -195,7 +195,7 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
|
|||
res = LLVMBuildBitCast(builder, res, vec_type, "");
|
||||
|
||||
res = LLVMBuildSub(builder, res, bias_, "");
|
||||
res = LLVMBuildMul(builder, res, lp_build_const_scalar(dst_type, scale), "");
|
||||
res = LLVMBuildMul(builder, res, lp_build_const_vec(dst_type, scale), "");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ lp_build_conv(LLVMBuilderRef builder,
|
|||
if(dst_min == 0.0)
|
||||
thres = bld.zero;
|
||||
else
|
||||
thres = lp_build_const_scalar(src_type, dst_min);
|
||||
thres = lp_build_const_vec(src_type, dst_min);
|
||||
for(i = 0; i < num_tmps; ++i)
|
||||
tmp[i] = lp_build_max(&bld, tmp[i], thres);
|
||||
}
|
||||
|
|
@ -260,7 +260,7 @@ lp_build_conv(LLVMBuilderRef builder,
|
|||
if(dst_max == 1.0)
|
||||
thres = bld.one;
|
||||
else
|
||||
thres = lp_build_const_scalar(src_type, dst_max);
|
||||
thres = lp_build_const_vec(src_type, dst_max);
|
||||
for(i = 0; i < num_tmps; ++i)
|
||||
tmp[i] = lp_build_min(&bld, tmp[i], thres);
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ lp_build_conv(LLVMBuilderRef builder,
|
|||
LLVMTypeRef tmp_vec_type;
|
||||
|
||||
if (dst_scale != 1.0) {
|
||||
LLVMValueRef scale = lp_build_const_scalar(tmp_type, dst_scale);
|
||||
LLVMValueRef scale = lp_build_const_vec(tmp_type, dst_scale);
|
||||
for(i = 0; i < num_tmps; ++i)
|
||||
tmp[i] = LLVMBuildMul(builder, tmp[i], scale, "");
|
||||
}
|
||||
|
|
@ -315,7 +315,7 @@ lp_build_conv(LLVMBuilderRef builder,
|
|||
|
||||
/* FIXME: compensate different offsets too */
|
||||
if(src_shift > dst_shift) {
|
||||
LLVMValueRef shift = lp_build_int_const_scalar(tmp_type, src_shift - dst_shift);
|
||||
LLVMValueRef shift = lp_build_const_int_vec(tmp_type, src_shift - dst_shift);
|
||||
for(i = 0; i < num_tmps; ++i)
|
||||
if(src_type.sign)
|
||||
tmp[i] = LLVMBuildAShr(builder, tmp[i], shift, "");
|
||||
|
|
@ -388,7 +388,7 @@ lp_build_conv(LLVMBuilderRef builder,
|
|||
}
|
||||
|
||||
if (src_scale != 1.0) {
|
||||
LLVMValueRef scale = lp_build_const_scalar(tmp_type, 1.0/src_scale);
|
||||
LLVMValueRef scale = lp_build_const_vec(tmp_type, 1.0/src_scale);
|
||||
for(i = 0; i < num_tmps; ++i)
|
||||
tmp[i] = LLVMBuildMul(builder, tmp[i], scale, "");
|
||||
}
|
||||
|
|
@ -400,7 +400,7 @@ lp_build_conv(LLVMBuilderRef builder,
|
|||
|
||||
/* FIXME: compensate different offsets too */
|
||||
if(src_shift < dst_shift) {
|
||||
LLVMValueRef shift = lp_build_int_const_scalar(tmp_type, dst_shift - src_shift);
|
||||
LLVMValueRef shift = lp_build_const_int_vec(tmp_type, dst_shift - src_shift);
|
||||
for(i = 0; i < num_tmps; ++i)
|
||||
tmp[i] = LLVMBuildShl(builder, tmp[i], shift, "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#define LP_BLD_CONV_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
struct lp_type;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#define LP_BLD_DEBUG_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
#include "pipe/p_compiler.h"
|
||||
#include "util/u_string.h"
|
||||
|
|
|
|||
|
|
@ -52,7 +52,14 @@
|
|||
* Z31 Z32 Z41 Z42 Z33 Z34 Z43 Z44 ...
|
||||
* ... ... ... ... ... ... ... ... ...
|
||||
*
|
||||
* FIXME: Code generate stencil test
|
||||
*
|
||||
* Stencil test:
|
||||
* Two-sided stencil test is supported but probably not as efficient as
|
||||
* it could be. Currently, we use if/then/else constructs to do the
|
||||
* operations for front vs. back-facing polygons. We could probably do
|
||||
* both the front and back arithmetic then use a Select() instruction to
|
||||
* choose the result depending on polyon orientation. We'd have to
|
||||
* measure performance both ways and see which is better.
|
||||
*
|
||||
* @author Jose Fonseca <jfonseca@vmware.com>
|
||||
*/
|
||||
|
|
@ -61,11 +68,264 @@
|
|||
#include "util/u_format.h"
|
||||
|
||||
#include "lp_bld_type.h"
|
||||
#include "lp_bld_arit.h"
|
||||
#include "lp_bld_const.h"
|
||||
#include "lp_bld_logic.h"
|
||||
#include "lp_bld_flow.h"
|
||||
#include "lp_bld_debug.h"
|
||||
#include "lp_bld_depth.h"
|
||||
#include "lp_bld_swizzle.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)
|
||||
{
|
||||
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(type, stencil->valuemask);
|
||||
stencilRef = LLVMBuildAnd(bld->builder, stencilRef, valuemask, "");
|
||||
/* compute stencilVals = stencilVals & valuemask */
|
||||
stencilVals = LLVMBuildAnd(bld->builder, stencilVals, valuemask, "");
|
||||
}
|
||||
|
||||
res = lp_build_cmp(bld, stencil->func, stencilVals, stencilRef);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do the one or two-sided stencil test comparison.
|
||||
* \sa lp_build_stencil_test_single
|
||||
* \param face an integer indicating front (+) or back (-) 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 face)
|
||||
{
|
||||
LLVMValueRef res;
|
||||
|
||||
assert(stencil[0].enabled);
|
||||
|
||||
if (stencil[1].enabled && face) {
|
||||
/* do two-sided test */
|
||||
struct lp_build_flow_context *flow_ctx;
|
||||
struct lp_build_if_state if_ctx;
|
||||
LLVMValueRef front_facing;
|
||||
LLVMValueRef zero = LLVMConstReal(LLVMFloatType(), 0.0);
|
||||
LLVMValueRef result = bld->undef;
|
||||
|
||||
flow_ctx = lp_build_flow_create(bld->builder);
|
||||
lp_build_flow_scope_begin(flow_ctx);
|
||||
|
||||
lp_build_flow_scope_declare(flow_ctx, &result);
|
||||
|
||||
/* front_facing = face > 0.0 */
|
||||
front_facing = LLVMBuildFCmp(bld->builder, LLVMRealUGT, face, zero, "");
|
||||
|
||||
lp_build_if(&if_ctx, flow_ctx, bld->builder, front_facing);
|
||||
{
|
||||
result = lp_build_stencil_test_single(bld, &stencil[0],
|
||||
stencilRefs[0], stencilVals);
|
||||
}
|
||||
lp_build_else(&if_ctx);
|
||||
{
|
||||
result = lp_build_stencil_test_single(bld, &stencil[1],
|
||||
stencilRefs[1], stencilVals);
|
||||
}
|
||||
lp_build_endif(&if_ctx);
|
||||
|
||||
lp_build_flow_scope_end(flow_ctx);
|
||||
lp_build_flow_destroy(flow_ctx);
|
||||
|
||||
res = result;
|
||||
}
|
||||
else {
|
||||
/* do single-side test */
|
||||
res = lp_build_stencil_test_single(bld, &stencil[0],
|
||||
stencilRefs[0], stencilVals);
|
||||
}
|
||||
|
||||
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,
|
||||
LLVMValueRef mask)
|
||||
|
||||
{
|
||||
const unsigned stencilMax = 255; /* XXX fix */
|
||||
struct lp_type type = bld->type;
|
||||
LLVMValueRef res;
|
||||
LLVMValueRef max = lp_build_const_int_vec(type, stencilMax);
|
||||
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(bld->builder, res, max, "");
|
||||
break;
|
||||
case PIPE_STENCIL_OP_DECR_WRAP:
|
||||
res = lp_build_sub(bld, stencilVals, bld->one);
|
||||
res = LLVMBuildAnd(bld->builder, res, max, "");
|
||||
break;
|
||||
case PIPE_STENCIL_OP_INVERT:
|
||||
res = LLVMBuildNot(bld->builder, stencilVals, "");
|
||||
res = LLVMBuildAnd(bld->builder, res, max, "");
|
||||
break;
|
||||
default:
|
||||
assert(0 && "bad stencil op mode");
|
||||
res = NULL;
|
||||
}
|
||||
|
||||
if (stencil->writemask != stencilMax) {
|
||||
/* compute res = (res & mask) | (stencilVals & ~mask) */
|
||||
LLVMValueRef mask = lp_build_const_int_vec(type, stencil->writemask);
|
||||
LLVMValueRef cmask = LLVMBuildNot(bld->builder, mask, "notWritemask");
|
||||
LLVMValueRef t1 = LLVMBuildAnd(bld->builder, res, mask, "t1");
|
||||
LLVMValueRef t2 = LLVMBuildAnd(bld->builder, stencilVals, cmask, "t2");
|
||||
res = LLVMBuildOr(bld->builder, t1, t2, "t1_or_t2");
|
||||
}
|
||||
|
||||
/* only the update the vector elements enabled by 'mask' */
|
||||
res = lp_build_select(bld, mask, res, stencilVals);
|
||||
|
||||
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 face)
|
||||
|
||||
{
|
||||
assert(stencil[0].enabled);
|
||||
|
||||
if (stencil[1].enabled && face) {
|
||||
/* do two-sided op */
|
||||
struct lp_build_flow_context *flow_ctx;
|
||||
struct lp_build_if_state if_ctx;
|
||||
LLVMValueRef front_facing;
|
||||
LLVMValueRef zero = LLVMConstReal(LLVMFloatType(), 0.0);
|
||||
LLVMValueRef result = bld->undef;
|
||||
|
||||
flow_ctx = lp_build_flow_create(bld->builder);
|
||||
lp_build_flow_scope_begin(flow_ctx);
|
||||
|
||||
lp_build_flow_scope_declare(flow_ctx, &result);
|
||||
|
||||
/* front_facing = face > 0.0 */
|
||||
front_facing = LLVMBuildFCmp(bld->builder, LLVMRealUGT, face, zero, "");
|
||||
|
||||
lp_build_if(&if_ctx, flow_ctx, bld->builder, front_facing);
|
||||
{
|
||||
result = lp_build_stencil_op_single(bld, &stencil[0], op,
|
||||
stencilRefs[0], stencilVals, mask);
|
||||
}
|
||||
lp_build_else(&if_ctx);
|
||||
{
|
||||
result = lp_build_stencil_op_single(bld, &stencil[1], op,
|
||||
stencilRefs[1], stencilVals, mask);
|
||||
}
|
||||
lp_build_endif(&if_ctx);
|
||||
|
||||
lp_build_flow_scope_end(flow_ctx);
|
||||
lp_build_flow_destroy(flow_ctx);
|
||||
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
/* do single-sided op */
|
||||
return lp_build_stencil_op_single(bld, &stencil[0], op,
|
||||
stencilRefs[0], stencilVals, mask);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -109,105 +369,303 @@ lp_depth_type(const struct util_format_description *format_desc,
|
|||
|
||||
|
||||
/**
|
||||
* Depth test.
|
||||
* 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.
|
||||
*/
|
||||
void
|
||||
lp_build_depth_test(LLVMBuilderRef builder,
|
||||
const struct pipe_depth_state *state,
|
||||
struct lp_type type,
|
||||
const struct util_format_description *format_desc,
|
||||
struct lp_build_mask_context *mask,
|
||||
LLVMValueRef src,
|
||||
LLVMValueRef dst_ptr)
|
||||
static boolean
|
||||
get_z_shift_and_mask(const struct util_format_description *format_desc,
|
||||
unsigned *shift, unsigned *mask)
|
||||
{
|
||||
struct lp_build_context bld;
|
||||
const unsigned total_bits = format_desc->block.bits;
|
||||
unsigned z_swizzle;
|
||||
LLVMValueRef dst;
|
||||
LLVMValueRef z_bitmask = NULL;
|
||||
LLVMValueRef test;
|
||||
|
||||
if(!state->enabled)
|
||||
return;
|
||||
|
||||
int 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;
|
||||
|
||||
if (z_swizzle == UTIL_FORMAT_SWIZZLE_NONE)
|
||||
return FALSE;
|
||||
|
||||
padding_right = 0;
|
||||
for (chan = 0; chan < z_swizzle; ++chan)
|
||||
padding_right += format_desc->channel[chan].size;
|
||||
|
||||
padding_left =
|
||||
total_bits - (padding_right + format_desc->channel[z_swizzle].size);
|
||||
|
||||
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_left;
|
||||
|
||||
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;
|
||||
int 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* \param zs_dst_ptr pointer to depth/stencil values in framebuffer
|
||||
* \param facing contains float value indicating front/back facing polygon
|
||||
*/
|
||||
void
|
||||
lp_build_depth_stencil_test(LLVMBuilderRef builder,
|
||||
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 z_src,
|
||||
LLVMValueRef zs_dst_ptr,
|
||||
LLVMValueRef face)
|
||||
{
|
||||
struct lp_build_context bld;
|
||||
struct lp_build_context sbld;
|
||||
struct lp_type s_type;
|
||||
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 = mask->value;
|
||||
|
||||
/* Sanity checking */
|
||||
assert(z_swizzle < 4);
|
||||
assert(format_desc->block.bits == type.width);
|
||||
if(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(!type.fixed);
|
||||
assert(!type.sign);
|
||||
assert(type.norm);
|
||||
}
|
||||
{
|
||||
const unsigned z_swizzle = format_desc->swizzle[0];
|
||||
const unsigned s_swizzle = format_desc->swizzle[1];
|
||||
|
||||
/* Setup build context */
|
||||
lp_build_context_init(&bld, builder, type);
|
||||
assert(z_swizzle != UTIL_FORMAT_SWIZZLE_NONE ||
|
||||
s_swizzle != UTIL_FORMAT_SWIZZLE_NONE);
|
||||
|
||||
dst = LLVMBuildLoad(builder, dst_ptr, "");
|
||||
assert(depth->enabled || stencil[0].enabled);
|
||||
|
||||
lp_build_name(dst, "zsbuf");
|
||||
assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS);
|
||||
assert(format_desc->block.width == 1);
|
||||
assert(format_desc->block.height == 1);
|
||||
|
||||
/* Align the source depth bits with the destination's, and mask out any
|
||||
* stencil or padding bits from both */
|
||||
if(format_desc->channel[z_swizzle].size == format_desc->block.bits) {
|
||||
assert(z_swizzle == 0);
|
||||
/* nothing to do */
|
||||
}
|
||||
else {
|
||||
unsigned padding_left;
|
||||
unsigned padding_right;
|
||||
unsigned chan;
|
||||
|
||||
assert(format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN);
|
||||
assert(format_desc->channel[z_swizzle].type == UTIL_FORMAT_TYPE_UNSIGNED);
|
||||
assert(format_desc->channel[z_swizzle].size <= format_desc->block.bits);
|
||||
assert(format_desc->channel[z_swizzle].normalized);
|
||||
|
||||
padding_right = 0;
|
||||
for(chan = 0; chan < z_swizzle; ++chan)
|
||||
padding_right += format_desc->channel[chan].size;
|
||||
padding_left = format_desc->block.bits -
|
||||
(padding_right + format_desc->channel[z_swizzle].size);
|
||||
|
||||
if(padding_left || padding_right) {
|
||||
const unsigned long long mask_left = ((unsigned long long)1 << (format_desc->block.bits - padding_left)) - 1;
|
||||
const unsigned long long mask_right = ((unsigned long long)1 << (padding_right)) - 1;
|
||||
z_bitmask = lp_build_int_const_scalar(type, mask_left ^ mask_right);
|
||||
if (stencil[0].enabled) {
|
||||
assert(format_desc->format == PIPE_FORMAT_Z24S8_UNORM ||
|
||||
format_desc->format == PIPE_FORMAT_S8Z24_UNORM);
|
||||
}
|
||||
|
||||
if(padding_left)
|
||||
src = LLVMBuildLShr(builder, src, lp_build_int_const_scalar(type, padding_left), "");
|
||||
if(padding_right)
|
||||
src = LLVMBuildAnd(builder, src, z_bitmask, "");
|
||||
if(padding_left || padding_right)
|
||||
dst = LLVMBuildAnd(builder, dst, z_bitmask, "");
|
||||
assert(z_swizzle < 4);
|
||||
assert(format_desc->block.bits == type.width);
|
||||
if (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(!type.fixed);
|
||||
assert(!type.sign);
|
||||
assert(type.norm);
|
||||
}
|
||||
}
|
||||
|
||||
lp_build_name(dst, "zsbuf.z");
|
||||
|
||||
test = lp_build_cmp(&bld, state->func, src, dst);
|
||||
lp_build_mask_update(mask, test);
|
||||
/* Setup build context for Z vals */
|
||||
lp_build_context_init(&bld, builder, type);
|
||||
|
||||
if(state->writemask) {
|
||||
if(z_bitmask)
|
||||
z_bitmask = LLVMBuildAnd(builder, mask->value, z_bitmask, "");
|
||||
/* Setup build context for stencil vals */
|
||||
s_type = lp_type_int_vec(type.width);
|
||||
lp_build_context_init(&sbld, builder, s_type);
|
||||
|
||||
/* Load current z/stencil value from z/stencil buffer */
|
||||
zs_dst = LLVMBuildLoad(builder, zs_dst_ptr, "");
|
||||
|
||||
lp_build_name(zs_dst, "zsbufval");
|
||||
|
||||
|
||||
/* Compute and apply the Z/stencil bitmasks and shifts.
|
||||
*/
|
||||
{
|
||||
unsigned z_shift, z_mask;
|
||||
unsigned s_shift, s_mask;
|
||||
|
||||
if (get_z_shift_and_mask(format_desc, &z_shift, &z_mask)) {
|
||||
if (z_shift) {
|
||||
LLVMValueRef shift = lp_build_const_int_vec(type, z_shift);
|
||||
z_src = LLVMBuildLShr(builder, z_src, shift, "");
|
||||
}
|
||||
|
||||
if (z_mask != 0xffffffff) {
|
||||
LLVMValueRef mask = lp_build_const_int_vec(type, z_mask);
|
||||
z_src = LLVMBuildAnd(builder, z_src, mask, "");
|
||||
z_dst = LLVMBuildAnd(builder, zs_dst, mask, "");
|
||||
z_bitmask = mask; /* used below */
|
||||
}
|
||||
else {
|
||||
z_dst = zs_dst;
|
||||
}
|
||||
|
||||
lp_build_name(z_dst, "zsbuf.z");
|
||||
}
|
||||
|
||||
if (get_s_shift_and_mask(format_desc, &s_shift, &s_mask)) {
|
||||
if (s_shift) {
|
||||
LLVMValueRef shift = lp_build_const_int_vec(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(type, s_mask);
|
||||
stencil_vals = LLVMBuildAnd(builder, stencil_vals, mask, "");
|
||||
}
|
||||
|
||||
lp_build_name(stencil_vals, "stencil");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (stencil[0].enabled) {
|
||||
/* convert scalar stencil refs into vectors */
|
||||
stencil_refs[0] = lp_build_broadcast_scalar(&bld, stencil_refs[0]);
|
||||
stencil_refs[1] = lp_build_broadcast_scalar(&bld, stencil_refs[1]);
|
||||
|
||||
s_pass_mask = lp_build_stencil_test(&sbld, stencil,
|
||||
stencil_refs, stencil_vals, face);
|
||||
|
||||
/* apply stencil-fail operator */
|
||||
{
|
||||
LLVMValueRef s_fail_mask = lp_build_andc(&bld, orig_mask, s_pass_mask);
|
||||
stencil_vals = lp_build_stencil_op(&sbld, stencil, S_FAIL_OP,
|
||||
stencil_refs, stencil_vals,
|
||||
s_fail_mask, face);
|
||||
}
|
||||
}
|
||||
|
||||
if (depth->enabled) {
|
||||
/* compare src Z to dst Z, returning 'pass' mask */
|
||||
z_pass = lp_build_cmp(&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 (depth->writemask) {
|
||||
if(z_bitmask)
|
||||
z_bitmask = LLVMBuildAnd(builder, mask->value, z_bitmask, "");
|
||||
else
|
||||
z_bitmask = mask->value;
|
||||
|
||||
z_dst = lp_build_select(&bld, z_bitmask, 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_andc(&bld, orig_mask, z_pass);
|
||||
stencil_vals = lp_build_stencil_op(&sbld, stencil, Z_FAIL_OP,
|
||||
stencil_refs, stencil_vals,
|
||||
z_fail_mask, face);
|
||||
|
||||
/* apply Z-pass operator */
|
||||
z_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, z_pass, "");
|
||||
stencil_vals = lp_build_stencil_op(&sbld, stencil, Z_PASS_OP,
|
||||
stencil_refs, stencil_vals,
|
||||
z_pass_mask, face);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* No depth test: apply Z-pass operator to stencil buffer values which
|
||||
* passed the stencil test.
|
||||
*/
|
||||
s_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, s_pass_mask, "");
|
||||
stencil_vals = lp_build_stencil_op(&sbld, stencil, Z_PASS_OP,
|
||||
stencil_refs, stencil_vals,
|
||||
s_pass_mask, face);
|
||||
}
|
||||
|
||||
/* The Z bits are already in the right place but we may need to shift the
|
||||
* stencil bits before ORing Z with Stencil to make the final pixel value.
|
||||
*/
|
||||
if (stencil_vals && stencil_shift)
|
||||
stencil_vals = LLVMBuildShl(bld.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(bld.builder, z_dst, stencil_vals, "");
|
||||
else if (z_dst)
|
||||
zs_dst = z_dst;
|
||||
else
|
||||
z_bitmask = mask->value;
|
||||
zs_dst = stencil_vals;
|
||||
|
||||
dst = lp_build_select(&bld, z_bitmask, src, dst);
|
||||
LLVMBuildStore(builder, dst, dst_ptr);
|
||||
LLVMBuildStore(builder, zs_dst, zs_dst_ptr);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#define LP_BLD_DEPTH_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
struct pipe_depth_state;
|
||||
|
|
@ -51,13 +51,16 @@ lp_depth_type(const struct util_format_description *format_desc,
|
|||
|
||||
|
||||
void
|
||||
lp_build_depth_test(LLVMBuilderRef builder,
|
||||
const struct pipe_depth_state *state,
|
||||
struct lp_type type,
|
||||
const struct util_format_description *format_desc,
|
||||
struct lp_build_mask_context *mask,
|
||||
LLVMValueRef src,
|
||||
LLVMValueRef dst_ptr);
|
||||
lp_build_depth_stencil_test(LLVMBuilderRef builder,
|
||||
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);
|
||||
|
||||
|
||||
#endif /* !LP_BLD_DEPTH_H */
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
#define LP_BLD_FLOW_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
struct lp_type;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
* Pixel format helpers.
|
||||
*/
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
#include "pipe/p_format.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -114,10 +114,10 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
|
|||
case UTIL_FORMAT_TYPE_UNSIGNED:
|
||||
if(type.floating) {
|
||||
if(start)
|
||||
input = LLVMBuildLShr(builder, input, lp_build_int_const_scalar(type, start), "");
|
||||
input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(type, start), "");
|
||||
if(stop < format_desc->block.bits) {
|
||||
unsigned mask = ((unsigned long long)1 << width) - 1;
|
||||
input = LLVMBuildAnd(builder, input, lp_build_int_const_scalar(type, mask), "");
|
||||
input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(type, mask), "");
|
||||
}
|
||||
|
||||
if(format_desc->channel[chan].normalized)
|
||||
|
|
|
|||
|
|
@ -289,17 +289,17 @@ pos_update(struct lp_build_interp_soa_context *bld, int quad_index)
|
|||
/* top-right or bottom-right quad in block */
|
||||
/* build x += xstep */
|
||||
x = lp_build_add(&bld->base, x,
|
||||
lp_build_const_scalar(bld->base.type, xstep));
|
||||
lp_build_const_vec(bld->base.type, xstep));
|
||||
}
|
||||
|
||||
if (quad_index == 2) {
|
||||
/* bottom-left quad in block */
|
||||
/* build y += ystep */
|
||||
y = lp_build_add(&bld->base, y,
|
||||
lp_build_const_scalar(bld->base.type, ystep));
|
||||
lp_build_const_vec(bld->base.type, ystep));
|
||||
/* build x -= xstep */
|
||||
x = lp_build_sub(&bld->base, x,
|
||||
lp_build_const_scalar(bld->base.type, xstep));
|
||||
lp_build_const_vec(bld->base.type, xstep));
|
||||
}
|
||||
|
||||
lp_build_name(x, "pos.x");
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
#define LP_BLD_INTERP_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
#include "tgsi/tgsi_exec.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#define LP_BLD_INTR_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ lp_build_compare(LLVMBuilderRef builder,
|
|||
if(table[func].gt &&
|
||||
((type.width == 8 && type.sign) ||
|
||||
(type.width != 8 && !type.sign))) {
|
||||
LLVMValueRef msb = lp_build_int_const_scalar(type, (unsigned long long)1 << (type.width - 1));
|
||||
LLVMValueRef msb = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
|
||||
a = LLVMBuildXor(builder, a, msb, "");
|
||||
b = LLVMBuildXor(builder, b, msb, "");
|
||||
}
|
||||
|
|
@ -483,3 +483,13 @@ lp_build_alloca(struct lp_build_context *bld)
|
|||
return LLVMBuildAlloca(bld->builder, lp_build_elem_type(type), "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Return (a & ~b) */
|
||||
LLVMValueRef
|
||||
lp_build_andc(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
|
||||
{
|
||||
b = LLVMBuildNot(bld->builder, b, "");
|
||||
b = LLVMBuildAnd(bld->builder, a, b, "");
|
||||
return b;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#define LP_BLD_LOGIC_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
#include "pipe/p_defines.h" /* For PIPE_FUNC_xxx */
|
||||
|
||||
|
|
@ -79,4 +79,9 @@ lp_build_select_aos(struct lp_build_context *bld,
|
|||
LLVMValueRef
|
||||
lp_build_alloca(struct lp_build_context *bld);
|
||||
|
||||
|
||||
LLVMValueRef
|
||||
lp_build_andc(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b);
|
||||
|
||||
|
||||
#endif /* !LP_BLD_LOGIC_H */
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ lp_build_unpack2(LLVMBuilderRef builder,
|
|||
|
||||
if(dst_type.sign && src_type.sign) {
|
||||
/* Replicate the sign bit in the most significant bits */
|
||||
msb = LLVMBuildAShr(builder, src, lp_build_int_const_scalar(src_type, src_type.width - 1), "");
|
||||
msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(src_type, src_type.width - 1), "");
|
||||
}
|
||||
else
|
||||
/* Most significant bits always zero */
|
||||
|
|
@ -361,7 +361,7 @@ lp_build_packs2(LLVMBuilderRef builder,
|
|||
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_int_const_scalar(src_type, ((unsigned long long)1 << dst_bits) - 1);
|
||||
LLVMValueRef dst_max = lp_build_const_int_vec(src_type, ((unsigned long long)1 << dst_bits) - 1);
|
||||
lp_build_context_init(&bld, builder, src_type);
|
||||
lo = lp_build_min(&bld, lo, dst_max);
|
||||
hi = lp_build_min(&bld, hi, dst_max);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#define LP_BLD_PACK_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
struct lp_type;
|
||||
|
|
|
|||
113
src/gallium/auxiliary/gallivm/lp_bld_printf.c
Normal file
113
src/gallium/auxiliary/gallivm/lp_bld_printf.c
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
|
||||
#include "util/u_debug.h"
|
||||
#include "util/u_memory.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;
|
||||
}
|
||||
default:
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
LLVMValueRef
|
||||
lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len)
|
||||
{
|
||||
LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8Type(), len + 1), "");
|
||||
LLVMSetGlobalConstant(string, TRUE);
|
||||
LLVMSetLinkage(string, LLVMInternalLinkage);
|
||||
LLVMSetInitializer(string, LLVMConstString(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(LLVMBuilderRef builder, const char *fmt, ...)
|
||||
{
|
||||
va_list arglist;
|
||||
int i = 0;
|
||||
int argcount = lp_get_printf_arg_count(fmt);
|
||||
LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
|
||||
LLVMValueRef params[50];
|
||||
LLVMValueRef fmtarg = lp_build_const_string_variable(module, fmt, strlen(fmt) + 1);
|
||||
LLVMValueRef int0 = LLVMConstInt(LLVMInt32Type(), 0, 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(LLVMIntType(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++)
|
||||
params[i] = va_arg(arglist, LLVMValueRef);
|
||||
va_end(arglist);
|
||||
|
||||
return LLVMBuildCall(builder, func_printf, params, argcount + 1, "");
|
||||
}
|
||||
|
||||
39
src/gallium/auxiliary/gallivm/lp_bld_printf.h
Normal file
39
src/gallium/auxiliary/gallivm/lp_bld_printf.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
* 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"
|
||||
|
||||
LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len);
|
||||
LLVMValueRef lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ lp_build_sample_offset(struct lp_build_context *bld,
|
|||
LLVMValueRef x_stride;
|
||||
LLVMValueRef offset;
|
||||
|
||||
x_stride = lp_build_const_scalar(bld->type, format_desc->block.bits/8);
|
||||
x_stride = lp_build_const_vec(bld->type, format_desc->block.bits/8);
|
||||
|
||||
if(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
|
||||
LLVMValueRef x_lo, x_hi;
|
||||
|
|
@ -195,9 +195,9 @@ lp_build_sample_offset(struct lp_build_context *bld,
|
|||
y_hi = LLVMBuildLShr(bld->builder, y, bld->one, "");
|
||||
|
||||
x_stride_lo = x_stride;
|
||||
y_stride_lo = lp_build_const_scalar(bld->type, 2*format_desc->block.bits/8);
|
||||
y_stride_lo = lp_build_const_vec(bld->type, 2*format_desc->block.bits/8);
|
||||
|
||||
x_stride_hi = lp_build_const_scalar(bld->type, 4*format_desc->block.bits/8);
|
||||
x_stride_hi = lp_build_const_vec(bld->type, 4*format_desc->block.bits/8);
|
||||
y_stride_hi = LLVMBuildShl(bld->builder, y_stride, bld->one, "");
|
||||
|
||||
x_offset_lo = lp_build_mul(bld, x_lo, x_stride_lo);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#define LP_BLD_SAMPLE_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
struct pipe_texture;
|
||||
struct pipe_sampler_state;
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
|
|||
int chan;
|
||||
for (chan = 0; chan < 4; chan++) {
|
||||
LLVMValueRef border_chan =
|
||||
lp_build_const_scalar(bld->texel_type,
|
||||
lp_build_const_vec(bld->texel_type,
|
||||
bld->static_state->border_color[chan]);
|
||||
texel[chan] = lp_build_select(&bld->texel_bld, use_border,
|
||||
border_chan, texel[chan]);
|
||||
|
|
@ -457,8 +457,8 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
|
|||
struct lp_build_context *coord_bld = &bld->coord_bld;
|
||||
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
|
||||
struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld;
|
||||
LLVMValueRef two = lp_build_const_scalar(coord_bld->type, 2.0);
|
||||
LLVMValueRef half = lp_build_const_scalar(coord_bld->type, 0.5);
|
||||
LLVMValueRef two = lp_build_const_vec(coord_bld->type, 2.0);
|
||||
LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
|
||||
LLVMValueRef length_f = lp_build_int_to_float(coord_bld, length);
|
||||
LLVMValueRef length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one);
|
||||
LLVMValueRef length_f_minus_one = lp_build_sub(coord_bld, length_f, coord_bld->one);
|
||||
|
|
@ -512,7 +512,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
|
|||
else {
|
||||
LLVMValueRef min, max;
|
||||
/* clamp to [0.5, length - 0.5] */
|
||||
min = lp_build_const_scalar(coord_bld->type, 0.5F);
|
||||
min = lp_build_const_vec(coord_bld->type, 0.5F);
|
||||
max = lp_build_sub(coord_bld, length_f, min);
|
||||
coord = lp_build_clamp(coord_bld, coord, min, max);
|
||||
}
|
||||
|
|
@ -533,7 +533,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
|
|||
if (bld->static_state->normalized_coords) {
|
||||
/* min = -1.0 / (2 * length) = -0.5 / length */
|
||||
min = lp_build_mul(coord_bld,
|
||||
lp_build_const_scalar(coord_bld->type, -0.5F),
|
||||
lp_build_const_vec(coord_bld->type, -0.5F),
|
||||
lp_build_rcp(coord_bld, length_f));
|
||||
/* max = 1.0 - min */
|
||||
max = lp_build_sub(coord_bld, coord_bld->one, min);
|
||||
|
|
@ -545,7 +545,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
|
|||
}
|
||||
else {
|
||||
/* clamp to [-0.5, length + 0.5] */
|
||||
min = lp_build_const_scalar(coord_bld->type, -0.5F);
|
||||
min = lp_build_const_vec(coord_bld->type, -0.5F);
|
||||
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);
|
||||
|
|
@ -620,7 +620,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
|
|||
LLVMValueRef min, max;
|
||||
/* min = -1.0 / (2 * length) = -0.5 / length */
|
||||
min = lp_build_mul(coord_bld,
|
||||
lp_build_const_scalar(coord_bld->type, -0.5F),
|
||||
lp_build_const_vec(coord_bld->type, -0.5F),
|
||||
lp_build_rcp(coord_bld, length_f));
|
||||
/* max = 1.0 - min */
|
||||
max = lp_build_sub(coord_bld, coord_bld->one, min);
|
||||
|
|
@ -665,7 +665,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
|
|||
struct lp_build_context *coord_bld = &bld->coord_bld;
|
||||
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
|
||||
struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld;
|
||||
LLVMValueRef two = lp_build_const_scalar(coord_bld->type, 2.0);
|
||||
LLVMValueRef two = lp_build_const_vec(coord_bld->type, 2.0);
|
||||
LLVMValueRef length_f = lp_build_int_to_float(coord_bld, length);
|
||||
LLVMValueRef length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one);
|
||||
LLVMValueRef length_f_minus_one = lp_build_sub(coord_bld, length_f, coord_bld->one);
|
||||
|
|
@ -708,7 +708,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
|
|||
}
|
||||
else {
|
||||
/* clamp to [0.5, length - 0.5] */
|
||||
min = lp_build_const_scalar(coord_bld->type, 0.5F);
|
||||
min = lp_build_const_vec(coord_bld->type, 0.5F);
|
||||
max = lp_build_sub(coord_bld, length_f, min);
|
||||
}
|
||||
/* coord = clamp(coord, min, max) */
|
||||
|
|
@ -724,7 +724,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
|
|||
if (bld->static_state->normalized_coords) {
|
||||
/* min = -1.0 / (2 * length) = -0.5 / length */
|
||||
min = lp_build_mul(coord_bld,
|
||||
lp_build_const_scalar(coord_bld->type, -0.5F),
|
||||
lp_build_const_vec(coord_bld->type, -0.5F),
|
||||
lp_build_rcp(coord_bld, length_f));
|
||||
/* max = length - min */
|
||||
max = lp_build_sub(coord_bld, length_f, min);
|
||||
|
|
@ -733,7 +733,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
|
|||
}
|
||||
else {
|
||||
/* clamp to [-0.5, length + 0.5] */
|
||||
min = lp_build_const_scalar(coord_bld->type, -0.5F);
|
||||
min = lp_build_const_vec(coord_bld->type, -0.5F);
|
||||
max = lp_build_sub(coord_bld, length_f, min);
|
||||
}
|
||||
/* coord = clamp(coord, min, max) */
|
||||
|
|
@ -1226,7 +1226,7 @@ static LLVMValueRef
|
|||
lp_build_cube_ima(struct lp_build_context *coord_bld, LLVMValueRef coord)
|
||||
{
|
||||
/* ima = -0.5 / abs(coord); */
|
||||
LLVMValueRef negHalf = lp_build_const_scalar(coord_bld->type, -0.5);
|
||||
LLVMValueRef negHalf = lp_build_const_vec(coord_bld->type, -0.5);
|
||||
LLVMValueRef absCoord = lp_build_abs(coord_bld, coord);
|
||||
LLVMValueRef ima = lp_build_mul(coord_bld, negHalf,
|
||||
lp_build_rcp(coord_bld, absCoord));
|
||||
|
|
@ -1246,7 +1246,7 @@ lp_build_cube_coord(struct lp_build_context *coord_bld,
|
|||
LLVMValueRef coord, LLVMValueRef ima)
|
||||
{
|
||||
/* return negate(coord) * ima * sign + 0.5; */
|
||||
LLVMValueRef half = lp_build_const_scalar(coord_bld->type, 0.5);
|
||||
LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
|
||||
LLVMValueRef res;
|
||||
|
||||
assert(negate_coord == +1 || negate_coord == -1);
|
||||
|
|
@ -1708,7 +1708,7 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
|
|||
LLVMValueRef packed,
|
||||
LLVMValueRef *rgba)
|
||||
{
|
||||
LLVMValueRef mask = lp_build_int_const_scalar(dst_type, 0xff);
|
||||
LLVMValueRef mask = lp_build_const_int_vec(dst_type, 0xff);
|
||||
unsigned chan;
|
||||
|
||||
/* Decode the input vector components */
|
||||
|
|
@ -1720,7 +1720,7 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
|
|||
input = packed;
|
||||
|
||||
if(start)
|
||||
input = LLVMBuildLShr(builder, input, lp_build_int_const_scalar(dst_type, start), "");
|
||||
input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(dst_type, start), "");
|
||||
|
||||
if(stop < 32)
|
||||
input = LLVMBuildAnd(builder, input, mask, "");
|
||||
|
|
@ -1782,17 +1782,17 @@ lp_build_sample_2d_linear_aos(struct lp_build_sample_context *bld,
|
|||
t = LLVMBuildFPToSI(builder, t, i32_vec_type, "");
|
||||
|
||||
/* subtract 0.5 (add -128) */
|
||||
i32_c128 = lp_build_int_const_scalar(i32.type, -128);
|
||||
i32_c128 = lp_build_const_int_vec(i32.type, -128);
|
||||
s = LLVMBuildAdd(builder, s, i32_c128, "");
|
||||
t = LLVMBuildAdd(builder, t, i32_c128, "");
|
||||
|
||||
/* compute floor (shift right 8) */
|
||||
i32_c8 = lp_build_int_const_scalar(i32.type, 8);
|
||||
i32_c8 = lp_build_const_int_vec(i32.type, 8);
|
||||
s_ipart = LLVMBuildAShr(builder, s, i32_c8, "");
|
||||
t_ipart = LLVMBuildAShr(builder, t, i32_c8, "");
|
||||
|
||||
/* compute fractional part (AND with 0xff) */
|
||||
i32_c255 = lp_build_int_const_scalar(i32.type, 255);
|
||||
i32_c255 = lp_build_const_int_vec(i32.type, 255);
|
||||
s_fpart = LLVMBuildAnd(builder, s, i32_c255, "");
|
||||
t_fpart = LLVMBuildAnd(builder, t, i32_c255, "");
|
||||
|
||||
|
|
@ -1959,7 +1959,7 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
|
|||
}
|
||||
|
||||
assert(res);
|
||||
res = lp_build_mul(texel_bld, res, lp_build_const_scalar(texel_bld->type, 0.25));
|
||||
res = lp_build_mul(texel_bld, res, lp_build_const_vec(texel_bld->type, 0.25));
|
||||
|
||||
/* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
|
||||
for(chan = 0; chan < 3; ++chan)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#define LP_BLD_STRUCT_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
#include <llvm-c/Target.h>
|
||||
|
||||
#include "util/u_debug.h"
|
||||
|
|
|
|||
|
|
@ -144,9 +144,9 @@ lp_build_broadcast_aos(struct lp_build_context *bld,
|
|||
#endif
|
||||
|
||||
if(shift > 0)
|
||||
tmp = LLVMBuildLShr(bld->builder, a, lp_build_int_const_scalar(type4, shift*type.width), "");
|
||||
tmp = LLVMBuildLShr(bld->builder, a, lp_build_const_int_vec(type4, shift*type.width), "");
|
||||
if(shift < 0)
|
||||
tmp = LLVMBuildShl(bld->builder, a, lp_build_int_const_scalar(type4, -shift*type.width), "");
|
||||
tmp = LLVMBuildShl(bld->builder, a, lp_build_const_int_vec(type4, -shift*type.width), "");
|
||||
|
||||
assert(tmp);
|
||||
if(tmp)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#define LP_BLD_SWIZZLE_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
struct lp_type;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
#ifndef LP_BLD_TGSI_H
|
||||
#define LP_BLD_TGSI_H
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
struct tgsi_token;
|
||||
|
|
|
|||
|
|
@ -475,7 +475,7 @@ emit_store(
|
|||
break;
|
||||
|
||||
case TGSI_SAT_MINUS_PLUS_ONE:
|
||||
value = lp_build_max(&bld->base, value, lp_build_const_scalar(bld->base.type, -1.0));
|
||||
value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0));
|
||||
value = lp_build_min(&bld->base, value, bld->base.one);
|
||||
break;
|
||||
|
||||
|
|
@ -651,32 +651,40 @@ emit_declaration(
|
|||
unsigned first = decl->Range.First;
|
||||
unsigned last = decl->Range.Last;
|
||||
unsigned idx, i;
|
||||
LLVMBasicBlockRef current_block =
|
||||
LLVMGetInsertBlock(bld->base.builder);
|
||||
LLVMBasicBlockRef first_block =
|
||||
LLVMGetEntryBasicBlock(
|
||||
LLVMGetBasicBlockParent(current_block));
|
||||
LLVMValueRef first_inst =
|
||||
LLVMGetFirstInstruction(first_block);
|
||||
|
||||
/* we want alloca's to be the first instruction
|
||||
* in the function so we need to rewind the builder
|
||||
* to the very beginning */
|
||||
LLVMPositionBuilderBefore(bld->base.builder,
|
||||
first_inst);
|
||||
|
||||
for (idx = first; idx <= last; ++idx) {
|
||||
boolean ok;
|
||||
|
||||
switch (decl->Declaration.File) {
|
||||
case TGSI_FILE_TEMPORARY:
|
||||
for (i = 0; i < NUM_CHANNELS; i++)
|
||||
bld->temps[idx][i] = lp_build_alloca(&bld->base);
|
||||
ok = TRUE;
|
||||
break;
|
||||
|
||||
case TGSI_FILE_OUTPUT:
|
||||
for (i = 0; i < NUM_CHANNELS; i++)
|
||||
bld->outputs[idx][i] = lp_build_alloca(&bld->base);
|
||||
ok = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* don't need to declare other vars */
|
||||
ok = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LLVMPositionBuilderAtEnd(bld->base.builder,
|
||||
current_block);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -996,7 +1004,7 @@ emit_instruction(
|
|||
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_scalar(bld->base.type, 0.5);
|
||||
tmp1 = lp_build_const_vec(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 );
|
||||
}
|
||||
|
|
@ -1713,7 +1721,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
|
|||
assert(num_immediates < LP_MAX_IMMEDIATES);
|
||||
for( i = 0; i < size; ++i )
|
||||
bld.immediates[num_immediates][i] =
|
||||
lp_build_const_scalar(type, parse.FullToken.FullImmediate.u[i].Float);
|
||||
lp_build_const_vec(type, parse.FullToken.FullImmediate.u[i].Float);
|
||||
for( i = size; i < 4; ++i )
|
||||
bld.immediates[num_immediates][i] = bld.base.undef;
|
||||
num_immediates++;
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@
|
|||
#define LP_BLD_TYPE_H
|
||||
|
||||
|
||||
#include "os/os_llvm.h"
|
||||
#include "pipe/p_compiler.h"
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
#include <pipe/p_compiler.h>
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -227,6 +227,8 @@ 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 FALSE;
|
||||
|
||||
|
|
@ -239,6 +241,13 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf,
|
|||
|
||||
if(!pb_check_usage(desc->usage, buf->base.base.usage))
|
||||
return FALSE;
|
||||
|
||||
map = pb_map(buf->buffer, PIPE_BUFFER_USAGE_DONTBLOCK);
|
||||
if (!map) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pb_unmap(buf->buffer);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ void x86_print_reg( struct x86_reg reg )
|
|||
foo++; \
|
||||
if (*foo) \
|
||||
foo++; \
|
||||
debug_printf( "\n% 4x% 15s ", p->csr - p->store, foo ); \
|
||||
debug_printf( "\n%4x %14s ", p->csr - p->store, foo ); \
|
||||
} while (0)
|
||||
|
||||
#define DUMP_I( I ) do { \
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ enum sse_cc {
|
|||
#define cc_Z cc_E
|
||||
#define cc_NZ cc_NE
|
||||
|
||||
/* Begin/end/retreive function creation:
|
||||
/* Begin/end/retrieve function creation:
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -311,8 +311,8 @@ void x87_fucom( struct x86_function *p, struct x86_reg arg );
|
|||
|
||||
|
||||
|
||||
/* Retreive a reference to one of the function arguments, taking into
|
||||
* account any push/pop activity. Note - doesn't track explict
|
||||
/* 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 );
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ static boolean is_digit_alpha_underscore( const char *cur )
|
|||
return is_digit( cur ) || is_alpha_underscore( cur );
|
||||
}
|
||||
|
||||
static boolean uprcase( char c )
|
||||
static char uprcase( char c )
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return c += 'A' - 'a';
|
||||
|
|
@ -76,7 +76,7 @@ streq_nocase_uprcase(const char *str1,
|
|||
str1++;
|
||||
str2++;
|
||||
}
|
||||
return TRUE;
|
||||
return *str1 == 0 && *str2 == 0;
|
||||
}
|
||||
|
||||
static boolean str_match_no_case( const char **pcur, const char *str )
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
#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 "util/u_surface.h"
|
||||
#include "util/u_rect.h"
|
||||
|
|
@ -280,6 +281,7 @@ regions_overlap(int srcX0, int srcY0,
|
|||
void
|
||||
util_blit_pixels_writemask(struct blit_state *ctx,
|
||||
struct pipe_surface *src,
|
||||
struct pipe_sampler_view *src_sampler_view,
|
||||
int srcX0, int srcY0,
|
||||
int srcX1, int srcY1,
|
||||
struct pipe_surface *dst,
|
||||
|
|
@ -290,7 +292,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
|
|||
{
|
||||
struct pipe_context *pipe = ctx->pipe;
|
||||
struct pipe_screen *screen = pipe->screen;
|
||||
struct pipe_texture *tex = NULL;
|
||||
struct pipe_sampler_view *sampler_view = NULL;
|
||||
struct pipe_framebuffer_state fb;
|
||||
const int srcW = abs(srcX1 - srcX0);
|
||||
const int srcH = abs(srcY1 - srcY0);
|
||||
|
|
@ -345,6 +347,8 @@ util_blit_pixels_writemask(struct blit_state *ctx,
|
|||
src->texture->last_level != 0)
|
||||
{
|
||||
struct pipe_texture texTemp;
|
||||
struct pipe_texture *tex;
|
||||
struct pipe_sampler_view sv_templ;
|
||||
struct pipe_surface *texSurf;
|
||||
const int srcLeft = MIN2(srcX0, srcX1);
|
||||
const int srcTop = MIN2(srcY0, srcY1);
|
||||
|
|
@ -376,6 +380,14 @@ util_blit_pixels_writemask(struct blit_state *ctx,
|
|||
if (!tex)
|
||||
return;
|
||||
|
||||
u_sampler_view_default_template(&sv_templ, tex, tex->format);
|
||||
|
||||
sampler_view = ctx->pipe->create_sampler_view(ctx->pipe, tex, &sv_templ);
|
||||
if (!sampler_view) {
|
||||
pipe_texture_reference(&tex, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0,
|
||||
PIPE_BUFFER_USAGE_GPU_WRITE);
|
||||
|
||||
|
|
@ -399,22 +411,25 @@ util_blit_pixels_writemask(struct blit_state *ctx,
|
|||
s1 = 1.0f;
|
||||
t0 = 0.0f;
|
||||
t1 = 1.0f;
|
||||
|
||||
pipe_texture_reference(&tex, NULL);
|
||||
}
|
||||
else {
|
||||
pipe_texture_reference(&tex, src->texture);
|
||||
s0 = srcX0 / (float)tex->width0;
|
||||
s1 = srcX1 / (float)tex->width0;
|
||||
t0 = srcY0 / (float)tex->height0;
|
||||
t1 = srcY1 / (float)tex->height0;
|
||||
pipe_sampler_view_reference(&sampler_view, src_sampler_view);
|
||||
s0 = srcX0 / (float)src->texture->width0;
|
||||
s1 = srcX1 / (float)src->texture->width0;
|
||||
t0 = srcY0 / (float)src->texture->height0;
|
||||
t1 = srcY1 / (float)src->texture->height0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 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_sampler_textures(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);
|
||||
|
|
@ -447,7 +462,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
|
|||
cso_set_viewport(ctx->cso, &ctx->viewport);
|
||||
|
||||
/* texture */
|
||||
cso_set_sampler_textures(ctx->cso, 1, &tex);
|
||||
cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view);
|
||||
|
||||
if (ctx->fs[writemask] == NULL)
|
||||
ctx->fs[writemask] =
|
||||
|
|
@ -486,7 +501,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
|
|||
cso_restore_depth_stencil_alpha(ctx->cso);
|
||||
cso_restore_rasterizer(ctx->cso);
|
||||
cso_restore_samplers(ctx->cso);
|
||||
cso_restore_sampler_textures(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);
|
||||
|
|
@ -494,13 +509,14 @@ util_blit_pixels_writemask(struct blit_state *ctx,
|
|||
cso_restore_clip(ctx->cso);
|
||||
cso_restore_vertex_elements(ctx->cso);
|
||||
|
||||
pipe_texture_reference(&tex, NULL);
|
||||
pipe_sampler_view_reference(&sampler_view, NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
util_blit_pixels(struct blit_state *ctx,
|
||||
struct pipe_surface *src,
|
||||
struct pipe_sampler_view *src_sampler_view,
|
||||
int srcX0, int srcY0,
|
||||
int srcX1, int srcY1,
|
||||
struct pipe_surface *dst,
|
||||
|
|
@ -508,7 +524,7 @@ util_blit_pixels(struct blit_state *ctx,
|
|||
int dstX1, int dstY1,
|
||||
float z, uint filter )
|
||||
{
|
||||
util_blit_pixels_writemask( ctx, src,
|
||||
util_blit_pixels_writemask( ctx, src, src_sampler_view,
|
||||
srcX0, srcY0,
|
||||
srcX1, srcY1,
|
||||
dst,
|
||||
|
|
@ -539,21 +555,23 @@ void util_blit_flush( struct blit_state *ctx )
|
|||
*/
|
||||
void
|
||||
util_blit_pixels_tex(struct blit_state *ctx,
|
||||
struct pipe_texture *tex,
|
||||
int srcX0, int srcY0,
|
||||
int srcX1, int srcY1,
|
||||
struct pipe_surface *dst,
|
||||
int dstX0, int dstY0,
|
||||
int dstX1, int dstY1,
|
||||
float z, uint filter)
|
||||
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)
|
||||
{
|
||||
struct pipe_framebuffer_state fb;
|
||||
float s0, t0, s1, t1;
|
||||
unsigned offset;
|
||||
struct pipe_texture *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);
|
||||
|
||||
|
|
@ -572,7 +590,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
|
|||
cso_save_depth_stencil_alpha(ctx->cso);
|
||||
cso_save_rasterizer(ctx->cso);
|
||||
cso_save_samplers(ctx->cso);
|
||||
cso_save_sampler_textures(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);
|
||||
|
|
@ -604,7 +622,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
|
|||
cso_set_viewport(ctx->cso, &ctx->viewport);
|
||||
|
||||
/* texture */
|
||||
cso_set_sampler_textures(ctx->cso, 1, &tex);
|
||||
cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view);
|
||||
|
||||
/* shaders */
|
||||
cso_set_fragment_shader_handle(ctx->cso, ctx->fs[TGSI_WRITEMASK_XYZW]);
|
||||
|
|
@ -638,7 +656,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
|
|||
cso_restore_depth_stencil_alpha(ctx->cso);
|
||||
cso_restore_rasterizer(ctx->cso);
|
||||
cso_restore_samplers(ctx->cso);
|
||||
cso_restore_sampler_textures(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);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ util_destroy_blit(struct blit_state *ctx);
|
|||
extern void
|
||||
util_blit_pixels(struct blit_state *ctx,
|
||||
struct pipe_surface *src,
|
||||
struct pipe_sampler_view *src_sampler_view,
|
||||
int srcX0, int srcY0,
|
||||
int srcX1, int srcY1,
|
||||
struct pipe_surface *dst,
|
||||
|
|
@ -63,6 +64,7 @@ util_blit_pixels(struct blit_state *ctx,
|
|||
void
|
||||
util_blit_pixels_writemask(struct blit_state *ctx,
|
||||
struct pipe_surface *src,
|
||||
struct pipe_sampler_view *src_sampler_view,
|
||||
int srcX0, int srcY0,
|
||||
int srcX1, int srcY1,
|
||||
struct pipe_surface *dst,
|
||||
|
|
@ -73,7 +75,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
|
|||
|
||||
extern void
|
||||
util_blit_pixels_tex(struct blit_state *ctx,
|
||||
struct pipe_texture *tex,
|
||||
struct pipe_sampler_view *src_sampler_view,
|
||||
int srcX0, int srcY0,
|
||||
int srcX1, int srcY1,
|
||||
struct pipe_surface *dst,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
#include "util/u_draw_quad.h"
|
||||
#include "util/u_pack_color.h"
|
||||
#include "util/u_rect.h"
|
||||
#include "util/u_sampler.h"
|
||||
#include "util/u_simple_shaders.h"
|
||||
#include "util/u_texture.h"
|
||||
|
||||
|
|
@ -96,6 +97,8 @@ struct blitter_context_priv
|
|||
/* Rasterizer state. */
|
||||
void *rs_state;
|
||||
|
||||
struct pipe_sampler_view *sampler_view;
|
||||
|
||||
/* Viewport state. */
|
||||
struct pipe_viewport_state viewport;
|
||||
|
||||
|
|
@ -127,7 +130,7 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
|
|||
ctx->blitter.saved_vs = INVALID_PTR;
|
||||
ctx->blitter.saved_velem_state = INVALID_PTR;
|
||||
ctx->blitter.saved_fb_state.nr_cbufs = ~0;
|
||||
ctx->blitter.saved_num_textures = ~0;
|
||||
ctx->blitter.saved_num_sampler_views = ~0;
|
||||
ctx->blitter.saved_num_sampler_states = ~0;
|
||||
|
||||
/* blend state objects */
|
||||
|
|
@ -252,6 +255,10 @@ void util_blitter_destroy(struct blitter_context *blitter)
|
|||
if (ctx->sampler_state[i])
|
||||
pipe->delete_sampler_state(pipe, ctx->sampler_state[i]);
|
||||
|
||||
if (ctx->sampler_view) {
|
||||
pipe_sampler_view_reference(&ctx->sampler_view, NULL);
|
||||
}
|
||||
|
||||
pipe_buffer_reference(&ctx->vbuf, NULL);
|
||||
FREE(ctx);
|
||||
}
|
||||
|
|
@ -305,11 +312,11 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx)
|
|||
ctx->blitter.saved_num_sampler_states = ~0;
|
||||
}
|
||||
|
||||
if (ctx->blitter.saved_num_textures != ~0) {
|
||||
pipe->set_fragment_sampler_textures(pipe,
|
||||
ctx->blitter.saved_num_textures,
|
||||
ctx->blitter.saved_textures);
|
||||
ctx->blitter.saved_num_textures = ~0;
|
||||
if (ctx->blitter.saved_num_sampler_views != ~0) {
|
||||
pipe->set_fragment_sampler_views(pipe,
|
||||
ctx->blitter.saved_num_sampler_views,
|
||||
ctx->blitter.saved_sampler_views);
|
||||
ctx->blitter.saved_num_sampler_views = ~0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -621,9 +628,10 @@ static void util_blitter_do_copy(struct blitter_context *blitter,
|
|||
struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
|
||||
struct pipe_context *pipe = ctx->pipe;
|
||||
struct pipe_framebuffer_state fb_state;
|
||||
struct pipe_sampler_view viewTempl, *view;
|
||||
|
||||
assert(blitter->saved_fb_state.nr_cbufs != ~0);
|
||||
assert(blitter->saved_num_textures != ~0);
|
||||
assert(blitter->saved_num_sampler_views != ~0);
|
||||
assert(blitter->saved_num_sampler_states != ~0);
|
||||
assert(src->texture->target < PIPE_MAX_TEXTURE_TYPES);
|
||||
|
||||
|
|
@ -651,12 +659,24 @@ static void util_blitter_do_copy(struct blitter_context *blitter,
|
|||
fb_state.zsbuf = 0;
|
||||
}
|
||||
|
||||
u_sampler_view_default_template(&viewTempl,
|
||||
src->texture,
|
||||
src->texture->format);
|
||||
view = pipe->create_sampler_view(pipe,
|
||||
src->texture,
|
||||
&viewTempl);
|
||||
|
||||
if (ctx->sampler_view) {
|
||||
pipe_sampler_view_reference(&ctx->sampler_view, NULL);
|
||||
}
|
||||
ctx->sampler_view = view;
|
||||
|
||||
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
|
||||
pipe->bind_vs_state(pipe, ctx->vs_tex);
|
||||
pipe->bind_fragment_sampler_states(pipe, 1,
|
||||
blitter_get_sampler_state(ctx, src->level));
|
||||
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
|
||||
pipe->set_fragment_sampler_textures(pipe, 1, &src->texture);
|
||||
pipe->set_fragment_sampler_views(pipe, 1, &view);
|
||||
pipe->set_framebuffer_state(pipe, &fb_state);
|
||||
|
||||
/* set texture coordinates */
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ struct blitter_context
|
|||
struct pipe_clip_state saved_clip;
|
||||
|
||||
int saved_num_sampler_states;
|
||||
void *saved_sampler_states[32];
|
||||
void *saved_sampler_states[PIPE_MAX_SAMPLERS];
|
||||
|
||||
int saved_num_textures;
|
||||
struct pipe_texture *saved_textures[32]; /* is 32 enough? */
|
||||
int saved_num_sampler_views;
|
||||
struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS];
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -242,17 +242,17 @@ void util_blitter_save_fragment_sampler_states(
|
|||
num_sampler_states * sizeof(void *));
|
||||
}
|
||||
|
||||
static INLINE
|
||||
void util_blitter_save_fragment_sampler_textures(
|
||||
struct blitter_context *blitter,
|
||||
int num_textures,
|
||||
struct pipe_texture **textures)
|
||||
static INLINE void
|
||||
util_blitter_save_fragment_sampler_views(struct blitter_context *blitter,
|
||||
int num_views,
|
||||
struct pipe_sampler_view **views)
|
||||
{
|
||||
assert(num_textures <= Elements(blitter->saved_textures));
|
||||
assert(num_views <= Elements(blitter->saved_sampler_views));
|
||||
|
||||
blitter->saved_num_textures = num_textures;
|
||||
memcpy(blitter->saved_textures, textures,
|
||||
num_textures * sizeof(struct pipe_texture *));
|
||||
blitter->saved_num_sampler_views = num_views;
|
||||
memcpy(blitter->saved_sampler_views,
|
||||
views,
|
||||
num_views * sizeof(struct pipe_sampler_view *));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@
|
|||
# - color space: rgb, yub, sz
|
||||
#
|
||||
# See also:
|
||||
# - http://msdn.microsoft.com/en-us/library/ee416489.aspx (D3D9)
|
||||
# - http://msdn.microsoft.com/en-us/library/ee415668.aspx (D3D9 -> D3D10)
|
||||
# - http://msdn.microsoft.com/en-us/library/ee418116.aspx (D3D10)
|
||||
# - 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
|
||||
|
|
@ -63,6 +63,7 @@ PIPE_FORMAT_A8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, r
|
|||
PIPE_FORMAT_X8R8G8B8_UNORM , plain, 1, 1, un8 , 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, un8 , un8 , un8 , un8 , wzy1, rgb
|
||||
PIPE_FORMAT_B5G5R5X1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , 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_B5G6R5_UNORM , plain, 1, 1, un5 , un6 , un5 , , zyx1, rgb
|
||||
|
|
@ -109,14 +110,18 @@ PIPE_FORMAT_UYVY , subsampled, 2, 1, x32 , , , , xyz
|
|||
PIPE_FORMAT_YUYV , subsampled, 2, 1, x32 , , , , xyz1, yuv
|
||||
|
||||
# Compressed formats
|
||||
PIPE_FORMAT_DXT1_RGB , compressed, 4, 4, x64 , , , , xyz1, rgb
|
||||
PIPE_FORMAT_DXT1_RGBA , compressed, 4, 4, x64 , , , , xyzw, rgb
|
||||
PIPE_FORMAT_DXT3_RGBA , compressed, 4, 4, x128, , , , xyzw, rgb
|
||||
PIPE_FORMAT_DXT5_RGBA , compressed, 4, 4, x128, , , , xyzw, rgb
|
||||
PIPE_FORMAT_DXT1_SRGB , compressed, 4, 4, x64 , , , , xyz1, srgb
|
||||
PIPE_FORMAT_DXT1_SRGBA , compressed, 4, 4, x64 , , , , xyzw, srgb
|
||||
PIPE_FORMAT_DXT3_SRGBA , compressed, 4, 4, x128, , , , xyzw, srgb
|
||||
PIPE_FORMAT_DXT5_SRGBA , compressed, 4, 4, x128, , , , xyzw, srgb
|
||||
# - 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
|
||||
|
||||
# Straightforward D3D10-like formats (also used for
|
||||
# vertex buffer element description)
|
||||
|
|
|
|||
|
Can't render this file because it contains an unexpected character in line 8 and column 3.
|
|
|
@ -56,15 +56,23 @@ enum util_format_layout {
|
|||
*
|
||||
* This is for formats like YV12 where there is less than one sample per
|
||||
* pixel.
|
||||
*
|
||||
* XXX: This could actually b
|
||||
*/
|
||||
UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3,
|
||||
|
||||
/**
|
||||
* An unspecified compression algorithm.
|
||||
* S3 Texture Compression formats.
|
||||
*/
|
||||
UTIL_FORMAT_LAYOUT_COMPRESSED = 4
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -210,7 +218,7 @@ util_format_name(enum pipe_format format)
|
|||
}
|
||||
|
||||
static INLINE boolean
|
||||
util_format_is_compressed(enum pipe_format format)
|
||||
util_format_is_s3tc(enum pipe_format format)
|
||||
{
|
||||
const struct util_format_description *desc = util_format_description(format);
|
||||
|
||||
|
|
@ -219,7 +227,7 @@ util_format_is_compressed(enum pipe_format format)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
return desc->layout == UTIL_FORMAT_LAYOUT_COMPRESSED ? TRUE : FALSE;
|
||||
return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
static INLINE boolean
|
||||
|
|
|
|||
|
|
@ -120,6 +120,13 @@ util_format_test_cases[] =
|
|||
* 16-bit rendertarget formats
|
||||
*/
|
||||
|
||||
{PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}},
|
||||
{PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}},
|
||||
{PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}},
|
||||
{PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 0.0}},
|
||||
{PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x8000), {0.0, 0.0, 0.0, 1.0}},
|
||||
{PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}},
|
||||
|
||||
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}},
|
||||
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}},
|
||||
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}},
|
||||
|
|
|
|||
|
|
@ -938,6 +938,7 @@ format_to_type_comps(enum pipe_format pformat,
|
|||
*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;
|
||||
|
|
@ -1460,7 +1461,7 @@ void util_gen_mipmap_flush( struct gen_mipmap_state *ctx )
|
|||
* Generate mipmap images. It's assumed all needed texture memory is
|
||||
* already allocated.
|
||||
*
|
||||
* \param pt the texture to generate mipmap levels for
|
||||
* \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
|
||||
|
|
@ -1469,12 +1470,13 @@ void util_gen_mipmap_flush( struct gen_mipmap_state *ctx )
|
|||
*/
|
||||
void
|
||||
util_gen_mipmap(struct gen_mipmap_state *ctx,
|
||||
struct pipe_texture *pt,
|
||||
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_texture *pt = psv->texture;
|
||||
void *fs = (pt->target == PIPE_TEXTURE_CUBE) ? ctx->fsCube : ctx->fs2d;
|
||||
uint dstLevel;
|
||||
uint zslice = 0;
|
||||
|
|
@ -1492,7 +1494,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
|
|||
filter == PIPE_TEX_FILTER_NEAREST);
|
||||
|
||||
/* check if we can render in the texture's format */
|
||||
if (!screen->is_format_supported(screen, pt->format, PIPE_TEXTURE_2D,
|
||||
if (!screen->is_format_supported(screen, psv->format, PIPE_TEXTURE_2D,
|
||||
PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
|
||||
fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel);
|
||||
return;
|
||||
|
|
@ -1503,7 +1505,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
|
|||
cso_save_depth_stencil_alpha(ctx->cso);
|
||||
cso_save_rasterizer(ctx->cso);
|
||||
cso_save_samplers(ctx->cso);
|
||||
cso_save_sampler_textures(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);
|
||||
|
|
@ -1572,7 +1574,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
|
|||
cso_single_sampler(ctx->cso, 0, &ctx->sampler);
|
||||
cso_single_sampler_done(ctx->cso);
|
||||
|
||||
cso_set_sampler_textures(ctx->cso, 1, &pt);
|
||||
cso_set_fragment_sampler_views(ctx->cso, 1, &psv);
|
||||
|
||||
/* quad coords in clip coords */
|
||||
offset = set_vertex_data(ctx,
|
||||
|
|
@ -1597,7 +1599,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
|
|||
cso_restore_depth_stencil_alpha(ctx->cso);
|
||||
cso_restore_rasterizer(ctx->cso);
|
||||
cso_restore_samplers(ctx->cso);
|
||||
cso_restore_sampler_textures(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);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue