# EGL driver install directory
EGL_DRIVER_INSTALL_DIR = @EGL_DRIVER_INSTALL_DIR@
+# VDPAU library install directory
+VDPAU_LIB_INSTALL_DIR=@VDPAU_LIB_INSTALL_DIR@
+
# Xorg driver install directory (for xorg state-tracker)
XORG_DRIVER_INSTALL_DIR = @XORG_DRIVER_INSTALL_DIR@
EGL_DRIVERS_DIRS = glx
DRIVER_DIRS = dri
-GALLIUM_WINSYS_DIRS = sw sw/xlib drm/vmware drm/intel drm/i965
+GALLIUM_WINSYS_DIRS = sw sw/xlib
GALLIUM_TARGET_DIRS = egl-swrast
-GALLIUM_STATE_TRACKERS_DIRS = egl
+GALLIUM_STATE_TRACKERS_DIRS = egl vdpau
-DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon \
- savage sis tdfx unichrome swrast
+DRI_DIRS = r300 radeon swrast
INTEL_LIBS = `pkg-config --libs libdrm_intel`
INTEL_CFLAGS = `pkg-config --cflags libdrm_intel`
# the new interface. i810 are missing because there is no x86-64
# system where they could *ever* be used.
#
-DRI_DIRS = i915 i965 mach64 mga r128 r200 r300 radeon savage tdfx unichrome
+DRI_DIRS = swrast
# mesa/es is required to build es state tracker
CORE_DIRS="$CORE_DIRS mesa/es"
;;
- xorg/xvmc)
- # Check for libXvMC?
+ xorg/xvmc)
+ # Check for xvmc?
if test "x$enable_gallium_g3dvl" != xyes; then
AC_MSG_ERROR([cannot build XvMC state tracker without --enable-gallium-g3dvl])
fi
HAVE_ST_XVMC="yes"
;;
+ vdpau)
+ # Check for libvdpau?
+ if test "x$enable_gallium_g3dvl" != xyes; then
+ AC_MSG_ERROR([cannot build vdpau state tracker without --enable-gallium-g3dvl])
+ fi
+ HAVE_ST_VDPAU="yes"
+ ;;
esac
done
GALLIUM_STATE_TRACKERS_DIRS="$state_trackers"
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 || test "x$HAVE_ST_XVMC" = xyes; then
+ if test "x$HAVE_ST_DRI" = xyes || test "x$HAVE_ST_EGL" = xyes || test "x$HAVE_ST_XORG" = xyes || test "x$HAVE_ST_XVMC" = xyes || test "x$HAVE_ST_VDPAU" = xyes; then
GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS $1"
fi
if test "x$HAVE_ST_DRI" = xyes && test "x$2" != x; then
if test "x$HAVE_ST_XVMC" = xyes && test "x$5" != x; then
GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $5"
fi
+ if test "x$HAVE_ST_VDPAU" = xyes && test "x$6" != x; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $6"
+ fi
}
if test "x$enable_gallium_g3dvl" = xyes; then
case "$mesa_driver" in
xlib)
- GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xvmc-softpipe"
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS vdpau-softpipe"
;;
dri)
GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS g3dvl/dri"
;;
esac
fi
+dnl Directory for VDPAU libs
+AC_ARG_WITH([vdpau-libdir],
+ [AS_HELP_STRING([--with-vdpau-libdir=DIR],
+ [directory for the VDPAU libraries @<:@default=${libdir}/vdpau@:>@])],
+ [VDPAU_LIB_INSTALL_DIR="$withval"],
+ [VDPAU_LIB_INSTALL_DIR='${libdir}/vdpau'])
+AC_SUBST([VDPAU_LIB_INSTALL_DIR])
dnl
dnl Gallium swrast configuration
LIBNAME = vdpautracker
+VDPAU_MAJOR = 1
+VDPAU_MINOR = 0
+LIBRARY_DEFINES = -DVER_MAJOR=$(VDPAU_MAJOR) -DVER_MINOR=$(VDPAU_MINOR) $(STATE_TRACKER_DEFINES)
+
LIBRARY_INCLUDES = \
$(shell pkg-config --cflags-only-I vdpau) \
-I$(TOP)/src/gallium/winsys/g3dvl
C_SOURCES = htab.c \
ftab.c \
device.c \
- query.c
+ query.c \
+ surface.c
+
include ../../Makefile.template
+
vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device, VdpGetProcAddress **get_proc_address)
{
VdpStatus ret;
- vlVdpDevice *dev;
+ vlVdpDevice *dev = NULL;
+ struct vl_screen *vlscreen = NULL;
if (!(display && device && get_proc_address))
return VDP_STATUS_INVALID_POINTER;
goto no_htab;
}
- dev = CALLOC(1, sizeof(vlVdpDevice));
+ dev = CALLOC(0, sizeof(vlVdpDevice));
if (!dev) {
ret = VDP_STATUS_RESOURCES;
goto no_dev;
}
+ dev->display = display;
+ dev->screen = screen;
+
*device = vlAddDataHTAB(dev);
if (*device == 0) {
0, /* VDP_FUNC_ID_GENERATE_CSC_MATRIX */
&vlVdpVideoSurfaceQueryCapabilities, /* VDP_FUNC_ID_VIDEO_SURFACE_QUERY_CAPABILITIES */
&vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities, /* VDP_FUNC_ID_VIDEO_SURFACE_QUERY_GET_PUT_BITS_Y_CB_CR_CAPABILITIES */
- 0, /* VDP_FUNC_ID_VIDEO_SURFACE_CREATE */
+ &vlVdpVideoSurfaceCreate, /* VDP_FUNC_ID_VIDEO_SURFACE_CREATE */
0, /* VDP_FUNC_ID_VIDEO_SURFACE_DESTROY */
0, /* VDP_FUNC_ID_VIDEO_SURFACE_GET_PARAMETERS */
0, /* VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_CB_CR */
**************************************************************************/
#include "vdpau_private.h"
+#include <vl_winsys.h>
+#include <assert.h>
+#include <pipe/p_screen.h>
+#include <math.h>
+
VdpStatus
vlVdpGetApiVersion(uint32_t *api_version)
if (!information_string)
return VDP_STATUS_INVALID_POINTER;
- *information_string = "VDPAU-G3DVL";
+ *information_string = INFORMATION_STRING;
return VDP_STATUS_OK;
}
vlVdpVideoSurfaceQueryCapabilities(VdpDevice device, VdpChromaType surface_chroma_type,
VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height)
{
+ uint32_t max_2d_texture_level;
+ VdpStatus ret;
+
if (!(is_supported && max_width && max_height))
return VDP_STATUS_INVALID_POINTER;
- return VDP_STATUS_NO_IMPLEMENTATION;
+ vlVdpDevice *dev = vlGetDataHTAB(device);
+ if (!dev)
+ return VDP_STATUS_INVALID_HANDLE;
+
+ if (!dev->vlscreen)
+ dev->vlscreen = vl_screen_create(dev->display, dev->screen);
+ if (!dev->vlscreen)
+ return VDP_STATUS_RESOURCES;
+
+ /* XXX: Current limits */
+ *is_supported = true;
+ if (surface_chroma_type != VDP_CHROMA_TYPE_420) {
+ *is_supported = false;
+ goto no_sup;
+ }
+
+ max_2d_texture_level = dev->vlscreen->pscreen->get_param( dev->vlscreen->pscreen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS );
+ if (!max_2d_texture_level) {
+ ret = VDP_STATUS_RESOURCES;
+ goto no_sup;
+ }
+
+ /* I am not quite sure if it is max_2d_texture_level-1 or just max_2d_texture_level */
+ *max_width = *max_height = pow(2,max_2d_texture_level-1);
+
+ return VDP_STATUS_OK;
+ no_sup:
+ return ret;
}
VdpStatus
if (!is_supported)
return VDP_STATUS_INVALID_POINTER;
- return VDP_STATUS_NO_IMPLEMENTATION;
+ vlVdpDevice *dev = vlGetDataHTAB(device);
+ if (!dev)
+ return VDP_STATUS_INVALID_HANDLE;
+
+ if (!dev->vlscreen)
+ dev->vlscreen = vl_screen_create(dev->display, dev->screen);
+ if (!dev->vlscreen)
+ return VDP_STATUS_RESOURCES;
+
+ if (bits_ycbcr_format != VDP_YCBCR_FORMAT_Y8U8V8A8)
+ *is_supported = dev->vlscreen->pscreen->is_format_supported(dev->vlscreen->pscreen,
+ FormatToPipe(bits_ycbcr_format),
+ PIPE_TEXTURE_2D,
+ PIPE_BIND_RENDER_TARGET,
+ PIPE_TEXTURE_GEOM_NON_SQUARE );
+
+ return VDP_STATUS_OK;
}
VdpStatus
*
**************************************************************************/
+#ifndef VDPAU_PRIVATE_H
+#define VDPAU_PRIVATE_H
+
+
#include <vdpau/vdpau.h>
#include <pipe/p_compiler.h>
+#include <vl_winsys.h>
+#include <assert.h>
+
+#define INFORMATION G3DVL VDPAU Driver Shared Library version VER_MAJOR.VER_MINOR
+#define QUOTEME(x) #x
+#define TOSTRING(x) QUOTEME(x)
+#define INFORMATION_STRING TOSTRING(INFORMATION)
+#define VL_HANDLES
+
+static enum pipe_video_chroma_format TypeToPipe(VdpChromaType vdpau_type)
+{
+ switch (vdpau_type) {
+ case VDP_CHROMA_TYPE_420:
+ return PIPE_VIDEO_CHROMA_FORMAT_420;
+ case VDP_CHROMA_TYPE_422:
+ return PIPE_VIDEO_CHROMA_FORMAT_422;
+ case VDP_CHROMA_TYPE_444:
+ return PIPE_VIDEO_CHROMA_FORMAT_444;
+ default:
+ assert(0);
+ }
+
+ return -1;
+}
+
+static VdpChromaType PipeToType(enum pipe_video_chroma_format pipe_type)
+{
+ switch (pipe_type) {
+ case PIPE_VIDEO_CHROMA_FORMAT_420:
+ return VDP_CHROMA_TYPE_420;
+ case PIPE_VIDEO_CHROMA_FORMAT_422:
+ return VDP_CHROMA_TYPE_422;
+ case PIPE_VIDEO_CHROMA_FORMAT_444:
+ return VDP_CHROMA_TYPE_444;
+ default:
+ assert(0);
+ }
+
+ return -1;
+}
+
+static enum pipe_format FormatToPipe(VdpYCbCrFormat vdpau_format)
+{
+ switch (vdpau_format) {
+ case VDP_YCBCR_FORMAT_NV12:
+ return PIPE_FORMAT_NV12;
+ case VDP_YCBCR_FORMAT_YV12:
+ return PIPE_FORMAT_YV12;
+ case VDP_YCBCR_FORMAT_UYVY:
+ return PIPE_FORMAT_UYVY;
+ case VDP_YCBCR_FORMAT_YUYV:
+ return PIPE_FORMAT_YUYV;
+ case VDP_YCBCR_FORMAT_Y8U8V8A8: /* Not defined in p_format.h */
+ return 0;
+ case VDP_YCBCR_FORMAT_V8U8Y8A8:
+ return PIPE_FORMAT_VUYA;
+ default:
+ assert(0);
+ }
+
+ return -1;
+}
+
+static VdpYCbCrFormat PipeToFormat(enum pipe_format p_format)
+{
+ switch (p_format) {
+ case PIPE_FORMAT_NV12:
+ return VDP_YCBCR_FORMAT_NV12;
+ case PIPE_FORMAT_YV12:
+ return VDP_YCBCR_FORMAT_YV12;
+ case PIPE_FORMAT_UYVY:
+ return VDP_YCBCR_FORMAT_UYVY;
+ case PIPE_FORMAT_YUYV:
+ return VDP_YCBCR_FORMAT_YUYV;
+ //case PIPE_FORMAT_YUVA:
+ // return VDP_YCBCR_FORMAT_Y8U8V8A8;
+ case PIPE_FORMAT_VUYA:
+ return VDP_YCBCR_FORMAT_V8U8Y8A8;
+ default:
+ assert(0);
+ }
+
+ return -1;
+}
typedef struct
{
- int dummy;
+ void *display;
+ int screen;
+ struct vl_screen *vlscreen;
+ struct vl_context *vctx;
} vlVdpDevice;
+typedef struct
+{
+ struct vl_screen *vlscreen;
+ struct pipe_surface *psurface;
+ enum pipe_video_chroma_format chroma_format;
+} vlVdpSurface;
+
typedef uint32_t vlHandle;
boolean vlCreateHTAB(void);
VdpVideoMixerQueryParameterValueRange vlVdpVideoMixerQueryParameterValueRange;
VdpVideoMixerQueryAttributeSupport vlVdpVideoMixerQueryAttributeSupport;
VdpVideoMixerQueryAttributeValueRange vlVdpVideoMixerQueryAttributeValueRange;
+VdpVideoSurfaceCreate vlVdpVideoSurfaceCreate;
+VdpVideoSurfaceDestroy vlVdpVideoSurfaceDestroy;
+VdpVideoSurfaceGetParameters vlVdpVideoSurfaceGetParameters;
+VdpVideoSurfaceGetBitsYCbCr vlVdpVideoSurfaceGetBitsYCbCr;
+VdpVideoSurfacePutBitsYCbCr vlVdpVideoSurfacePutBitsYCbCr;
+
+#endif // VDPAU_PRIVATE_H
\ No newline at end of file
LIBBASENAME = vdpau_g3dvl
LIBNAME = lib$(LIBBASENAME).so
+VDPAU_LIB_GLOB=lib$(LIBBASENAME).*so*
VDPAU_MAJOR = 1
VDPAU_MINOR = 0
INCLUDES = -I$(TOP)/src/gallium/include \
-I$(TOP)/src/gallium/auxiliary \
-I$(TOP)/src/gallium/winsys/g3dvl \
$(DRIVER_INCLUDES)
-DEFINES = -DGALLIUM_TRACE $(DRIVER_DEFINES)
+DEFINES = -DGALLIUM_TRACE -DVER_MAJOR=$(VDPAU_MAJOR) -DVER_MINOR=$(VDPAU_MINOR) $(DRIVER_DEFINES)
LIBS = $(EXTRA_LIB_PATH) $(DRIVER_LIBS) -lvdpau -lXext -lX11 -lm
STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/vdpau/libvdpautracker.a
-rm -f *.o *~ *.so $(SYMLINKS)
-rm -f depend depend.bak
-#install: $(LIBNAME)
-# $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
-# $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR)
+install: default
+ $(INSTALL) -d $(DESTDIR)$(VDPAU_LIB_INSTALL_DIR)
+ $(MINSTALL) -m 755 $(TOP)/$(LIB_DIR)/gallium/$(VDPAU_LIB_GLOB) $(DESTDIR)$(VDPAU_LIB_INSTALL_DIR)
include depend
+++ /dev/null
-This is an application written in python to replay the traces captured by the
- trace pipe driver.
-
-
-To use it follow the instructions in src/gallium/drivers/trace/README and
-src/gallium/state_trackers/python/README, and then do
-
- python src/gallium/state_trackers/python/samples/retrace/interpreter.py filename.trace
-
-
-This is still work in progress:
-- not everything is captured/replayed
- - surface/textures contents
-- any tiny error will result in a crash
-
---
-Jose Fonseca <jrfonseca@tungstengraphics.com>
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-import sys
-
-
-class Formatter:
- '''Plain formatter'''
-
- def __init__(self, stream):
- self.stream = stream
-
- def text(self, text):
- self.stream.write(text)
-
- def newline(self):
- self.text('\n')
-
- def function(self, name):
- self.text(name)
-
- def variable(self, name):
- self.text(name)
-
- def literal(self, value):
- self.text(str(value))
-
- def address(self, addr):
- self.text(str(addr))
-
-
-class AnsiFormatter(Formatter):
- '''Formatter for plain-text files which outputs ANSI escape codes. See
- http://en.wikipedia.org/wiki/ANSI_escape_code for more information
- concerning ANSI escape codes.
- '''
-
- _csi = '\33['
-
- _normal = '0m'
- _bold = '1m'
- _italic = '3m'
- _red = '31m'
- _green = '32m'
- _blue = '34m'
-
- def _escape(self, code):
- self.text(self._csi + code)
-
- def function(self, name):
- self._escape(self._bold)
- Formatter.function(self, name)
- self._escape(self._normal)
-
- def variable(self, name):
- self._escape(self._italic)
- Formatter.variable(self, name)
- self._escape(self._normal)
-
- def literal(self, value):
- self._escape(self._blue)
- Formatter.literal(self, value)
- self._escape(self._normal)
-
- def address(self, value):
- self._escape(self._green)
- Formatter.address(self, value)
- self._escape(self._normal)
-
-
-class WindowsConsoleFormatter(Formatter):
- '''Formatter for the Windows Console. See
- http://code.activestate.com/recipes/496901/ for more information.
- '''
-
- STD_INPUT_HANDLE = -10
- STD_OUTPUT_HANDLE = -11
- STD_ERROR_HANDLE = -12
-
- FOREGROUND_BLUE = 0x01
- FOREGROUND_GREEN = 0x02
- FOREGROUND_RED = 0x04
- FOREGROUND_INTENSITY = 0x08
- BACKGROUND_BLUE = 0x10
- BACKGROUND_GREEN = 0x20
- BACKGROUND_RED = 0x40
- BACKGROUND_INTENSITY = 0x80
-
- _normal = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED
- _bold = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY
- _italic = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED
- _red = FOREGROUND_RED | FOREGROUND_INTENSITY
- _green = FOREGROUND_GREEN | FOREGROUND_INTENSITY
- _blue = FOREGROUND_BLUE | FOREGROUND_INTENSITY
-
- def __init__(self, stream):
- Formatter.__init__(self, stream)
-
- if stream is sys.stdin:
- nStdHandle = self.STD_INPUT_HANDLE
- elif stream is sys.stdout:
- nStdHandle = self.STD_OUTPUT_HANDLE
- elif stream is sys.stderr:
- nStdHandle = self.STD_ERROR_HANDLE
- else:
- nStdHandle = None
-
- if nStdHandle:
- import ctypes
- self.handle = ctypes.windll.kernel32.GetStdHandle(nStdHandle)
- else:
- self.handle = None
-
- def _attribute(self, attr):
- if self.handle:
- import ctypes
- ctypes.windll.kernel32.SetConsoleTextAttribute(self.handle, attr)
-
- def function(self, name):
- self._attribute(self._bold)
- Formatter.function(self, name)
- self._attribute(self._normal)
-
- def variable(self, name):
- self._attribute(self._italic)
- Formatter.variable(self, name)
- self._attribute(self._normal)
-
- def literal(self, value):
- self._attribute(self._blue)
- Formatter.literal(self, value)
- self._attribute(self._normal)
-
- def address(self, value):
- self._attribute(self._green)
- Formatter.address(self, value)
- self._attribute(self._normal)
-
-
-def DefaultFormatter(stream):
- if sys.platform in ('linux2', 'cygwin'):
- return AnsiFormatter(stream)
- elif sys.platform in ('win32',):
- return WindowsConsoleFormatter(stream)
- else:
- return Formatter(stream)
-
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-'''Trace data model.'''
-
-
-import sys
-import string
-import format
-
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
-
-
-class Node:
-
- def visit(self, visitor):
- raise NotImplementedError
-
- def __str__(self):
- stream = StringIO()
- formatter = format.DefaultFormatter(stream)
- pretty_printer = PrettyPrinter(formatter)
- self.visit(pretty_printer)
- return stream.getvalue()
-
-
-class Literal(Node):
-
- def __init__(self, value):
- self.value = value
-
- def visit(self, visitor):
- visitor.visit_literal(self)
-
-
-class NamedConstant(Node):
-
- def __init__(self, name):
- self.name = name
-
- def visit(self, visitor):
- visitor.visit_named_constant(self)
-
-
-class Array(Node):
-
- def __init__(self, elements):
- self.elements = elements
-
- def visit(self, visitor):
- visitor.visit_array(self)
-
-
-class Struct(Node):
-
- def __init__(self, name, members):
- self.name = name
- self.members = members
-
- def visit(self, visitor):
- visitor.visit_struct(self)
-
-
-class Pointer(Node):
-
- def __init__(self, address):
- self.address = address
-
- def visit(self, visitor):
- visitor.visit_pointer(self)
-
-
-class Call:
-
- def __init__(self, no, klass, method, args, ret):
- self.no = no
- self.klass = klass
- self.method = method
- self.args = args
- self.ret = ret
-
- def visit(self, visitor):
- visitor.visit_call(self)
-
-
-class Trace:
-
- def __init__(self, calls):
- self.calls = calls
-
- def visit(self, visitor):
- visitor.visit_trace(self)
-
-
-class Visitor:
-
- def visit_literal(self, node):
- raise NotImplementedError
-
- def visit_named_constant(self, node):
- raise NotImplementedError
-
- def visit_array(self, node):
- raise NotImplementedError
-
- def visit_struct(self, node):
- raise NotImplementedError
-
- def visit_pointer(self, node):
- raise NotImplementedError
-
- def visit_call(self, node):
- raise NotImplementedError
-
- def visit_trace(self, node):
- raise NotImplementedError
-
-
-class PrettyPrinter:
-
- def __init__(self, formatter):
- self.formatter = formatter
-
- def visit_literal(self, node):
- if isinstance(node.value, basestring):
- if len(node.value) >= 4096 or node.value.strip(string.printable):
- self.formatter.text('...')
- return
-
- self.formatter.literal('"' + node.value + '"')
- return
-
- self.formatter.literal(repr(node.value))
-
- def visit_named_constant(self, node):
- self.formatter.literal(node.name)
-
- def visit_array(self, node):
- self.formatter.text('{')
- sep = ''
- for value in node.elements:
- self.formatter.text(sep)
- value.visit(self)
- sep = ', '
- self.formatter.text('}')
-
- def visit_struct(self, node):
- self.formatter.text('{')
- sep = ''
- for name, value in node.members:
- self.formatter.text(sep)
- self.formatter.variable(name)
- self.formatter.text(' = ')
- value.visit(self)
- sep = ', '
- self.formatter.text('}')
-
- def visit_pointer(self, node):
- self.formatter.address(node.address)
-
- def visit_call(self, node):
- self.formatter.text('%s ' % node.no)
- if node.klass is not None:
- self.formatter.function(node.klass + '::' + node.method)
- else:
- self.formatter.function(node.method)
- self.formatter.text('(')
- sep = ''
- for name, value in node.args:
- self.formatter.text(sep)
- self.formatter.variable(name)
- self.formatter.text(' = ')
- value.visit(self)
- sep = ', '
- self.formatter.text(')')
- if node.ret is not None:
- self.formatter.text(' = ')
- node.ret.visit(self)
-
- def visit_trace(self, node):
- for call in node.calls:
- call.visit(self)
- self.formatter.newline()
-
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-import sys
-import xml.parsers.expat
-import binascii
-import optparse
-
-from model import *
-
-
-ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF = range(4)
-
-
-class XmlToken:
-
- def __init__(self, type, name_or_data, attrs = None, line = None, column = None):
- assert type in (ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF)
- self.type = type
- self.name_or_data = name_or_data
- self.attrs = attrs
- self.line = line
- self.column = column
-
- def __str__(self):
- if self.type == ELEMENT_START:
- return '<' + self.name_or_data + ' ...>'
- if self.type == ELEMENT_END:
- return '</' + self.name_or_data + '>'
- if self.type == CHARACTER_DATA:
- return self.name_or_data
- if self.type == EOF:
- return 'end of file'
- assert 0
-
-
-class XmlTokenizer:
- """Expat based XML tokenizer."""
-
- def __init__(self, fp, skip_ws = True):
- self.fp = fp
- self.tokens = []
- self.index = 0
- self.final = False
- self.skip_ws = skip_ws
-
- self.character_pos = 0, 0
- self.character_data = ''
-
- self.parser = xml.parsers.expat.ParserCreate()
- self.parser.StartElementHandler = self.handle_element_start
- self.parser.EndElementHandler = self.handle_element_end
- self.parser.CharacterDataHandler = self.handle_character_data
-
- def handle_element_start(self, name, attributes):
- self.finish_character_data()
- line, column = self.pos()
- token = XmlToken(ELEMENT_START, name, attributes, line, column)
- self.tokens.append(token)
-
- def handle_element_end(self, name):
- self.finish_character_data()
- line, column = self.pos()
- token = XmlToken(ELEMENT_END, name, None, line, column)
- self.tokens.append(token)
-
- def handle_character_data(self, data):
- if not self.character_data:
- self.character_pos = self.pos()
- self.character_data += data
-
- def finish_character_data(self):
- if self.character_data:
- if not self.skip_ws or not self.character_data.isspace():
- line, column = self.character_pos
- token = XmlToken(CHARACTER_DATA, self.character_data, None, line, column)
- self.tokens.append(token)
- self.character_data = ''
-
- def next(self):
- size = 16*1024
- while self.index >= len(self.tokens) and not self.final:
- self.tokens = []
- self.index = 0
- data = self.fp.read(size)
- self.final = len(data) < size
- data = data.rstrip('\0')
- try:
- self.parser.Parse(data, self.final)
- except xml.parsers.expat.ExpatError, e:
- #if e.code == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS:
- if e.code == 3:
- pass
- else:
- raise e
- if self.index >= len(self.tokens):
- line, column = self.pos()
- token = XmlToken(EOF, None, None, line, column)
- else:
- token = self.tokens[self.index]
- self.index += 1
- return token
-
- def pos(self):
- return self.parser.CurrentLineNumber, self.parser.CurrentColumnNumber
-
-
-class TokenMismatch(Exception):
-
- def __init__(self, expected, found):
- self.expected = expected
- self.found = found
-
- def __str__(self):
- return '%u:%u: %s expected, %s found' % (self.found.line, self.found.column, str(self.expected), str(self.found))
-
-
-
-class XmlParser:
- """Base XML document parser."""
-
- def __init__(self, fp):
- self.tokenizer = XmlTokenizer(fp)
- self.consume()
-
- def consume(self):
- self.token = self.tokenizer.next()
-
- def match_element_start(self, name):
- return self.token.type == ELEMENT_START and self.token.name_or_data == name
-
- def match_element_end(self, name):
- return self.token.type == ELEMENT_END and self.token.name_or_data == name
-
- def element_start(self, name):
- while self.token.type == CHARACTER_DATA:
- self.consume()
- if self.token.type != ELEMENT_START:
- raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token)
- if self.token.name_or_data != name:
- raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token)
- attrs = self.token.attrs
- self.consume()
- return attrs
-
- def element_end(self, name):
- while self.token.type == CHARACTER_DATA:
- self.consume()
- if self.token.type != ELEMENT_END:
- raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token)
- if self.token.name_or_data != name:
- raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token)
- self.consume()
-
- def character_data(self, strip = True):
- data = ''
- while self.token.type == CHARACTER_DATA:
- data += self.token.name_or_data
- self.consume()
- if strip:
- data = data.strip()
- return data
-
-
-class TraceParser(XmlParser):
-
- def __init__(self, fp):
- XmlParser.__init__(self, fp)
- self.last_call_no = 0
-
- def parse(self):
- self.element_start('trace')
- while self.token.type not in (ELEMENT_END, EOF):
- call = self.parse_call()
- self.handle_call(call)
- if self.token.type != EOF:
- self.element_end('trace')
-
- def parse_call(self):
- attrs = self.element_start('call')
- try:
- no = int(attrs['no'])
- except KeyError:
- self.last_call_no += 1
- no = self.last_call_no
- else:
- self.last_call_no = no
- klass = attrs['class']
- method = attrs['method']
- args = []
- ret = None
- while self.token.type == ELEMENT_START:
- if self.token.name_or_data == 'arg':
- arg = self.parse_arg()
- args.append(arg)
- elif self.token.name_or_data == 'ret':
- ret = self.parse_ret()
- elif self.token.name_or_data == 'call':
- # ignore nested function calls
- self.parse_call()
- else:
- raise TokenMismatch("<arg ...> or <ret ...>", self.token)
- self.element_end('call')
-
- return Call(no, klass, method, args, ret)
-
- def parse_arg(self):
- attrs = self.element_start('arg')
- name = attrs['name']
- value = self.parse_value()
- self.element_end('arg')
-
- return name, value
-
- def parse_ret(self):
- attrs = self.element_start('ret')
- value = self.parse_value()
- self.element_end('ret')
-
- return value
-
- def parse_value(self):
- expected_tokens = ('null', 'bool', 'int', 'uint', 'float', 'string', 'enum', 'array', 'struct', 'ptr', 'bytes')
- if self.token.type == ELEMENT_START:
- if self.token.name_or_data in expected_tokens:
- method = getattr(self, 'parse_' + self.token.name_or_data)
- return method()
- raise TokenMismatch(" or " .join(expected_tokens), self.token)
-
- def parse_null(self):
- self.element_start('null')
- self.element_end('null')
- return Literal(None)
-
- def parse_bool(self):
- self.element_start('bool')
- value = int(self.character_data())
- self.element_end('bool')
- return Literal(value)
-
- def parse_int(self):
- self.element_start('int')
- value = int(self.character_data())
- self.element_end('int')
- return Literal(value)
-
- def parse_uint(self):
- self.element_start('uint')
- value = int(self.character_data())
- self.element_end('uint')
- return Literal(value)
-
- def parse_float(self):
- self.element_start('float')
- value = float(self.character_data())
- self.element_end('float')
- return Literal(value)
-
- def parse_enum(self):
- self.element_start('enum')
- name = self.character_data()
- self.element_end('enum')
- return NamedConstant(name)
-
- def parse_string(self):
- self.element_start('string')
- value = self.character_data()
- self.element_end('string')
- return Literal(value)
-
- def parse_bytes(self):
- self.element_start('bytes')
- value = binascii.a2b_hex(self.character_data())
- self.element_end('bytes')
- return Literal(value)
-
- def parse_array(self):
- self.element_start('array')
- elems = []
- while self.token.type != ELEMENT_END:
- elems.append(self.parse_elem())
- self.element_end('array')
- return Array(elems)
-
- def parse_elem(self):
- self.element_start('elem')
- value = self.parse_value()
- self.element_end('elem')
- return value
-
- def parse_struct(self):
- attrs = self.element_start('struct')
- name = attrs['name']
- members = []
- while self.token.type != ELEMENT_END:
- members.append(self.parse_member())
- self.element_end('struct')
- return Struct(name, members)
-
- def parse_member(self):
- attrs = self.element_start('member')
- name = attrs['name']
- value = self.parse_value()
- self.element_end('member')
-
- return name, value
-
- def parse_ptr(self):
- self.element_start('ptr')
- address = self.character_data()
- self.element_end('ptr')
-
- return Pointer(address)
-
- def handle_call(self, call):
- pass
-
-
-class TraceDumper(TraceParser):
-
- def __init__(self, fp):
- TraceParser.__init__(self, fp)
- self.formatter = format.DefaultFormatter(sys.stdout)
- self.pretty_printer = PrettyPrinter(self.formatter)
-
- def handle_call(self, call):
- call.visit(self.pretty_printer)
- self.formatter.newline()
-
-
-class Main:
- '''Common main class for all retrace command line utilities.'''
-
- def __init__(self):
- pass
-
- def main(self):
- optparser = self.get_optparser()
- (options, args) = optparser.parse_args(sys.argv[1:])
-
- if args:
- for arg in args:
- if arg.endswith('.gz'):
- from gzip import GzipFile
- stream = GzipFile(arg, 'rt')
- elif arg.endswith('.bz2'):
- from bz2 import BZ2File
- stream = BZ2File(arg, 'rU')
- else:
- stream = open(arg, 'rt')
- self.process_arg(stream, options)
- else:
- self.process_arg(stream, options)
-
- def get_optparser(self):
- optparser = optparse.OptionParser(
- usage="\n\t%prog [options] [traces] ...")
- return optparser
-
- def process_arg(self, stream, options):
- parser = TraceDumper(stream)
- parser.parse()
-
-
-if __name__ == '__main__':
- Main().main()
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-from parse import *
-
-
-if __name__ == '__main__':
- Main().main()
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2009 VMware
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-from gallium import *
-
-
-def make_image(surface):
- data = surface.get_tile_rgba8(0, 0, surface.width, surface.height)
-
- import Image
- outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1)
- return outimage
-
-def save_image(filename, surface):
- outimage = make_image(surface)
- outimage.save(filename, "PNG")
-
-def show_image(surface):
- outimage = make_image(surface)
-
- import Tkinter as tk
- from PIL import Image, ImageTk
- root = tk.Tk()
-
- root.title('background image')
-
- image1 = ImageTk.PhotoImage(outimage)
- w = image1.width()
- h = image1.height()
- x = 100
- y = 100
- root.geometry("%dx%d+%d+%d" % (w, h, x, y))
- panel1 = tk.Label(root, image=image1)
- panel1.pack(side='top', fill='both', expand='yes')
- panel1.image = image1
- root.mainloop()
-
-
-def test(dev):
- ctx = dev.context_create()
-
- width = 255
- height = 255
- minz = 0.0
- maxz = 1.0
-
- # disabled blending/masking
- blend = Blend()
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].colormask = PIPE_MASK_RGBA
- ctx.set_blend(blend)
-
- # depth/stencil/alpha
- depth_stencil_alpha = DepthStencilAlpha()
- depth_stencil_alpha.depth.enabled = 1
- depth_stencil_alpha.depth.writemask = 1
- depth_stencil_alpha.depth.func = PIPE_FUNC_LESS
- ctx.set_depth_stencil_alpha(depth_stencil_alpha)
-
- # rasterizer
- rasterizer = Rasterizer()
- rasterizer.front_winding = PIPE_WINDING_CW
- rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.scissor = 1
- ctx.set_rasterizer(rasterizer)
-
- # viewport
- viewport = Viewport()
- scale = FloatArray(4)
- scale[0] = width / 2.0
- scale[1] = -height / 2.0
- scale[2] = (maxz - minz) / 2.0
- scale[3] = 1.0
- viewport.scale = scale
- translate = FloatArray(4)
- translate[0] = width / 2.0
- translate[1] = height / 2.0
- translate[2] = (maxz - minz) / 2.0
- translate[3] = 0.0
- viewport.translate = translate
- ctx.set_viewport(viewport)
-
- # samplers
- sampler = Sampler()
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE
- sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.normalized_coords = 1
- ctx.set_sampler(0, sampler)
-
- # scissor
- scissor = Scissor()
- scissor.minx = 0
- scissor.miny = 0
- scissor.maxx = width
- scissor.maxy = height
- ctx.set_scissor(scissor)
-
- clip = Clip()
- clip.nr = 0
- ctx.set_clip(clip)
-
- # framebuffer
- cbuf = dev.resource_create(
- PIPE_FORMAT_B8G8R8X8_UNORM,
- width, height,
- bind=PIPE_BIND_RENDER_TARGET,
- ).get_surface()
- zbuf = dev.resource_create(
- PIPE_FORMAT_Z32_UNORM,
- width, height,
- bind=PIPE_BIND_DEPTH_STENCIL,
- ).get_surface()
- fb = Framebuffer()
- fb.width = width
- fb.height = height
- fb.nr_cbufs = 1
- fb.set_cbuf(0, cbuf)
- fb.set_zsbuf(zbuf)
- ctx.set_framebuffer(fb)
- rgba = FloatArray(4);
- rgba[0] = 0.0
- rgba[1] = 0.0
- rgba[2] = 0.0
- rgba[3] = 0.0
- ctx.clear(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0xff)
-
- # vertex shader
- vs = Shader('''
- VERT
- DCL IN[0], POSITION, CONSTANT
- DCL IN[1], COLOR, CONSTANT
- DCL OUT[0], POSITION, CONSTANT
- DCL OUT[1], COLOR, CONSTANT
- 0:MOV OUT[0], IN[0]
- 1:MOV OUT[1], IN[1]
- 2:END
- ''')
- ctx.set_vertex_shader(vs)
-
- gs = Shader('''
- GEOM
- PROPERTY GS_INPUT_PRIMITIVE TRIANGLES
- PROPERTY GS_OUTPUT_PRIMITIVE TRIANGLE_STRIP
- DCL IN[][0], POSITION, CONSTANT
- DCL IN[][1], COLOR, CONSTANT
- DCL OUT[0], POSITION, CONSTANT
- DCL OUT[1], COLOR, CONSTANT
- 0:MOV OUT[0], IN[0][0]
- 1:MOV OUT[1], IN[0][1]
- 2:EMIT
- 3:MOV OUT[0], IN[1][0]
- 4:MOV OUT[1], IN[1][1]
- 5:EMIT
- 6:MOV OUT[0], IN[2][0]
- 7:MOV OUT[1], IN[2][1]
- 8:EMIT
- 9:ENDPRIM
- 10:END
- ''')
- ctx.set_geometry_shader(gs)
-
- # fragment shader
- fs = Shader('''
- FRAG
- DCL IN[0], COLOR, LINEAR
- DCL OUT[0], COLOR, CONSTANT
- 0:MOV OUT[0], IN[0]
- 1:END
- ''')
- ctx.set_fragment_shader(fs)
-
- nverts = 3
- nattrs = 2
- verts = FloatArray(nverts * nattrs * 4)
-
- verts[ 0] = 0.0 # x1
- verts[ 1] = 0.8 # y1
- verts[ 2] = 0.2 # z1
- verts[ 3] = 1.0 # w1
- verts[ 4] = 1.0 # r1
- verts[ 5] = 0.0 # g1
- verts[ 6] = 0.0 # b1
- verts[ 7] = 1.0 # a1
- verts[ 8] = -0.8 # x2
- verts[ 9] = -0.8 # y2
- verts[10] = 0.5 # z2
- verts[11] = 1.0 # w2
- verts[12] = 0.0 # r2
- verts[13] = 1.0 # g2
- verts[14] = 0.0 # b2
- verts[15] = 1.0 # a2
- verts[16] = 0.8 # x3
- verts[17] = -0.8 # y3
- verts[18] = 0.8 # z3
- verts[19] = 1.0 # w3
- verts[20] = 0.0 # r3
- verts[21] = 0.0 # g3
- verts[22] = 1.0 # b3
- verts[23] = 1.0 # a3
-
- ctx.draw_vertices(PIPE_PRIM_TRIANGLES,
- nverts,
- nattrs,
- verts)
-
- ctx.flush()
-
- show_image(cbuf)
- #show_image(zbuf)
- #save_image('cbuf.png', cbuf)
- #save_image('zbuf.png', zbuf)
-
-
-
-def main():
- dev = Device()
- test(dev)
-
-
-if __name__ == '__main__':
- main()
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-from gallium import *
-
-
-def make_image(ctx, surface):
- data = ctx.surface_read_rgba8(surface, 0, 0, surface.width, surface.height)
-
- import Image
- outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1)
- return outimage
-
-def save_image(ctx, surface, filename):
- outimage = make_image(ctx, surface)
- outimage.save(filename, "PNG")
-
-def show_image(ctx, surface):
- outimage = make_image(ctx, surface)
-
- import Tkinter as tk
- from PIL import Image, ImageTk
- root = tk.Tk()
-
- root.title('background image')
-
- image1 = ImageTk.PhotoImage(outimage)
- w = image1.width()
- h = image1.height()
- x = 100
- y = 100
- root.geometry("%dx%d+%d+%d" % (w, h, x, y))
- panel1 = tk.Label(root, image=image1)
- panel1.pack(side='top', fill='both', expand='yes')
- panel1.image = image1
- root.mainloop()
-
-
-def test(dev):
- ctx = dev.context_create()
-
- width = 255
- height = 255
- minz = 0.0
- maxz = 1.0
-
- # disabled blending/masking
- blend = Blend()
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].colormask = PIPE_MASK_RGBA
- ctx.set_blend(blend)
-
- # depth/stencil/alpha
- depth_stencil_alpha = DepthStencilAlpha()
- depth_stencil_alpha.depth.enabled = 1
- depth_stencil_alpha.depth.writemask = 1
- depth_stencil_alpha.depth.func = PIPE_FUNC_LESS
- ctx.set_depth_stencil_alpha(depth_stencil_alpha)
-
- # rasterizer
- rasterizer = Rasterizer()
- rasterizer.front_winding = PIPE_WINDING_CW
- rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.scissor = 1
- ctx.set_rasterizer(rasterizer)
-
- # viewport
- viewport = Viewport()
- scale = FloatArray(4)
- scale[0] = width / 2.0
- scale[1] = -height / 2.0
- scale[2] = (maxz - minz) / 2.0
- scale[3] = 1.0
- viewport.scale = scale
- translate = FloatArray(4)
- translate[0] = width / 2.0
- translate[1] = height / 2.0
- translate[2] = (maxz - minz) / 2.0
- translate[3] = 0.0
- viewport.translate = translate
- ctx.set_viewport(viewport)
-
- # samplers
- sampler = Sampler()
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE
- sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.normalized_coords = 1
- ctx.set_fragment_sampler(0, sampler)
-
- # scissor
- scissor = Scissor()
- scissor.minx = 0
- scissor.miny = 0
- scissor.maxx = width
- scissor.maxy = height
- ctx.set_scissor(scissor)
-
- # clip
- clip = Clip()
- clip.nr = 0
- ctx.set_clip(clip)
-
- # framebuffer
- cbuf = dev.resource_create(
- PIPE_FORMAT_B8G8R8X8_UNORM,
- width, height,
- bind=PIPE_BIND_RENDER_TARGET,
- ).get_surface()
- zbuf = dev.resource_create(
- PIPE_FORMAT_Z32_UNORM,
- width, height,
- bind=PIPE_BIND_DEPTH_STENCIL,
- ).get_surface()
- fb = Framebuffer()
- fb.width = width
- fb.height = height
- fb.nr_cbufs = 1
- fb.set_cbuf(0, cbuf)
- fb.set_zsbuf(zbuf)
- ctx.set_framebuffer(fb)
- rgba = FloatArray(4);
- rgba[0] = 0.0
- rgba[1] = 0.0
- rgba[2] = 0.0
- rgba[3] = 0.0
- ctx.clear(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0xff)
-
- # vertex shader
- vs = Shader('''
- VERT
- DCL IN[0], POSITION, CONSTANT
- DCL IN[1], COLOR, CONSTANT
- DCL OUT[0], POSITION, CONSTANT
- DCL OUT[1], COLOR, CONSTANT
- 0:MOV OUT[0], IN[0]
- 1:MOV OUT[1], IN[1]
- 2:END
- ''')
- ctx.set_vertex_shader(vs)
-
- # fragment shader
- fs = Shader('''
- FRAG
- DCL IN[0], COLOR, LINEAR
- DCL OUT[0], COLOR, CONSTANT
- 0:MOV OUT[0], IN[0]
- 1:END
- ''')
- ctx.set_fragment_shader(fs)
-
- nverts = 3
- nattrs = 2
- verts = FloatArray(nverts * nattrs * 4)
-
- verts[ 0] = 0.0 # x1
- verts[ 1] = 0.8 # y1
- verts[ 2] = 0.2 # z1
- verts[ 3] = 1.0 # w1
- verts[ 4] = 1.0 # r1
- verts[ 5] = 0.0 # g1
- verts[ 6] = 0.0 # b1
- verts[ 7] = 1.0 # a1
- verts[ 8] = -0.8 # x2
- verts[ 9] = -0.8 # y2
- verts[10] = 0.5 # z2
- verts[11] = 1.0 # w2
- verts[12] = 0.0 # r2
- verts[13] = 1.0 # g2
- verts[14] = 0.0 # b2
- verts[15] = 1.0 # a2
- verts[16] = 0.8 # x3
- verts[17] = -0.8 # y3
- verts[18] = 0.8 # z3
- verts[19] = 1.0 # w3
- verts[20] = 0.0 # r3
- verts[21] = 0.0 # g3
- verts[22] = 1.0 # b3
- verts[23] = 1.0 # a3
-
- ctx.draw_vertices(PIPE_PRIM_TRIANGLES,
- nverts,
- nattrs,
- verts)
-
- ctx.flush()
-
- show_image(ctx, cbuf)
- show_image(ctx, zbuf)
- save_image(ctx, cbuf, 'cbuf.png')
- save_image(ctx, zbuf, 'zbuf.png')
-
-
-
-def main():
- dev = Device()
- test(dev)
-
-
-if __name__ == '__main__':
- main()
+++ /dev/null
-*.txt
-*.tsv
-*.dot
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2009 VMware, Inc.
-# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-"""Base classes for tests.
-
-Loosely inspired on Python's unittest module.
-"""
-
-
-import os.path
-import sys
-
-from gallium import *
-
-
-# Enumerate all pixel formats
-formats = {}
-for name, value in globals().items():
- if name.startswith("PIPE_FORMAT_") and isinstance(value, int) and name not in ("PIPE_FORMAT_NONE", "PIPE_FORMAT_COUNT"):
- formats[value] = name
-
-def make_image(width, height, rgba):
- import Image
- outimage = Image.new(
- mode='RGB',
- size=(width, height),
- color=(0,0,0))
- outpixels = outimage.load()
- for y in range(0, height):
- for x in range(0, width):
- offset = (y*width + x)*4
- r, g, b, a = [int(min(max(rgba[offset + ch], 0.0), 1.0)*255) for ch in range(4)]
- outpixels[x, y] = r, g, b
- return outimage
-
-def save_image(width, height, rgba, filename):
- outimage = make_image(width, height, rgba)
- outimage.save(filename, "PNG")
-
-def show_image(width, height, **rgbas):
- import Tkinter as tk
- from PIL import Image, ImageTk
-
- root = tk.Tk()
-
- x = 64
- y = 64
-
- labels = rgbas.keys()
- labels.sort()
- for i in range(len(labels)):
- label = labels[i]
- outimage = make_image(width, height, rgbas[label])
-
- if i:
- window = tk.Toplevel(root)
- else:
- window = root
- window.title(label)
- image1 = ImageTk.PhotoImage(outimage)
- w = image1.width()
- h = image1.height()
- window.geometry("%dx%d+%d+%d" % (w, h, x, y))
- panel1 = tk.Label(window, image=image1)
- panel1.pack(side='top', fill='both', expand='yes')
- panel1.image = image1
- x += w + 2
-
- root.mainloop()
-
-
-class TestFailure(Exception):
-
- pass
-
-class TestSkip(Exception):
-
- pass
-
-
-class Test:
-
- def __init__(self):
- pass
-
- def _run(self, result):
- raise NotImplementedError
-
- def run(self):
- result = TestResult()
- self._run(result)
- result.report()
-
- def assert_rgba(self, ctx, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85):
- total = h*w
- different = ctx.surface_compare_rgba(surface, x, y, w, h, expected_rgba, tol=pixel_tol)
- if different:
- sys.stderr.write("%u out of %u pixels differ\n" % (different, total))
-
- if float(total - different)/float(total) < surface_tol:
- if 0:
- rgba = FloatArray(h*w*4)
- ctx.surface_read_rgba(surface, x, y, w, h, rgba)
- show_image(w, h, Result=rgba, Expected=expected_rgba)
- save_image(w, h, rgba, "result.png")
- save_image(w, h, expected_rgba, "expected.png")
- #sys.exit(0)
-
- raise TestFailure
-
-
-class TestCase(Test):
-
- tags = ()
-
- def __init__(self, dev, **kargs):
- Test.__init__(self)
- self.dev = dev
- self.__dict__.update(kargs)
-
- def description(self):
- descriptions = []
- for tag in self.tags:
- value = self.get(tag)
- if value is not None and value != '':
- descriptions.append(tag + '=' + str(value))
- return ' '.join(descriptions)
-
- def get(self, tag):
- try:
- method = getattr(self, '_get_' + tag)
- except AttributeError:
- return getattr(self, tag, None)
- else:
- return method()
-
- def _get_target(self):
- return {
- PIPE_TEXTURE_1D: "1d",
- PIPE_TEXTURE_2D: "2d",
- PIPE_TEXTURE_3D: "3d",
- PIPE_TEXTURE_CUBE: "cube",
- }[self.target]
-
- def _get_format(self):
- name = formats[self.format]
- if name.startswith('PIPE_FORMAT_'):
- name = name[12:]
- name = name.lower()
- return name
-
- def _get_face(self):
- if self.target == PIPE_TEXTURE_CUBE:
- return {
- PIPE_TEX_FACE_POS_X: "+x",
- PIPE_TEX_FACE_NEG_X: "-x",
- PIPE_TEX_FACE_POS_Y: "+y",
- PIPE_TEX_FACE_NEG_Y: "-y",
- PIPE_TEX_FACE_POS_Z: "+z",
- PIPE_TEX_FACE_NEG_Z: "-z",
- }[self.face]
- else:
- return ''
-
- def test(self):
- raise NotImplementedError
-
- def _run(self, result):
- result.test_start(self)
- try:
- self.test()
- except KeyboardInterrupt:
- raise
- except TestSkip:
- result.test_skipped(self)
- except TestFailure:
- result.test_failed(self)
- else:
- result.test_passed(self)
-
-
-class TestSuite(Test):
-
- def __init__(self, tests = None):
- Test.__init__(self)
- if tests is None:
- self.tests = []
- else:
- self.tests = tests
-
- def add_test(self, test):
- self.tests.append(test)
-
- def _run(self, result):
- for test in self.tests:
- test._run(result)
-
-
-class TestResult:
-
- def __init__(self):
- self.tests = 0
- self.passed = 0
- self.skipped = 0
- self.failed = 0
-
- self.names = ['result']
- self.types = ['pass skip fail']
- self.rows = []
-
- def test_start(self, test):
- sys.stdout.write("Running %s...\n" % test.description())
- sys.stdout.flush()
- self.tests += 1
-
- def test_passed(self, test):
- sys.stdout.write("PASS\n")
- sys.stdout.flush()
- self.passed += 1
- self.log_result(test, 'pass')
-
- def test_skipped(self, test):
- sys.stdout.write("SKIP\n")
- sys.stdout.flush()
- self.skipped += 1
- self.log_result(test, 'skip')
-
- def test_failed(self, test):
- sys.stdout.write("FAIL\n")
- sys.stdout.flush()
- self.failed += 1
- self.log_result(test, 'fail')
-
- def log_result(self, test, result):
- row = ['']*len(self.names)
-
- # add result
- assert self.names[0] == 'result'
- assert result in ('pass', 'skip', 'fail')
- row[0] = result
-
- # add tags
- for tag in test.tags:
- value = test.get(tag)
-
- # infer type
- if value is None:
- continue
- elif isinstance(value, (int, float)):
- value = str(value)
- type = 'c' # continous
- elif isinstance(value, basestring):
- type = 'd' # discrete
- else:
- assert False
- value = str(value)
- type = 'd' # discrete
-
- # insert value
- try:
- col = self.names.index(tag, 1)
- except ValueError:
- self.names.append(tag)
- self.types.append(type)
- row.append(value)
- else:
- row[col] = value
- assert self.types[col] == type
-
- self.rows.append(row)
-
- def report(self):
- sys.stdout.write("%u tests, %u passed, %u skipped, %u failed\n\n" % (self.tests, self.passed, self.skipped, self.failed))
- sys.stdout.flush()
-
- name, ext = os.path.splitext(os.path.basename(sys.argv[0]))
-
- tree = self.report_tree(name)
- self.report_junit(name, stdout=tree)
-
- def report_tree(self, name):
- filename = name + '.tsv'
- stream = file(filename, 'wt')
-
- # header
- stream.write('\t'.join(self.names) + '\n')
- stream.write('\t'.join(self.types) + '\n')
- stream.write('class\n')
-
- # rows
- for row in self.rows:
- if row[0] == 'skip':
- continue
- row += ['']*(len(self.names) - len(row))
- stream.write('\t'.join(row) + '\n')
-
- stream.close()
-
- # See http://www.ailab.si/orange/doc/ofb/c_otherclass.htm
- try:
- import orange
- import orngTree
- except ImportError:
- sys.stderr.write('Install Orange from http://www.ailab.si/orange/ for a classification tree.\n')
- return None
-
- data = orange.ExampleTable(filename)
-
- tree = orngTree.TreeLearner(data, sameMajorityPruning=1, mForPruning=2)
-
- orngTree.printTxt(tree, maxDepth=4)
-
- text_tree = orngTree.dumpTree(tree)
-
- file(name + '.txt', 'wt').write(text_tree)
-
- orngTree.printDot(tree, fileName=name+'.dot', nodeShape='ellipse', leafShape='box')
-
- return text_tree
-
- def report_junit(self, name, stdout=None, stderr=None):
- """Write test results in ANT's junit XML format, to use with Hudson CI.
-
- See also:
- - http://fisheye.hudson-ci.org/browse/Hudson/trunk/hudson/main/core/src/test/resources/hudson/tasks/junit
- - http://www.junit.org/node/399
- - http://wiki.apache.org/ant/Proposals/EnhancedTestReports
- """
-
- stream = file(name + '.xml', 'wt')
-
- stream.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
- stream.write('<testsuite name="%s">\n' % self.escape_xml(name))
- stream.write(' <properties>\n')
- stream.write(' </properties>\n')
-
- names = self.names[1:]
-
- for row in self.rows:
-
- test_name = ' '.join(['%s=%s' % pair for pair in zip(self.names[1:], row[1:])])
-
- stream.write(' <testcase name="%s">\n' % (self.escape_xml(test_name)))
-
- result = row[0]
- if result == 'pass':
- pass
- elif result == 'skip':
- stream.write(' <skipped/>\n')
- else:
- stream.write(' <failure/>\n')
-
- stream.write(' </testcase>\n')
-
- if stdout:
- stream.write(' <system-out>%s</system-out>\n' % self.escape_xml(stdout))
- if stderr:
- stream.write(' <system-err>%s</system-err>\n' % self.escape_xml(stderr))
-
- stream.write('</testsuite>\n')
-
- stream.close()
-
- def escape_xml(self, s):
- '''Escape a XML string.'''
- s = s.replace('&', '&')
- s = s.replace('<', '<')
- s = s.replace('>', '>')
- s = s.replace('"', '"')
- s = s.replace("'", ''')
- return s
-
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { -0.5, -0.4, -0.6, 0.0 }
-
-ADD TEMP[0], IN[0], IMM[0]
-ABS OUT[0], TEMP[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-ADD OUT[0], IN[0], IN[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-DCL CONST[1]
-DCL CONST[3]
-DCL TEMP[0..1]
-
-ADD TEMP[0], IN[0], CONST[1]
-RCP TEMP[1], CONST[3].xxxx
-MUL OUT[0], TEMP[0], TEMP[1]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DP3 OUT[0], IN[0], IN[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DP4 OUT[0], IN[0].xyzx, IN[0].xyzx
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DST OUT[0], IN[0], IN[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-EX2 TEMP[0], IN[0].xxxx
-MUL OUT[0], TEMP[0], IN[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { 2.5, 4.0, 2.0, 1.0 }
-IMM FLT32 { 0.4, 0.25, 0.5, 1.0 }
-
-MUL TEMP[0], IN[0], IMM[0]
-FLR TEMP[0], TEMP[0]
-MUL OUT[0], TEMP[0], IMM[1]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { 2.7, 3.1, 4.5, 1.0 }
-
-MUL TEMP[0], IN[0], IMM[0]
-FRC OUT[0], TEMP[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
-IMM FLT32 { 0.5, 0.0, 0.0, 0.0 }
-
-ADD TEMP[0], IN[0], IMM[0]
-LG2 TEMP[0].x, TEMP[0].xxxx
-ADD OUT[0], TEMP[0], IMM[1]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-LIT OUT[0], IN[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-ABS TEMP[0], IN[0]
-LRP OUT[0], TEMP[0], IN[0].xxxx, IN[0].yyyy
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-IMM FLT32 { 0.5, 0.4, 0.6, 1.0 }
-IMM FLT32 { 0.5, 0.4, 0.6, 0.0 }
-
-MAD OUT[0], IN[0], IMM[0], IMM[1]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-IMM FLT32 { 0.4, 0.4, 0.4, 0.0 }
-
-MAX OUT[0], IN[0], IMM[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-IMM FLT32 { 0.6, 0.6, 0.6, 1.0 }
-
-MIN OUT[0], IN[0], IMM[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-MOV OUT[0], IN[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-IMM FLT32 { 0.5, 0.6, 0.7, 1.0 }
-
-MUL OUT[0], IN[0], IMM[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
-IMM FLT32 { 1.5, 0.0, 0.0, 0.0 }
-
-ADD TEMP[0], IN[0], IMM[0]
-RCP TEMP[0].x, TEMP[0].xxxx
-SUB OUT[0], TEMP[0], IMM[1]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
-IMM FLT32 { 1.5, 0.0, 0.0, 0.0 }
-
-ADD TEMP[0], IN[0], IMM[0]
-RSQ TEMP[0].x, TEMP[0].xxxx
-SUB OUT[0], TEMP[0], IMM[1]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { 0.6, 0.6, 0.6, 0.0 }
-
-SGE TEMP[0], IN[0], IMM[0]
-MUL OUT[0], IN[0], TEMP[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { 0.6, 0.6, 0.6, 0.0 }
-
-SLT TEMP[0], IN[0], IMM[0]
-MUL OUT[0], IN[0], TEMP[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { -0.3, -0.5, -0.4, 0.0 }
-
-ADD TEMP[0], IN[0], IMM[0]
-MOV OUT[0], |TEMP[0]|
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-IMM FLT32 { -0.2, -0.3, -0.4, 0.0 }
-IMM FLT32 { -1.0, -1.0, -1.0, -1.0 }
-
-ADD TEMP[0], IN[0], IMM[0]
-MOV TEMP[0], -|TEMP[0]|
-MUL OUT[0], TEMP[0], IMM[1]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-DCL TEMP[0]
-
-SUB TEMP[0], IN[0], IN[0].yzxw
-MOV OUT[0], -TEMP[0]
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-MOV OUT[0], IN[0].yxzw
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-SUB OUT[0], IN[0], IN[0].yzxw
-
-END
+++ /dev/null
-FRAG
-
-DCL IN[0], COLOR, LINEAR
-DCL OUT[0], COLOR
-
-XPD OUT[0], IN[0], IN[0].yzxw
-
-END
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2009 VMware, Inc.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-import struct
-
-from gallium import *
-
-def make_image(surface):
- data = surface.get_tile_rgba8(0, 0, surface.width, surface.height)
-
- import Image
- outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1)
- return outimage
-
-def save_image(filename, surface):
- outimage = make_image(surface)
- outimage.save(filename, "PNG")
-
-def test(dev, name):
- ctx = dev.context_create()
-
- width = 320
- height = 320
- minz = 0.0
- maxz = 1.0
-
- # disabled blending/masking
- blend = Blend()
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].colormask = PIPE_MASK_RGBA
- ctx.set_blend(blend)
-
- # depth/stencil/alpha
- depth_stencil_alpha = DepthStencilAlpha()
- depth_stencil_alpha.depth.enabled = 0
- depth_stencil_alpha.depth.writemask = 1
- depth_stencil_alpha.depth.func = PIPE_FUNC_LESS
- ctx.set_depth_stencil_alpha(depth_stencil_alpha)
-
- # rasterizer
- rasterizer = Rasterizer()
- rasterizer.front_winding = PIPE_WINDING_CW
- rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.scissor = 1
- ctx.set_rasterizer(rasterizer)
-
- # viewport
- viewport = Viewport()
- scale = FloatArray(4)
- scale[0] = width / 2.0
- scale[1] = -height / 2.0
- scale[2] = (maxz - minz) / 2.0
- scale[3] = 1.0
- viewport.scale = scale
- translate = FloatArray(4)
- translate[0] = width / 2.0
- translate[1] = height / 2.0
- translate[2] = (maxz - minz) / 2.0
- translate[3] = 0.0
- viewport.translate = translate
- ctx.set_viewport(viewport)
-
- # samplers
- sampler = Sampler()
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE
- sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.normalized_coords = 1
- ctx.set_fragment_sampler(0, sampler)
-
- # scissor
- scissor = Scissor()
- scissor.minx = 0
- scissor.miny = 0
- scissor.maxx = width
- scissor.maxy = height
- ctx.set_scissor(scissor)
-
- clip = Clip()
- clip.nr = 0
- ctx.set_clip(clip)
-
- # framebuffer
- cbuf = dev.resource_create(
- PIPE_FORMAT_B8G8R8X8_UNORM,
- width, height,
- bind=PIPE_BIND_RENDER_TARGET,
- ).get_surface()
- fb = Framebuffer()
- fb.width = width
- fb.height = height
- fb.nr_cbufs = 1
- fb.set_cbuf(0, cbuf)
- ctx.set_framebuffer(fb)
- rgba = FloatArray(4);
- rgba[0] = 0.5
- rgba[1] = 0.5
- rgba[2] = 0.5
- rgba[3] = 0.5
- ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
-
- # vertex shader
- vs = Shader('''
- VERT
- DCL IN[0], POSITION
- DCL IN[1], COLOR
- DCL OUT[0], POSITION
- DCL OUT[1], COLOR
- MOV OUT[0], IN[0]
- MOV OUT[1], IN[1]
- END
- ''')
- ctx.set_vertex_shader(vs)
-
- # fragment shader
- fs = Shader(file('frag-' + name + '.sh', 'rt').read())
- ctx.set_fragment_shader(fs)
-
- constbuf0 = dev.buffer_create(64,
- (PIPE_BUFFER_USAGE_CONSTANT |
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE),
- 4 * 4 * 4)
-
- cbdata = ''
- cbdata += struct.pack('4f', 0.4, 0.0, 0.0, 1.0)
- cbdata += struct.pack('4f', 1.0, 1.0, 1.0, 1.0)
- cbdata += struct.pack('4f', 2.0, 2.0, 2.0, 2.0)
- cbdata += struct.pack('4f', 4.0, 8.0, 16.0, 32.0)
-
- constbuf0.write(cbdata, 0)
-
- ctx.set_constant_buffer(PIPE_SHADER_FRAGMENT,
- 0,
- constbuf0)
-
- constbuf1 = dev.buffer_create(64,
- (PIPE_BUFFER_USAGE_CONSTANT |
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE),
- 4 * 4 * 4)
-
- cbdata = ''
- cbdata += struct.pack('4f', 0.1, 0.1, 0.1, 0.1)
- cbdata += struct.pack('4f', 0.25, 0.25, 0.25, 0.25)
- cbdata += struct.pack('4f', 0.5, 0.5, 0.5, 0.5)
- cbdata += struct.pack('4f', 0.75, 0.75, 0.75, 0.75)
-
- constbuf1.write(cbdata, 0)
-
- ctx.set_constant_buffer(PIPE_SHADER_FRAGMENT,
- 1,
- constbuf1)
-
- xy = [
- -0.8, -0.8,
- 0.8, -0.8,
- 0.0, 0.8,
- ]
- color = [
- 1.0, 0.0, 0.0,
- 0.0, 1.0, 0.0,
- 0.0, 0.0, 1.0,
- ]
-
- nverts = 3
- nattrs = 2
- verts = FloatArray(nverts * nattrs * 4)
-
- for i in range(0, nverts):
- verts[i * nattrs * 4 + 0] = xy[i * 2 + 0] # x
- verts[i * nattrs * 4 + 1] = xy[i * 2 + 1] # y
- verts[i * nattrs * 4 + 2] = 0.5 # z
- verts[i * nattrs * 4 + 3] = 1.0 # w
- verts[i * nattrs * 4 + 4] = color[i * 3 + 0] # r
- verts[i * nattrs * 4 + 5] = color[i * 3 + 1] # g
- verts[i * nattrs * 4 + 6] = color[i * 3 + 2] # b
- verts[i * nattrs * 4 + 7] = 1.0 # a
-
- ctx.draw_vertices(PIPE_PRIM_TRIANGLES,
- nverts,
- nattrs,
- verts)
-
- ctx.flush()
-
- save_image('frag-' + name + '.png', cbuf)
-
-def main():
- tests = [
- 'abs',
- 'add',
- 'cb-1d',
- 'cb-2d',
- 'dp3',
- 'dp4',
- 'dst',
- 'ex2',
- 'flr',
- 'frc',
- 'lg2',
- 'lit',
- 'lrp',
- 'mad',
- 'max',
- 'min',
- 'mov',
- 'mul',
- 'rcp',
- 'rsq',
- 'sge',
- 'slt',
- 'srcmod-abs',
- 'srcmod-absneg',
- 'srcmod-neg',
- 'srcmod-swz',
- 'sub',
- 'xpd',
- ]
-
- dev = Device()
- for t in tests:
- test(dev, t)
-
-if __name__ == '__main__':
- main()
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2009 VMware, Inc.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-import struct
-
-from gallium import *
-
-def make_image(surface):
- data = surface.get_tile_rgba8(0, 0, surface.width, surface.height)
-
- import Image
- outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1)
- return outimage
-
-def save_image(filename, surface):
- outimage = make_image(surface)
- outimage.save(filename, "PNG")
-
-def test(dev, name):
- ctx = dev.context_create()
-
- width = 320
- height = 320
- minz = 0.0
- maxz = 1.0
-
- # disabled blending/masking
- blend = Blend()
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].colormask = PIPE_MASK_RGBA
- ctx.set_blend(blend)
-
- # depth/stencil/alpha
- depth_stencil_alpha = DepthStencilAlpha()
- depth_stencil_alpha.depth.enabled = 0
- depth_stencil_alpha.depth.writemask = 1
- depth_stencil_alpha.depth.func = PIPE_FUNC_LESS
- ctx.set_depth_stencil_alpha(depth_stencil_alpha)
-
- # rasterizer
- rasterizer = Rasterizer()
- rasterizer.front_winding = PIPE_WINDING_CW
- rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.scissor = 1
- ctx.set_rasterizer(rasterizer)
-
- # viewport
- viewport = Viewport()
- scale = FloatArray(4)
- scale[0] = width / 2.0
- scale[1] = -height / 2.0
- scale[2] = (maxz - minz) / 2.0
- scale[3] = 1.0
- viewport.scale = scale
- translate = FloatArray(4)
- translate[0] = width / 2.0
- translate[1] = height / 2.0
- translate[2] = (maxz - minz) / 2.0
- translate[3] = 0.0
- viewport.translate = translate
- ctx.set_viewport(viewport)
-
- # samplers
- sampler = Sampler()
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE
- sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.normalized_coords = 1
- ctx.set_fragment_sampler(0, sampler)
-
- # scissor
- scissor = Scissor()
- scissor.minx = 0
- scissor.miny = 0
- scissor.maxx = width
- scissor.maxy = height
- ctx.set_scissor(scissor)
-
- clip = Clip()
- clip.nr = 0
- ctx.set_clip(clip)
-
- # framebuffer
- cbuf = dev.resource_create(
- PIPE_FORMAT_B8G8R8X8_UNORM,
- width, height,
- bind=PIPE_BIND_RENDER_TARGET,
- ).get_surface()
- fb = Framebuffer()
- fb.width = width
- fb.height = height
- fb.nr_cbufs = 1
- fb.set_cbuf(0, cbuf)
- ctx.set_framebuffer(fb)
- rgba = FloatArray(4);
- rgba[0] = 0.5
- rgba[1] = 0.5
- rgba[2] = 0.5
- rgba[3] = 0.5
- ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
-
- # vertex shader
- vs = Shader(file('vert-' + name + '.sh', 'rt').read())
- ctx.set_vertex_shader(vs)
-
- # fragment shader
- fs = Shader('''
- FRAG
- DCL IN[0], COLOR, LINEAR
- DCL OUT[0], COLOR, CONSTANT
- 0:MOV OUT[0], IN[0]
- 1:END
- ''')
- ctx.set_fragment_shader(fs)
-
- constbuf0 = dev.buffer_create(64,
- (PIPE_BUFFER_USAGE_CONSTANT |
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE),
- 4 * 4 * 4)
-
- cbdata = ''
- cbdata += struct.pack('4f', 0.4, 0.0, 0.0, 1.0)
- cbdata += struct.pack('4f', 1.0, 1.0, 1.0, 1.0)
- cbdata += struct.pack('4f', 2.0, 2.0, 2.0, 2.0)
- cbdata += struct.pack('4f', 4.0, 8.0, 16.0, 32.0)
-
- constbuf0.write(cbdata, 0)
-
- ctx.set_constant_buffer(PIPE_SHADER_VERTEX,
- 0,
- constbuf0)
-
- constbuf1 = dev.buffer_create(64,
- (PIPE_BUFFER_USAGE_CONSTANT |
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE),
- 4 * 4 * 4)
-
- cbdata = ''
- cbdata += struct.pack('4f', 0.1, 0.1, 0.1, 0.1)
- cbdata += struct.pack('4f', 0.25, 0.25, 0.25, 0.25)
- cbdata += struct.pack('4f', 0.5, 0.5, 0.5, 0.5)
- cbdata += struct.pack('4f', 0.75, 0.75, 0.75, 0.75)
-
- constbuf1.write(cbdata, 0)
-
- ctx.set_constant_buffer(PIPE_SHADER_VERTEX,
- 1,
- constbuf1)
-
- xy = [
- 0.0, 0.8,
- -0.2, 0.4,
- 0.2, 0.4,
- -0.4, 0.0,
- 0.0, 0.0,
- 0.4, 0.0,
- -0.6, -0.4,
- -0.2, -0.4,
- 0.2, -0.4,
- 0.6, -0.4,
- -0.8, -0.8,
- -0.4, -0.8,
- 0.0, -0.8,
- 0.4, -0.8,
- 0.8, -0.8,
- ]
- color = [
- 1.0, 0.0, 0.0,
- 0.0, 1.0, 0.0,
- 0.0, 0.0, 1.0,
- ]
- tri = [
- 1, 2, 0,
- 3, 4, 1,
- 4, 2, 1,
- 4, 5, 2,
- 6, 7, 3,
- 7, 4, 3,
- 7, 8, 4,
- 8, 5, 4,
- 8, 9, 5,
- 10, 11, 6,
- 11, 7, 6,
- 11, 12, 7,
- 12, 8, 7,
- 12, 13, 8,
- 13, 9, 8,
- 13, 14, 9,
- ]
-
- nverts = 16 * 3
- nattrs = 2
- verts = FloatArray(nverts * nattrs * 4)
-
- for i in range(0, nverts):
- verts[i * nattrs * 4 + 0] = xy[tri[i] * 2 + 0] # x
- verts[i * nattrs * 4 + 1] = xy[tri[i] * 2 + 1] # y
- verts[i * nattrs * 4 + 2] = 0.5 # z
- verts[i * nattrs * 4 + 3] = 1.0 # w
- verts[i * nattrs * 4 + 4] = color[(i % 3) * 3 + 0] # r
- verts[i * nattrs * 4 + 5] = color[(i % 3) * 3 + 1] # g
- verts[i * nattrs * 4 + 6] = color[(i % 3) * 3 + 2] # b
- verts[i * nattrs * 4 + 7] = 1.0 # a
-
- ctx.draw_vertices(PIPE_PRIM_TRIANGLES,
- nverts,
- nattrs,
- verts)
-
- ctx.flush()
-
- save_image('vert-' + name + '.png', cbuf)
-
-def main():
- tests = [
- 'abs',
- 'add',
- 'arl',
- 'arr',
- 'cb-1d',
- 'cb-2d',
- 'dp3',
- 'dp4',
- 'dst',
- 'ex2',
- 'flr',
- 'frc',
- 'lg2',
- 'lit',
- 'lrp',
- 'mad',
- 'max',
- 'min',
- 'mov',
- 'mul',
- 'rcp',
- 'rsq',
- 'sge',
- 'slt',
- 'srcmod-abs',
- 'srcmod-absneg',
- 'srcmod-neg',
- 'srcmod-swz',
- 'sub',
- 'xpd',
- ]
-
- dev = Device()
- for t in tests:
- test(dev, t)
-
-if __name__ == '__main__':
- main()
+++ /dev/null
-#!/usr/bin/env python
-##########################################################################
-#
-# Copyright 2009 VMware, Inc.
-# All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sub license, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice (including the
-# next paragraph) shall be included in all copies or substantial portions
-# of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
-# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-##########################################################################
-
-
-from gallium import *
-from base import *
-
-
-def lods(*dims):
- size = max(dims)
- lods = 0
- while size:
- lods += 1
- size >>= 1
- return lods
-
-
-class TextureTest(TestCase):
-
- tags = (
- 'target',
- 'format',
- 'width',
- 'height',
- 'depth',
- 'last_level',
- 'face',
- 'level',
- 'zslice',
- )
-
- def test(self):
- dev = self.dev
-
- target = self.target
- format = self.format
- width = self.width
- height = self.height
- depth = self.depth
- last_level = self.last_level
- face = self.face
- level = self.level
- zslice = self.zslice
-
- # textures
- dst_texture = dev.resource_create(
- target = target,
- format = format,
- width = width,
- height = height,
- depth = depth,
- last_level = last_level,
- bind = PIPE_BIND_RENDER_TARGET,
- )
- if dst_texture is None:
- raise TestSkip
-
- dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice)
-
- ref_texture = dev.resource_create(
- target = target,
- format = format,
- width = dst_surface.width,
- height = dst_surface.height,
- depth = 1,
- last_level = 0,
- bind = PIPE_BIND_SAMPLER_VIEW,
- )
-
- ref_surface = ref_texture.get_surface()
-
- src_texture = dev.resource_create(
- target = target,
- format = PIPE_FORMAT_B8G8R8A8_UNORM,
- width = dst_surface.width,
- height = dst_surface.height,
- depth = 1,
- last_level = 0,
- bind = PIPE_BIND_SAMPLER_VIEW,
- )
-
- src_surface = src_texture.get_surface()
-
- expected_rgba = FloatArray(height*width*4)
- ref_surface.sample_rgba(expected_rgba)
-
- src_surface.put_tile_rgba(0, 0, src_surface.width, src_surface.height, expected_rgba)
-
- ctx = self.dev.context_create()
-
- # disabled blending/masking
- blend = Blend()
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
- blend.rt[0].colormask = PIPE_MASK_RGBA
- ctx.set_blend(blend)
-
- # no-op depth/stencil/alpha
- depth_stencil_alpha = DepthStencilAlpha()
- ctx.set_depth_stencil_alpha(depth_stencil_alpha)
-
- # rasterizer
- rasterizer = Rasterizer()
- rasterizer.front_winding = PIPE_WINDING_CW
- rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.bypass_vs_clip_and_viewport = 1
- ctx.set_rasterizer(rasterizer)
-
- # samplers
- sampler = Sampler()
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
- sampler.normalized_coords = 1
- sampler.min_lod = 0
- sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1
- ctx.set_fragment_sampler(0, sampler)
- ctx.set_fragment_sampler_texture(0, src_texture)
-
- # framebuffer
- cbuf_tex = dev.resource_create(
- PIPE_FORMAT_B8G8R8A8_UNORM,
- width,
- height,
- bind = PIPE_BIND_RENDER_TARGET,
- )
-
- fb = Framebuffer()
- fb.width = dst_surface.width
- fb.height = dst_surface.height
- fb.nr_cbufs = 1
- fb.set_cbuf(0, dst_surface)
- ctx.set_framebuffer(fb)
- rgba = FloatArray(4);
- rgba[0] = 0.0
- rgba[1] = 0.0
- rgba[2] = 0.0
- rgba[3] = 0.0
- ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
- del fb
-
- # vertex shader
- vs = Shader('''
- VERT
- DCL IN[0], POSITION, CONSTANT
- DCL IN[1], GENERIC, CONSTANT
- DCL OUT[0], POSITION, CONSTANT
- DCL OUT[1], GENERIC, CONSTANT
- 0:MOV OUT[0], IN[0]
- 1:MOV OUT[1], IN[1]
- 2:END
- ''')
- #vs.dump()
- ctx.set_vertex_shader(vs)
-
- # fragment shader
- fs = Shader('''
- FRAG
- DCL IN[0], GENERIC[0], LINEAR
- DCL OUT[0], COLOR, CONSTANT
- DCL SAMP[0], CONSTANT
- 0:TEX OUT[0], IN[0], SAMP[0], 2D
- 1:END
- ''')
- #fs.dump()
- ctx.set_fragment_shader(fs)
-
- nverts = 4
- nattrs = 2
- verts = FloatArray(nverts * nattrs * 4)
-
- x = 0
- y = 0
- w = dst_surface.width
- h = dst_surface.height
-
- pos = [
- [x, y],
- [x+w, y],
- [x+w, y+h],
- [x, y+h],
- ]
-
- tex = [
- [0.0, 0.0],
- [1.0, 0.0],
- [1.0, 1.0],
- [0.0, 1.0],
- ]
-
- for i in range(0, 4):
- j = 8*i
- verts[j + 0] = pos[i][0] # x
- verts[j + 1] = pos[i][1] # y
- verts[j + 2] = 0.0 # z
- verts[j + 3] = 1.0 # w
- verts[j + 4] = tex[i][0] # s
- verts[j + 5] = tex[i][1] # r
- verts[j + 6] = 0.0
- verts[j + 7] = 1.0
-
- ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN,
- nverts,
- nattrs,
- verts)
-
- ctx.flush()
-
- self.assert_rgba(dst_surface, x, y, w, h, expected_rgba, 4.0/256, 0.85)
-
-
-
-def main():
- dev = Device()
- suite = TestSuite()
-
- targets = [
- PIPE_TEXTURE_2D,
- PIPE_TEXTURE_CUBE,
- #PIPE_TEXTURE_3D,
- ]
-
- formats = [
- PIPE_FORMAT_B8G8R8A8_UNORM,
- PIPE_FORMAT_B8G8R8X8_UNORM,
- #PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_FORMAT_B5G6R5_UNORM,
- PIPE_FORMAT_B5G5R5A1_UNORM,
- PIPE_FORMAT_B4G4R4A4_UNORM,
- #PIPE_FORMAT_Z32_UNORM,
- #PIPE_FORMAT_S8_USCALED_Z24_UNORM,
- #PIPE_FORMAT_X8Z24_UNORM,
- #PIPE_FORMAT_Z16_UNORM,
- #PIPE_FORMAT_S8_USCALED,
- PIPE_FORMAT_A8_UNORM,
- PIPE_FORMAT_L8_UNORM,
- #PIPE_FORMAT_DXT1_RGB,
- #PIPE_FORMAT_DXT1_RGBA,
- #PIPE_FORMAT_DXT3_RGBA,
- #PIPE_FORMAT_DXT5_RGBA,
- ]
-
- sizes = [64, 32, 16, 8, 4, 2, 1]
- #sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
- #sizes = [64]
- #sizes = [63]
-
- faces = [
- PIPE_TEX_FACE_POS_X,
- PIPE_TEX_FACE_NEG_X,
- PIPE_TEX_FACE_POS_Y,
- PIPE_TEX_FACE_NEG_Y,
- PIPE_TEX_FACE_POS_Z,
- PIPE_TEX_FACE_NEG_Z,
- ]
-
- for target in targets:
- for format in formats:
- for size in sizes:
- if target == PIPE_TEXTURE_3D:
- depth = size
- else:
- depth = 1
- for face in faces:
- if target != PIPE_TEXTURE_CUBE and face:
- continue
- levels = lods(size)
- for last_level in range(levels):
- for level in range(0, last_level + 1):
- zslice = 0
- while zslice < depth >> level:
- test = TextureTest(
- dev = dev,
- target = target,
- format = format,
- width = size,
- height = size,
- depth = depth,
- last_level = last_level,
- face = face,
- level = level,
- zslice = zslice,
- )
- suite.add_test(test)
- zslice = (zslice + 1)*2 - 1
- suite.run()
-
-
-if __name__ == '__main__':
- main()
+++ /dev/null
-#!/usr/bin/env python
-#
-# See also:
-# http://www.ailab.si/orange/doc/ofb/c_otherclass.htm
-
-import os.path
-import sys
-
-import orange
-import orngTree
-
-for arg in sys.argv[1:]:
- name, ext = os.path.splitext(arg)
-
- data = orange.ExampleTable(arg)
-
- tree = orngTree.TreeLearner(data, sameMajorityPruning=1, mForPruning=2)
-
- orngTree.printTxt(tree)
-
- file(name+'.txt', 'wt').write(orngTree.dumpTree(tree) + '\n')
-
- orngTree.printDot(tree, fileName=name+'.dot', nodeShape='ellipse', leafShape='box')
+++ /dev/null
-tri
-quad-tex
-result.bmp
+++ /dev/null
-# 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 $(LINKS)
- $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -ldl -o $@
+++ /dev/null
-# progs/gallium/simple/Makefile
-
-TOP = ../../../..
-include $(TOP)/configs/current
-
-INCLUDES = \
- -I. \
- -I$(TOP)/src/gallium/include \
- -I$(TOP)/src/gallium/auxiliary \
- -I$(TOP)/src/gallium/drivers \
- -I$(TOP)/src/gallium/winsys \
- $(PROG_INCLUDES)
-
-LINKS = \
- $(TOP)/src/gallium/drivers/trace/libtrace.a \
- $(TOP)/src/gallium/winsys/sw/null/libws_null.a \
- $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
- $(GALLIUM_AUXILIARIES) \
- $(PROG_LINKS)
-
-SOURCES = \
- pipe_barrier_test.c \
- u_cache_test.c \
- u_half_test.c \
- u_format_test.c
-
-
-OBJECTS = $(SOURCES:.c=.o)
-
-PROGS = $(OBJECTS:.o=)
-
-##### TARGETS #####
-
-default: $(PROGS)
-
-clean:
- -rm -f $(PROGS)
- -rm -f *.o
- -rm -f result.bmp
-
-##### RULES #####
-
-$(OBJECTS): %.o: %.c
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@
-
-$(PROGS): %: %.o
- $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -ldl -o $@
+++ /dev/null
-Import('*')
-
-env = env.Clone()
-
-env.Prepend(LIBS = [gallium])
-
-progs = [
- 'pipe_barrier_test',
- 'u_cache_test',
- 'u_format_test',
- 'u_half_test'
-]
-
-for prog in progs:
- prog = env.Program(
- target = prog,
- source = prog + '.c',
- )
-
- env.InstallProgram(prog)
-
- # http://www.scons.org/wiki/UnitTests
- test_alias = env.Alias('unit', [prog], prog[0].abspath)
- AlwaysBuild(test_alias)
-
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009-2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-/*
- * Test case for pipe_barrier.
- *
- * The test succeeds if no thread exits before all the other threads reach
- * the barrier.
- */
-
-
-#include <stdio.h>
-
-#include "os/os_thread.h"
-#include "os/os_time.h"
-
-
-#define NUM_THREADS 10
-
-static pipe_thread threads[NUM_THREADS];
-static pipe_barrier barrier;
-static int thread_ids[NUM_THREADS];
-
-
-static PIPE_THREAD_ROUTINE(thread_function, thread_data)
-{
- int thread_id = *((int *) thread_data);
-
- printf("thread %d starting\n", thread_id);
- os_time_sleep(thread_id * 1000 * 1000);
- printf("thread %d before barrier\n", thread_id);
- pipe_barrier_wait(&barrier);
- printf("thread %d exiting\n", thread_id);
-
- return NULL;
-}
-
-
-int main()
-{
- int i;
-
- printf("pipe_barrier_test starting\n");
-
- pipe_barrier_init(&barrier, NUM_THREADS);
-
- for (i = 0; i < NUM_THREADS; i++) {
- thread_ids[i] = i;
- threads[i] = pipe_thread_create(thread_function, (void *) &thread_ids[i]);
- }
-
- for (i = 0; i < NUM_THREADS; i++ ) {
- pipe_thread_wait(threads[i]);
- }
-
- pipe_barrier_destroy(&barrier);
-
- printf("pipe_barrier_test exiting\n");
-
- return 0;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-/*
- * Test case for u_cache.
- */
-
-
-#include <assert.h>
-#include <stdio.h>
-
-#include "util/u_cache.h"
-#include "util/u_hash.h"
-
-
-typedef uint32_t cache_test_key;
-typedef uint32_t cache_test_value;
-
-
-static uint32_t
-cache_test_hash(const void *key)
-{
- return util_hash_crc32(key, sizeof(cache_test_key));
-}
-
-
-static void
-cache_test_destroy(void *key, void *value)
-{
- free(key);
- free(value);
-}
-
-
-static int
-cache_test_compare(const void *key1, const void *key2) {
- return !(key1 == key2);
-}
-
-
-int main() {
- unsigned cache_size;
- unsigned cache_count;
-
- for (cache_size = 2; cache_size < (1 << 15); cache_size *= 2) {
- for (cache_count = (cache_size << 5); cache_count < (cache_size << 10); cache_count *= 2) {
- struct util_cache * cache;
- cache_test_key *key;
- cache_test_value *value_in;
- cache_test_value *value_out;
- int i;
-
- printf("Testing cache size of %d with %d values.\n", cache_size, cache_count);
-
- cache = util_cache_create(cache_test_hash,
- cache_test_compare,
- cache_test_destroy,
- cache_size);
-
- /*
- * Retrieve a value from an empty cache.
- */
- key = malloc(sizeof(cache_test_key));
- *key = 0xdeadbeef;
- value_out = (cache_test_value *) util_cache_get(cache, key);
- assert(value_out == NULL);
- free(key);
-
-
- /*
- * Repeatedly insert into and retrieve values from the cache.
- */
- for (i = 0; i < cache_count; i++) {
- key = malloc(sizeof(cache_test_key));
- value_in = malloc(sizeof(cache_test_value));
-
- *key = rand();
- *value_in = rand();
- util_cache_set(cache, key, value_in);
-
- value_out = util_cache_get(cache, key);
- assert(value_out != NULL);
- assert(value_in == value_out);
- assert(*value_in == *value_out);
- }
-
- /*
- * In debug builds, this will trigger a self-check by the cache of
- * the distribution of hits in its internal cache entries.
- */
- util_cache_destroy(cache);
- }
- }
-
- return 0;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009-2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <float.h>
-
-#include "util/u_half.h"
-#include "util/u_format.h"
-#include "util/u_format_tests.h"
-#include "util/u_format_s3tc.h"
-
-
-static boolean
-compare_float(float x, float y)
-{
- float error = y - x;
-
- if (error < 0.0f)
- error = -error;
-
- if (error > FLT_EPSILON) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-static void
-print_packed(const struct util_format_description *format_desc,
- const char *prefix,
- const uint8_t *packed,
- const char *suffix)
-{
- unsigned i;
- const char *sep = "";
-
- printf("%s", prefix);
- for (i = 0; i < format_desc->block.bits/8; ++i) {
- printf("%s%02x", sep, packed[i]);
- sep = " ";
- }
- printf("%s", suffix);
-}
-
-
-static void
-print_unpacked_rgba_doubl(const struct util_format_description *format_desc,
- const char *prefix,
- const double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
- const char *suffix)
-{
- unsigned i, j;
- const char *sep = "";
-
- printf("%s", prefix);
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
- sep = ", ";
- }
- sep = ",\n";
- }
- printf("%s", suffix);
-}
-
-
-static void
-print_unpacked_rgba_float(const struct util_format_description *format_desc,
- const char *prefix,
- float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
- const char *suffix)
-{
- unsigned i, j;
- const char *sep = "";
-
- printf("%s", prefix);
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
- sep = ", ";
- }
- sep = ",\n";
- }
- printf("%s", suffix);
-}
-
-
-static void
-print_unpacked_rgba_8unorm(const struct util_format_description *format_desc,
- const char *prefix,
- uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
- const char *suffix)
-{
- unsigned i, j;
- const char *sep = "";
-
- printf("%s", prefix);
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- printf("%s{0x%02x, 0x%02x, 0x%02x, 0x%02x}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
- sep = ", ";
- }
- }
- printf("%s", suffix);
-}
-
-
-static void
-print_unpacked_z_float(const struct util_format_description *format_desc,
- const char *prefix,
- float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
- const char *suffix)
-{
- unsigned i, j;
- const char *sep = "";
-
- printf("%s", prefix);
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- printf("%s%f", sep, unpacked[i][j]);
- sep = ", ";
- }
- sep = ",\n";
- }
- printf("%s", suffix);
-}
-
-
-static void
-print_unpacked_z_32unorm(const struct util_format_description *format_desc,
- const char *prefix,
- uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
- const char *suffix)
-{
- unsigned i, j;
- const char *sep = "";
-
- printf("%s", prefix);
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- printf("%s0x%08x", sep, unpacked[i][j]);
- sep = ", ";
- }
- }
- printf("%s", suffix);
-}
-
-
-static void
-print_unpacked_s_8uscaled(const struct util_format_description *format_desc,
- const char *prefix,
- uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
- const char *suffix)
-{
- unsigned i, j;
- const char *sep = "";
-
- printf("%s", prefix);
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- printf("%s0x%02x", sep, unpacked[i][j]);
- sep = ", ";
- }
- }
- printf("%s", suffix);
-}
-
-
-static boolean
-test_format_fetch_rgba_float(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
- unsigned i, j, k;
- boolean success;
-
- success = TRUE;
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- format_desc->fetch_rgba_float(unpacked[i][j], test->packed, j, i);
- for (k = 0; k < 4; ++k) {
- if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
- success = FALSE;
- }
- }
- }
- }
-
- if (!success) {
- print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n");
- print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_unpack_rgba_float(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
- unsigned i, j, k;
- boolean success;
-
- format_desc->unpack_rgba_float(&unpacked[0][0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
-
- success = TRUE;
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- for (k = 0; k < 4; ++k) {
- if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
- success = FALSE;
- }
- }
- }
- }
-
- if (!success) {
- print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n");
- print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_pack_rgba_float(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
- uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
- unsigned i, j, k;
- boolean success;
-
- if (test->format == PIPE_FORMAT_DXT1_RGBA) {
- /*
- * Skip S3TC as packed representation is not canonical.
- *
- * TODO: Do a round trip conversion.
- */
- return TRUE;
- }
-
- memset(packed, 0, sizeof packed);
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- for (k = 0; k < 4; ++k) {
- unpacked[i][j][k] = (float) test->unpacked[i][j][k];
- }
- }
- }
-
- format_desc->pack_rgba_float(packed, 0,
- &unpacked[0][0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
-
- success = TRUE;
- for (i = 0; i < format_desc->block.bits/8; ++i)
- if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
- success = FALSE;
-
- if (!success) {
- print_packed(format_desc, "FAILED: ", packed, " obtained\n");
- print_packed(format_desc, " ", test->packed, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-convert_float_to_8unorm(uint8_t *dst, const double *src)
-{
- unsigned i;
- boolean accurate = TRUE;
-
- for (i = 0; i < UTIL_FORMAT_MAX_UNPACKED_HEIGHT*UTIL_FORMAT_MAX_UNPACKED_WIDTH*4; ++i) {
- if (src[i] < 0.0) {
- accurate = FALSE;
- dst[i] = 0;
- }
- else if (src[i] > 1.0) {
- accurate = FALSE;
- dst[i] = 255;
- }
- else {
- dst[i] = src[i] * 255.0;
- }
- }
-
- return accurate;
-}
-
-
-static boolean
-test_format_unpack_rgba_8unorm(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
- uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
- unsigned i, j, k;
- boolean success;
-
- format_desc->unpack_rgba_8unorm(&unpacked[0][0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
-
- convert_float_to_8unorm(&expected[0][0][0], &test->unpacked[0][0][0]);
-
- success = TRUE;
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- for (k = 0; k < 4; ++k) {
- if (expected[i][j][k] != unpacked[i][j][k]) {
- success = FALSE;
- }
- }
- }
- }
-
- if (!success) {
- print_unpacked_rgba_8unorm(format_desc, "FAILED: ", unpacked, " obtained\n");
- print_unpacked_rgba_8unorm(format_desc, " ", expected, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_pack_rgba_8unorm(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
- uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
- unsigned i;
- boolean success;
-
- if (test->format == PIPE_FORMAT_DXT1_RGBA) {
- /*
- * Skip S3TC as packed representation is not canonical.
- *
- * TODO: Do a round trip conversion.
- */
- return TRUE;
- }
-
- if (!convert_float_to_8unorm(&unpacked[0][0][0], &test->unpacked[0][0][0])) {
- /*
- * Skip test cases which cannot be represented by four unorm bytes.
- */
- return TRUE;
- }
-
- memset(packed, 0, sizeof packed);
-
- format_desc->pack_rgba_8unorm(packed, 0,
- &unpacked[0][0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
-
- success = TRUE;
- for (i = 0; i < format_desc->block.bits/8; ++i)
- if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
- success = FALSE;
-
- if (!success) {
- print_packed(format_desc, "FAILED: ", packed, " obtained\n");
- print_packed(format_desc, " ", test->packed, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_unpack_z_float(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
- unsigned i, j;
- boolean success;
-
- format_desc->unpack_z_float(&unpacked[0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
-
- success = TRUE;
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- if (!compare_float(test->unpacked[i][j][0], unpacked[i][j])) {
- success = FALSE;
- }
- }
- }
-
- if (!success) {
- print_unpacked_z_float(format_desc, "FAILED: ", unpacked, " obtained\n");
- print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_pack_z_float(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
- uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
- unsigned i, j;
- boolean success;
-
- memset(packed, 0, sizeof packed);
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- unpacked[i][j] = (float) test->unpacked[i][j][0];
- if (test->unpacked[i][j][1]) {
- return TRUE;
- }
- }
- }
-
- format_desc->pack_z_float(packed, 0,
- &unpacked[0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
-
- success = TRUE;
- for (i = 0; i < format_desc->block.bits/8; ++i)
- if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
- success = FALSE;
-
- if (!success) {
- print_packed(format_desc, "FAILED: ", packed, " obtained\n");
- print_packed(format_desc, " ", test->packed, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_unpack_z_32unorm(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
- uint32_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
- unsigned i, j;
- boolean success;
-
- format_desc->unpack_z_32unorm(&unpacked[0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
-
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- expected[i][j] = test->unpacked[i][j][0] * 0xffffffff;
- }
- }
-
- success = TRUE;
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- if (expected[i][j] != unpacked[i][j]) {
- success = FALSE;
- }
- }
- }
-
- if (!success) {
- print_unpacked_z_32unorm(format_desc, "FAILED: ", unpacked, " obtained\n");
- print_unpacked_z_32unorm(format_desc, " ", expected, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_pack_z_32unorm(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
- uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
- unsigned i, j;
- boolean success;
-
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- unpacked[i][j] = test->unpacked[i][j][0] * 0xffffffff;
- if (test->unpacked[i][j][1]) {
- return TRUE;
- }
- }
- }
-
- memset(packed, 0, sizeof packed);
-
- format_desc->pack_z_32unorm(packed, 0,
- &unpacked[0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
-
- success = TRUE;
- for (i = 0; i < format_desc->block.bits/8; ++i)
- if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
- success = FALSE;
-
- if (!success) {
- print_packed(format_desc, "FAILED: ", packed, " obtained\n");
- print_packed(format_desc, " ", test->packed, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_unpack_s_8uscaled(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
- uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
- unsigned i, j;
- boolean success;
-
- format_desc->unpack_s_8uscaled(&unpacked[0][0], sizeof unpacked[0],
- test->packed, 0,
- format_desc->block.width, format_desc->block.height);
-
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- expected[i][j] = test->unpacked[i][j][1];
- }
- }
-
- success = TRUE;
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- if (expected[i][j] != unpacked[i][j]) {
- success = FALSE;
- }
- }
- }
-
- if (!success) {
- print_unpacked_s_8uscaled(format_desc, "FAILED: ", unpacked, " obtained\n");
- print_unpacked_s_8uscaled(format_desc, " ", expected, " expected\n");
- }
-
- return success;
-}
-
-
-static boolean
-test_format_pack_s_8uscaled(const struct util_format_description *format_desc,
- const struct util_format_test_case *test)
-{
- uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
- uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
- unsigned i, j;
- boolean success;
-
- for (i = 0; i < format_desc->block.height; ++i) {
- for (j = 0; j < format_desc->block.width; ++j) {
- unpacked[i][j] = test->unpacked[i][j][1];
- if (test->unpacked[i][j][0]) {
- return TRUE;
- }
- }
- }
-
- memset(packed, 0, sizeof packed);
-
- format_desc->pack_s_8uscaled(packed, 0,
- &unpacked[0][0], sizeof unpacked[0],
- format_desc->block.width, format_desc->block.height);
-
- success = TRUE;
- for (i = 0; i < format_desc->block.bits/8; ++i)
- if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
- success = FALSE;
-
- if (!success) {
- print_packed(format_desc, "FAILED: ", packed, " obtained\n");
- print_packed(format_desc, " ", test->packed, " expected\n");
- }
-
- return success;
-}
-
-
-typedef boolean
-(*test_func_t)(const struct util_format_description *format_desc,
- const struct util_format_test_case *test);
-
-
-static boolean
-test_one_func(const struct util_format_description *format_desc,
- test_func_t func,
- const char *suffix)
-{
- unsigned i;
- bool success = TRUE;
-
- printf("Testing util_format_%s_%s ...\n",
- format_desc->short_name, suffix);
-
- for (i = 0; i < util_format_nr_test_cases; ++i) {
- const struct util_format_test_case *test = &util_format_test_cases[i];
-
- if (test->format == format_desc->format) {
- if (!func(format_desc, &util_format_test_cases[i])) {
- success = FALSE;
- }
- }
- }
-
- return success;
-}
-
-
-static boolean
-test_all(void)
-{
- enum pipe_format format;
- bool success = TRUE;
-
- for (format = 1; format < PIPE_FORMAT_COUNT; ++format) {
- const struct util_format_description *format_desc;
-
- format_desc = util_format_description(format);
- if (!format_desc) {
- continue;
- }
-
- if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC &&
- !util_format_s3tc_enabled) {
- continue;
- }
-
-# define TEST_ONE_FUNC(name) \
- if (format_desc->name) { \
- if (!test_one_func(format_desc, &test_format_##name, #name)) { \
- success = FALSE; \
- } \
- }
-
- TEST_ONE_FUNC(fetch_rgba_float);
- TEST_ONE_FUNC(pack_rgba_float);
- TEST_ONE_FUNC(unpack_rgba_float);
- TEST_ONE_FUNC(pack_rgba_8unorm);
- TEST_ONE_FUNC(unpack_rgba_8unorm);
-
- TEST_ONE_FUNC(unpack_z_32unorm);
- TEST_ONE_FUNC(pack_z_32unorm);
- TEST_ONE_FUNC(unpack_z_float);
- TEST_ONE_FUNC(pack_z_float);
- TEST_ONE_FUNC(unpack_s_8uscaled);
- TEST_ONE_FUNC(pack_s_8uscaled);
-
-# undef TEST_ONE_FUNC
- }
-
- return success;
-}
-
-
-int main(int argc, char **argv)
-{
- boolean success;
-
- util_format_s3tc_init();
-
- success = test_all();
-
- return success ? 0 : 1;
-}
+++ /dev/null
-#include <stdlib.h>
-#include <stdio.h>
-#include <float.h>
-
-#include "util/u_math.h"
-#include "util/u_half.h"
-
-int
-main(int argc, char **argv)
-{
- unsigned i;
- unsigned roundtrip_fails = 0;
- for(i = 0; i < 1 << 16; ++i)
- {
- uint16_t h = (uint16_t) i;
- union fi f;
- uint16_t rh;
- f.ui = util_half_to_floatui(h);
- rh = util_floatui_to_half(f.ui);
- if(h != rh)
- {
- printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh);
- ++roundtrip_fails;
- }
- }
-
- if(roundtrip_fails)
- printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails);
- else
- printf("Success!\n");
- return 0;
-}