Skip to content

Commit

Permalink
drm: Add backends for i915 and i965.
Browse files Browse the repository at this point in the history
As proof-of-principle add the nearly working demonstrations of using DRM
to render directly with the GPU bypassing both RENDER and GL for
performance whilst preserving high quality rendering.

The basis behind developing these chip specific backends is that this is
the idealised interface that we desire for this chips, and so a target
for cairo-gl as we continue to develop both it and our GL stack.

Note that this backends do not yet fully pass the test suite, so only
use if you are brave and willing to help develop them further.
  • Loading branch information
Chris Wilson committed Jan 22, 2010
1 parent b9407af commit 77afe84
Show file tree
Hide file tree
Showing 35 changed files with 22,675 additions and 1,116 deletions.
2 changes: 1 addition & 1 deletion boilerplate/cairo-boilerplate-drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _cairo_boilerplate_drm_create_surface (const char *name,
int id,
void **closure)
{
cairo_drm_device_t *device;
cairo_device_t *device;

device = cairo_drm_device_default ();
if (device == NULL)
Expand Down
17 changes: 17 additions & 0 deletions src/Makefile.sources
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,29 @@ cairo_directfb_sources = cairo-directfb-surface.c
cairo_drm_headers = cairo-drm.h
cairo_drm_private = drm/cairo-drm-private.h \
drm/cairo-drm-intel-private.h \
drm/cairo-drm-i915-private.h \
drm/cairo-drm-i965-private.h \
drm/cairo-drm-intel-brw-defines.h \
drm/cairo-drm-intel-brw-structs.h \
drm/cairo-drm-intel-brw-eu.h \
drm/cairo-drm-radeon-private.h
cairo_drm_sources = drm/cairo-drm.c \
drm/cairo-drm-bo.c \
drm/cairo-drm-surface.c \
drm/cairo-drm-intel.c \
drm/cairo-drm-intel-debug.c \
drm/cairo-drm-intel-surface.c \
drm/cairo-drm-i915-surface.c \
drm/cairo-drm-i915-glyphs.c \
drm/cairo-drm-i915-shader.c \
drm/cairo-drm-i915-spans.c \
drm/cairo-drm-i965-surface.c \
drm/cairo-drm-i965-glyphs.c \
drm/cairo-drm-i965-shader.c \
drm/cairo-drm-i965-spans.c \
drm/cairo-drm-intel-brw-eu.c \
drm/cairo-drm-intel-brw-eu-emit.c \
drm/cairo-drm-intel-brw-eu-util.c \
drm/cairo-drm-radeon.c \
drm/cairo-drm-radeon-surface.c
cairo_gallium_sources = drm/cairo-drm-gallium-surface.c
Expand Down
31 changes: 8 additions & 23 deletions src/cairo-drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,41 @@

CAIRO_BEGIN_DECLS

typedef struct _cairo_drm_device cairo_drm_device_t;

struct udev_device;

cairo_public cairo_drm_device_t *
cairo_public cairo_device_t *
cairo_drm_device_get (struct udev_device *device);

cairo_public cairo_drm_device_t *
cairo_public cairo_device_t *
cairo_drm_device_get_for_fd (int fd);

cairo_public cairo_drm_device_t *
cairo_public cairo_device_t *
cairo_drm_device_default (void);

cairo_public cairo_drm_device_t *
cairo_drm_device_reference (cairo_drm_device_t *device);

cairo_public cairo_status_t
cairo_drm_device_status (cairo_drm_device_t *device);

cairo_public int
cairo_drm_device_get_fd (cairo_drm_device_t *device);
cairo_drm_device_get_fd (cairo_device_t *device);

cairo_public void
cairo_drm_device_throttle (cairo_drm_device_t *device);

cairo_public void
cairo_drm_device_destroy (cairo_drm_device_t *device);

cairo_drm_device_throttle (cairo_device_t *device);

cairo_public cairo_surface_t *
cairo_drm_surface_create (cairo_drm_device_t *device,
cairo_drm_surface_create (cairo_device_t *device,
cairo_content_t content,
int width, int height);

cairo_public cairo_surface_t *
cairo_drm_surface_create_for_name (cairo_drm_device_t *device,
cairo_drm_surface_create_for_name (cairo_device_t *device,
unsigned int name,
cairo_format_t format,
int width, int height, int stride);

cairo_public cairo_surface_t *
cairo_drm_surface_create_from_cacheable_image (cairo_drm_device_t *device,
cairo_drm_surface_create_from_cacheable_image (cairo_device_t *device,
cairo_surface_t *surface);

cairo_public cairo_status_t
cairo_drm_surface_enable_scan_out (cairo_surface_t *surface);

cairo_public cairo_drm_device_t *
cairo_drm_surface_get_device (cairo_surface_t *abstract_surface);

cairo_public unsigned int
cairo_drm_surface_get_handle (cairo_surface_t *surface);

Expand Down
57 changes: 57 additions & 0 deletions src/cairo-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,63 @@ _cairo_lround (double d)
#undef LSW
}

/* Convert a 32-bit IEEE single precision floating point number to a
* 'half' representation (s10.5)
*/
uint16_t
_cairo_half_from_float (float f)
{
union {
uint32_t ui;
float f;
} u;
int s, e, m;

u.f = f;
s = (u.ui >> 16) & 0x00008000;
e = ((u.ui >> 23) & 0x000000ff) - (127 - 15);
m = u.ui & 0x007fffff;
if (e <= 0) {
if (e < -10) {
/* underflow */
return 0;
}

m = (m | 0x00800000) >> (1 - e);

/* round to nearest, round 0.5 up. */
if (m & 0x00001000)
m += 0x00002000;
return s | (m >> 13);
} else if (e == 0xff - (127 - 15)) {
if (m == 0) {
/* infinity */
return s | 0x7c00;
} else {
/* nan */
m >>= 13;
return s | 0x7c00 | m | (m == 0);
}
} else {
/* round to nearest, round 0.5 up. */
if (m & 0x00001000) {
m += 0x00002000;

if (m & 0x00800000) {
m = 0;
e += 1;
}
}

if (e > 30) {
/* overflow -> infinity */
return s | 0x7c00;
}

return s | (e << 10) | (m >> 13);
}
}


#ifdef _WIN32

Expand Down
2 changes: 2 additions & 0 deletions src/cairoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,8 @@ _cairo_round (double r)

cairo_private int
_cairo_lround (double d) cairo_const;
cairo_private uint16_t
_cairo_half_from_float (float f) cairo_const;

/* cairo-gstate.c */
cairo_private cairo_status_t
Expand Down
13 changes: 11 additions & 2 deletions src/drm/cairo-drm-bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@

#include "cairo-drm-private.h"
#include "cairo-drm-ioctl-private.h"

#include "cairo-error-private.h"

#include <sys/ioctl.h>
#include <errno.h>

#define ERR_DEBUG(x) x

struct drm_gem_close {
/** Handle of the object to be closed. */
uint32_t handle;
Expand Down Expand Up @@ -79,8 +82,11 @@ _cairo_drm_bo_open_for_name (const cairo_drm_device_t *dev,
do {
ret = ioctl (dev->fd, DRM_IOCTL_GEM_OPEN, &open);
} while (ret == -1 && errno == EINTR);
if (ret == -1)
if (ret == -1) {
ERR_DEBUG((fprintf (stderr, "Failed to open bo for name %d: %s\n",
name, strerror (errno))));
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}

bo->name = name;
bo->size = open.size;
Expand All @@ -99,8 +105,11 @@ _cairo_drm_bo_flink (const cairo_drm_device_t *dev,
memset (&flink, 0, sizeof (flink));
flink.handle = bo->handle;
ret = ioctl (dev->fd, DRM_IOCTL_GEM_FLINK, &flink);
if (ret == -1)
if (ret == -1) {
ERR_DEBUG((fprintf (stderr, "Failed to flink bo: %s\n",
strerror (errno))));
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}

bo->name = flink.name;

Expand Down
3 changes: 1 addition & 2 deletions src/drm/cairo-drm-gallium-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ gallium_surface_create_internal (gallium_device_t *device,

_cairo_surface_init (&surface->base.base,
&gallium_surface_backend,
NULL, /* device */
content);
_cairo_drm_surface_init (&surface->base, &device->base);

Expand Down Expand Up @@ -551,7 +550,6 @@ gallium_surface_create_for_name (cairo_drm_device_t *base_dev,
content = _cairo_content_from_format (format);
_cairo_surface_init (&surface->base.base,
&gallium_surface_backend,
NULL, /* device */
content);
_cairo_drm_surface_init (&surface->base, base_dev);

Expand Down Expand Up @@ -659,6 +657,7 @@ _cairo_drm_gallium_device_create (int fd, dev_t dev, int vendor_id, int chip_id)
device->base.surface.enable_scan_out = NULL;
device->base.surface.flink = gallium_surface_flink;

device->base.device.flush = NULL;
device->base.device.throttle = NULL;
device->base.device.destroy = gallium_device_destroy;

Expand Down
Loading

0 comments on commit 77afe84

Please sign in to comment.