695 changes: 695 additions & 0 deletions src/gallium/drivers/tegra/tegra_screen.c

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/gallium/drivers/tegra/tegra_screen.h
@@ -0,0 +1,19 @@
#ifndef TEGRA_SCREEN_H
#define TEGRA_SCREEN_H

#include "pipe/p_screen.h"

#include <libdrm/tegra.h>

struct tegra_screen {
struct pipe_screen base;
};

static INLINE struct tegra_screen *tegra_screen(struct pipe_screen *screen)
{
return (struct tegra_screen *)screen;
}

struct pipe_screen *tegra_screen_create(struct drm_tegra *drm);

#endif
343 changes: 343 additions & 0 deletions src/gallium/drivers/tegra/tegra_state.c
@@ -0,0 +1,343 @@
#include <stdio.h>

#include "tegra_state.h"

static void tegra_set_sample_mask(struct pipe_context *pcontext,
unsigned int sample_mask)
{
fprintf(stdout, "> %s(pcontext=%p, sample_mask=%x)\n", __func__,
pcontext, sample_mask);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_set_constant_buffer(struct pipe_context *pcontext,
unsigned int shader, unsigned int index,
struct pipe_constant_buffer *buffer)
{
fprintf(stdout, "> %s(pcontext=%p, shader=%u, index=%u, buffer=%p)\n",
__func__, pcontext, shader, index, buffer);
fprintf(stdout, "< %s()\n", __func__);
}

static void
tegra_set_framebuffer_state(struct pipe_context *pcontext,
const struct pipe_framebuffer_state *framebuffer)
{
fprintf(stdout, "> %s(pcontext=%p, framebuffer=%p)\n", __func__,
pcontext, framebuffer);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_set_polygon_stipple(struct pipe_context *pcontext,
const struct pipe_poly_stipple *stipple)
{
fprintf(stdout, "> %s(pcontext=%p, stipple=%p)\n", __func__, pcontext,
stipple);
fprintf(stdout, "< %s()\n", __func__);
}

static void
tegra_set_viewport_state(struct pipe_context *pcontext,
const struct pipe_viewport_state *viewport)
{
fprintf(stdout, "> %s(pcontext=%p, viewport=%p)\n", __func__,
pcontext, viewport);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_set_vertex_buffers(struct pipe_context *pcontext,
unsigned int start, unsigned int count,
const struct pipe_vertex_buffer *buffer)
{
fprintf(stdout, "> %s(pcontext=%p, start=%u, count=%u, buffer=%p)\n",
__func__, pcontext, start, count, buffer);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_set_index_buffer(struct pipe_context *pcontext,
const struct pipe_index_buffer *buffer)
{
fprintf(stdout, "> %s(pcontext=%p, buffer=%p)\n", __func__, pcontext,
buffer);
fprintf(stdout, "< %s()\n", __func__);
}

void tegra_context_state_init(struct pipe_context *pcontext)
{
pcontext->set_sample_mask = tegra_set_sample_mask;
pcontext->set_constant_buffer = tegra_set_constant_buffer;
pcontext->set_framebuffer_state = tegra_set_framebuffer_state;
pcontext->set_polygon_stipple = tegra_set_polygon_stipple;
pcontext->set_viewport_state = tegra_set_viewport_state;
pcontext->set_vertex_buffers = tegra_set_vertex_buffers;
pcontext->set_index_buffer = tegra_set_index_buffer;
}

static void *tegra_create_blend_state(struct pipe_context *pcontext,
const struct pipe_blend_state *template)
{
struct tegra_blend_state *so;

fprintf(stdout, "> %s(pcontext=%p, template=%p)\n", __func__,
pcontext, template);

so = calloc(1, sizeof(*so));
if (!so) {
fprintf(stdout, "< %s() = NULL\n", __func__);
return NULL;
}

so->base = *template;

fprintf(stdout, "< %s() = %p\n", __func__, so);
return so;
}

static void tegra_bind_blend_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_delete_blend_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);

free(so);

fprintf(stdout, "< %s()\n", __func__);
}

void tegra_context_blend_init(struct pipe_context *pcontext)
{
pcontext->create_blend_state = tegra_create_blend_state;
pcontext->bind_blend_state = tegra_bind_blend_state;
pcontext->delete_blend_state = tegra_delete_blend_state;
}

static void *
tegra_create_rasterizer_state(struct pipe_context *pcontext,
const struct pipe_rasterizer_state *template)
{
struct tegra_rasterizer_state *so;

fprintf(stdout, "> %s(pcontext=%p, template=%p)\n", __func__,
pcontext, template);

so = calloc(1, sizeof(*so));
if (!so) {
fprintf(stdout, "< %s() = NULL\n", __func__);
return NULL;
}

so->base = *template;

fprintf(stdout, "< %s() = %p\n", __func__, so);
return so;
}

static void tegra_bind_rasterizer_state(struct pipe_context *pcontext,
void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_delete_rasterizer_state(struct pipe_context *pcontext,
void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);

free(so);

fprintf(stdout, "< %s()\n", __func__);
}

void tegra_context_rasterizer_init(struct pipe_context *pcontext)
{
pcontext->create_rasterizer_state = tegra_create_rasterizer_state;
pcontext->bind_rasterizer_state = tegra_bind_rasterizer_state;
pcontext->delete_rasterizer_state = tegra_delete_rasterizer_state;
}

static void *
tegra_create_zsa_state(struct pipe_context *pcontext,
const struct pipe_depth_stencil_alpha_state *template)
{
struct tegra_zsa_state *so;

fprintf(stdout, "> %s(pcontext=%p, template=%p)\n", __func__,
pcontext, template);

so = calloc(1, sizeof(*so));
if (!so) {
fprintf(stdout, "< %s() = NULL\n", __func__);
return NULL;
}

so->base = *template;

fprintf(stdout, "< %s() = %p\n", __func__, so);
return so;
}

static void tegra_bind_zsa_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_delete_zsa_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);

free(so);

fprintf(stdout, "< %s()\n", __func__);
}

void tegra_context_zsa_init(struct pipe_context *pcontext)
{
pcontext->create_depth_stencil_alpha_state = tegra_create_zsa_state;
pcontext->bind_depth_stencil_alpha_state = tegra_bind_zsa_state;
pcontext->delete_depth_stencil_alpha_state = tegra_delete_zsa_state;
}

static void *
tegra_create_vs_state(struct pipe_context *pcontext,
const struct pipe_shader_state *template)
{
struct tegra_vs_state *so;

fprintf(stdout, "> %s(pcontext=%p, template=%p)\n", __func__,
pcontext, template);

so = calloc(1, sizeof(*so));
if (!so) {
fprintf(stdout, "< %s() = NULL\n", __func__);
return NULL;
}

so->base = *template;

fprintf(stdout, "< %s() = %p\n", __func__, so);
return so;
}

static void tegra_bind_vs_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_delete_vs_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);

free(so);

fprintf(stdout, "< %s()\n", __func__);
}

void tegra_context_vs_init(struct pipe_context *pcontext)
{
pcontext->create_vs_state = tegra_create_vs_state;
pcontext->bind_vs_state = tegra_bind_vs_state;
pcontext->delete_vs_state = tegra_delete_vs_state;
}

static void *
tegra_create_fs_state(struct pipe_context *pcontext,
const struct pipe_shader_state *template)
{
struct tegra_fs_state *so;

fprintf(stdout, "> %s(pcontext=%p, template=%p)\n", __func__,
pcontext, template);

so = calloc(1, sizeof(*so));
if (!so) {
fprintf(stdout, "< %s() = NULL\n", __func__);
return NULL;
}

so->base = *template;

fprintf(stdout, "< %s() = %p\n", __func__, so);
return so;
}

static void tegra_bind_fs_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_delete_fs_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);

free(so);

fprintf(stdout, "< %s()\n", __func__);
}

void tegra_context_fs_init(struct pipe_context *pcontext)
{
pcontext->create_fs_state = tegra_create_fs_state;
pcontext->bind_fs_state = tegra_bind_fs_state;
pcontext->delete_fs_state = tegra_delete_fs_state;
}

static void *
tegra_create_vbo_state(struct pipe_context *pcontext, unsigned int count,
const struct pipe_vertex_element *elements)
{
struct tegra_vbo_state *so;

fprintf(stdout, "> %s(pcontext=%p, count=%u, elements=%p)\n",
__func__, pcontext, count, elements);

so = calloc(1, sizeof(*so));
if (!so) {
fprintf(stdout, "< %s() = NULL\n", __func__);
return NULL;
}

memcpy(so->elements, elements, sizeof(*elements) * count);
so->num_elements = count;

fprintf(stdout, "< %s() = %p\n", __func__, so);
return so;
}

static void tegra_bind_vbo_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);
fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_delete_vbo_state(struct pipe_context *pcontext, void *so)
{
fprintf(stdout, "> %s(pcontext=%p, so=%p)\n", __func__, pcontext, so);

free(so);

fprintf(stdout, "< %s()\n", __func__);
}

static void tegra_draw_vbo(struct pipe_context *pcontext,
const struct pipe_draw_info *info)
{
fprintf(stdout, "> %s(pcontext=%p, info=%p)\n", __func__, pcontext,
info);
fprintf(stdout, "< %s()\n", __func__);
}

void tegra_context_vbo_init(struct pipe_context *pcontext)
{
pcontext->create_vertex_elements_state = tegra_create_vbo_state;
pcontext->bind_vertex_elements_state = tegra_bind_vbo_state;
pcontext->delete_vertex_elements_state = tegra_delete_vbo_state;
pcontext->draw_vbo = tegra_draw_vbo;
}
40 changes: 40 additions & 0 deletions src/gallium/drivers/tegra/tegra_state.h
@@ -0,0 +1,40 @@
#ifndef TEGRA_STATE_H
#define TEGRA_STATE_H

#include "pipe/p_context.h"
#include "pipe/p_state.h"

struct tegra_blend_state {
struct pipe_blend_state base;
};

struct tegra_rasterizer_state {
struct pipe_rasterizer_state base;
};

struct tegra_zsa_state {
struct pipe_depth_stencil_alpha_state base;
};

struct tegra_vs_state {
struct pipe_shader_state base;
};

struct tegra_fs_state {
struct pipe_shader_state base;
};

struct tegra_vbo_state {
struct pipe_vertex_element elements[PIPE_MAX_ATTRIBS];
unsigned int num_elements;
};

void tegra_context_state_init(struct pipe_context *pcontext);
void tegra_context_blend_init(struct pipe_context *pcontext);
void tegra_context_rasterizer_init(struct pipe_context *pcontext);
void tegra_context_zsa_init(struct pipe_context *pcontext);
void tegra_context_vs_init(struct pipe_context *pcontext);
void tegra_context_fs_init(struct pipe_context *pcontext);
void tegra_context_vbo_init(struct pipe_context *pcontext);

#endif
43 changes: 43 additions & 0 deletions src/gallium/drivers/tegra/tegra_surface.c
@@ -0,0 +1,43 @@
#include <stdio.h>

#include "util/u_inlines.h"

#include "tegra_surface.h"

static struct pipe_surface *
tegra_create_surface(struct pipe_context *context,
struct pipe_resource *resource,
const struct pipe_surface *template)
{
struct tegra_surface *surface;

fprintf(stdout, "> %s(context=%p, resource=%p, template=%p)\n",
__func__, context, resource, template);

surface = calloc(1, sizeof(*surface));
if (!surface) {
fprintf(stdout, "< %s() = NULL\n", __func__);
return NULL;
}

pipe_resource_reference(&surface->base.texture, resource);
pipe_reference_init(&surface->base.reference, 1);
surface->base.context = context;

fprintf(stdout, "< %s() = %p\n", __func__, &surface->base);
return &surface->base;
}

static void tegra_surface_destroy(struct pipe_context *context,
struct pipe_surface *surface)
{
fprintf(stdout, "> %s(context=%p, surface=%p)\n", __func__, context,
surface);
fprintf(stdout, "< %s()\n", __func__);
}

void tegra_context_surface_init(struct pipe_context *context)
{
context->create_surface = tegra_create_surface;
context->surface_destroy = tegra_surface_destroy;
}
13 changes: 13 additions & 0 deletions src/gallium/drivers/tegra/tegra_surface.h
@@ -0,0 +1,13 @@
#ifndef TEGRA_SURFACE_H
#define TEGRA_SURFACE_H

#include "pipe/p_context.h"
#include "pipe/p_state.h"

struct tegra_surface {
struct pipe_surface base;
};

void tegra_context_surface_init(struct pipe_context *context);

#endif
73 changes: 73 additions & 0 deletions src/gallium/targets/dri-tegra/Makefile.am
@@ -0,0 +1,73 @@
# Copyright © 2012 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.

include $(top_srcdir)/src/gallium/Automake.inc

AM_CFLAGS = \
$(GALLIUM_CFLAGS) \
$(PTHREAD_CFLAGS) \
$(LIBDRM_CFLAGS) \
$(TEGRA_CFLAGS)

AM_CPPFLAGS = \
-I$(top_srcdir)/src/gallium/drivers \
-I$(top_srcdir)/src/gallium/winsys \
-I$(top_srcdir)/src/mesa \
-I$(top_srcdir)/src/mapi \
-I$(top_builddir)/src/mesa/drivers/dri/common \
-DGALLIUM_RBUG \
-DGALLIUM_TRACE

dridir = $(DRI_DRIVER_INSTALL_DIR)
dri_LTLIBRARIES = tegra_dri.la

nodist_EXTRA_tegra_dri_la_SOURCES = dummy.cpp
tegra_dri_la_SOURCES = \
target.c \
$(top_srcdir)/src/mesa/drivers/dri/common/utils.c \
$(top_srcdir)/src/mesa/drivers/dri/common/dri_util.c \
$(top_srcdir)/src/mesa/drivers/dri/common/xmlconfig.c

tegra_dri_la_LDFLAGS = -module -avoid-version -shared -no-undefined

tegra_dri_la_LIBADD = \
$(top_builddir)/src/mesa/libmesagallium.la \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/state_trackers/dri/drm/libdridrm.la \
$(top_builddir)/src/gallium/winsys/tegra/drm/libtegradrm.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/drivers/rbug/librbug.la \
$(top_builddir)/src/gallium/drivers/tegra/libtegra.la \
$(GALLIUM_DRI_LIB_DEPS) \
$(LIBDRM_LIBS) \
$(TEGRA_LIBS)

if HAVE_MESA_LLVM
tegra_dri_la_LDFLAGS += $(LLVM_LDFLAGS)
tegra_dri_la_LIBADD += $(LLVM_LIBS)
endif

# Provide compatibility with scripts for the old Mesa build system for
# a while by putting a link to the driver into /lib of the build tree.
all-local: tegra_dri.la
$(MKDIR_P) $(top_builddir)/$(LIB_DIR)/gallium
ln -f .libs/tegra_dri.so $(top_builddir)/$(LIB_DIR)/gallium/tegra_dri.so
24 changes: 24 additions & 0 deletions src/gallium/targets/dri-tegra/target.c
@@ -0,0 +1,24 @@
#include <stdio.h>

#include "target-helpers/inline_debug_helper.h"
#include "tegra/drm/tegra_drm_public.h"
#include "state_tracker/drm_driver.h"

static struct pipe_screen *create_screen(int fd)
{
struct pipe_screen *screen;

fprintf(stderr, "> %s(fd=%d)\n", __func__, fd);

screen = tegra_drm_screen_create(fd);
if (!screen)
goto out;

screen = debug_screen_wrap(screen);

out:
fprintf(stderr, "< %s() = %p\n", __func__, screen);
return screen;
}

DRM_DRIVER_DESCRIPTOR("tegra", "tegra", create_screen, NULL)
33 changes: 33 additions & 0 deletions src/gallium/winsys/tegra/drm/Makefile.am
@@ -0,0 +1,33 @@
# Copyright © 2012 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.

include $(top_srcdir)/src/gallium/Automake.inc

AM_CFLAGS = \
-I$(top_srcdir)/src/gallium/drivers \
$(GALLIUM_CFLAGS) \
$(TEGRA_CFLAGS)

noinst_LTLIBRARIES = libtegradrm.la

libtegradrm_la_SOURCES = \
tegra_drm_winsys.c
8 changes: 8 additions & 0 deletions src/gallium/winsys/tegra/drm/tegra_drm_public.h
@@ -0,0 +1,8 @@
#ifndef TEGRA_DRM_PUBLIC_H
#define TEGRA_DRM_PUBLIC_H

struct pipe_screen;

struct pipe_screen *tegra_drm_screen_create(int fd);

#endif
26 changes: 26 additions & 0 deletions src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>

#include <libdrm/tegra.h>

#include "tegra/tegra_screen.h"
#include "tegra_drm_public.h"

struct pipe_screen *tegra_drm_screen_create(int fd)
{
struct pipe_screen *screen = NULL;
struct drm_tegra *drm;
int err;

fprintf(stderr, "> %s(fd=%d)\n", __func__, fd);

err = drm_tegra_open(fd, &drm);
if (err < 0)
goto out;

screen = tegra_screen_create(drm);

out:
fprintf(stderr, "< %s() = %p\n", __func__, screen);
return screen;
}