st/python: Remove bindings, and all its dependencies.

Because:
- bindings are not fully automatic, and they are broken most of the time
- unit tests/samples can be written in C on top of graw
- tracing/retracing is more useful at API levels with stable ABIs such as
  GL, producing traces that cover more layers of the driver stack and and
  can be used for regression testing
This commit is contained in:
José Fonseca 2011-04-04 11:41:30 +01:00
parent 14b574433c
commit afeaf1771d
101 changed files with 8 additions and 7401 deletions

View File

@ -1,72 +0,0 @@
"""gallium
Frontend-tool for Gallium3D architecture.
"""
#
# 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 distutils.sysconfig
import os.path
def generate(env):
# See http://www.scons.org/wiki/PythonExtensions
if sys.platform in ['win32']:
python_root = sys.prefix
python_version = '%u%u' % sys.version_info[:2]
python_include = os.path.join(python_root, 'include')
python_libs = os.path.join(python_root, 'libs')
python_lib = os.path.join(python_libs, 'python' + python_version + '.lib')
env.Append(CPPPATH = [python_include])
env.Append(LIBPATH = [python_libs])
env.Append(LIBS = ['python' + python_version + '.lib'])
env.Replace(SHLIBPREFIX = '')
env.Replace(SHLIBSUFFIX = '.pyd')
# XXX; python25_d.lib is not included in Python for windows, and
# we'll get missing symbols unless we undefine _DEBUG
cppdefines = env['CPPDEFINES']
cppdefines = [define for define in cppdefines if define != '_DEBUG']
env.Replace(CPPDEFINES = cppdefines)
env.AppendUnique(CPPFLAGS = ['/U_DEBUG'])
env.AppendUnique(LINKFLAGS = ['/nodefaultlib:python25_d.lib'])
else:
#env.ParseConfig('python-config --cflags --ldflags --libs')
env.AppendUnique(CPPPATH = [distutils.sysconfig.get_python_inc()])
env.Replace(SHLIBPREFIX = '')
env.Replace(SHLIBSUFFIX = distutils.sysconfig.get_config_vars()['SO'])
# for debugging
#print env.Dump()
def exists(env):
return 1

View File

@ -53,7 +53,6 @@ if env['drm']:
# Needed by some state trackers
SConscript('winsys/sw/null/SConscript')
SConscript('state_trackers/python/SConscript')
if env['platform'] != 'embedded':
SConscript('state_trackers/vega/SConscript')
SConscript('state_trackers/egl/SConscript')

View File

@ -13,12 +13,17 @@ It can traces all incoming calls.
For tracing then do
GALLIUM_TRACE=tri.trace progs/trivial/tri
GALLIUM_TRACE=tri.trace trivial/tri
which should create a tri.trace file, which is an XML file. You can view copying
trace.xsl to the same directory, and opening with a XSLT capable browser such as
Firefox or Internet Explorer.
For long traces you can use the
src/gallium/tools/trace/dump.py tri.trace | less -R
== Remote debugging ==
For remote debugging see:

View File

@ -1,43 +0,0 @@
This directory contains Python bindings to Gallium3D. It looks like a state
tracker from the pipe driver perspective, and it looks like a pipe driver from
the python script perspective.
To build you'll need:
* Python (with development packages)
* SCons
* SWIG, http://www.swig.org/download.html
* Python Imaging Library with TK support, http://www.pythonware.com/products/pil/,
for the samples
On a debian-based distro you can simply do:
aptitude install python-dev scons swig python-imaging python-imaging-tk
On a Windows machine ensure the swig command is in your PATH.
Invoke scons on the top dir as
scons debug=yes statetrackers=python drivers=softpipe winsys=none
To use it set PYTHONPATH appropriately, e.g, in Linux do:
export PYTHONPATH=$PWD/build/linux-x86-debug/gallium/state_trackers/python
or (in Windows)
set PYTHONPATH=%CD%\build\windows-x86-debug\gallium\state_trackers\python
and then try running
python progs/gallium/python/samples/tri.py
which should show a triangle.
This is still work in progress:
- errors are not handled properly and almost always result in crash
- state atoms with array members are awkward to set
--
Jose Fonseca <jfonseca@vmware.com>

View File

@ -1,66 +0,0 @@
import sys
import os.path
Import('*')
if env['toolchain'] == 'crossmingw':
# Cross-compilation not supported
Return()
if not env.Detect(['swig']):
Return()
env = env.Clone()
env.Tool('python')
env.Tool('swig')
env.Append(SWIGPATH = ['#src/gallium/include', '#src/gallium/include/pipe'])
env.Append(SWIGFLAGS = ['-python', '-keyword'])
env.Append(CPPPATH = '.')
if env['platform'] == 'windows':
env.Append(LIBS = [
'opengl32',
'gdi32',
'user32',
'kernel32',
'ws2_32',
])
else:
env.Append(CPPDEFINES = ['GCC_HASCLASSVISIBILITY'])
env.Append(LIBS = [
'GL',
'X11',
])
sources = [
'gallium.i',
'st_device.c',
'st_sample.c',
'st_hardpipe_winsys.c',
'st_softpipe_winsys.c',
]
env.Prepend(LIBS = [
ws_null,
trace,
gallium,
])
if env['llvm']:
env.Append(CPPDEFINES = ['HAVE_LLVMPIPE'])
env.Prepend(LIBS = [llvmpipe])
if True:
env.Append(CPPDEFINES = ['HAVE_SOFTPIPE'])
env.Prepend(LIBS = [softpipe])
env['no_import_lib'] = 1
pyst = env.SharedLibrary(
target = '_gallium',
source = sources,
)
env.Alias('python', pyst)

View File

@ -1,105 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/**
* @file
* SWIG interface definion for Gallium types.
*
* @author Jose Fonseca <jrfonseca@tungstengraphics.com>
*/
%module gallium;
%{
#include <stdio.h>
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h"
#include "os/os_stream.h"
#include "util/u_inlines.h"
#include "util/u_draw_quad.h"
#include "util/u_tile.h"
#include "util/u_math.h"
#include "util/u_format.h"
#include "util/u_dump.h"
#include "util/u_memory.h"
#include "util/u_sampler.h"
#include "cso_cache/cso_context.h"
#include "tgsi/tgsi_text.h"
#include "tgsi/tgsi_dump.h"
#include "st_device.h"
#include "st_sample.h"
%}
%include "typemaps.i"
%include "exception.i"
%include "cstring.i"
%include "carrays.i"
%array_class(unsigned char, ByteArray);
%array_class(int, IntArray);
%array_class(unsigned, UnsignedArray);
%array_class(float, FloatArray);
%rename(Device) st_device;
%rename(Context) st_context;
%rename(Resource) pipe_resource;
%rename(Surface) st_surface;
%rename(BlendColor) pipe_blend_color;
%rename(Blend) pipe_blend_state;
%rename(Clip) pipe_clip_state;
%rename(Depth) pipe_depth_state;
%rename(Stencil) pipe_stencil_state;
%rename(Alpha) pipe_alpha_state;
%rename(DepthStencilAlpha) pipe_depth_stencil_alpha_state;
%rename(Framebuffer) pipe_framebuffer_state;
%rename(PolyStipple) pipe_poly_stipple;
%rename(Rasterizer) pipe_rasterizer_state;
%rename(Sampler) pipe_sampler_state;
%rename(Scissor) pipe_scissor_state;
%rename(Shader) pipe_shader_state;
%rename(VertexBuffer) pipe_vertex_buffer;
%rename(VertexElement) pipe_vertex_element;
%rename(Viewport) pipe_viewport_state;
%include "p_compiler.i"
%include "p_defines.h"
%include "p_format.h"
%include "p_device.i"
%include "p_context.i"
%include "p_texture.i"
%include "p_state.i"
%include "u_format.i"

View File

@ -1,29 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
typedef unsigned char ubyte;

View File

@ -1,756 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/**
* @file
* SWIG interface definion for Gallium types.
*
* @author Jose Fonseca <jrfonseca@tungstengraphics.com>
*/
%nodefaultctor st_context;
%nodefaultdtor st_context;
struct st_context {
};
%extend st_context {
~st_context() {
st_context_destroy($self);
}
/*
* State functions (create/bind/destroy state objects)
*/
void set_blend( const struct pipe_blend_state *state ) {
cso_set_blend($self->cso, state);
}
void set_fragment_sampler( unsigned index, const struct pipe_sampler_state *state ) {
cso_single_sampler($self->cso, index, state);
cso_single_sampler_done($self->cso);
}
void set_vertex_sampler( unsigned index, const struct pipe_sampler_state *state ) {
cso_single_vertex_sampler($self->cso, index, state);
cso_single_vertex_sampler_done($self->cso);
}
void set_rasterizer( const struct pipe_rasterizer_state *state ) {
cso_set_rasterizer($self->cso, state);
}
void set_depth_stencil_alpha(const struct pipe_depth_stencil_alpha_state *state) {
cso_set_depth_stencil_alpha($self->cso, state);
}
void set_fragment_shader( const struct pipe_shader_state *state ) {
void *fs;
if(!state) {
cso_set_fragment_shader_handle($self->cso, NULL);
return;
}
fs = $self->pipe->create_fs_state($self->pipe, state);
if(!fs)
return;
if(cso_set_fragment_shader_handle($self->cso, fs) != PIPE_OK)
return;
cso_delete_fragment_shader($self->cso, $self->fs);
$self->fs = fs;
}
void set_vertex_shader( const struct pipe_shader_state *state ) {
void *vs;
if(!state) {
cso_set_vertex_shader_handle($self->cso, NULL);
return;
}
vs = $self->pipe->create_vs_state($self->pipe, state);
if(!vs)
return;
if(cso_set_vertex_shader_handle($self->cso, vs) != PIPE_OK)
return;
cso_delete_vertex_shader($self->cso, $self->vs);
$self->vs = vs;
}
void set_geometry_shader( const struct pipe_shader_state *state ) {
void *gs;
if(!state) {
cso_set_geometry_shader_handle($self->cso, NULL);
return;
}
gs = $self->pipe->create_gs_state($self->pipe, state);
if(!gs)
return;
if(cso_set_geometry_shader_handle($self->cso, gs) != PIPE_OK)
return;
cso_delete_geometry_shader($self->cso, $self->gs);
$self->gs = gs;
}
struct pipe_sampler_view *
create_sampler_view(struct pipe_resource *texture,
enum pipe_format format = PIPE_FORMAT_NONE,
unsigned first_level = 0,
unsigned last_level = ~0,
unsigned first_layer = 0,
unsigned last_layer = ~0,
unsigned swizzle_r = 0,
unsigned swizzle_g = 1,
unsigned swizzle_b = 2,
unsigned swizzle_a = 3)
{
struct pipe_context *pipe = $self->pipe;
struct pipe_sampler_view templat;
memset(&templat, 0, sizeof templat);
if (format == PIPE_FORMAT_NONE) {
templat.format = texture->format;
} else {
templat.format = format;
}
templat.u.tex.last_level = MIN2(last_level, texture->last_level);
templat.u.tex.first_level = first_level;
templat.u.tex.first_layer = first_layer;
templat.u.tex.last_layer = last_layer;
templat.swizzle_r = swizzle_r;
templat.swizzle_g = swizzle_g;
templat.swizzle_b = swizzle_b;
templat.swizzle_a = swizzle_a;
return pipe->create_sampler_view(pipe, texture, &templat);
}
void
sampler_view_destroy(struct pipe_context *ctx,
struct pipe_sampler_view *view)
{
struct pipe_context *pipe = $self->pipe;
pipe->sampler_view_destroy(pipe, view);
}
/*
* Parameter-like state (or properties)
*/
void set_blend_color(const struct pipe_blend_color *state ) {
cso_set_blend_color($self->cso, state);
}
void set_stencil_ref(const struct pipe_stencil_ref *state ) {
cso_set_stencil_ref($self->cso, state);
}
void set_clip(const struct pipe_clip_state *state ) {
$self->pipe->set_clip_state($self->pipe, state);
}
void set_constant_buffer(unsigned shader, unsigned index,
struct pipe_resource *buffer )
{
$self->pipe->set_constant_buffer($self->pipe, shader, index, buffer);
}
void set_framebuffer(const struct pipe_framebuffer_state *state )
{
memcpy(&$self->framebuffer, state, sizeof *state);
cso_set_framebuffer($self->cso, state);
}
void set_polygon_stipple(const struct pipe_poly_stipple *state ) {
$self->pipe->set_polygon_stipple($self->pipe, state);
}
void set_scissor(const struct pipe_scissor_state *state ) {
$self->pipe->set_scissor_state($self->pipe, state);
}
void set_viewport(const struct pipe_viewport_state *state) {
cso_set_viewport($self->cso, state);
}
void set_fragment_sampler_view(unsigned index,
struct pipe_sampler_view *view)
{
pipe_sampler_view_reference(&$self->fragment_sampler_views[index], view);
$self->pipe->set_fragment_sampler_views($self->pipe,
PIPE_MAX_SAMPLERS,
$self->fragment_sampler_views);
}
void set_vertex_sampler_view(unsigned index,
struct pipe_sampler_view *view)
{
pipe_sampler_view_reference(&$self->vertex_sampler_views[index], view);
$self->pipe->set_vertex_sampler_views($self->pipe,
PIPE_MAX_VERTEX_SAMPLERS,
$self->vertex_sampler_views);
}
void set_fragment_sampler_texture(unsigned index,
struct pipe_resource *texture) {
struct pipe_sampler_view templ;
if(!texture)
texture = $self->default_texture;
pipe_sampler_view_reference(&$self->fragment_sampler_views[index], NULL);
u_sampler_view_default_template(&templ,
texture,
texture->format);
$self->fragment_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe,
texture,
&templ);
$self->pipe->set_fragment_sampler_views($self->pipe,
PIPE_MAX_SAMPLERS,
$self->fragment_sampler_views);
}
void set_vertex_sampler_texture(unsigned index,
struct pipe_resource *texture) {
struct pipe_sampler_view templ;
if(!texture)
texture = $self->default_texture;
pipe_sampler_view_reference(&$self->vertex_sampler_views[index], NULL);
u_sampler_view_default_template(&templ,
texture,
texture->format);
$self->vertex_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe,
texture,
&templ);
$self->pipe->set_vertex_sampler_views($self->pipe,
PIPE_MAX_VERTEX_SAMPLERS,
$self->vertex_sampler_views);
}
void set_vertex_buffer(unsigned index,
unsigned stride,
unsigned buffer_offset,
struct pipe_resource *buffer)
{
unsigned i;
struct pipe_vertex_buffer state;
memset(&state, 0, sizeof(state));
state.stride = stride;
state.buffer_offset = buffer_offset;
state.buffer = buffer;
memcpy(&$self->vertex_buffers[index], &state, sizeof(state));
for(i = 0; i < PIPE_MAX_ATTRIBS; ++i)
if(self->vertex_buffers[i].buffer)
$self->num_vertex_buffers = i + 1;
$self->pipe->set_vertex_buffers($self->pipe,
$self->num_vertex_buffers,
$self->vertex_buffers);
}
void set_index_buffer(unsigned index_size,
unsigned offset,
struct pipe_resource *buffer)
{
struct pipe_index_buffer ib;
memset(&ib, 0, sizeof(ib));
ib.index_size = index_size;
ib.offset = offset;
ib.buffer = buffer;
$self->pipe->set_index_buffer($self->pipe, &ib);
}
void set_vertex_element(unsigned index,
const struct pipe_vertex_element *element)
{
memcpy(&$self->vertex_elements[index], element, sizeof(*element));
}
void set_vertex_elements(unsigned num)
{
$self->num_vertex_elements = num;
cso_set_vertex_elements($self->cso,
$self->num_vertex_elements,
$self->vertex_elements);
}
/*
* Draw functions
*/
void draw_arrays(unsigned mode, unsigned start, unsigned count) {
util_draw_arrays($self->pipe, mode, start, count);
}
void draw_vbo(const struct pipe_draw_info *info)
{
$self->pipe->draw_vbo($self->pipe, info);
}
void draw_vertices(unsigned prim,
unsigned num_verts,
unsigned num_attribs,
const float *vertices)
{
struct pipe_context *pipe = $self->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_resource *vbuf;
struct pipe_transfer *transfer;
struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
struct pipe_vertex_buffer vbuffer;
float *map;
unsigned size;
unsigned i;
size = num_verts * num_attribs * 4 * sizeof(float);
vbuf = pipe_buffer_create(screen,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
size);
if(!vbuf)
goto error1;
map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer);
if (!map)
goto error2;
memcpy(map, vertices, size);
pipe_buffer_unmap(pipe, transfer);
cso_save_vertex_elements($self->cso);
/* tell pipe about the vertex attributes */
for (i = 0; i < num_attribs; i++) {
velements[i].src_offset = i * 4 * sizeof(float);
velements[i].instance_divisor = 0;
velements[i].vertex_buffer_index = 0;
velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
}
cso_set_vertex_elements($self->cso, num_attribs, velements);
/* tell pipe about the vertex buffer */
memset(&vbuffer, 0, sizeof(vbuffer));
vbuffer.buffer = vbuf;
vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */
vbuffer.buffer_offset = 0;
pipe->set_vertex_buffers(pipe, 1, &vbuffer);
/* draw */
util_draw_arrays(pipe, prim, 0, num_verts);
cso_restore_vertex_elements($self->cso);
error2:
pipe_resource_reference(&vbuf, NULL);
error1:
;
}
void
clear(unsigned buffers, const float *rgba, double depth = 0.0f,
unsigned stencil = 0)
{
$self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
}
void
flush(unsigned flags = 0) {
struct pipe_fence_handle *fence = NULL;
$self->pipe->flush($self->pipe, &fence);
if(fence) {
/* TODO: allow asynchronous operation */
$self->pipe->screen->fence_finish( $self->pipe->screen, fence, PIPE_TIMEOUT_INFINITE );
$self->pipe->screen->fence_reference( $self->pipe->screen, &fence, NULL );
}
}
/*
* Surface functions
*/
void resource_copy_region(struct pipe_resource *dst,
unsigned dst_level,
unsigned dstx, unsigned dsty, unsigned dstz,
struct pipe_resource *src,
unsigned src_level,
const struct pipe_box *src_box)
{
$self->pipe->resource_copy_region($self->pipe,
dst, dst_level, dstx, dsty, dstz,
src, src_level, src_box);
}
void clear_render_target(struct st_surface *dst,
float *rgba,
unsigned x, unsigned y,
unsigned width, unsigned height)
{
struct pipe_surface *_dst = NULL;
_dst = st_pipe_surface($self->pipe, dst, PIPE_BIND_RENDER_TARGET);
if(!_dst)
SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
$self->pipe->clear_render_target($self->pipe, _dst, rgba, x, y, width, height);
fail:
pipe_surface_reference(&_dst, NULL);
}
void clear_depth_stencil(struct st_surface *dst,
unsigned clear_flags,
double depth,
unsigned stencil,
unsigned x, unsigned y,
unsigned width, unsigned height)
{
struct pipe_surface *_dst = NULL;
_dst = st_pipe_surface($self->pipe, dst, PIPE_BIND_DEPTH_STENCIL);
if(!_dst)
SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
$self->pipe->clear_depth_stencil($self->pipe, _dst, clear_flags, depth, stencil,
x, y, width, height);
fail:
pipe_surface_reference(&_dst, NULL);
}
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
void
surface_read_raw(struct st_surface *surface,
unsigned x, unsigned y, unsigned w, unsigned h,
char **STRING, int *LENGTH)
{
struct pipe_resource *texture = surface->texture;
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
unsigned stride;
stride = util_format_get_stride(texture->format, w);
*LENGTH = util_format_get_nblocksy(texture->format, h) * stride;
*STRING = (char *) malloc(*LENGTH);
if(!*STRING)
return;
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_READ,
x, y, w, h);
if(transfer) {
pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
pipe->transfer_destroy(pipe, transfer);
}
}
%cstring_input_binary(const char *STRING, unsigned LENGTH);
void
surface_write_raw(struct st_surface *surface,
unsigned x, unsigned y, unsigned w, unsigned h,
const char *STRING, unsigned LENGTH, unsigned stride = 0)
{
struct pipe_resource *texture = surface->texture;
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
if(stride == 0)
stride = util_format_get_stride(texture->format, w);
if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_WRITE,
x, y, w, h);
if(!transfer)
SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
pipe->transfer_destroy(pipe, transfer);
fail:
return;
}
void
surface_read_rgba(struct st_surface *surface,
unsigned x, unsigned y, unsigned w, unsigned h,
float *rgba)
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_READ,
x, y, w, h);
if(transfer) {
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
pipe->transfer_destroy(pipe, transfer);
}
}
void
surface_write_rgba(struct st_surface *surface,
unsigned x, unsigned y, unsigned w, unsigned h,
const float *rgba)
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_WRITE,
x, y, w, h);
if(transfer) {
pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
pipe->transfer_destroy(pipe, transfer);
}
}
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
void
surface_read_rgba8(struct st_surface *surface,
unsigned x, unsigned y, unsigned w, unsigned h,
char **STRING, int *LENGTH)
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
float *rgba;
unsigned char *rgba8;
unsigned i, j, k;
*LENGTH = 0;
*STRING = NULL;
if (!surface)
return;
*LENGTH = h*w*4;
*STRING = (char *) malloc(*LENGTH);
if(!*STRING)
return;
rgba = malloc(h*w*4*sizeof(float));
if(!rgba)
return;
rgba8 = (unsigned char *) *STRING;
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_READ,
x, y, w, h);
if(transfer) {
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
for(j = 0; j < h; ++j) {
for(i = 0; i < w; ++i)
for(k = 0; k <4; ++k)
rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
}
pipe->transfer_destroy(pipe, transfer);
}
free(rgba);
}
void
surface_read_z(struct st_surface *surface,
unsigned x, unsigned y, unsigned w, unsigned h,
unsigned *z)
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_READ,
x, y, w, h);
if(transfer) {
pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
pipe->transfer_destroy(pipe, transfer);
}
}
void
surface_write_z(struct st_surface *surface,
unsigned x, unsigned y, unsigned w, unsigned h,
const unsigned *z)
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_WRITE,
x, y, w, h);
if(transfer) {
pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
pipe->transfer_destroy(pipe, transfer);
}
}
void
surface_sample_rgba(struct st_surface *surface,
float *rgba,
int norm = 0)
{
st_sample_surface($self->pipe, surface, rgba, norm != 0);
}
unsigned
surface_compare_rgba(struct st_surface *surface,
unsigned x, unsigned y, unsigned w, unsigned h,
const float *rgba, float tol = 0.0)
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
float *rgba2;
const float *p1;
const float *p2;
unsigned i, j, n;
rgba2 = MALLOC(h*w*4*sizeof(float));
if(!rgba2)
return ~0;
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_READ,
x, y, w, h);
if(!transfer) {
FREE(rgba2);
return ~0;
}
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
pipe->transfer_destroy(pipe, transfer);
p1 = rgba;
p2 = rgba2;
n = 0;
for(i = h*w; i; --i) {
unsigned differs = 0;
for(j = 4; j; --j) {
float delta = *p2++ - *p1++;
if (delta < -tol || delta > tol)
differs = 1;
}
n += differs;
}
FREE(rgba2);
return n;
}
%cstring_input_binary(const char *STRING, unsigned LENGTH);
void
transfer_inline_write(struct pipe_resource *resource,
unsigned level,
unsigned usage,
const struct pipe_box *box,
const char *STRING, unsigned LENGTH,
unsigned stride,
unsigned layer_stride)
{
struct pipe_context *pipe = $self->pipe;
pipe->transfer_inline_write(pipe, resource, level, usage, box, STRING, stride, layer_stride);
}
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
void buffer_read(struct pipe_resource *buffer,
char **STRING, int *LENGTH)
{
struct pipe_context *pipe = $self->pipe;
assert(buffer->target == PIPE_BUFFER);
*LENGTH = buffer->width0;
*STRING = (char *) malloc(buffer->width0);
if(!*STRING)
return;
pipe_buffer_read(pipe, buffer, 0, buffer->width0, *STRING);
}
void buffer_write(struct pipe_resource *buffer,
const char *STRING, unsigned LENGTH, unsigned offset = 0)
{
struct pipe_context *pipe = $self->pipe;
assert(buffer->target == PIPE_BUFFER);
if(offset > buffer->width0)
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
if(offset + LENGTH > buffer->width0)
SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
pipe_buffer_write(pipe, buffer, offset, LENGTH, STRING);
fail:
return;
}
};

View File

@ -1,138 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/**
* @file
* SWIG interface definion for Gallium types.
*
* @author Jose Fonseca <jrfonseca@tungstengraphics.com>
*/
%nodefaultctor st_device;
%nodefaultdtor st_device;
struct st_device {
};
%newobject st_device::texture_create;
%newobject st_device::context_create;
%newobject st_device::buffer_create;
%extend st_device {
st_device(int hardware = 1) {
return st_device_create(hardware ? TRUE : FALSE);
}
~st_device() {
st_device_destroy($self);
}
const char * get_name( void ) {
return $self->screen->get_name($self->screen);
}
const char * get_vendor( void ) {
return $self->screen->get_vendor($self->screen);
}
/**
* Query an integer-valued capability/parameter/limit
* \param param one of PIPE_CAP_x
*/
int get_param( int param ) {
return $self->screen->get_param($self->screen, param);
}
/**
* Query a float-valued capability/parameter/limit
* \param param one of PIPE_CAP_x
*/
float get_paramf( int param ) {
return $self->screen->get_paramf($self->screen, param);
}
/**
* Check if the given pipe_format is supported as a texture or
* drawing surface.
* \param bind bitmask of PIPE_BIND flags
*/
int is_format_supported( enum pipe_format format,
enum pipe_texture_target target,
unsigned sample_count,
unsigned bind ) {
/* We can't really display surfaces with the python statetracker so mask
* out that usage */
bind &= ~PIPE_BIND_DISPLAY_TARGET;
return $self->screen->is_format_supported( $self->screen,
format,
target,
sample_count,
bind );
}
struct st_context *
context_create(void) {
return st_context_create($self);
}
struct pipe_resource *
resource_create(
enum pipe_format format,
unsigned width,
unsigned height,
unsigned depth = 1,
unsigned last_level = 0,
enum pipe_texture_target target = PIPE_TEXTURE_2D,
unsigned bind = 0
) {
struct pipe_resource templat;
/* We can't really display surfaces with the python statetracker so mask
* out that usage */
bind &= ~PIPE_BIND_DISPLAY_TARGET;
memset(&templat, 0, sizeof(templat));
templat.format = format;
templat.width0 = width;
templat.height0 = height;
templat.depth0 = depth;
templat.last_level = last_level;
templat.target = target;
templat.bind = bind;
return $self->screen->resource_create($self->screen, &templat);
}
struct pipe_resource *
buffer_create(unsigned size, unsigned usage, unsigned bind = 0) {
return pipe_buffer_create($self->screen, bind, usage, size);
}
};

View File

@ -1,186 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/**
* @file
* SWIG interface definion for Gallium types.
*
* @author Jose Fonseca <jrfonseca@tungstengraphics.com>
*/
%module gallium;
%ignore winsys;
%ignore pipe_vertex_buffer::buffer;
%include "pipe/p_compiler.h";
%include "pipe/p_state.h";
%array_class(struct pipe_stencil_state, StencilArray);
%extend pipe_rt_blend_state
{
struct pipe_rt_blend_state *
__getitem__(int index)
{
if(index < 0 || index >= PIPE_MAX_COLOR_BUFS)
SWIG_exception(SWIG_ValueError, "index out of bounds");
return $self + index;
fail:
return NULL;
};
};
%extend pipe_blend_state
{
pipe_blend_state(void)
{
return CALLOC_STRUCT(pipe_blend_state);
}
%cstring_input_binary(const char *STRING, unsigned LENGTH);
pipe_blend_state(const char *STRING, unsigned LENGTH)
{
struct pipe_blend_state *state;
state = CALLOC_STRUCT(pipe_blend_state);
if (state) {
LENGTH = MIN2(sizeof *state, LENGTH);
memcpy(state, STRING, LENGTH);
}
return state;
}
%cstring_output_allocate_size(char **STRING, int *LENGTH, os_free(*$1));
void __str__(char **STRING, int *LENGTH)
{
struct os_stream *stream;
stream = os_str_stream_create(1);
util_dump_blend_state(stream, $self);
*STRING = os_str_stream_get_and_close(stream);
*LENGTH = strlen(*STRING);
}
};
%extend pipe_framebuffer_state {
pipe_framebuffer_state(void) {
return CALLOC_STRUCT(pipe_framebuffer_state);
}
~pipe_framebuffer_state() {
unsigned index;
for(index = 0; index < PIPE_MAX_COLOR_BUFS; ++index)
pipe_surface_reference(&$self->cbufs[index], NULL);
pipe_surface_reference(&$self->zsbuf, NULL);
FREE($self);
}
void
set_cbuf(unsigned index, struct st_surface *surface)
{
struct pipe_surface *_surface = NULL;
if(index >= PIPE_MAX_COLOR_BUFS)
SWIG_exception(SWIG_ValueError, "index out of bounds");
if(surface) {
/* XXX need a context here */
_surface = st_pipe_surface(NULL, surface, PIPE_BIND_RENDER_TARGET);
if(!_surface)
SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing");
}
pipe_surface_reference(&$self->cbufs[index], _surface);
fail:
return;
}
void
set_zsbuf(struct st_surface *surface)
{
struct pipe_surface *_surface = NULL;
if(surface) {
/* XXX need a context here */
_surface = st_pipe_surface(NULL, surface, PIPE_BIND_DEPTH_STENCIL);
if(!_surface)
SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing");
}
pipe_surface_reference(&$self->zsbuf, _surface);
fail:
return;
}
};
%extend pipe_shader_state {
pipe_shader_state(const char *text, unsigned num_tokens = 1024) {
struct tgsi_token *tokens;
struct pipe_shader_state *shader;
tokens = MALLOC(num_tokens * sizeof(struct tgsi_token));
if(!tokens)
goto error1;
if(tgsi_text_translate(text, tokens, num_tokens ) != TRUE)
goto error2;
shader = CALLOC_STRUCT(pipe_shader_state);
if(!shader)
goto error3;
shader->tokens = tokens;
return shader;
error3:
error2:
FREE(tokens);
error1:
return NULL;
}
~pipe_shader_state() {
FREE((void*)$self->tokens);
FREE($self);
}
void dump(unsigned flags = 0) {
tgsi_dump($self->tokens, flags);
}
}

View File

@ -1,152 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/**
* @file
* SWIG interface definion for Gallium types.
*
* @author Jose Fonseca <jrfonseca@tungstengraphics.com>
*/
%nodefaultctor pipe_resource;
%nodefaultctor st_surface;
%nodefaultdtor pipe_resource;
%nodefaultdtor st_surface;
%ignore pipe_resource::screen;
%immutable st_surface::texture;
%immutable st_surface::level;
%immutable st_surface::layer;
%newobject pipe_resource::get_surface;
/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */
%rename(read) read_;
%rename(write) write_;
%extend pipe_resource {
~pipe_resource() {
struct pipe_resource *ptr = $self;
pipe_resource_reference(&ptr, NULL);
}
unsigned get_width(unsigned level=0) {
return u_minify($self->width0, level);
}
unsigned get_height(unsigned level=0) {
return u_minify($self->height0, level);
}
unsigned get_depth(unsigned level=0) {
return u_minify($self->depth0, level);
}
/** Get a surface which is a "view" into a texture */
struct st_surface *
get_surface(unsigned level=0, unsigned layer=0)
{
struct st_surface *surface;
if(level > $self->last_level)
SWIG_exception(SWIG_ValueError, "level out of bounds");
if(layer >= ($self->target == PIPE_TEXTURE_3D ?
u_minify($self->depth0, level) : $self->depth0))
SWIG_exception(SWIG_ValueError, "layer out of bounds");
surface = CALLOC_STRUCT(st_surface);
if(!surface)
return NULL;
pipe_resource_reference(&surface->texture, $self);
surface->level = level;
surface->layer = layer;
return surface;
fail:
return NULL;
}
unsigned __len__(void)
{
assert($self->target == PIPE_BUFFER);
assert(p_atomic_read(&$self->reference.count) > 0);
return $self->width0;
}
};
struct st_surface
{
%immutable;
struct pipe_resource *texture;
unsigned level;
unsigned layer;
};
%extend st_surface {
%immutable;
unsigned format;
unsigned width;
unsigned height;
~st_surface() {
pipe_resource_reference(&$self->texture, NULL);
FREE($self);
}
};
%{
static enum pipe_format
st_surface_format_get(struct st_surface *surface)
{
return surface->texture->format;
}
static unsigned
st_surface_width_get(struct st_surface *surface)
{
return u_minify(surface->texture->width0, surface->level);
}
static unsigned
st_surface_height_get(struct st_surface *surface)
{
return u_minify(surface->texture->height0, surface->level);
}
%}

View File

@ -1,305 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h"
#include "util/u_inlines.h"
#include "cso_cache/cso_context.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_sampler.h"
#include "util/u_simple_shaders.h"
#include "trace/tr_public.h"
#include "st_device.h"
#include "st_winsys.h"
static void
st_device_really_destroy(struct st_device *st_dev)
{
if(st_dev->screen) {
/* FIXME: Don't really destroy until we keep track of every single
* reference or we end up causing a segmentation fault every time
* python exits. */
#if 0
st_dev->screen->destroy(st_dev->screen);
#endif
}
FREE(st_dev);
}
static void
st_device_reference(struct st_device **ptr, struct st_device *st_dev)
{
struct st_device *old_dev = *ptr;
if (pipe_reference(&(*ptr)->reference, &st_dev->reference))
st_device_really_destroy(old_dev);
*ptr = st_dev;
}
void
st_device_destroy(struct st_device *st_dev)
{
st_device_reference(&st_dev, NULL);
}
struct st_device *
st_device_create(boolean hardware)
{
struct pipe_screen *screen;
struct st_device *st_dev;
if (hardware)
screen = st_hardware_screen_create();
else
screen = st_software_screen_create("softpipe");
screen = trace_screen_create(screen);
if (!screen)
goto no_screen;
st_dev = CALLOC_STRUCT(st_device);
if (!st_dev)
goto no_device;
pipe_reference_init(&st_dev->reference, 1);
st_dev->screen = screen;
return st_dev;
no_device:
screen->destroy(screen);
no_screen:
return NULL;
}
void
st_context_destroy(struct st_context *st_ctx)
{
unsigned i;
if(st_ctx) {
struct st_device *st_dev = st_ctx->st_dev;
if(st_ctx->cso) {
cso_delete_vertex_shader(st_ctx->cso, st_ctx->vs);
cso_delete_fragment_shader(st_ctx->cso, st_ctx->fs);
cso_destroy_context(st_ctx->cso);
}
if(st_ctx->pipe)
st_ctx->pipe->destroy(st_ctx->pipe);
for(i = 0; i < PIPE_MAX_SAMPLERS; ++i)
pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], NULL);
for(i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], NULL);
pipe_resource_reference(&st_ctx->default_texture, NULL);
FREE(st_ctx);
st_device_reference(&st_dev, NULL);
}
}
struct st_context *
st_context_create(struct st_device *st_dev)
{
struct st_context *st_ctx;
st_ctx = CALLOC_STRUCT(st_context);
if(!st_ctx)
return NULL;
st_device_reference(&st_ctx->st_dev, st_dev);
st_ctx->pipe = st_dev->screen->context_create(st_dev->screen, NULL);
if(!st_ctx->pipe) {
st_context_destroy(st_ctx);
return NULL;
}
st_ctx->cso = cso_create_context(st_ctx->pipe);
if(!st_ctx->cso) {
st_context_destroy(st_ctx);
return NULL;
}
/* disabled blending/masking */
{
struct pipe_blend_state blend;
memset(&blend, 0, sizeof(blend));
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
blend.rt[0].colormask = PIPE_MASK_RGBA;
cso_set_blend(st_ctx->cso, &blend);
}
/* no-op depth/stencil/alpha */
{
struct pipe_depth_stencil_alpha_state depthstencil;
memset(&depthstencil, 0, sizeof(depthstencil));
cso_set_depth_stencil_alpha(st_ctx->cso, &depthstencil);
}
/* rasterizer */
{
struct pipe_rasterizer_state rasterizer;
memset(&rasterizer, 0, sizeof(rasterizer));
rasterizer.cull_face = PIPE_FACE_NONE;
cso_set_rasterizer(st_ctx->cso, &rasterizer);
}
/* clip */
{
struct pipe_clip_state clip;
memset(&clip, 0, sizeof(clip));
st_ctx->pipe->set_clip_state(st_ctx->pipe, &clip);
}
/* identity viewport */
{
struct pipe_viewport_state viewport;
viewport.scale[0] = 1.0;
viewport.scale[1] = 1.0;
viewport.scale[2] = 1.0;
viewport.scale[3] = 1.0;
viewport.translate[0] = 0.0;
viewport.translate[1] = 0.0;
viewport.translate[2] = 0.0;
viewport.translate[3] = 0.0;
cso_set_viewport(st_ctx->cso, &viewport);
}
/* samplers */
{
struct pipe_sampler_state sampler;
unsigned i;
memset(&sampler, 0, sizeof(sampler));
sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
sampler.normalized_coords = 1;
for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
cso_single_sampler(st_ctx->cso, i, &sampler);
cso_single_sampler_done(st_ctx->cso);
}
/* default textures */
{
struct pipe_context *pipe = st_ctx->pipe;
struct pipe_screen *screen = st_dev->screen;
struct pipe_resource templat;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *view;
unsigned i;
memset( &templat, 0, sizeof( templat ) );
templat.target = PIPE_TEXTURE_2D;
templat.format = PIPE_FORMAT_B8G8R8A8_UNORM;
templat.width0 = 1;
templat.height0 = 1;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.bind = PIPE_BIND_SAMPLER_VIEW;
st_ctx->default_texture = screen->resource_create( screen, &templat );
if(st_ctx->default_texture) {
struct pipe_box box;
uint32_t zero = 0;
u_box_origin_2d( 1, 1, &box );
pipe->transfer_inline_write(pipe,
st_ctx->default_texture,
0,
PIPE_TRANSFER_WRITE,
&box,
&zero,
sizeof zero,
0);
}
u_sampler_view_default_template(&view_templ,
st_ctx->default_texture,
st_ctx->default_texture->format);
view = st_ctx->pipe->create_sampler_view(st_ctx->pipe,
st_ctx->default_texture,
&view_templ);
for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], view);
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++)
pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], view);
st_ctx->pipe->set_fragment_sampler_views(st_ctx->pipe,
PIPE_MAX_SAMPLERS,
st_ctx->fragment_sampler_views);
st_ctx->pipe->set_vertex_sampler_views(st_ctx->pipe,
PIPE_MAX_VERTEX_SAMPLERS,
st_ctx->vertex_sampler_views);
pipe_sampler_view_reference(&view, NULL);
}
/* vertex shader */
{
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_GENERIC };
const uint semantic_indexes[] = { 0, 0 };
st_ctx->vs = util_make_vertex_passthrough_shader(st_ctx->pipe,
2,
semantic_names,
semantic_indexes);
cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs);
}
/* fragment shader */
{
st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe);
cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs);
}
return st_ctx;
}

View File

@ -1,111 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifndef ST_DEVICE_H_
#define ST_DEVICE_H_
#include "pipe/p_state.h"
struct cso_context;
struct pipe_screen;
struct pipe_context;
struct st_winsys;
struct st_surface
{
struct pipe_resource *texture;
unsigned level;
unsigned layer;
};
struct st_context
{
struct st_device *st_dev;
struct pipe_context *pipe;
struct cso_context *cso;
void *vs;
void *fs;
void *gs;
struct pipe_resource *default_texture;
struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
unsigned num_vertex_buffers;
struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
unsigned num_vertex_elements;
struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS];
struct pipe_framebuffer_state framebuffer;
};
struct st_device
{
/* FIXME: we also need to refcount for textures and surfaces... */
struct pipe_reference reference;
struct pipe_screen *screen;
};
static INLINE struct pipe_surface *
st_pipe_surface(struct pipe_context *pipe, struct st_surface *surface, unsigned usage)
{
struct pipe_resource *texture = surface->texture;
struct pipe_surface surf_tmpl;
memset(&surf_tmpl, 0, sizeof(surf_tmpl));
surf_tmpl.format = texture->format;
surf_tmpl.usage = usage;
surf_tmpl.u.tex.level = surface->level;
surf_tmpl.u.tex.first_layer = surface->layer;
surf_tmpl.u.tex.last_layer = surface->layer;
return pipe->create_surface(pipe, texture, &surf_tmpl);
}
struct st_context *
st_context_create(struct st_device *st_dev);
void
st_context_destroy(struct st_context *st_ctx);
struct st_device *
st_device_create(boolean hardware);
void
st_device_destroy(struct st_device *st_dev);
#endif /* ST_DEVICE_H_ */

View File

@ -1,212 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Bismarck, ND., USA
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
*
**************************************************************************/
/**
* @file
* Get a hardware accelerated Gallium screen/context from the OpenGL driver.
*/
#include "pipe/p_compiler.h"
#ifdef PIPE_OS_WINDOWS
#include <windows.h>
#include <GL/gl.h>
#else
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/gl.h>
#include <GL/glx.h>
#endif
#include "st_winsys.h"
typedef struct pipe_screen * (GLAPIENTRY *PFNGETGALLIUMSCREENMESAPROC) (void);
typedef struct pipe_context * (GLAPIENTRY* PFNCREATEGALLIUMCONTEXTMESAPROC) (void);
static PFNGETGALLIUMSCREENMESAPROC pfnGetGalliumScreenMESA = NULL;
static PFNCREATEGALLIUMCONTEXTMESAPROC pfnCreateGalliumContextMESA = NULL;
#ifdef PIPE_OS_WINDOWS
static INLINE boolean
st_hardpipe_load(void)
{
WNDCLASS wc;
HWND hwnd;
HGLRC hglrc;
HDC hdc;
PIXELFORMATDESCRIPTOR pfd;
int iPixelFormat;
if(pfnGetGalliumScreenMESA && pfnCreateGalliumContextMESA)
return TRUE;
memset(&wc, 0, sizeof wc);
wc.lpfnWndProc = DefWindowProc;
wc.lpszClassName = "gallium";
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
hwnd = CreateWindow(wc.lpszClassName, "gallium", 0, 0, 0, 0, 0, NULL, 0, wc.hInstance, NULL);
if (!hwnd)
return FALSE;
hdc = GetDC(hwnd);
if (!hdc)
return FALSE;
pfd.cColorBits = 3;
pfd.cRedBits = 1;
pfd.cGreenBits = 1;
pfd.cBlueBits = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
if (!iPixelFormat) {
pfd.dwFlags |= PFD_DOUBLEBUFFER;
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
}
if (!iPixelFormat)
return FALSE;
SetPixelFormat(hdc, iPixelFormat, &pfd);
hglrc = wglCreateContext(hdc);
if (!hglrc)
return FALSE;
if (!wglMakeCurrent(hdc, hglrc))
return FALSE;
pfnGetGalliumScreenMESA = (PFNGETGALLIUMSCREENMESAPROC)wglGetProcAddress("wglGetGalliumScreenMESA");
if(!pfnGetGalliumScreenMESA)
return FALSE;
pfnCreateGalliumContextMESA = (PFNCREATEGALLIUMCONTEXTMESAPROC)wglGetProcAddress("wglCreateGalliumContextMESA");
if(!pfnCreateGalliumContextMESA)
return FALSE;
DestroyWindow(hwnd);
return TRUE;
}
#else
static INLINE boolean
st_hardpipe_load(void)
{
Display *dpy;
int scrnum;
Window root;
int attribSingle[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
None };
int attribDouble[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
None };
XVisualInfo *visinfo;
GLXContext ctx = NULL;
XSetWindowAttributes attr;
unsigned long mask;
int width = 100, height = 100;
Window win;
dpy = XOpenDisplay(NULL);
if (!dpy)
return FALSE;
scrnum = 0;
root = RootWindow(dpy, scrnum);
visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
if (!visinfo)
visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
if (!visinfo)
return FALSE;
ctx = glXCreateContext( dpy, visinfo, NULL, True );
if (!ctx)
return FALSE;
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
win = XCreateWindow(dpy, root, 0, 0, width, height,
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr);
if (!glXMakeCurrent(dpy, win, ctx))
return FALSE;
pfnGetGalliumScreenMESA = (PFNGETGALLIUMSCREENMESAPROC)glXGetProcAddressARB((const GLubyte *)"glXGetGalliumScreenMESA");
if(!pfnGetGalliumScreenMESA)
return FALSE;
pfnCreateGalliumContextMESA = (PFNCREATEGALLIUMCONTEXTMESAPROC)glXGetProcAddressARB((const GLubyte *)"glXCreateGalliumContextMESA");
if(!pfnCreateGalliumContextMESA)
return FALSE;
glXDestroyContext(dpy, ctx);
XFree(visinfo);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return TRUE;
}
#endif
struct pipe_screen *
st_hardware_screen_create(void)
{
if(st_hardpipe_load())
return pfnGetGalliumScreenMESA();
else
return st_software_screen_create(NULL);
}

View File

@ -1,594 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "pipe/p_compiler.h"
#include "pipe/p_format.h"
#include "pipe/p_state.h"
#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_tile.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "st_device.h"
#include "st_sample.h"
/**
* Use our own pseudo random generator to ensure consistent runs among
* multiple runs and platforms.
*
* @sa http://en.wikipedia.org/wiki/Linear_congruential_generator
*/
static uint32_t st_random(void) {
static uint64_t seed = UINT64_C(0xbb9a063afb0a739d);
seed = UINT64_C(134775813) * seed + UINT64_C(1);
return (uint32_t)(seed >> 32);
}
/**
* We don't want to include the patent-encumbered DXT code here, so instead
* we store several uncompressed/compressed data pairs for hardware testing
* purposes.
*/
struct dxt_data
{
uint8_t rgba[16*4];
uint8_t raw[16];
};
static const struct dxt_data
dxt1_rgb_data[] = {
{
{
0x99, 0xb0, 0x8e, 0xff,
0x5d, 0x62, 0x89, 0xff,
0x99, 0xb0, 0x8e, 0xff,
0x99, 0xb0, 0x8e, 0xff,
0xd6, 0xff, 0x94, 0xff,
0x5d, 0x62, 0x89, 0xff,
0x99, 0xb0, 0x8e, 0xff,
0xd6, 0xff, 0x94, 0xff,
0x5d, 0x62, 0x89, 0xff,
0x5d, 0x62, 0x89, 0xff,
0x99, 0xb0, 0x8e, 0xff,
0x21, 0x14, 0x84, 0xff,
0x5d, 0x62, 0x89, 0xff,
0x21, 0x14, 0x84, 0xff,
0x21, 0x14, 0x84, 0xff,
0x99, 0xb0, 0x8e, 0xff
},
{0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97}
},
{
{
0xb5, 0xcf, 0x9c, 0xff,
0x83, 0x8c, 0x8b, 0xff,
0x21, 0x08, 0x6b, 0xff,
0x83, 0x8c, 0x8b, 0xff,
0x52, 0x4a, 0x7b, 0xff,
0x83, 0x8c, 0x8b, 0xff,
0x83, 0x8c, 0x8b, 0xff,
0xb5, 0xcf, 0x9c, 0xff,
0x21, 0x08, 0x6b, 0xff,
0xb5, 0xcf, 0x9c, 0xff,
0x83, 0x8c, 0x8b, 0xff,
0x52, 0x4a, 0x7b, 0xff,
0xb5, 0xcf, 0x9c, 0xff,
0x83, 0x8c, 0x8b, 0xff,
0x52, 0x4a, 0x7b, 0xff,
0x83, 0x8c, 0x8b, 0xff
},
{0x73, 0xb6, 0x4d, 0x20, 0x98, 0x2b, 0xe1, 0xb8}
},
{
{
0x00, 0x2c, 0xff, 0xff,
0x94, 0x8d, 0x7b, 0xff,
0x4a, 0x5c, 0xbd, 0xff,
0x4a, 0x5c, 0xbd, 0xff,
0x4a, 0x5c, 0xbd, 0xff,
0x94, 0x8d, 0x7b, 0xff,
0x94, 0x8d, 0x7b, 0xff,
0x94, 0x8d, 0x7b, 0xff,
0xde, 0xbe, 0x39, 0xff,
0x94, 0x8d, 0x7b, 0xff,
0xde, 0xbe, 0x39, 0xff,
0xde, 0xbe, 0x39, 0xff,
0xde, 0xbe, 0x39, 0xff,
0xde, 0xbe, 0x39, 0xff,
0xde, 0xbe, 0x39, 0xff,
0x94, 0x8d, 0x7b, 0xff
},
{0xe7, 0xdd, 0x7f, 0x01, 0xf9, 0xab, 0x08, 0x80}
},
{
{
0x6b, 0x24, 0x21, 0xff,
0x7b, 0x4f, 0x5d, 0xff,
0x7b, 0x4f, 0x5d, 0xff,
0x8b, 0x7a, 0x99, 0xff,
0x7b, 0x4f, 0x5d, 0xff,
0x7b, 0x4f, 0x5d, 0xff,
0x6b, 0x24, 0x21, 0xff,
0x8b, 0x7a, 0x99, 0xff,
0x9c, 0xa6, 0xd6, 0xff,
0x6b, 0x24, 0x21, 0xff,
0x7b, 0x4f, 0x5d, 0xff,
0x8b, 0x7a, 0x99, 0xff,
0x6b, 0x24, 0x21, 0xff,
0x8b, 0x7a, 0x99, 0xff,
0x7b, 0x4f, 0x5d, 0xff,
0x9c, 0xa6, 0xd6, 0xff
},
{0x3a, 0x9d, 0x24, 0x69, 0xbd, 0x9f, 0xb4, 0x39}
}
};
static const struct dxt_data
dxt1_rgba_data[] = {
{
{
0x00, 0x00, 0x00, 0x00,
0x4e, 0xaa, 0x90, 0xff,
0x4e, 0xaa, 0x90, 0xff,
0x00, 0x00, 0x00, 0x00,
0x4e, 0xaa, 0x90, 0xff,
0x29, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00,
0x4e, 0xaa, 0x90, 0xff,
0x73, 0x55, 0x21, 0xff,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x4e, 0xaa, 0x90, 0xff,
0x4e, 0xaa, 0x90, 0xff,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x4e, 0xaa, 0x90, 0xff
},
{0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe}
},
{
{
0xb5, 0xe3, 0x63, 0xff,
0x00, 0x00, 0x00, 0x00,
0x6b, 0x24, 0x84, 0xff,
0xb5, 0xe3, 0x63, 0xff,
0x00, 0x00, 0x00, 0x00,
0xb5, 0xe3, 0x63, 0xff,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x6b, 0x24, 0x84, 0xff,
0x6b, 0x24, 0x84, 0xff,
0x00, 0x00, 0x00, 0x00,
0xb5, 0xe3, 0x63, 0xff,
0x90, 0x83, 0x73, 0xff,
0xb5, 0xe3, 0x63, 0xff
},
{0x30, 0x69, 0x0c, 0xb7, 0x4d, 0xf7, 0x0f, 0x67}
},
{
{
0x00, 0x00, 0x00, 0x00,
0xc6, 0x86, 0x8c, 0xff,
0xc6, 0x86, 0x8c, 0xff,
0x21, 0x65, 0x42, 0xff,
0x21, 0x65, 0x42, 0xff,
0x21, 0x65, 0x42, 0xff,
0x21, 0x65, 0x42, 0xff,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x21, 0x65, 0x42, 0xff,
0xc6, 0x86, 0x8c, 0xff,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xc6, 0x86, 0x8c, 0xff
},
{0x28, 0x23, 0x31, 0xc4, 0x17, 0xc0, 0xd3, 0x7f}
},
{
{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xc6, 0xe3, 0x9c, 0xff,
0x7b, 0x1c, 0x52, 0xff,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x7b, 0x1c, 0x52, 0xff,
0x00, 0x00, 0x00, 0x00,
0x7b, 0x1c, 0x52, 0xff,
0xa0, 0x7f, 0x77, 0xff,
0xc6, 0xe3, 0x9c, 0xff,
0x00, 0x00, 0x00, 0x00,
0xa0, 0x7f, 0x77, 0xff
},
{0xea, 0x78, 0x13, 0xc7, 0x7f, 0xfc, 0x33, 0xb6}
},
};
static const struct dxt_data
dxt3_rgba_data[] = {
{
{
0x6d, 0xc6, 0x96, 0x77,
0x6d, 0xc6, 0x96, 0xee,
0x6d, 0xc6, 0x96, 0xaa,
0x8c, 0xff, 0xb5, 0x44,
0x6d, 0xc6, 0x96, 0xff,
0x6d, 0xc6, 0x96, 0x88,
0x31, 0x55, 0x5a, 0x66,
0x6d, 0xc6, 0x96, 0x99,
0x31, 0x55, 0x5a, 0xbb,
0x31, 0x55, 0x5a, 0x55,
0x31, 0x55, 0x5a, 0x11,
0x6d, 0xc6, 0x96, 0xcc,
0x6d, 0xc6, 0x96, 0xcc,
0x6d, 0xc6, 0x96, 0x11,
0x31, 0x55, 0x5a, 0x44,
0x31, 0x55, 0x5a, 0x88
},
{0xe7, 0x4a, 0x8f, 0x96, 0x5b, 0xc1, 0x1c, 0x84, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a}
},
{
{
0xad, 0xeb, 0x73, 0x99,
0x97, 0xaa, 0x86, 0x66,
0x6b, 0x28, 0xad, 0x99,
0xad, 0xeb, 0x73, 0x99,
0x6b, 0x28, 0xad, 0x22,
0xad, 0xeb, 0x73, 0xff,
0x97, 0xaa, 0x86, 0x55,
0x6b, 0x28, 0xad, 0x55,
0x6b, 0x28, 0xad, 0x44,
0xad, 0xeb, 0x73, 0x33,
0x6b, 0x28, 0xad, 0xee,
0x6b, 0x28, 0xad, 0x99,
0x97, 0xaa, 0x86, 0x66,
0xad, 0xeb, 0x73, 0xbb,
0x97, 0xaa, 0x86, 0x99,
0xad, 0xeb, 0x73, 0xbb
},
{0x69, 0x99, 0xf2, 0x55, 0x34, 0x9e, 0xb6, 0xb9, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22}
},
{
{
0x63, 0xd7, 0xd6, 0x00,
0x57, 0x62, 0x5d, 0xdd,
0x57, 0x62, 0x5d, 0xcc,
0x57, 0x62, 0x5d, 0xbb,
0x52, 0x28, 0x21, 0xaa,
0x57, 0x62, 0x5d, 0xcc,
0x57, 0x62, 0x5d, 0xcc,
0x57, 0x62, 0x5d, 0x66,
0x57, 0x62, 0x5d, 0x22,
0x57, 0x62, 0x5d, 0xdd,
0x63, 0xd7, 0xd6, 0xee,
0x57, 0x62, 0x5d, 0x33,
0x63, 0xd7, 0xd6, 0x55,
0x52, 0x28, 0x21, 0x55,
0x57, 0x62, 0x5d, 0x11,
0x5d, 0x9c, 0x99, 0xee
},
{0xd0, 0xbc, 0xca, 0x6c, 0xd2, 0x3e, 0x55, 0xe1, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4}
},
{
{
0x94, 0x6f, 0x60, 0x22,
0x94, 0x6f, 0x60, 0x22,
0xc5, 0xab, 0x76, 0x11,
0xc5, 0xab, 0x76, 0xee,
0x63, 0x34, 0x4a, 0xdd,
0x63, 0x34, 0x4a, 0x33,
0x94, 0x6f, 0x60, 0x77,
0xf7, 0xe7, 0x8c, 0x00,
0x94, 0x6f, 0x60, 0x33,
0x63, 0x34, 0x4a, 0xaa,
0x94, 0x6f, 0x60, 0x77,
0x63, 0x34, 0x4a, 0xcc,
0x94, 0x6f, 0x60, 0xaa,
0xf7, 0xe7, 0x8c, 0x99,
0x63, 0x34, 0x4a, 0x44,
0xc5, 0xab, 0x76, 0xaa
},
{0x22, 0xe1, 0x3d, 0x07, 0xa3, 0xc7, 0x9a, 0xa4, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93}
},
};
static const struct dxt_data
dxt5_rgba_data[] = {
{
{
0x6d, 0xc6, 0x96, 0x74,
0x6d, 0xc6, 0x96, 0xf8,
0x6d, 0xc6, 0x96, 0xb6,
0x8c, 0xff, 0xb5, 0x53,
0x6d, 0xc6, 0x96, 0xf8,
0x6d, 0xc6, 0x96, 0x95,
0x31, 0x55, 0x5a, 0x53,
0x6d, 0xc6, 0x96, 0x95,
0x31, 0x55, 0x5a, 0xb6,
0x31, 0x55, 0x5a, 0x53,
0x31, 0x55, 0x5a, 0x11,
0x6d, 0xc6, 0x96, 0xd7,
0x6d, 0xc6, 0x96, 0xb6,
0x6d, 0xc6, 0x96, 0x11,
0x31, 0x55, 0x5a, 0x32,
0x31, 0x55, 0x5a, 0x95
},
{0xf8, 0x11, 0xc5, 0x0c, 0x9a, 0x73, 0xb4, 0x9c, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a}
},
{
{
0xad, 0xeb, 0x73, 0xa1,
0x97, 0xaa, 0x86, 0x65,
0x6b, 0x28, 0xad, 0xa1,
0xad, 0xeb, 0x73, 0xa1,
0x6b, 0x28, 0xad, 0x2a,
0xad, 0xeb, 0x73, 0xfb,
0x97, 0xaa, 0x86, 0x47,
0x6b, 0x28, 0xad, 0x65,
0x6b, 0x28, 0xad, 0x47,
0xad, 0xeb, 0x73, 0x47,
0x6b, 0x28, 0xad, 0xdd,
0x6b, 0x28, 0xad, 0xa1,
0x97, 0xaa, 0x86, 0x65,
0xad, 0xeb, 0x73, 0xbf,
0x97, 0xaa, 0x86, 0xa1,
0xad, 0xeb, 0x73, 0xbf
},
{0xfb, 0x2a, 0x34, 0x19, 0xdc, 0xbf, 0xe8, 0x71, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22}
},
{
{
0x63, 0xd7, 0xd6, 0x00,
0x57, 0x62, 0x5d, 0xf5,
0x57, 0x62, 0x5d, 0xd2,
0x57, 0x62, 0x5d, 0xaf,
0x52, 0x28, 0x21, 0xaf,
0x57, 0x62, 0x5d, 0xd2,
0x57, 0x62, 0x5d, 0xd2,
0x57, 0x62, 0x5d, 0x69,
0x57, 0x62, 0x5d, 0x23,
0x57, 0x62, 0x5d, 0xd2,
0x63, 0xd7, 0xd6, 0xf5,
0x57, 0x62, 0x5d, 0x46,
0x63, 0xd7, 0xd6, 0x46,
0x52, 0x28, 0x21, 0x69,
0x57, 0x62, 0x5d, 0x23,
0x5d, 0x9c, 0x99, 0xf5
},
{0xf5, 0x00, 0x81, 0x36, 0xa9, 0x17, 0xec, 0x1e, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4}
},
{
{
0x94, 0x6f, 0x60, 0x25,
0x94, 0x6f, 0x60, 0x25,
0xc5, 0xab, 0x76, 0x05,
0xc5, 0xab, 0x76, 0xe8,
0x63, 0x34, 0x4a, 0xe8,
0x63, 0x34, 0x4a, 0x25,
0x94, 0x6f, 0x60, 0x86,
0xf7, 0xe7, 0x8c, 0x05,
0x94, 0x6f, 0x60, 0x25,
0x63, 0x34, 0x4a, 0xa7,
0x94, 0x6f, 0x60, 0x66,
0x63, 0x34, 0x4a, 0xc7,
0x94, 0x6f, 0x60, 0xa7,
0xf7, 0xe7, 0x8c, 0xa7,
0x63, 0x34, 0x4a, 0x45,
0xc5, 0xab, 0x76, 0xa7
},
{0xe8, 0x05, 0x7f, 0x80, 0x33, 0x5f, 0xb5, 0x79, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93}
},
};
static INLINE void
st_sample_dxt_pixel_block(enum pipe_format format,
uint8_t *raw,
float *rgba, unsigned rgba_stride,
unsigned w, unsigned h)
{
const struct dxt_data *data;
unsigned n;
unsigned i;
unsigned x, y, ch;
switch(format) {
case PIPE_FORMAT_DXT1_RGB:
data = dxt1_rgb_data;
n = sizeof(dxt1_rgb_data)/sizeof(dxt1_rgb_data[0]);
break;
case PIPE_FORMAT_DXT1_RGBA:
data = dxt1_rgba_data;
n = sizeof(dxt1_rgba_data)/sizeof(dxt1_rgba_data[0]);
break;
case PIPE_FORMAT_DXT3_RGBA:
data = dxt3_rgba_data;
n = sizeof(dxt3_rgba_data)/sizeof(dxt3_rgba_data[0]);
break;
case PIPE_FORMAT_DXT5_RGBA:
data = dxt5_rgba_data;
n = sizeof(dxt5_rgba_data)/sizeof(dxt5_rgba_data[0]);
break;
default:
assert(0);
return;
}
i = st_random() % n;
for(y = 0; y < h; ++y)
for(x = 0; x < w; ++x)
for(ch = 0; ch < 4; ++ch)
rgba[y*rgba_stride + x*4 + ch] = (float)(data[i].rgba[y*4*4 + x*4 + ch])/255.0f;
memcpy(raw, data[i].raw, util_format_get_blocksize(format));
}
static INLINE void
st_sample_generic_pixel_block(enum pipe_format format,
uint8_t *raw,
float *rgba, unsigned rgba_stride,
unsigned w, unsigned h,
boolean norm)
{
unsigned i;
unsigned x, y, ch;
int blocksize = util_format_get_blocksize(format);
if (norm) {
for (y = 0; y < h; ++y) {
for (x = 0; x < w; ++x) {
for (ch = 0; ch < 4; ++ch) {
unsigned offset = y*rgba_stride + x*4 + ch;
rgba[offset] = (st_random() & 0xff) / (double)0xff;
}
}
}
util_format_write_4f(format,
rgba, rgba_stride * sizeof(float),
raw, util_format_get_stride(format, w),
0, 0, w, h);
} else {
for (i = 0; i < blocksize; ++i)
raw[i] = (uint8_t)st_random();
}
util_format_read_4f(format,
rgba, rgba_stride * sizeof(float),
raw, util_format_get_stride(format, w),
0, 0, w, h);
if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
for (y = 0; y < h; ++y) {
for (x = 0; x < w; ++x) {
for (ch = 0; ch < 4; ++ch) {
unsigned offset = y*rgba_stride + x*4 + ch;
rgba[offset] = CLAMP(rgba[offset], 0.0f, 1.0f);
}
}
}
}
}
/**
* Randomly sample pixels.
*/
void
st_sample_pixel_block(enum pipe_format format,
void *raw,
float *rgba, unsigned rgba_stride,
unsigned w, unsigned h,
boolean norm)
{
switch(format) {
case PIPE_FORMAT_DXT1_RGB:
case PIPE_FORMAT_DXT1_RGBA:
case PIPE_FORMAT_DXT3_RGBA:
case PIPE_FORMAT_DXT5_RGBA:
st_sample_dxt_pixel_block(format, raw, rgba, rgba_stride, w, h);
break;
default:
st_sample_generic_pixel_block(format, raw, rgba, rgba_stride, w, h, norm);
break;
}
}
void
st_sample_surface(struct pipe_context *pipe,
struct st_surface *surface,
float *rgba,
boolean norm)
{
struct pipe_resource *texture = surface->texture;
unsigned width = u_minify(texture->width0, surface->level);
unsigned height = u_minify(texture->height0, surface->level);
uint rgba_stride = width * 4;
struct pipe_transfer *transfer;
void *raw;
transfer = pipe_get_transfer(pipe,
surface->texture,
surface->level,
surface->layer,
PIPE_TRANSFER_WRITE,
0, 0,
width,
height);
if (!transfer)
return;
raw = pipe->transfer_map(pipe, transfer);
if (raw) {
enum pipe_format format = texture->format;
uint x, y;
int nblocksx = util_format_get_nblocksx(format, width);
int nblocksy = util_format_get_nblocksy(format, height);
int blockwidth = util_format_get_blockwidth(format);
int blockheight = util_format_get_blockheight(format);
int blocksize = util_format_get_blocksize(format);
for (y = 0; y < nblocksy; ++y) {
for (x = 0; x < nblocksx; ++x) {
st_sample_pixel_block(format,
(uint8_t *) raw + y * transfer->stride + x * blocksize,
rgba + y * blockheight * rgba_stride + x * blockwidth * 4,
rgba_stride,
MIN2(blockwidth, width - x*blockwidth),
MIN2(blockheight, height - y*blockheight),
norm);
}
}
pipe->transfer_unmap(pipe, transfer);
}
pipe->transfer_destroy(pipe, transfer);
}

View File

@ -1,53 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifndef ST_SAMPLE_H_
#define ST_SAMPLE_H_
#include "pipe/p_format.h"
struct pipe_context;
struct st_surface;
void
st_sample_pixel_block(enum pipe_format format,
void *raw,
float *rgba, unsigned rgba_stride,
unsigned w, unsigned h,
boolean norm);
void
st_sample_surface(struct pipe_context *pipe,
struct st_surface *surface,
float *rgba,
boolean norm);
#endif /* ST_SAMPLE_H_ */

View File

@ -1,78 +0,0 @@
/**************************************************************************
*
* Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
*
**************************************************************************/
#include "util/u_debug.h"
#include "softpipe/sp_public.h"
#include "llvmpipe/lp_public.h"
#include "state_tracker/sw_winsys.h"
#include "sw/null/null_sw_winsys.h"
#include "st_winsys.h"
struct pipe_screen *
st_software_screen_create(const char *driver)
{
struct sw_winsys *ws;
struct pipe_screen *screen = NULL;
if (!driver) {
const char *default_driver;
#if defined(HAVE_LLVMPIPE)
default_driver = "llvmpipe";
#elif defined(HAVE_SOFTPIPE)
default_driver = "softpipe";
#else
default_driver = "";
#endif
driver = debug_get_option("GALLIUM_DRIVER", default_driver);
}
ws = null_sw_create();
if(!ws)
return NULL;
#ifdef HAVE_LLVMPIPE
if (strcmp(driver, "llvmpipe") == 0) {
screen = llvmpipe_create_screen(ws);
}
#endif
#ifdef HAVE_SOFTPIPE
if (strcmp(driver, "softpipe") == 0) {
screen = softpipe_create_screen(ws);
}
#endif
if (!screen) {
ws->destroy(ws);
}
return screen;
}

View File

@ -1,43 +0,0 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifndef ST_WINSYS_H_
#define ST_WINSYS_H_
struct pipe_screen;
struct pipe_screen *
st_hardware_screen_create(void);
struct pipe_screen *
st_software_screen_create(const char *driver);
#endif /* ST_WINSYS_H_ */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -1,88 +0,0 @@
/**************************************************************************
*
* Copyright 2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
**************************************************************************/
static INLINE const char *
util_format_name(enum pipe_format format);
static INLINE boolean
util_format_is_s3tc(enum pipe_format format);
static INLINE boolean
util_format_is_depth_or_stencil(enum pipe_format format);
static INLINE boolean
util_format_is_depth_and_stencil(enum pipe_format format);
uint
util_format_get_blocksizebits(enum pipe_format format);
uint
util_format_get_blocksize(enum pipe_format format);
uint
util_format_get_blockwidth(enum pipe_format format);
uint
util_format_get_blockheight(enum pipe_format format);
unsigned
util_format_get_nblocksx(enum pipe_format format,
unsigned x);
unsigned
util_format_get_nblocksy(enum pipe_format format,
unsigned y);
unsigned
util_format_get_nblocks(enum pipe_format format,
unsigned width,
unsigned height);
size_t
util_format_get_stride(enum pipe_format format,
unsigned width);
size_t
util_format_get_2d_size(enum pipe_format format,
size_t stride,
unsigned height);
uint
util_format_get_component_bits(enum pipe_format format,
enum util_format_colorspace colorspace,
uint component);
boolean
util_format_has_alpha(enum pipe_format format);
unsigned
util_format_get_nr_components(enum pipe_format format);

View File

@ -1,17 +0,0 @@
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>

View File

@ -1,733 +0,0 @@
#!/usr/bin/env python
##########################################################################
#
# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sub license, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice (including the
# next paragraph) shall be included in all copies or substantial portions
# of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
##########################################################################
import sys
import struct
import gallium
import model
import parse as parser
try:
from struct import unpack_from
except ImportError:
def unpack_from(fmt, buf, offset=0):
size = struct.calcsize(fmt)
return struct.unpack(fmt, buf[offset:offset + size])
def make_image(ctx, surface, x=None, y=None, w=None, h=None):
if x is None:
x = 0
if y is None:
y = 0
if w is None:
w = surface.width - x
if h is None:
h = surface.height - y
data = ctx.surface_read_rgba8(surface, x, y, surface.width, surface.height)
import Image
outimage = Image.fromstring('RGBA', (w, h), data, "raw", 'RGBA', 0, 1)
return outimage
def save_image(ctx, filename, surface, x=None, y=None, w=None, h=None):
outimage = make_image(ctx, surface, x, y, w, h)
outimage.save(filename, "PNG")
def show_image(ctx, surface, title, x=None, y=None, w=None, h=None):
outimage = make_image(ctx, surface, x, y, w, h)
import Tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
root.title(title)
image1 = ImageTk.PhotoImage(outimage)
w = image1.width()
h = image1.height()
x = 100
y = 100
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
panel1.image = image1
root.mainloop()
class Struct:
"""C-like struct"""
# A basic Python class can pass as a C-like structure
pass
struct_factories = {
"pipe_blend_color": gallium.BlendColor,
"pipe_blend_state": gallium.Blend,
#"pipe_clip_state": gallium.Clip,
#"pipe_buffer": gallium.Buffer,
"pipe_depth_state": gallium.Depth,
"pipe_stencil_state": gallium.Stencil,
"pipe_alpha_state": gallium.Alpha,
"pipe_depth_stencil_alpha_state": gallium.DepthStencilAlpha,
#"pipe_framebuffer_state": gallium.Framebuffer,
"pipe_poly_stipple": gallium.PolyStipple,
"pipe_rasterizer_state": gallium.Rasterizer,
"pipe_sampler_state": gallium.Sampler,
"pipe_scissor_state": gallium.Scissor,
#"pipe_shader_state": gallium.Shader,
#"pipe_vertex_buffer": gallium.VertexBuffer,
"pipe_vertex_element": gallium.VertexElement,
"pipe_viewport_state": gallium.Viewport,
#"pipe_texture": gallium.Texture,
'pipe_subresource': gallium.pipe_subresource,
'pipe_box': gallium.pipe_box,
'pipe_draw_info': gallium.pipe_draw_info,
}
member_array_factories = {
#"pipe_rasterizer_state": {"sprite_coord_mode": gallium.ByteArray},
"pipe_poly_stipple": {"stipple": gallium.UnsignedArray},
"pipe_viewport_state": {"scale": gallium.FloatArray, "translate": gallium.FloatArray},
#"pipe_clip_state": {"ucp": gallium.FloatArray},
"pipe_depth_stencil_alpha_state": {"stencil": gallium.StencilArray},
"pipe_blend_color": {"color": gallium.FloatArray},
"pipe_sampler_state": {"border_color": gallium.FloatArray},
}
class Translator(model.Visitor):
"""Translate model arguments into regular Python objects"""
def __init__(self, interpreter):
self.interpreter = interpreter
self.result = None
def visit(self, node):
self.result = None
node.visit(self)
return self.result
def visit_literal(self, node):
self.result = node.value
def visit_named_constant(self, node):
# lookup the named constant in the gallium module
self.result = getattr(gallium, node.name)
def visit_array(self, node):
array = []
for element in node.elements:
array.append(self.visit(element))
self.result = array
def visit_struct(self, node):
struct_factory = struct_factories.get(node.name, Struct)
struct = struct_factory()
for member_name, member_node in node.members:
member_value = self.visit(member_node)
try:
array_factory = member_array_factories[node.name][member_name]
except KeyError:
pass
else:
assert isinstance(member_value, list)
array = array_factory(len(member_value))
for i in range(len(member_value)):
array[i] = member_value[i]
member_value = array
#print node.name, member_name, member_value
assert isinstance(struct, Struct) or hasattr(struct, member_name)
setattr(struct, member_name, member_value)
self.result = struct
def visit_pointer(self, node):
self.result = self.interpreter.lookup_object(node.address)
class Object:
def __init__(self, interpreter, real):
self.interpreter = interpreter
self.real = real
class Global(Object):
def __init__(self, interpreter, real):
self.interpreter = interpreter
self.real = real
def pipe_screen_create(self):
real = gallium.Device()
return Screen(self.interpreter, real)
def pipe_context_create(self, screen):
context = screen.real.context_create()
return Context(self.interpreter, context)
class Transfer:
def __init__(self, resource, usage, subresource, box):
self.resource = resource
self.usage = usage
self.subresource = subresource
self.box = box
class Screen(Object):
def __init__(self, interpreter, real):
Object.__init__(self, interpreter, real)
self.context = self.real.context_create()
def destroy(self):
pass
def get_name(self):
pass
def get_vendor(self):
pass
def get_param(self, param):
pass
def get_paramf(self, param):
pass
def context_create(self):
context = self.real.context_create()
return Context(self.interpreter, context)
def is_format_supported(self, format, target, sample_count, bind, geom_flags):
return self.real.is_format_supported(format, target, sample_count, bind, geom_flags)
def resource_create(self, templat):
return self.real.resource_create(
format = templat.format,
width = templat.width,
height = templat.height,
depth = templat.depth,
last_level = templat.last_level,
target = templat.target,
bind = templat.bind,
)
def texture_destroy(self, texture):
self.interpreter.unregister_object(texture)
def texture_release(self, surface):
pass
def tex_surface_release(self, surface):
pass
def user_buffer_create(self, data, size, usage):
bind = usage
# We don't really care to distinguish between user and regular buffers
buffer = self.real.buffer_create(size, bind)
assert size == len(data)
self.context.buffer_write(buffer, data)
return buffer
def buffer_create(self, alignment, usage, size):
return self.real.buffer_create(size, alignment, usage)
def buffer_destroy(self, buffer):
pass
def fence_finish(self, fence, flags):
pass
def fence_reference(self, dst, src):
pass
def flush_frontbuffer(self, resource):
pass
class Context(Object):
def __init__(self, interpreter, real):
Object.__init__(self, interpreter, real)
self.cbufs = []
self.zsbuf = None
self.vbufs = []
self.velems = []
self.dirty = False
def destroy(self):
pass
def create_blend_state(self, state):
if isinstance(state, str):
state = gallium.Blend(state)
sys.stdout.write('\t%s\n' % state)
return state
def bind_blend_state(self, state):
if state is not None:
self.real.set_blend(state)
def delete_blend_state(self, state):
pass
def create_sampler_state(self, state):
return state
def delete_sampler_state(self, state):
pass
def bind_vertex_sampler_states(self, num_states, states):
for i in range(num_states):
self.real.set_vertex_sampler(i, states[i])
def bind_fragment_sampler_states(self, num_states, states):
for i in range(num_states):
self.real.set_fragment_sampler(i, states[i])
def create_rasterizer_state(self, state):
return state
def bind_rasterizer_state(self, state):
if state is not None:
self.real.set_rasterizer(state)
def delete_rasterizer_state(self, state):
pass
def create_depth_stencil_alpha_state(self, state):
return state
def bind_depth_stencil_alpha_state(self, state):
if state is not None:
self.real.set_depth_stencil_alpha(state)
def delete_depth_stencil_alpha_state(self, state):
pass
def create_fs_state(self, state):
tokens = str(state.tokens)
shader = gallium.Shader(tokens)
return shader
create_vs_state = create_fs_state
def bind_fs_state(self, state):
self.real.set_fragment_shader(state)
def bind_vs_state(self, state):
self.real.set_vertex_shader(state)
def delete_fs_state(self, state):
pass
delete_vs_state = delete_fs_state
def set_blend_color(self, state):
self.real.set_blend_color(state)
def set_stencil_ref(self, state):
self.real.set_stencil_ref(state)
def set_clip_state(self, state):
_state = gallium.Clip()
_state.nr = state.nr
if state.nr:
# FIXME
ucp = gallium.FloatArray(gallium.PIPE_MAX_CLIP_PLANES*4)
for i in range(len(state.ucp)):
for j in range(len(state.ucp[i])):
ucp[i*4 + j] = state.ucp[i][j]
_state.ucp = ucp
self.real.set_clip(_state)
def dump_constant_buffer(self, buffer):
if not self.interpreter.verbosity(2):
return
data = self.real.buffer_read(buffer)
format = '4f'
index = 0
for offset in range(0, len(data), struct.calcsize(format)):
x, y, z, w = unpack_from(format, data, offset)
sys.stdout.write('\tCONST[%2u] = {%10.4f, %10.4f, %10.4f, %10.4f}\n' % (index, x, y, z, w))
index += 1
sys.stdout.flush()
def set_constant_buffer(self, shader, index, buffer):
if buffer is not None:
self.real.set_constant_buffer(shader, index, buffer)
self.dump_constant_buffer(buffer)
def set_framebuffer_state(self, state):
_state = gallium.Framebuffer()
_state.width = state.width
_state.height = state.height
_state.nr_cbufs = state.nr_cbufs
for i in range(len(state.cbufs)):
_state.set_cbuf(i, state.cbufs[i])
_state.set_zsbuf(state.zsbuf)
self.real.set_framebuffer(_state)
self.cbufs = state.cbufs
self.zsbuf = state.zsbuf
def set_polygon_stipple(self, state):
self.real.set_polygon_stipple(state)
def set_scissor_state(self, state):
self.real.set_scissor(state)
def set_viewport_state(self, state):
self.real.set_viewport(state)
def create_sampler_view(self, texture, templ):
return self.real.create_sampler_view(texture,
format = templ.format,
first_level = templ.first_level,
last_level = templ.last_level,
swizzle_r = templ.swizzle_r,
swizzle_g = templ.swizzle_r,
swizzle_b = templ.swizzle_g,
swizzle_a = templ.swizzle_a)
def sampler_view_destroy(self, view):
pass
def set_fragment_sampler_views(self, num, views):
for i in range(num):
self.real.set_fragment_sampler_view(i, views[i])
def set_vertex_sampler_views(self, num, views):
for i in range(num):
self.real.set_vertex_sampler_view(i, views[i])
def set_vertex_buffers(self, num_buffers, buffers):
self.vbufs = buffers[0:num_buffers]
for i in range(num_buffers):
vbuf = buffers[i]
self.real.set_vertex_buffer(
i,
stride = vbuf.stride,
max_index = vbuf.max_index,
buffer_offset = vbuf.buffer_offset,
buffer = vbuf.buffer,
)
def create_vertex_elements_state(self, num_elements, elements):
return elements[0:num_elements]
def bind_vertex_elements_state(self, state):
if state is None:
self.real.set_vertex_elements(0)
return
elements = state
num_elements = len(elements)
self.velems = elements
for i in range(num_elements):
self.real.set_vertex_element(i, elements[i])
self.real.set_vertex_elements(num_elements)
def delete_vertex_elements_state(self, state):
pass
def dump_vertices(self, start, count):
if not self.interpreter.verbosity(2):
return
for index in range(start, start + count):
if index >= start + 16:
sys.stdout.write('\t...\n')
break
sys.stdout.write('\t{\n')
for velem in self.velems:
vbuf = self.vbufs[velem.vertex_buffer_index]
offset = vbuf.buffer_offset + velem.src_offset + vbuf.stride*index
format = {
gallium.PIPE_FORMAT_R32_FLOAT: 'f',
gallium.PIPE_FORMAT_R32G32_FLOAT: '2f',
gallium.PIPE_FORMAT_R32G32B32_FLOAT: '3f',
gallium.PIPE_FORMAT_R32G32B32A32_FLOAT: '4f',
gallium.PIPE_FORMAT_A8R8G8B8_UNORM: '4B',
gallium.PIPE_FORMAT_R8G8B8A8_UNORM: '4B',
gallium.PIPE_FORMAT_B8G8R8A8_UNORM: '4B',
gallium.PIPE_FORMAT_R16G16B16_SNORM: '3h',
}[velem.src_format]
data = self.real.buffer_read(vbuf.buffer)
values = unpack_from(format, data, offset)
sys.stdout.write('\t\t{' + ', '.join(map(str, values)) + '},\n')
sys.stdout.write('\t},\n')
sys.stdout.flush()
def dump_indices(self, ibuf, isize, ibias, start, count):
if not self.interpreter.verbosity(2):
return
format = {
1: 'B',
2: 'H',
4: 'I',
}[isize]
assert struct.calcsize(format) == isize
data = self.real.buffer_read(ibuf)
maxindex, minindex = 0, 0xffffffff
sys.stdout.write('\t{\n')
for i in range(start, start + count):
if i >= start + 16 and not self.interpreter.verbosity(3):
sys.stdout.write('\t...\n')
break
offset = i*isize
index, = unpack_from(format, data, offset)
sys.stdout.write('\t\t%u,\n' % index)
minindex = min(minindex, index)
maxindex = max(maxindex, index)
sys.stdout.write('\t},\n')
sys.stdout.flush()
return minindex + ibias, maxindex + ibias
def set_index_buffer(self, ib):
if ib:
self.real.set_index_buffer(ib.index_size, ib.offset, ib.buffer)
else:
self.real.set_index_buffer(0, 0, None)
def draw_vbo(self, info):
if self.interpreter.verbosity(2):
if 0:
minindex, maxindex = self.dump_indices(indexBuffer, indexSize, indexBias, start, count)
self.dump_vertices(info.minindex, info.maxindex + 1 - info.minindex)
self.real.draw_vbo(info)
self._set_dirty()
def resource_copy_region(self, dst, subdst, dstx, dsty, dstz, src, subsrc, srcx, srcy, srcz, width, height):
if dst is not None and src is not None:
if self.interpreter.options.all:
self.interpreter.present(self.real, src, 'resource_copy_src', srcx, srcy, width, height)
self.real.resource_copy_region(dst, subdst, dstx, dsty, dstx, src, subsrc, srcx, srcy, srcz, width, height)
flags = 0
self.flush(flags)
if self.interpreter.options.all:
self.interpreter.present(self.real, dst, 'resource_copy_dst', dstx, dsty, width, height)
def is_resource_referenced(self, texture, face, level):
#return self.real.is_resource_referenced(format, texture, face, level)
pass
def buffer_write(self, buffer, data, size, offset=0):
assert size == len(data)
self.buffer_write(buffer, data)
def surface_write(self, surface, data, stride, size):
if surface is None:
return
# assert surface.nblocksy * stride == size
surface.put_tile_raw(0, 0, surface.width, surface.height, data, stride)
def get_transfer(self, texture, sr, usage, box):
if texture is None:
return None
transfer = Transfer(texture, sr, usage, box)
if transfer and usage & gallium.PIPE_TRANSFER_READ:
if self.interpreter.options.all:
surface = texture.get_surface(sr.face, sr.level, box.z)
self.interpreter.present(self.real, transfer.surface, 'transf_read', box.x, box.y, box.width, box.height)
return transfer
def tex_transfer_destroy(self, transfer):
self.interpreter.unregister_object(transfer)
def transfer_inline_write(self, resource, sr, usage, box, stride, slice_stride, data):
self.real.transfer_inline_write(resource, sr, usage, box, data, stride, slice_stride)
if self.interpreter.options.all:
for z in range(box.z, box.z + box.depth):
surface = resource.get_surface(sr.face, sr.level, box.z)
self.interpreter.present(self.real, surface, 'transf_inline_write%u' % z, box.x, box.y, box.width, box.height)
def _set_dirty(self):
if self.interpreter.options.step:
self._present()
else:
self.dirty = True
def flush(self, flags):
self.real.flush(flags)
if self.dirty:
if flags & gallium.PIPE_FLUSH_FRAME:
self._present()
self.dirty = False
return None
def clear(self, buffers, rgba, depth, stencil):
_rgba = gallium.FloatArray(4)
for i in range(4):
_rgba[i] = rgba[i]
self.real.clear(buffers, _rgba, depth, stencil)
def clear_render_target(self, dst, rgba, dstx, dsty, width, height):
_rgba = gallium.FloatArray(4)
for i in range(4):
_rgba[i] = rgba[i]
self.real.clear_render_target(dst, _rgba, dstx, dsty, width, height)
def clear_depth_stencil(self, dst, clear_flags, depth, stencil, dstx, dsty, width, height):
self.real.clear_depth_stencil(dst, clear_flags, depth, stencil, dstx, dsty, width, height)
def _present(self):
self.real.flush()
if self.cbufs and self.cbufs[0]:
self.interpreter.present(self.real, self.cbufs[0], "cbuf")
if self.zsbuf:
if self.interpreter.options.all:
self.interpreter.present(self.real, self.zsbuf, "zsbuf")
def create_surface(self, texture, level, layer, usage):
if texture is None:
return None
return texture.get_surface(level, layer)
def surface_destroy(self, surface):
self.interpreter.unregister_object(surface)
class Interpreter(parser.TraceDumper):
ignore_calls = set((
('pipe_screen', 'is_format_supported'),
('pipe_screen', 'get_param'),
('pipe_screen', 'get_paramf'),
))
def __init__(self, stream, options):
parser.TraceDumper.__init__(self, stream)
self.options = options
self.objects = {}
self.result = None
self.globl = Global(self, None)
self.call_no = None
def register_object(self, address, object):
self.objects[address] = object
def unregister_object(self, object):
# FIXME:
pass
def lookup_object(self, address):
return self.objects[address]
def interpret(self, trace):
for call in trace.calls:
self.interpret_call(call)
def handle_call(self, call):
if self.options.stop and call.no > self.options.stop:
sys.exit(0)
if (call.klass, call.method) in self.ignore_calls:
return
self.call_no = call.no
if self.verbosity(1):
parser.TraceDumper.handle_call(self, call)
sys.stdout.flush()
args = [(str(name), self.interpret_arg(arg)) for name, arg in call.args]
if call.klass:
name, obj = args[0]
args = args[1:]
else:
obj = self.globl
method = getattr(obj, call.method)
ret = method(**dict(args))
if call.ret and isinstance(call.ret, model.Pointer):
if ret is None:
sys.stderr.write('warning: NULL returned\n')
self.register_object(call.ret.address, ret)
self.call_no = None
def interpret_arg(self, node):
translator = Translator(self)
return translator.visit(node)
def verbosity(self, level):
return self.options.verbosity >= level
def present(self, ctx, surface, description, x=None, y=None, w=None, h=None):
if self.call_no < self.options.start:
return
if self.options.images:
filename = '%04u_%s.png' % (self.call_no, description)
save_image(ctx, filename, surface, x, y, w, h)
else:
title = '%u. %s' % (self.call_no, description)
show_image(ctx, surface, title, x, y, w, h)
class Main(parser.Main):
def get_optparser(self):
optparser = parser.Main.get_optparser(self)
optparser.add_option("-q", "--quiet", action="store_const", const=0, dest="verbosity", help="no messages")
optparser.add_option("-v", "--verbose", action="count", dest="verbosity", default=1, help="increase verbosity level")
optparser.add_option("-i", "--images", action="store_true", dest="images", default=False, help="save images instead of showing them")
optparser.add_option("-a", "--all", action="store_true", dest="all", default=False, help="show depth, stencil, and transfers")
optparser.add_option("-s", "--step", action="store_true", dest="step", default=False, help="step trhough every draw")
optparser.add_option("-f", "--from", action="store", type="int", dest="start", default=0, help="from call no")
optparser.add_option("-t", "--to", action="store", type="int", dest="stop", default=0, help="until call no")
return optparser
def process_arg(self, stream, options):
parser = Interpreter(stream, options)
parser.parse()
if __name__ == '__main__':
Main().main()

View File

@ -1,254 +0,0 @@
#!/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()

View File

@ -1,233 +0,0 @@
#!/usr/bin/env python
##########################################################################
#
# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sub license, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice (including the
# next paragraph) shall be included in all copies or substantial portions
# of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
##########################################################################
from gallium import *
def make_image(ctx, surface):
data = ctx.surface_read_rgba8(surface, 0, 0, surface.width, surface.height)
import Image
outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1)
return outimage
def save_image(ctx, surface, filename):
outimage = make_image(ctx, surface)
outimage.save(filename, "PNG")
def show_image(ctx, surface):
outimage = make_image(ctx, surface)
import Tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
root.title('background image')
image1 = ImageTk.PhotoImage(outimage)
w = image1.width()
h = image1.height()
x = 100
y = 100
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
panel1.image = image1
root.mainloop()
def test(dev):
ctx = dev.context_create()
width = 255
height = 255
minz = 0.0
maxz = 1.0
# disabled blending/masking
blend = Blend()
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
blend.rt[0].colormask = PIPE_MASK_RGBA
ctx.set_blend(blend)
# depth/stencil/alpha
depth_stencil_alpha = DepthStencilAlpha()
depth_stencil_alpha.depth.enabled = 1
depth_stencil_alpha.depth.writemask = 1
depth_stencil_alpha.depth.func = PIPE_FUNC_LESS
ctx.set_depth_stencil_alpha(depth_stencil_alpha)
# rasterizer
rasterizer = Rasterizer()
rasterizer.front_ccw = False
rasterizer.cull_face = PIPE_FACE_NONE
rasterizer.scissor = 1
ctx.set_rasterizer(rasterizer)
# viewport
viewport = Viewport()
scale = FloatArray(4)
scale[0] = width / 2.0
scale[1] = -height / 2.0
scale[2] = (maxz - minz) / 2.0
scale[3] = 1.0
viewport.scale = scale
translate = FloatArray(4)
translate[0] = width / 2.0
translate[1] = height / 2.0
translate[2] = (maxz - minz) / 2.0
translate[3] = 0.0
viewport.translate = translate
ctx.set_viewport(viewport)
# samplers
sampler = Sampler()
sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE
sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.normalized_coords = 1
ctx.set_fragment_sampler(0, sampler)
# scissor
scissor = Scissor()
scissor.minx = 0
scissor.miny = 0
scissor.maxx = width
scissor.maxy = height
ctx.set_scissor(scissor)
# clip
clip = Clip()
clip.nr = 0
ctx.set_clip(clip)
# framebuffer
cbuf = dev.resource_create(
PIPE_FORMAT_B8G8R8X8_UNORM,
width, height,
bind=PIPE_BIND_RENDER_TARGET,
).get_surface()
zbuf = dev.resource_create(
PIPE_FORMAT_Z32_UNORM,
width, height,
bind=PIPE_BIND_DEPTH_STENCIL,
).get_surface()
fb = Framebuffer()
fb.width = width
fb.height = height
fb.nr_cbufs = 1
fb.set_cbuf(0, cbuf)
fb.set_zsbuf(zbuf)
ctx.set_framebuffer(fb)
rgba = FloatArray(4);
rgba[0] = 0.0
rgba[1] = 0.0
rgba[2] = 0.0
rgba[3] = 0.0
ctx.clear(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0xff)
# vertex shader
vs = Shader('''
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], COLOR, CONSTANT
0:MOV OUT[0], IN[0]
1:MOV OUT[1], IN[1]
2:END
''')
ctx.set_vertex_shader(vs)
# fragment shader
fs = Shader('''
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR, CONSTANT
0:MOV OUT[0], IN[0]
1:END
''')
ctx.set_fragment_shader(fs)
nverts = 3
nattrs = 2
verts = FloatArray(nverts * nattrs * 4)
verts[ 0] = 0.0 # x1
verts[ 1] = 0.8 # y1
verts[ 2] = 0.2 # z1
verts[ 3] = 1.0 # w1
verts[ 4] = 1.0 # r1
verts[ 5] = 0.0 # g1
verts[ 6] = 0.0 # b1
verts[ 7] = 1.0 # a1
verts[ 8] = -0.8 # x2
verts[ 9] = -0.8 # y2
verts[10] = 0.5 # z2
verts[11] = 1.0 # w2
verts[12] = 0.0 # r2
verts[13] = 1.0 # g2
verts[14] = 0.0 # b2
verts[15] = 1.0 # a2
verts[16] = 0.8 # x3
verts[17] = -0.8 # y3
verts[18] = 0.8 # z3
verts[19] = 1.0 # w3
verts[20] = 0.0 # r3
verts[21] = 0.0 # g3
verts[22] = 1.0 # b3
verts[23] = 1.0 # a3
ctx.draw_vertices(PIPE_PRIM_TRIANGLES,
nverts,
nattrs,
verts)
ctx.flush()
show_image(ctx, cbuf)
show_image(ctx, zbuf)
save_image(ctx, cbuf, 'cbuf.png')
save_image(ctx, zbuf, 'zbuf.png')
def main():
dev = Device()
test(dev)
if __name__ == '__main__':
main()

View File

@ -1,3 +0,0 @@
*.txt
*.tsv
*.dot

View File

@ -1,399 +0,0 @@
#!/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('&', '&amp;')
s = s.replace('<', '&lt;')
s = s.replace('>', '&gt;')
s = s.replace('"', '&quot;')
s = s.replace("'", '&apos;')
return s

View File

@ -1,13 +0,0 @@
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

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
ADD OUT[0], IN[0], IN[0]
END

View File

@ -1,13 +0,0 @@
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

View File

@ -1,9 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL CONST[1][6]
MOV OUT[0], CONST[1][6]
END

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DP3 OUT[0], IN[0], IN[0]
END

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DP4 OUT[0], IN[0].xyzx, IN[0].xyzx
END

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DST OUT[0], IN[0], IN[0]
END

View File

@ -1,11 +0,0 @@
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

View File

@ -1,14 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL IN[1], FACE, CONSTANT
DCL OUT[0], COLOR
DCL TEMP[0]
IMM FLT32 { 0.5, 1.0, 0.0, 0.0 }
MUL TEMP[0], IN[1].xxxx, IMM[0].xxxx
ADD TEMP[0], TEMP[0], IMM[0].yyyy
MOV OUT[0], TEMP[0]
END

View File

@ -1,15 +0,0 @@
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

View File

@ -1,13 +0,0 @@
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

View File

@ -1,18 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL TEMP[0]
IMM FLT32 { 0.6, 0.6, 0.6, 0.0 }
IMM FLT32 { 0.01, 0.0, 0.0, 0.0 }
IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
SLT TEMP[0], IN[0], IMM[0]
MUL OUT[0], IN[0], TEMP[0]
MOV OUT[0].w, IMM[2].xxxx
SUB TEMP[0], TEMP[0], IMM[1].xxxy
KIL TEMP[0]
END

View File

@ -1,15 +0,0 @@
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

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
LIT OUT[0], IN[0]
END

View File

@ -1,11 +0,0 @@
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

View File

@ -1,10 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL IMMX[0..1] {{ 0.5, 0.4, 0.6, 1.0 },
{ 0.5, 0.4, 0.6, 0.0 }}
MAD OUT[0], IN[0], IMMX[0], IMMX[1]
END

View File

@ -1,11 +0,0 @@
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

View File

@ -1,10 +0,0 @@
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

View File

@ -1,10 +0,0 @@
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

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
MOV OUT[0], IN[0]
END

View File

@ -1,10 +0,0 @@
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

View File

@ -1,15 +0,0 @@
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

View File

@ -1,15 +0,0 @@
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

View File

@ -1,13 +0,0 @@
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

View File

@ -1,13 +0,0 @@
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

View File

@ -1,13 +0,0 @@
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

View File

@ -1,15 +0,0 @@
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

View File

@ -1,11 +0,0 @@
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

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
MOV OUT[0], IN[0].yxzw
END

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
SUB OUT[0], IN[0], IN[0].yzxw
END

View File

@ -1,14 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL TEMPX[0][0..1]
IMM FLT32 { -0.5, -0.4, -0.6, 0.0 }
ADD TEMPX[0][0], IN[0], IMM[0]
ADD TEMPX[0][1], IN[0], IMM[0]
ABS OUT[0], TEMPX[0][1]
END

View File

@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
XPD OUT[0], IN[0], IN[0].yzxw
END

View File

@ -1,257 +0,0 @@
#!/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()

View File

@ -1 +0,0 @@
*.png

View File

@ -1,15 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM FLT32 { 0.2, 0.2, 0.0, 0.0 }
ADD TEMP[0], IN[0], IMM[0]
ABS OUT[0], TEMP[0]
MOV OUT[1], IN[1]
END

View File

@ -1,13 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
IMM FLT32 { 0.2, -0.1, 0.0, 0.0 }
ADD OUT[0], IN[0], IMM[0]
MOV OUT[1], IN[1]
END

View File

@ -1,23 +0,0 @@
VERT
DCL IN[0]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
DCL ADDR[0]
IMM FLT32 { 3.0, 1.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 0.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 1.0, 1.0 }
MOV OUT[0], IN[0]
MUL TEMP[0], IN[0], IMM[0]
ARL ADDR[0].x, TEMP[0]
MOV OUT[1], IMM[ADDR[0].x + 3]
END

View File

@ -1,23 +0,0 @@
VERT
DCL IN[0]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
DCL ADDR[0]
IMM FLT32 { 3.0, 1.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 0.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 1.0, 1.0 }
MOV OUT[0], IN[0]
MUL TEMP[0], IN[0], IMM[0]
ARR ADDR[0].x, TEMP[0]
MOV OUT[1], IMM[ADDR[0].x + 3]
END

View File

@ -1,16 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL CONST[1]
DCL CONST[3]
DCL TEMP[0..1]
MOV OUT[0], IN[0]
ADD TEMP[0], IN[1], CONST[1]
RCP TEMP[1], CONST[3].xxxx
MUL OUT[1], TEMP[0], TEMP[1]
END

View File

@ -1,12 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL CONST[1][1..2]
MOV OUT[0], IN[0]
MAD OUT[1], IN[1], CONST[1][2], CONST[1][1]
END

View File

@ -1,16 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
DP3 TEMP[0].xy, IN[0], IN[0]
MOV TEMP[0].zw, IMM[0]
MUL OUT[0], IN[0], TEMP[0]
MOV OUT[1], IN[1]
END

View File

@ -1,16 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
DP4 TEMP[0].xy, IN[0], IN[0]
MOV TEMP[0].zw, IMM[0]
MUL OUT[0], IN[0], TEMP[0]
MOV OUT[1], IN[1]
END

View File

@ -1,11 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
MOV OUT[0], IN[0]
DST OUT[1], IN[1], IN[0]
END

View File

@ -1,18 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0..1]
IMM FLT32 { 0.3, 0.3, 0.3, 1.0 }
EX2 TEMP[0], IN[0]
EX2 TEMP[1], IN[1].yyyy
MUL TEMP[0], TEMP[0], IMM[0]
MOV OUT[0], IN[0]
MUL OUT[1], TEMP[0], TEMP[1]
END

View File

@ -1,23 +0,0 @@
VERT
DCL IN[0]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
DCL ADDR[0]
IMM FLT32 { 3.0, 1.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 0.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 1.0, 1.0 }
MOV OUT[0], IN[0]
MUL TEMP[0], IN[0], IMM[0]
FLR ADDR[0].x, TEMP[0]
MOV OUT[1], IMM[ADDR[0].x + 3]
END

View File

@ -1,15 +0,0 @@
VERT
DCL IN[0]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM FLT32 { 2.7, 3.1, 4.5, 1.0 }
MUL TEMP[0], IN[0].xyxw, IMM[0]
MOV OUT[0], IN[0]
FRC OUT[1], TEMP[0]
END

View File

@ -1,18 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], 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]
MOV OUT[1], IN[1]
END

View File

@ -1,11 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
MOV OUT[0], IN[0]
LIT OUT[1], IN[1]
END

View File

@ -1,14 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
ABS TEMP[0], IN[0]
MOV OUT[0], IN[0]
LRP OUT[1], TEMP[0], IN[1].xxxx, IN[1].yyyy
END

View File

@ -1,14 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
IMM FLT32 { 0.5, 1.0, 1.0, 1.0 }
IMM FLT32 { 0.5, 0.0, 0.0, 0.0 }
MAD OUT[0], IN[0], IMM[0], IMM[1]
MOV OUT[1], IN[1]
END

View File

@ -1,13 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
IMM FLT32 { 0.5, 0.5, 0.5, 0.0 }
MOV OUT[0], IN[0]
MAX OUT[1], IN[1], IMM[0]
END

View File

@ -1,13 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
IMM FLT32 { 0.5, 0.5, 0.5, 0.0 }
MOV OUT[0], IN[0]
MIN OUT[1], IN[1], IMM[0]
END

View File

@ -1,11 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
MOV OUT[0], IN[0]
MOV OUT[1], IN[1]
END

View File

@ -1,13 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
IMM FLT32 { 0.6, 0.6, 1.0, 1.0 }
MUL OUT[0], IN[0], IMM[0]
MOV OUT[1], IN[1]
END

View File

@ -1,18 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], 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]
MOV OUT[1], IN[1]
END

View File

@ -1,18 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], 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]
MOV OUT[1], IN[1]
END

View File

@ -1,16 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM FLT32 { -0.1, -0.1, 1.0, 0.0 }
SGE TEMP[0], IN[0], IMM[0]
MOV OUT[0], IN[0]
MUL OUT[1], IN[1], TEMP[0]
END

View File

@ -1,16 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM FLT32 { 0.6, 0.6, 0.0, 0.0 }
SLT TEMP[0], IN[0], IMM[0]
MOV OUT[0], IN[0]
MUL OUT[1], IN[1], TEMP[0]
END

View File

@ -1,15 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM FLT32 { 0.1, 0.1, 0.0, 0.0 }
ADD TEMP[0], IN[0], IMM[0]
MOV OUT[0], |TEMP[0]|
MOV OUT[1], IN[1]
END

View File

@ -1,16 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM FLT32 { -0.2, -0.2, 0.0, 0.0 }
ADD TEMP[0], IN[0], IMM[0]
MOV OUT[0].xy, -|TEMP[0]|
MOV OUT[0].zw, IN[0]
MOV OUT[1], IN[1]
END

View File

@ -1,12 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
MOV OUT[0].xy, -IN[0]
MOV OUT[0].zw, IN[0]
MOV OUT[1], IN[1]
END

View File

@ -1,11 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
MOV OUT[0], IN[0].yxzw
MOV OUT[1], IN[1]
END

View File

@ -1,13 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
IMM FLT32 { 0.1, 0.1, 0.0, 0.0 }
SUB OUT[0], IN[0], IMM[0]
MOV OUT[1], IN[1]
END

View File

@ -1,11 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
MOV OUT[0], IN[0]
XPD OUT[1], IN[0], IN[1]
END

View File

@ -1,287 +0,0 @@
#!/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()

View File

@ -1,201 +0,0 @@
#!/usr/bin/env python
##########################################################################
#
# Copyright 2009 VMware, Inc.
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sub license, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice (including the
# next paragraph) shall be included in all copies or substantial portions
# of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
##########################################################################
import os
import random
from gallium import *
from base import *
def lods(*dims):
size = max(dims)
lods = 0
while size:
lods += 1
size >>= 1
return lods
class TextureTest(TestCase):
tags = (
'target',
'format',
'width',
'height',
'depth',
'last_level',
'face',
'level',
'zslice',
)
def test(self):
dev = self.dev
ctx = self.ctx
target = self.target
format = self.format
width = self.width
height = self.height
depth = self.depth
last_level = self.last_level
face = self.face
level = self.level
zslice = self.zslice
bind = PIPE_BIND_SAMPLER_VIEW
geom_flags = 0
sample_count = 0
if not dev.is_format_supported(format, target, sample_count, bind, geom_flags):
raise TestSkip
if not dev.is_format_supported(format, target, sample_count, bind, geom_flags):
raise TestSkip
# textures
dst_texture = dev.resource_create(
target = target,
format = format,
width = width,
height = height,
depth = depth,
last_level = last_level,
bind = bind,
)
dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice)
src_texture = dev.resource_create(
target = target,
format = format,
width = dst_surface.width,
height = dst_surface.height,
depth = 1,
last_level = 0,
bind = PIPE_BIND_SAMPLER_VIEW,
)
src_surface = src_texture.get_surface()
w = dst_surface.width
h = dst_surface.height
stride = util_format_get_stride(format, w)
size = util_format_get_nblocksy(format, h) * stride
src_raw = os.urandom(size)
ctx.surface_write_raw(src_surface, 0, 0, w, h, src_raw, stride)
ctx.surface_copy(dst_surface, 0, 0,
src_surface, 0, 0, w, h)
dst_raw = ctx.surface_read_raw(dst_surface, 0, 0, w, h)
if dst_raw != src_raw:
raise TestFailure
def main():
dev = Device()
ctx = dev.context_create()
suite = TestSuite()
targets = [
PIPE_TEXTURE_2D,
PIPE_TEXTURE_CUBE,
PIPE_TEXTURE_3D,
]
sizes = [64, 32, 16, 8, 4, 2, 1]
#sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
#sizes = [64]
#sizes = [63]
faces = [
PIPE_TEX_FACE_POS_X,
PIPE_TEX_FACE_NEG_X,
PIPE_TEX_FACE_POS_Y,
PIPE_TEX_FACE_NEG_Y,
PIPE_TEX_FACE_POS_Z,
PIPE_TEX_FACE_NEG_Z,
]
try:
n = int(sys.argv[1])
except:
n = 10000
for i in range(n):
format = random.choice(formats.keys())
if not util_format_is_depth_or_stencil(format):
is_depth_or_stencil = util_format_is_depth_or_stencil(format)
if is_depth_or_stencil:
target = PIPE_TEXTURE_2D
else:
target = random.choice(targets)
size = random.choice(sizes)
if target == PIPE_TEXTURE_3D:
depth = size
else:
depth = 1
if target == PIPE_TEXTURE_CUBE:
face = random.choice(faces)
else:
face = PIPE_TEX_FACE_POS_X
levels = lods(size)
last_level = random.randint(0, levels - 1)
level = random.randint(0, last_level)
zslice = random.randint(0, max(depth >> level, 1) - 1)
test = TextureTest(
dev = dev,
ctx = ctx,
target = target,
format = format,
width = size,
height = size,
depth = depth,
last_level = last_level,
face = face,
level = level,
zslice = zslice,
)
suite.add_test(test)
suite.run()
if __name__ == '__main__':
main()

View File

@ -1,638 +0,0 @@
#!/usr/bin/env python
##########################################################################
#
# Copyright 2009 VMware, Inc.
# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sub license, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice (including the
# next paragraph) shall be included in all copies or substantial portions
# of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
##########################################################################
import random
from gallium import *
from base import *
def lods(*dims):
size = max(dims)
lods = 0
while size:
lods += 1
size >>= 1
return lods
def minify(dims, level = 1):
return [max(dim>>level, 1) for dim in dims]
def tex_coords(texture, face, level, zslice):
st = [
[0.0, 0.0],
[1.0, 0.0],
[1.0, 1.0],
[0.0, 1.0],
]
if texture.target == PIPE_TEXTURE_2D or texture.target == PIPE_TEXTURE_RECT:
return [[s, t, 0.0] for s, t in st]
elif texture.target == PIPE_TEXTURE_3D:
depth = texture.get_depth(level)
if depth > 1:
r = float(zslice)/float(depth - 1)
else:
r = 0.0
return [[s, t, r] for s, t in st]
elif texture.target == PIPE_TEXTURE_CUBE:
result = []
for s, t in st:
# See http://developer.nvidia.com/object/cube_map_ogl_tutorial.html
sc = 2.0*s - 1.0
tc = 2.0*t - 1.0
if face == PIPE_TEX_FACE_POS_X:
rx = 1.0
ry = -tc
rz = -sc
if face == PIPE_TEX_FACE_NEG_X:
rx = -1.0
ry = -tc
rz = sc
if face == PIPE_TEX_FACE_POS_Y:
rx = sc
ry = 1.0
rz = tc
if face == PIPE_TEX_FACE_NEG_Y:
rx = sc
ry = -1.0
rz = -tc
if face == PIPE_TEX_FACE_POS_Z:
rx = sc
ry = -tc
rz = 1.0
if face == PIPE_TEX_FACE_NEG_Z:
rx = -sc
ry = -tc
rz = -1.0
result.append([rx, ry, rz])
return result
def is_pot(n):
return n & (n - 1) == 0
class TextureColorSampleTest(TestCase):
tags = (
'target',
'format',
'width',
'height',
'depth',
'last_level',
'face',
'level',
'zslice',
)
def test(self):
dev = self.dev
ctx = self.ctx
target = self.target
format = self.format
width = self.width
height = self.height
depth = self.depth
last_level = self.last_level
face = self.face
level = self.level
zslice = self.zslice
minz = 0.0
maxz = 1.0
bind = PIPE_BIND_SAMPLER_VIEW
geom_flags = 0
sample_count = 0
if width != height:
geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE
if not is_pot(width) or not is_pot(height) or not is_pot(depth):
geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO
if not dev.is_format_supported(format, target, sample_count, bind, geom_flags):
raise TestSkip
# disabled blending/masking
blend = Blend()
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
blend.rt[0].colormask = PIPE_MASK_RGBA
ctx.set_blend(blend)
# no-op depth/stencil/alpha
depth_stencil_alpha = DepthStencilAlpha()
ctx.set_depth_stencil_alpha(depth_stencil_alpha)
# rasterizer
rasterizer = Rasterizer()
rasterizer.front_winding = PIPE_WINDING_CW
rasterizer.cull_mode = PIPE_WINDING_NONE
ctx.set_rasterizer(rasterizer)
# samplers
sampler = Sampler()
sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.normalized_coords = 1
sampler.min_lod = 0
sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1
ctx.set_fragment_sampler(0, sampler)
# texture
texture = dev.resource_create(
target = target,
format = format,
width = width,
height = height,
depth = depth,
last_level = last_level,
bind = bind,
)
expected_rgba = FloatArray(height*width*4)
surface = texture.get_surface(
face = face,
level = level,
zslice = zslice,
)
ctx.surface_sample_rgba(surface, expected_rgba, True)
ctx.set_fragment_sampler_texture(0, texture)
# viewport
viewport = Viewport()
scale = FloatArray(4)
scale[0] = width
scale[1] = height
scale[2] = (maxz - minz) / 2.0
scale[3] = 1.0
viewport.scale = scale
translate = FloatArray(4)
translate[0] = 0.0
translate[1] = 0.0
translate[2] = (maxz - minz) / 2.0
translate[3] = 0.0
viewport.translate = translate
ctx.set_viewport(viewport)
# scissor
scissor = Scissor()
scissor.minx = 0
scissor.miny = 0
scissor.maxx = width
scissor.maxy = height
ctx.set_scissor(scissor)
# clip
clip = Clip()
clip.nr = 0
ctx.set_clip(clip)
# framebuffer
cbuf_tex = dev.resource_create(
PIPE_FORMAT_B8G8R8A8_UNORM,
width,
height,
bind = PIPE_BIND_RENDER_TARGET,
)
cbuf = cbuf_tex.get_surface()
fb = Framebuffer()
fb.width = width
fb.height = height
fb.nr_cbufs = 1
fb.set_cbuf(0, cbuf)
ctx.set_framebuffer(fb)
rgba = FloatArray(4);
rgba[0] = 0.5
rgba[1] = 0.5
rgba[2] = 0.5
rgba[3] = 0.5
ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
del fb
# vertex shader
vs = Shader('''
VERT
DCL IN[0], POSITION, CONSTANT
DCL IN[1], GENERIC, CONSTANT
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], GENERIC, CONSTANT
0:MOV OUT[0], IN[0]
1:MOV OUT[1], IN[1]
2:END
''')
#vs.dump()
ctx.set_vertex_shader(vs)
# fragment shader
op = {
PIPE_TEXTURE_1D: "1D",
PIPE_TEXTURE_2D: "2D",
PIPE_TEXTURE_3D: "3D",
PIPE_TEXTURE_CUBE: "CUBE",
}[target]
fs = Shader('''
FRAG
DCL IN[0], GENERIC[0], LINEAR
DCL OUT[0], COLOR, CONSTANT
DCL SAMP[0], CONSTANT
0:TEX OUT[0], IN[0], SAMP[0], %s
1:END
''' % op)
#fs.dump()
ctx.set_fragment_shader(fs)
nverts = 4
nattrs = 2
verts = FloatArray(nverts * nattrs * 4)
x = 0
y = 0
w, h = minify((width, height), level)
pos = [
[x, y],
[x+w, y],
[x+w, y+h],
[x, y+h],
]
tex = tex_coords(texture, face, level, zslice)
for i in range(0, 4):
j = 8*i
verts[j + 0] = pos[i][0]/float(width) # x
verts[j + 1] = pos[i][1]/float(height) # y
verts[j + 2] = 0.0 # z
verts[j + 3] = 1.0 # w
verts[j + 4] = tex[i][0] # s
verts[j + 5] = tex[i][1] # r
verts[j + 6] = tex[i][2] # q
verts[j + 7] = 1.0
ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN,
nverts,
nattrs,
verts)
ctx.flush()
cbuf = cbuf_tex.get_surface()
self.assert_rgba(ctx, cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
class TextureDepthSampleTest(TestCase):
tags = (
'target',
'format',
'width',
'height',
'depth',
'last_level',
'face',
'level',
'zslice',
)
def test(self):
dev = self.dev
ctx = self.ctx
target = self.target
format = self.format
width = self.width
height = self.height
depth = self.depth
last_level = self.last_level
face = self.face
level = self.level
zslice = self.zslice
minz = 0.0
maxz = 1.0
bind = PIPE_BIND_SAMPLER_VIEW
geom_flags = 0
sample_count = 0
if width != height:
geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE
if not is_pot(width) or not is_pot(height) or not is_pot(depth):
geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO
if not dev.is_format_supported(format, target, sample_count, bind, geom_flags):
raise TestSkip
# disabled blending/masking
blend = Blend()
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
blend.rt[0].colormask = PIPE_MASK_RGBA
ctx.set_blend(blend)
# depth/stencil/alpha
depth_stencil_alpha = DepthStencilAlpha()
depth_stencil_alpha.depth.enabled = 1
depth_stencil_alpha.depth.writemask = 1
depth_stencil_alpha.depth.func = PIPE_FUNC_LESS
ctx.set_depth_stencil_alpha(depth_stencil_alpha)
# rasterizer
rasterizer = Rasterizer()
rasterizer.front_winding = PIPE_WINDING_CW
rasterizer.cull_mode = PIPE_WINDING_NONE
ctx.set_rasterizer(rasterizer)
# viewport
viewport = Viewport()
scale = FloatArray(4)
scale[0] = width
scale[1] = height
scale[2] = (maxz - minz) / 2.0
scale[3] = 1.0
viewport.scale = scale
translate = FloatArray(4)
translate[0] = 0.0
translate[1] = 0.0
translate[2] = (maxz - minz) / 2.0
translate[3] = 0.0
viewport.translate = translate
ctx.set_viewport(viewport)
# samplers
sampler = Sampler()
sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.normalized_coords = 1
sampler.min_lod = 0
sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1
ctx.set_fragment_sampler(0, sampler)
# texture
texture = dev.resource_create(
target = target,
format = format,
width = width,
height = height,
depth = depth,
last_level = last_level,
bind = bind,
)
expected_rgba = FloatArray(height*width*4)
surface = texture.get_surface(
face = face,
level = level,
zslice = zslice,
)
ctx.surface_sample_rgba(surface, expected_rgba, True)
ctx.set_fragment_sampler_texture(0, texture)
# scissor
scissor = Scissor()
scissor.minx = 0
scissor.miny = 0
scissor.maxx = width
scissor.maxy = height
ctx.set_scissor(scissor)
# clip
clip = Clip()
clip.nr = 0
ctx.set_clip(clip)
# framebuffer
cbuf_tex = dev.resource_create(
PIPE_FORMAT_B8G8R8A8_UNORM,
width,
height,
bind = PIPE_BIND_RENDER_TARGET,
)
zsbuf_tex = dev.resource_create(
PIPE_FORMAT_X8Z24_UNORM,
width,
height,
bind = PIPE_BIND_RENDER_TARGET,
)
cbuf = cbuf_tex.get_surface()
zsbuf = zsbuf_tex.get_surface()
fb = Framebuffer()
fb.width = width
fb.height = height
fb.nr_cbufs = 1
fb.set_cbuf(0, cbuf)
fb.set_zsbuf(zsbuf)
ctx.set_framebuffer(fb)
rgba = FloatArray(4);
rgba[0] = 0.5
rgba[1] = 0.5
rgba[2] = 0.5
rgba[3] = 0.5
ctx.clear(PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0)
del fb
# vertex shader
vs = Shader('''
VERT
DCL IN[0], POSITION, CONSTANT
DCL IN[1], GENERIC, CONSTANT
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], GENERIC, CONSTANT
0:MOV OUT[0], IN[0]
1:MOV OUT[1], IN[1]
2:END
''')
#vs.dump()
ctx.set_vertex_shader(vs)
# fragment shader
op = {
PIPE_TEXTURE_1D: "1D",
PIPE_TEXTURE_2D: "2D",
PIPE_TEXTURE_3D: "3D",
PIPE_TEXTURE_CUBE: "CUBE",
}[target]
fs = Shader('''
FRAG
DCL IN[0], GENERIC[0], LINEAR
DCL SAMP[0], CONSTANT
DCL OUT[0].z, POSITION
0:TEX OUT[0].z, IN[0], SAMP[0], %s
1:END
''' % op)
#fs.dump()
ctx.set_fragment_shader(fs)
nverts = 4
nattrs = 2
verts = FloatArray(nverts * nattrs * 4)
x = 0
y = 0
w, h = minify((width, height), level)
pos = [
[x, y],
[x+w, y],
[x+w, y+h],
[x, y+h],
]
tex = tex_coords(texture, face, level, zslice)
for i in range(0, 4):
j = 8*i
verts[j + 0] = pos[i][0]/float(width) # x
verts[j + 1] = pos[i][1]/float(height) # y
verts[j + 2] = 0.0 # z
verts[j + 3] = 1.0 # w
verts[j + 4] = tex[i][0] # s
verts[j + 5] = tex[i][1] # r
verts[j + 6] = tex[i][2] # q
verts[j + 7] = 1.0
ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN,
nverts,
nattrs,
verts)
ctx.flush()
zsbuf = zsbuf_tex.get_surface()
self.assert_rgba(ctx, zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
def main():
random.seed(0xdead3eef)
dev = Device()
ctx = dev.context_create()
suite = TestSuite()
targets = [
PIPE_TEXTURE_2D,
PIPE_TEXTURE_CUBE,
PIPE_TEXTURE_3D,
]
#sizes = [64, 32, 16, 8, 4, 2, 1]
#sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
sizes = [64]
#sizes = [63]
faces = [
PIPE_TEX_FACE_POS_X,
PIPE_TEX_FACE_NEG_X,
PIPE_TEX_FACE_POS_Y,
PIPE_TEX_FACE_NEG_Y,
PIPE_TEX_FACE_POS_Z,
PIPE_TEX_FACE_NEG_Z,
]
try:
n = int(sys.argv[1])
except:
n = 10000
for i in range(n):
format = random.choice(formats.keys())
if not util_format_is_depth_or_stencil(format):
is_depth_or_stencil = util_format_is_depth_or_stencil(format)
if is_depth_or_stencil:
target = PIPE_TEXTURE_2D
else:
target = random.choice(targets)
size = random.choice(sizes)
if target == PIPE_TEXTURE_3D:
depth = size
else:
depth = 1
if target == PIPE_TEXTURE_CUBE:
face = random.choice(faces)
else:
face = PIPE_TEX_FACE_POS_X
levels = lods(size)
last_level = random.randint(0, levels - 1)
level = random.randint(0, last_level)
zslice = random.randint(0, max(depth >> level, 1) - 1)
if is_depth_or_stencil:
klass = TextureDepthSampleTest
else:
klass = TextureColorSampleTest
test = klass(
dev = dev,
ctx = ctx,
target = target,
format = format,
width = size,
height = size,
depth = depth,
last_level = last_level,
face = face,
level = level,
zslice = zslice,
)
suite.add_test(test)
suite.run()
if __name__ == '__main__':
main()

View File

@ -1,320 +0,0 @@
#!/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()

View File

@ -1,182 +0,0 @@
#!/usr/bin/env python
##########################################################################
#
# Copyright 2009 VMware, Inc.
# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sub license, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice (including the
# next paragraph) shall be included in all copies or substantial portions
# of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
##########################################################################
import os
import random
from gallium import *
from base import *
def lods(*dims):
size = max(dims)
lods = 0
while size:
lods += 1
size >>= 1
return lods
class TextureTest(TestCase):
tags = (
'target',
'format',
'width',
'height',
'depth',
'last_level',
'face',
'level',
'zslice',
)
def test(self):
dev = self.dev
ctx = self.ctx
target = self.target
format = self.format
width = self.width
height = self.height
depth = self.depth
last_level = self.last_level
face = self.face
level = self.level
zslice = self.zslice
bind = PIPE_BIND_SAMPLER_VIEW
geom_flags = 0
sample_count = 0
if not dev.is_format_supported(format, target, sample_count, bind, geom_flags):
raise TestSkip
# textures
texture = dev.resource_create(
target = target,
format = format,
width = width,
height = height,
depth = depth,
last_level = last_level,
bind = bind,
)
surface = texture.get_surface(face, level, zslice)
stride = util_format_get_stride(format, surface.width)
size = util_format_get_nblocksy(format, surface.height) * stride
in_raw = os.urandom(size)
ctx.surface_write_raw(surface, 0, 0, surface.width, surface.height, in_raw, stride)
out_raw = ctx.surface_read_raw(surface, 0, 0, surface.width, surface.height)
if in_raw != out_raw:
raise TestFailure
def main():
dev = Device()
ctx = dev.context_create()
suite = TestSuite()
targets = [
PIPE_TEXTURE_2D,
PIPE_TEXTURE_CUBE,
PIPE_TEXTURE_3D,
]
sizes = [64, 32, 16, 8, 4, 2, 1]
#sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
#sizes = [64]
#sizes = [63]
faces = [
PIPE_TEX_FACE_POS_X,
PIPE_TEX_FACE_NEG_X,
PIPE_TEX_FACE_POS_Y,
PIPE_TEX_FACE_NEG_Y,
PIPE_TEX_FACE_POS_Z,
PIPE_TEX_FACE_NEG_Z,
]
try:
n = int(sys.argv[1])
except:
n = 10000
for i in range(n):
format = random.choice(formats.keys())
if not util_format_is_depth_or_stencil(format):
is_depth_or_stencil = util_format_is_depth_or_stencil(format)
if is_depth_or_stencil:
target = PIPE_TEXTURE_2D
else:
target = random.choice(targets)
size = random.choice(sizes)
if target == PIPE_TEXTURE_3D:
depth = size
else:
depth = 1
if target == PIPE_TEXTURE_CUBE:
face = random.choice(faces)
else:
face = PIPE_TEX_FACE_POS_X
levels = lods(size)
last_level = random.randint(0, levels - 1)
level = random.randint(0, last_level)
zslice = random.randint(0, max(depth >> level, 1) - 1)
test = TextureTest(
dev = dev,
ctx = ctx,
target = target,
format = format,
width = size,
height = size,
depth = depth,
last_level = last_level,
face = face,
level = level,
zslice = zslice,
)
suite.add_test(test)
suite.run()
if __name__ == '__main__':
main()

View File

@ -1,23 +0,0 @@
#!/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')

View File

@ -153,7 +153,8 @@ class PrettyPrinter:
def visit_literal(self, node):
if isinstance(node.value, basestring):
if len(node.value) >= 4096 or node.value.strip(string.printable):
self.formatter.text('...')
self.formatter.address('blob(%u)' % len(node.value))
#self.formatter.text('...')
return
self.formatter.literal('"' + node.value + '"')

Some files were not shown because too many files have changed in this diff Show More