Initial import of intel-graphics-tools with some microbenchmarks.

This commit is contained in:
Eric Anholt 2009-03-26 17:15:11 -07:00
commit 8c64183a46
19 changed files with 4185 additions and 0 deletions

32
.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
.deps
.libs
Makefile
Makefile.in
*.la
*.lo
*.o
*~
aclocal.m4
autom4te.cache
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
configure.lineno
depcomp
doltcompile
doltlibtool
install-sh
libtool
ltmain.sh
missing
shave
shave-libtool
stamp-h1
cscope.*
benchmarks/intel_upload_blit_large
benchmarks/intel_upload_blit_small

25
Makefile.am Normal file
View File

@ -0,0 +1,25 @@
# Copyright © 2005 Adam Jackson.
# Copyright © 2009 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# on the rights to use, copy, modify, merge, publish, distribute, sub
# license, and/or sell copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
# ADAM JACKSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = tests tools benchmarks

25
README Normal file
View File

@ -0,0 +1,25 @@
This is a collection of tools for development and testing of the Intel DRM
driver. There are many macro-level test suites that get used against our
driver, including xtest, rendercheck, piglit, and oglconform, but failures
from those can be difficult to track down to kernel changes, and many require
complicated build procedures or specific testing environments to get useful
results.
Thus, intel-graphics-tools was a project I started to collect some low-level
tools I intended to build. There are 3 subdirectories:
benchmarks/
This should be a collection of useful microbenchmarks. The hope is
that people can use these to tune some pieces of DRM code in relevant
ways.
tests/
This is a set of automated tests to run against the DRM to validate
changes. Hopefully this can cover the relevant cases we need to
worry about, including backwards compatibility.
tools/
This is a collection of debugging tools that had previously been
built with the 2D driver but not shipped. Some distros were hacking
up the 2D build to ship them. Instead, here's a separate package for
people debugging the driver.

12
autogen.sh Executable file
View File

@ -0,0 +1,12 @@
#! /bin/sh
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd $srcdir
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
$srcdir/configure --enable-maintainer-mode "$@"

14
benchmarks/Makefile.am Normal file
View File

@ -0,0 +1,14 @@
bin_PROGRAMS = \
intel_upload_blit_large \
intel_upload_blit_small
BENCHMARK_LIBS = \
../lib/libintel_tools.la \
$(DRM_LIBS)
intel_upload_blit_large_LDADD = $(BENCHMARK_LIBS)
intel_upload_blit_small_LDADD = $(BENCHMARK_LIBS)
AM_CFLAGS = $(DRM_CFLAGS) $(WARN_CFLAGS) \
-I$(srcdir)/.. \
-I$(srcdir)/../lib

View File

@ -0,0 +1,157 @@
/*
* Copyright © 2009 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
/**
* Roughly simulates repeatedly uploading frames of images, by uploading
* the data all at once with pwrite, and then blitting it to another buffer.
*
* You might think of this like a movie player, but that wouldn't be entirely
* accurate, since the access patterns of the memory would be different
* (generally, smaller source image, upscaled, an thus different memory access
* pattern in both texel fetch for the stretching and the destination writes).
* However, some things like swfdec would be doing something like this since
* they compute their data in host memory and upload the full sw rendered
* frame.
*
* Additionally, those applications should be rendering at the screen refresh
* rate, while this test has no limits, and so can get itself into the
* working set larger than aperture size performance disaster.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "drm.h"
#include "i915_drm.h"
#include "drmtest.h"
#include "intel_bufmgr.h"
#include "intel_batchbuffer.h"
#define OBJECT_WIDTH 1280
#define OBJECT_HEIGHT 720
static double
get_time_in_secs(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + tv.tv_usec / 1000000.0;
}
static void
do_render(drm_intel_bufmgr *bufmgr, struct intel_batchbuffer *batch,
drm_intel_bo *dst_bo, int width, int height)
{
uint32_t data[width * height];
drm_intel_bo *src_bo;
int i;
/* Generate some junk. Real workloads would be doing a lot more
* work to generate the junk.
*/
for (i = 0; i < width * height; i++) {
data[i] = (uint32_t)random();
}
/* Upload the junk. */
src_bo = drm_intel_bo_alloc(bufmgr, "src", sizeof(data), 4096);
drm_intel_bo_subdata(src_bo, 0, sizeof(data), data);
/* Render the junk to the dst. */
BEGIN_BATCH(8);
OUT_BATCH(XY_SRC_COPY_BLT_CMD |
XY_SRC_COPY_BLT_WRITE_ALPHA |
XY_SRC_COPY_BLT_WRITE_RGB);
OUT_BATCH((3 << 24) | /* 32 bits */
(0xcc << 16) | /* copy ROP */
(width * 4) /* dst pitch */);
OUT_BATCH(0); /* dst x1,y1 */
OUT_BATCH((height << 16) | width); /* dst x2,y2 */
OUT_RELOC(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
OUT_BATCH(0); /* src x1,y1 */
OUT_BATCH(width * 4); /* src pitch */
OUT_RELOC(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
ADVANCE_BATCH();
intel_batchbuffer_flush(batch);
drm_intel_bo_unreference(src_bo);
}
int main(int argc, char **argv)
{
int fd;
int object_size = OBJECT_WIDTH * OBJECT_HEIGHT * 4;
double start_time, end_time;
drm_intel_bo *dst_bo;
drm_intel_bufmgr *bufmgr;
struct intel_batchbuffer *batch;
int i;
fd = drm_open_any();
bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
drm_intel_bufmgr_gem_enable_reuse(bufmgr);
batch = intel_batchbuffer_alloc(bufmgr);
dst_bo = drm_intel_bo_alloc(bufmgr, "dst", object_size, 4096);
/* Prep loop to get us warmed up. */
for (i = 0; i < 60; i++) {
do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
}
drm_intel_bo_wait_rendering(dst_bo);
/* Do the actual timing. */
start_time = get_time_in_secs();
for (i = 0; i < 200; i++) {
do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
}
drm_intel_bo_wait_rendering(dst_bo);
end_time = get_time_in_secs();
printf("%d iterations in %.03f secs: %.01f MB/sec\n", i,
end_time - start_time,
(double)OBJECT_WIDTH * OBJECT_HEIGHT * 4 /
(end_time - start_time));
intel_batchbuffer_free(batch);
drm_intel_bufmgr_destroy(bufmgr);
close(fd);
return 0;
}

View File

@ -0,0 +1,172 @@
/*
* Copyright © 2009 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
/**
* Roughly simulates Mesa's current vertex buffer behavior: do a series of
* small pwrites on a moderately-sized buffer, then render using it.
*
* The vertex buffer uploads
*
* You might think of this like a movie player, but that wouldn't be entirely
* accurate, since the access patterns of the memory would be different
* (generally, smaller source image, upscaled, an thus different memory access
* pattern in both texel fetch for the stretching and the destination writes).
* However, some things like swfdec would be doing something like this since
* they compute their data in host memory and upload the full sw rendered
* frame.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "drm.h"
#include "i915_drm.h"
#include "drmtest.h"
#include "intel_bufmgr.h"
#include "intel_batchbuffer.h"
/* Happens to be 128k, the size of the VBOs used by i965's Mesa driver. */
#define OBJECT_WIDTH 256
#define OBJECT_HEIGHT 128
static double
get_time_in_secs(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + tv.tv_usec / 1000000.0;
}
static void
do_render(drm_intel_bufmgr *bufmgr, struct intel_batchbuffer *batch,
drm_intel_bo *dst_bo, int width, int height)
{
uint32_t data[64];
drm_intel_bo *src_bo;
int i;
src_bo = drm_intel_bo_alloc(bufmgr, "src", width * height * 4, 4096);
/* Upload some junk. Real workloads would be doing a lot more
* work to generate the junk.
*/
for (i = 0; i < width * height;) {
int size, j;
/* Choose a size from 1 to 64 dwords to upload.
* Normal workloads have a distribution of sizes with a
* large tail (something in your scene's going to have a big
* pile of vertices, most likely), but I'm trying to get at
* the cost of the small uploads here.
*/
size = random() % 64 + 1;
if (i + size > width * height)
size = width * height - i;
for (j = 0; j < size; j++)
data[j] = (uint32_t)random();
/* Upload the junk. */
drm_intel_bo_subdata(src_bo, i * 4, size * 4, data);
i += size;
}
/* Render the junk to the dst. */
BEGIN_BATCH(8);
OUT_BATCH(XY_SRC_COPY_BLT_CMD |
XY_SRC_COPY_BLT_WRITE_ALPHA |
XY_SRC_COPY_BLT_WRITE_RGB);
OUT_BATCH((3 << 24) | /* 32 bits */
(0xcc << 16) | /* copy ROP */
(width * 4) /* dst pitch */);
OUT_BATCH(0); /* dst x1,y1 */
OUT_BATCH((height << 16) | width); /* dst x2,y2 */
OUT_RELOC(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
OUT_BATCH(0); /* src x1,y1 */
OUT_BATCH(width * 4); /* src pitch */
OUT_RELOC(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
ADVANCE_BATCH();
intel_batchbuffer_flush(batch);
drm_intel_bo_unreference(src_bo);
}
int main(int argc, char **argv)
{
int fd;
int object_size = OBJECT_WIDTH * OBJECT_HEIGHT * 4;
double start_time, end_time;
drm_intel_bo *dst_bo;
drm_intel_bufmgr *bufmgr;
struct intel_batchbuffer *batch;
int i;
fd = drm_open_any();
bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
drm_intel_bufmgr_gem_enable_reuse(bufmgr);
batch = intel_batchbuffer_alloc(bufmgr);
dst_bo = drm_intel_bo_alloc(bufmgr, "dst", object_size, 4096);
/* Prep loop to get us warmed up. */
for (i = 0; i < 20; i++) {
do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
}
drm_intel_bo_wait_rendering(dst_bo);
/* Do the actual timing. */
start_time = get_time_in_secs();
for (i = 0; i < 1000; i++) {
do_render(bufmgr, batch, dst_bo, OBJECT_WIDTH, OBJECT_HEIGHT);
}
drm_intel_bo_wait_rendering(dst_bo);
end_time = get_time_in_secs();
printf("%d iterations in %.03f secs: %.01f MB/sec\n", i,
end_time - start_time,
(double)OBJECT_WIDTH * OBJECT_HEIGHT * 4 /
(end_time - start_time));
intel_batchbuffer_free(batch);
drm_intel_bufmgr_destroy(bufmgr);
close(fd);
return 0;
}

70
configure.ac Normal file
View File

@ -0,0 +1,70 @@
# Copyright 2005 Adam Jackson.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# on the rights to use, copy, modify, merge, publish, distribute, sub
# license, and/or sell copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
# ADAM JACKSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Process this file with autoconf to produce a configure script
AC_PREREQ(2.57)
AC_INIT([xf86-video-intel],
2.6.99.1,
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
xf86-video-intel)
AC_CONFIG_SRCDIR([Makefile.am])
AM_CONFIG_HEADER([config.h])
AC_CONFIG_AUX_DIR(.)
AM_INIT_AUTOMAKE([dist-bzip2])
AM_MAINTAINER_MODE
AC_CONFIG_FILES([
shave
shave-libtool
])
# Checks for programs.
AC_DISABLE_STATIC
AC_PROG_LIBTOOL
DOLT
AC_PROG_CC
AM_PROG_CC_C_O
PKG_CHECK_MODULES(DRM, [libdrm_intel >= 2.4.5])
PKG_CHECK_MODULES(PCIACCESS, [pciaccess >= 0.10])
dnl Use lots of warning flags with GCC
WARN_CFLAGS=""
if test "x$GCC" = "xyes"; then
WARN_CFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes \
-Wmissing-prototypes -Wmissing-declarations \
-Wnested-externs -fno-strict-aliasing"
fi
AC_SUBST([WARN_CFLAGS])
SHAVE_INIT([.], [enable])
AC_OUTPUT([
Makefile
benchmarks/Makefile
lib/Makefile
])

2872
i810_reg.h Normal file

File diff suppressed because it is too large Load Diff

10
lib/Makefile.am Normal file
View File

@ -0,0 +1,10 @@
libintel_tools_la_SOURCES = \
intel_batchbuffer.c \
intel_batchbuffer.h \
drmtest.c \
drmtest.h
noinst_LTLIBRARIES = libintel_tools.la
AM_CFLAGS = $(DRM_CFLAGS) $(WARN_CFLAGS) \
-I$(srcdir)/..

84
lib/drmtest.c Normal file
View File

@ -0,0 +1,84 @@
/*
* Copyright © 2007 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include "drmtest.h"
/** Open the first DRM device we can find, searching up to 16 device nodes */
int drm_open_any(void)
{
char name[20];
int i, fd;
for (i = 0; i < 16; i++) {
sprintf(name, "/dev/dri/card%d", i);
fd = open(name, O_RDWR);
if (fd != -1)
return fd;
}
abort();
}
/**
* Open the first DRM device we can find where we end up being the master.
*/
int drm_open_any_master(void)
{
char name[20];
int i, fd;
for (i = 0; i < 16; i++) {
drm_client_t client;
int ret;
sprintf(name, "/dev/dri/card%d", i);
fd = open(name, O_RDWR);
if (fd == -1)
continue;
/* Check that we're the only opener and authed. */
client.idx = 0;
ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
assert (ret == 0);
if (!client.auth) {
close(fd);
continue;
}
client.idx = 1;
ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
if (ret != -1 || errno != EINVAL) {
close(fd);
continue;
}
return fd;
}
fprintf(stderr, "Couldn't find an un-controlled DRM device\n");
abort();
}

37
lib/drmtest.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright © 2007 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include "xf86drm.h"
int drm_open_any(void);
int drm_open_any_master(void);

139
lib/intel_batchbuffer.c Normal file
View File

@ -0,0 +1,139 @@
/**************************************************************************
*
* Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "drm.h"
#include "intel_batchbuffer.h"
#include "intel_bufmgr.h"
void
intel_batchbuffer_reset(struct intel_batchbuffer *batch)
{
if (batch->bo != NULL) {
drm_intel_bo_unreference(batch->bo);
batch->bo = NULL;
}
if (!batch->buffer)
batch->buffer = malloc(BATCH_SZ);
batch->bo = drm_intel_bo_alloc(batch->bufmgr, "batchbuffer",
BATCH_SZ, 4096);
batch->map = batch->buffer;
batch->size = BATCH_SZ;
batch->ptr = batch->map;
}
struct intel_batchbuffer *
intel_batchbuffer_alloc(drm_intel_bufmgr *bufmgr)
{
struct intel_batchbuffer *batch = calloc(sizeof(*batch), 1);
batch->bufmgr = bufmgr;
intel_batchbuffer_reset(batch);
return batch;
}
void
intel_batchbuffer_free(struct intel_batchbuffer *batch)
{
free (batch->buffer);
drm_intel_bo_unreference(batch->bo);
batch->bo = NULL;
free(batch);
}
void
intel_batchbuffer_flush(struct intel_batchbuffer *batch)
{
unsigned int used = batch->ptr - batch->map;
int ret;
if (used == 0)
return;
/* Round batchbuffer usage to 2 DWORDs. */
if ((used & 4) == 0) {
*(uint32_t *) (batch->ptr) = 0; /* noop */
batch->ptr += 4;
used = batch->ptr - batch->map;
}
/* Mark the end of the buffer. */
*(uint32_t *) (batch->ptr) = MI_BATCH_BUFFER_END; /* noop */
batch->ptr += 4;
used = batch->ptr - batch->map;
drm_intel_bo_subdata(batch->bo, 0, used, batch->buffer);
batch->map = NULL;
batch->ptr = NULL;
ret = drm_intel_bo_exec(batch->bo, used, NULL, 0, 0);
assert(ret == 0);
intel_batchbuffer_reset(batch);
}
/* This is the only way buffers get added to the validate list.
*/
void
intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
drm_intel_bo *buffer, uint32_t delta,
uint32_t read_domains, uint32_t write_domain)
{
int ret;
if (batch->ptr - batch->map > batch->bo->size)
printf("bad relocation ptr %p map %p offset %d size %ld\n",
batch->ptr, batch->map, batch->ptr - batch->map,
batch->bo->size);
ret = drm_intel_bo_emit_reloc(batch->bo, batch->ptr - batch->map,
buffer, delta,
read_domains, write_domain);
intel_batchbuffer_emit_dword(batch, buffer->offset + delta);
assert(ret == 0);
}
void
intel_batchbuffer_data(struct intel_batchbuffer *batch,
const void *data, unsigned int bytes)
{
assert((bytes & 3) == 0);
intel_batchbuffer_require_space(batch, bytes);
memcpy(batch->ptr, data, bytes);
batch->ptr += bytes;
}

117
lib/intel_batchbuffer.h Normal file
View File

@ -0,0 +1,117 @@
#ifndef INTEL_BATCHBUFFER_H
#define INTEL_BATCHBUFFER_H
#include "intel_bufmgr.h"
#include "i810_reg.h"
#define BATCH_SZ 4096
#define BATCH_RESERVED 16
struct intel_batchbuffer
{
drm_intel_bufmgr *bufmgr;
drm_intel_bo *bo;
uint8_t *buffer;
uint8_t *map;
uint8_t *ptr;
/* debug stuff */
struct {
uint8_t *start_ptr;
unsigned int total;
} emit;
unsigned int size;
};
struct intel_batchbuffer *intel_batchbuffer_alloc(drm_intel_bufmgr *bufmgr);
void intel_batchbuffer_free(struct intel_batchbuffer *batch);
void intel_batchbuffer_flush(struct intel_batchbuffer *batch);
void intel_batchbuffer_reset(struct intel_batchbuffer *batch);
void intel_batchbuffer_data(struct intel_batchbuffer *batch,
const void *data, unsigned int bytes);
void intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
drm_intel_bo *buffer,
uint32_t delta,
uint32_t read_domains,
uint32_t write_domain);
/* Inline functions - might actually be better off with these
* non-inlined. Certainly better off switching all command packets to
* be passed as structs rather than dwords, but that's a little bit of
* work...
*/
static inline int
intel_batchbuffer_space(struct intel_batchbuffer *batch)
{
return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
}
static inline void
intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, uint32_t dword)
{
assert(batch->map);
assert(intel_batchbuffer_space(batch) >= 4);
*(uint32_t *) (batch->ptr) = dword;
batch->ptr += 4;
}
static inline void
intel_batchbuffer_require_space(struct intel_batchbuffer *batch,
unsigned int sz)
{
assert(sz < batch->size - 8);
if (intel_batchbuffer_space(batch) < sz)
intel_batchbuffer_flush(batch);
}
/* Here are the crusty old macros, to be removed:
*/
#define BATCH_LOCALS
#define BEGIN_BATCH(n) do { \
intel_batchbuffer_require_space(batch, (n)*4); \
assert(batch->emit.start_ptr == NULL); \
batch->emit.total = (n) * 4; \
batch->emit.start_ptr = batch->ptr; \
} while (0)
#define OUT_BATCH(d) intel_batchbuffer_emit_dword(batch, d)
#define OUT_RELOC(buf, read_domains, write_domain, delta) do { \
assert((delta) >= 0); \
intel_batchbuffer_emit_reloc(batch, buf, delta, \
read_domains, write_domain); \
} while (0)
#define ADVANCE_BATCH() do { \
unsigned int _n = batch->ptr - batch->emit.start_ptr; \
assert(batch->emit.start_ptr != NULL); \
if (_n != batch->emit.total) { \
fprintf(stderr, \
"ADVANCE_BATCH: %d of %d dwords emitted\n", \
_n, batch->emit.total); \
abort(); \
} \
batch->emit.start_ptr = NULL; \
} while(0)
static inline void
intel_batchbuffer_emit_mi_flush(struct intel_batchbuffer *batch)
{
intel_batchbuffer_require_space(batch, 4);
intel_batchbuffer_emit_dword(batch, MI_FLUSH);
}
#endif

178
m4/dolt.m4 Normal file
View File

@ -0,0 +1,178 @@
dnl dolt, a replacement for libtool
dnl Copyright © 2007-2008 Josh Triplett <josh@freedesktop.org>
dnl Copying and distribution of this file, with or without modification,
dnl are permitted in any medium without royalty provided the copyright
dnl notice and this notice are preserved.
dnl
dnl To use dolt, invoke the DOLT macro immediately after the libtool macros.
dnl Optionally, copy this file into acinclude.m4, to avoid the need to have it
dnl installed when running autoconf on your project.
AC_DEFUN([DOLT], [
AC_REQUIRE([AC_CANONICAL_HOST])
# dolt, a replacement for libtool
# Josh Triplett <josh@freedesktop.org>
AC_PATH_PROG(DOLT_BASH, bash)
AC_MSG_CHECKING([if dolt supports this host])
dolt_supported=yes
if test x$DOLT_BASH = x; then
dolt_supported=no
fi
if test x$GCC != xyes; then
dolt_supported=no
fi
case $host in
i?86-*-linux*|x86_64-*-linux*|powerpc-*-linux* \
|amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*)
pic_options='-fPIC'
;;
i?86-apple-darwin*)
pic_options='-fno-common'
;;
*)
dolt_supported=no
;;
esac
if test x$dolt_supported = xno ; then
AC_MSG_RESULT([no, falling back to libtool])
LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
else
AC_MSG_RESULT([yes, replacing libtool])
dnl Start writing out doltcompile.
cat <<__DOLTCOMPILE__EOF__ >doltcompile
#!$DOLT_BASH
__DOLTCOMPILE__EOF__
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
args=("$[]@")
for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
if test x"${args@<:@$arg@:>@}" = x-o ; then
objarg=$((arg+1))
break
fi
done
if test x$objarg = x ; then
echo 'Error: no -o on compiler command line' 1>&2
exit 1
fi
lo="${args@<:@$objarg@:>@}"
obj="${lo%.lo}"
if test x"$lo" = x"$obj" ; then
echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
exit 1
fi
objbase="${obj##*/}"
__DOLTCOMPILE__EOF__
dnl Write out shared compilation code.
if test x$enable_shared = xyes; then
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
libobjdir="${obj%$objbase}.libs"
if test ! -d "$libobjdir" ; then
mkdir_out="$(mkdir "$libobjdir" 2>&1)"
mkdir_ret=$?
if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
echo "$mkdir_out" 1>&2
exit $mkdir_ret
fi
fi
pic_object="$libobjdir/$objbase.o"
args@<:@$objarg@:>@="$pic_object"
__DOLTCOMPILE__EOF__
cat <<__DOLTCOMPILE__EOF__ >>doltcompile
"\${args@<:@@@:>@}" $pic_options -DPIC || exit \$?
__DOLTCOMPILE__EOF__
fi
dnl Write out static compilation code.
dnl Avoid duplicate compiler output if also building shared objects.
if test x$enable_static = xyes; then
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
non_pic_object="$obj.o"
args@<:@$objarg@:>@="$non_pic_object"
__DOLTCOMPILE__EOF__
if test x$enable_shared = xyes; then
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
"${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
__DOLTCOMPILE__EOF__
else
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
"${args@<:@@@:>@}" || exit $?
__DOLTCOMPILE__EOF__
fi
fi
dnl Write out the code to write the .lo file.
dnl The second line of the .lo file must match "^# Generated by .*libtool"
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
{
echo "# $lo - a libtool object file"
echo "# Generated by doltcompile, not libtool"
__DOLTCOMPILE__EOF__
if test x$enable_shared = xyes; then
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
echo "pic_object='.libs/${objbase}.o'"
__DOLTCOMPILE__EOF__
else
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
echo pic_object=none
__DOLTCOMPILE__EOF__
fi
if test x$enable_static = xyes; then
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
echo "non_pic_object='${objbase}.o'"
__DOLTCOMPILE__EOF__
else
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
echo non_pic_object=none
__DOLTCOMPILE__EOF__
fi
cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
} > "$lo"
__DOLTCOMPILE__EOF__
dnl Done writing out doltcompile; substitute it for libtool compilation.
chmod +x doltcompile
LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
dnl a target, so write out a libtool wrapper to handle that case.
dnl Note that doltlibtool does not handle inferred tags or option arguments
dnl without '=', because automake does not use them.
cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
#!$DOLT_BASH
__DOLTLIBTOOL__EOF__
cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
top_builddir_slash="${0%%doltlibtool}"
: ${top_builddir_slash:=./}
args=()
modeok=false
tagok=false
for arg in "$[]@"; do
case "$arg" in
--silent) ;;
--mode=compile) modeok=true ;;
--tag=CC|--tag=CXX) tagok=true ;;
*) args@<:@${#args[@]}@:>@="$arg" ;;
esac
done
if $modeok && $tagok ; then
. ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
else
exec ${top_builddir_slash}libtool "$[]@"
fi
__DOLTLIBTOOL__EOF__
dnl Done writing out doltlibtool; substitute it for libtool.
chmod +x doltlibtool
LIBTOOL='$(top_builddir)/doltlibtool'
fi
AC_SUBST(LTCOMPILE)
AC_SUBST(LTCXXCOMPILE)
# end dolt
])

73
m4/shave.m4 Normal file
View File

@ -0,0 +1,73 @@
dnl Make automake/libtool output more friendly to humans
dnl
dnl SHAVE_INIT([shavedir],[default_mode])
dnl
dnl shavedir: the directory where the shave scripts are, it defaults to
dnl $(top_builddir)
dnl default_mode: (enable|disable) default shave mode. This parameter
dnl controls shave's behaviour when no option has been
dnl given to configure. It defaults to disable.
dnl
dnl * SHAVE_INIT should be called late in your configure.(ac|in) file (just
dnl before AC_CONFIG_FILE/AC_OUTPUT is perfect. This macro rewrites CC and
dnl LIBTOOL, you don't want the configure tests to have these variables
dnl re-defined.
dnl * This macro requires GNU make's -s option.
AC_DEFUN([_SHAVE_ARG_ENABLE],
[
AC_ARG_ENABLE([shave],
AS_HELP_STRING(
[--enable-shave],
[use shave to make the build pretty [[default=$1]]]),,
[enable_shave=$1]
)
])
AC_DEFUN([SHAVE_INIT],
[
dnl you can tweak the default value of enable_shave
m4_if([$2], [enable], [_SHAVE_ARG_ENABLE(yes)], [_SHAVE_ARG_ENABLE(no)])
if test x"$enable_shave" = xyes; then
dnl where can we find the shave scripts?
m4_if([$1],,
[shavedir="$ac_pwd"],
[shavedir="$ac_pwd/$1"])
AC_SUBST(shavedir)
dnl make is now quiet
AC_SUBST([MAKEFLAGS], [-s])
AC_SUBST([AM_MAKEFLAGS], ['`test -z $V && echo -s`'])
dnl we need sed
AC_CHECK_PROG(SED,sed,sed,false)
dnl substitute libtool
SHAVE_SAVED_LIBTOOL=$LIBTOOL
LIBTOOL="${SHELL} ${shavedir}/shave-libtool '${SHAVE_SAVED_LIBTOOL}'"
AC_SUBST(LIBTOOL)
dnl substitute cc/cxx
SHAVE_SAVED_CC=$CC
SHAVE_SAVED_CXX=$CXX
SHAVE_SAVED_FC=$FC
SHAVE_SAVED_F77=$F77
CC="${SHELL} ${shavedir}/shave cc ${SHAVE_SAVED_CC}"
CXX="${SHELL} ${shavedir}/shave cxx ${SHAVE_SAVED_CXX}"
FC="${SHELL} ${shavedir}/shave fc ${SHAVE_SAVED_FC}"
F77="${SHELL} ${shavedir}/shave f77 ${SHAVE_SAVED_F77}"
AC_SUBST(CC)
AC_SUBST(CXX)
AC_SUBST(FC)
AC_SUBST(F77)
V=@
else
V=1
fi
Q='$(V:1=)'
AC_SUBST(V)
AC_SUBST(Q)
])

69
shave-libtool.in Normal file
View File

@ -0,0 +1,69 @@
#!/bin/sh
# we need sed
SED=@SED@
if test -z "$SED" ; then
SED=sed
fi
lt_unmangle ()
{
last_result=`echo $1 | $SED -e 's#.libs/##' -e 's#[0-9a-zA-Z_\-\.]*_la-##'`
}
# the real libtool to use
LIBTOOL="$1"
shift
# if 1, don't print anything, the underlaying wrapper will do it
pass_though=0
# scan the arguments, keep the right ones for libtool, and discover the mode
preserved_args=
while test "$#" -gt 0; do
opt="$1"
shift
case $opt in
--mode=*)
mode=`echo $opt | $SED -e 's/[-_a-zA-Z0-9]*=//'`
preserved_args="$preserved_args $opt"
;;
-o)
lt_output="$1"
preserved_args="$preserved_args $opt"
;;
*)
preserved_args="$preserved_args $opt"
;;
esac
done
case "$mode" in
compile)
# shave will be called and print the actual CC/CXX/LINK line
preserved_args="$preserved_args --shave-mode=$mode"
pass_though=1
;;
link)
preserved_args="$preserved_args --shave-mode=$mode"
Q=" LINK "
;;
*)
# let's u
# echo "*** libtool: Unimplemented mode: $mode, fill a bug report"
;;
esac
lt_unmangle "$lt_output"
output=$last_result
if test -z $V; then
if test $pass_though -eq 0; then
echo "$Q$output"
fi
$LIBTOOL --silent $preserved_args
else
echo $LIBTOOL $preserved_args
$LIBTOOL $preserved_args
fi

76
shave.in Normal file
View File

@ -0,0 +1,76 @@
#!/bin/sh
# we need sed
SED=@SED@
if test -z "$SED" ; then
SED=sed
fi
lt_unmangle ()
{
last_result=`echo $1 | $SED -e 's#.libs/##' -e 's#[0-9a-zA-Z_\-\.]*_la-##'`
}
# the tool to wrap (cc, cxx, ar, ranlib, ..)
tool="$1"
shift
# the reel tool (to call)
REEL_TOOL="$1"
shift
pass_through=0
preserved_args=
while test "$#" -gt 0; do
opt="$1"
shift
case $opt in
--shave-mode=*)
mode=`echo $opt | $SED -e 's/[-_a-zA-Z0-9]*=//'`
;;
-o)
lt_output="$1"
preserved_args="$preserved_args $opt"
;;
*)
preserved_args="$preserved_args $opt"
;;
esac
done
# mode=link is handled in the libtool wrapper
case "$mode,$tool" in
link,*)
pass_through=1
;;
*,cxx)
Q=" CXX "
;;
*,cc)
Q=" CC "
;;
*,fc)
Q=" FC "
;;
*,f77)
Q=" F77 "
;;
*,*)
# should not happen
Q=" CC "
;;
esac
lt_unmangle "$lt_output"
output=$last_result
if test -z $V; then
if test $pass_through -eq 0; then
echo "$Q$output"
fi
$REEL_TOOL $preserved_args
else
echo $REEL_TOOL $preserved_args
$REEL_TOOL $preserved_args
fi

23
tests/Makefile.am Normal file
View File

@ -0,0 +1,23 @@
TESTS = auth \
openclose \
getversion \
getclient \
getstats \
lock \
setversion \
updatedraw \
gem_basic \
gem_flink \
gem_readwrite \
gem_mmap
EXTRA_LTLIBRARIES = libdrmtest.la
EXTRA_LTLIBRARIES = libdrmtest.la
libdrmtest_la_SOURCES = \
drmtest.c \
drmtest.h
libdrmtest_la_LIBADD = \
$(top_builddir)/libdrm/libdrm.la
EXTRA_PROGRAMS = $(TESTS)
CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES)