Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render targets + more #3

Merged
merged 6 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/gallium/drivers/tegra/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ libtegra_la_SOURCES = \
tegra_context.c \
tegra_context.h \
tegra_fence.h \
tegra_program.c \
tegra_program.h \
tegra_resource.c \
tegra_resource.h \
tegra_screen.c \
Expand Down
21 changes: 14 additions & 7 deletions src/gallium/drivers/tegra/tegra_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@
#include "util/u_upload_mgr.h"

#include "tegra_context.h"
#include "tegra_program.h"
#include "tegra_resource.h"
#include "tegra_screen.h"
#include "tegra_state.h"
#include "tegra_surface.h"

static int tegra_channel_create(struct tegra_context *context,
enum host1x_class client,
enum drm_tegra_class class,
struct tegra_channel **channelp)
{
struct tegra_screen *screen = tegra_screen(context->base.screen);
int err;
struct drm_tegra_channel *drm_channel;
struct tegra_channel *channel;

struct tegra_channel *channel = CALLOC_STRUCT(tegra_channel);
err = drm_tegra_channel_open(&drm_channel, screen->drm, class);
if (err < 0)
return err;

channel = CALLOC_STRUCT(tegra_channel);
if (!channel)
return -ENOMEM;

channel->context = context;

err = tegra_stream_create(screen->drm, &channel->stream, 32768);
err = tegra_stream_create(screen->drm, drm_channel, &channel->stream, 32768);
if (err < 0) {
FREE(channel);
drm_tegra_channel_close(drm_channel);
return err;
}

Expand Down Expand Up @@ -97,13 +105,13 @@ struct pipe_context *tegra_screen_context_create(struct pipe_screen *pscreen,
context->base.screen = pscreen;
context->base.priv = priv;

err = tegra_channel_create(context, HOST1X_CLASS_GR2D, &context->gr2d);
err = tegra_channel_create(context, DRM_TEGRA_GR2D, &context->gr2d);
if (err < 0) {
fprintf(stderr, "tegra_channel_create() failed: %d\n", err);
return NULL;
}

err = tegra_channel_create(context, HOST1X_CLASS_GR3D, &context->gr3d);
err = tegra_channel_create(context, DRM_TEGRA_GR3D, &context->gr3d);
if (err < 0) {
fprintf(stderr, "tegra_channel_create() failed: %d\n", err);
return NULL;
Expand All @@ -123,8 +131,7 @@ struct pipe_context *tegra_screen_context_create(struct pipe_screen *pscreen,
tegra_context_sampler_init(&context->base);
tegra_context_rasterizer_init(&context->base);
tegra_context_zsa_init(&context->base);
tegra_context_vs_init(&context->base);
tegra_context_fs_init(&context->base);
tegra_context_program_init(&context->base);
tegra_context_vbo_init(&context->base);

return &context->base;
Expand Down
4 changes: 4 additions & 0 deletions src/gallium/drivers/tegra/tegra_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

struct tegra_framebuffer_state {
struct pipe_framebuffer_state base;
int num_rts;
struct drm_tegra_bo *bos[16];
uint32_t rt_params[16];
uint32_t mask;
};

struct tegra_channel {
Expand Down
75 changes: 75 additions & 0 deletions src/gallium/drivers/tegra/tegra_program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <stdio.h>

#include "util/u_memory.h"

#include "tgsi/tgsi_dump.h"

#include "tegra_context.h"
#include "tegra_screen.h"
#include "tegra_program.h"

#define unimplemented() printf("TODO: %s()\n", __func__)


static void *
tegra_create_vs_state(struct pipe_context *pcontext,
const struct pipe_shader_state *template)
{
struct tegra_vs_state *so = CALLOC_STRUCT(tegra_vs_state);
if (!so)
return NULL;

so->base = *template;

if (tegra_debug & TEGRA_DEBUG_TGSI) {
fprintf(stderr, "DEBUG: TGSI:\n");
tgsi_dump(template->tokens, 0);
fprintf(stderr, "\n");
}

return so;
}

static void tegra_bind_vs_state(struct pipe_context *pcontext, void *so)
{
unimplemented();
}

static void tegra_delete_vs_state(struct pipe_context *pcontext, void *so)
{
FREE(so);
}

static void *
tegra_create_fs_state(struct pipe_context *pcontext,
const struct pipe_shader_state *template)
{
struct tegra_fs_state *so = CALLOC_STRUCT(tegra_fs_state);
if (!so)
return NULL;

so->base = *template;

return so;
}

static void tegra_bind_fs_state(struct pipe_context *pcontext, void *so)
{
unimplemented();
}

static void tegra_delete_fs_state(struct pipe_context *pcontext, void *so)
{
FREE(so);
}

void tegra_context_program_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;

pcontext->create_fs_state = tegra_create_fs_state;
pcontext->bind_fs_state = tegra_bind_fs_state;
pcontext->delete_fs_state = tegra_delete_fs_state;
}
17 changes: 17 additions & 0 deletions src/gallium/drivers/tegra/tegra_program.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef TEGRA_PROGRAM_H
#define TEGRA_PROGRAM_H

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

struct tegra_vs_state {
struct pipe_shader_state base;
};

struct tegra_fs_state {
struct pipe_shader_state base;
};

void tegra_context_program_init(struct pipe_context *pcontext);

#endif
43 changes: 42 additions & 1 deletion src/gallium/drivers/tegra/tegra_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "tegra_screen.h"

#include "host1x01_hardware.h"
#include "tgr_3d.xml.h"

#include <libdrm/tegra_drm.h>
#include <libdrm/tegra.h>
Expand Down Expand Up @@ -142,6 +143,35 @@ tegra_screen_can_create_resource(struct pipe_screen *pscreen,
return TRUE;
}

int tegra_pixel_format(enum pipe_format format)
{
switch (format) {
case PIPE_FORMAT_A8_UNORM:
return TGR3D_PIXEL_FORMAT_A8;
case PIPE_FORMAT_L8_UNORM:
return TGR3D_PIXEL_FORMAT_L8;
case PIPE_FORMAT_L8A8_UNORM:
return TGR3D_PIXEL_FORMAT_LA88;
case PIPE_FORMAT_B5G6R5_UNORM:
return TGR3D_PIXEL_FORMAT_RGB565;
case PIPE_FORMAT_B5G5R5A1_UNORM:
return TGR3D_PIXEL_FORMAT_RGBA5551;
case PIPE_FORMAT_B4G4R4A4_UNORM:
return TGR3D_PIXEL_FORMAT_RGBA4444;
case PIPE_FORMAT_B8G8R8A8_UNORM:
case PIPE_FORMAT_B8G8R8X8_UNORM:
return TGR3D_PIXEL_FORMAT_RGBA8888;
case PIPE_FORMAT_R32G32B32A32_FLOAT:
return TGR3D_PIXEL_FORMAT_RGBA_FP32;
case PIPE_FORMAT_S8_UINT:
return TGR3D_PIXEL_FORMAT_S8;
case PIPE_FORMAT_Z16_UNORM:
return TGR3D_PIXEL_FORMAT_D16_LINEAR;
default:
return -1;
}
}

static struct pipe_resource *
tegra_screen_resource_create(struct pipe_screen *pscreen,
const struct pipe_resource *template)
Expand Down Expand Up @@ -179,6 +209,13 @@ tegra_screen_resource_create(struct pipe_screen *pscreen,
// }
}

if (template->target != PIPE_BUFFER) {
/* pick pixel-format */
int format = tegra_pixel_format(template->format);
assert(format >= 0);
resource->format = format;
}

size = resource->pitch * height;

err = drm_tegra_bo_new(&resource->bo, screen->drm, flags, size);
Expand All @@ -198,7 +235,7 @@ tegra_screen_resource_from_handle(struct pipe_screen *pscreen,
{
struct tegra_screen *screen = tegra_screen(pscreen);
struct tegra_resource *resource;
int err;
int err, format;

resource = CALLOC_STRUCT(tegra_resource);
if (!resource)
Expand All @@ -220,6 +257,10 @@ tegra_screen_resource_from_handle(struct pipe_screen *pscreen,

resource->pitch = handle->stride;

format = tegra_pixel_format(template->format);
assert(format >= 0);
resource->format = format;

return &resource->base.b;
}

Expand Down
3 changes: 3 additions & 0 deletions src/gallium/drivers/tegra/tegra_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct tegra_resource {
struct drm_tegra_bo *bo;
unsigned int pitch;
unsigned int tiled : 1;
unsigned int format : 5;
};

static inline struct tegra_resource *
Expand All @@ -17,6 +18,8 @@ tegra_resource(struct pipe_resource *resource)
return (struct tegra_resource *)resource;
}

int tegra_pixel_format(enum pipe_format format);

void tegra_context_resource_init(struct pipe_context *pcontext);
void tegra_screen_resource_init(struct pipe_screen *pscreen);

Expand Down
22 changes: 2 additions & 20 deletions src/gallium/drivers/tegra/tegra_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,27 +505,9 @@ static boolean tegra_screen_is_format_supported(struct pipe_screen *pscreen,
unsigned int sample_count,
unsigned int usage)
{
if (usage & PIPE_BIND_RENDER_TARGET) {
switch (format) {
case PIPE_FORMAT_B8G8R8A8_UNORM:
case PIPE_FORMAT_B8G8R8X8_UNORM:
case PIPE_FORMAT_A8R8G8B8_UNORM:
case PIPE_FORMAT_X8R8G8B8_UNORM:
break;
default:
if (usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL)) {
if (tegra_pixel_format(format) < 0)
return false;
}
}

if (usage & PIPE_BIND_DEPTH_STENCIL) {
switch (format) {
case PIPE_FORMAT_Z16_UNORM:
case PIPE_FORMAT_Z24_UNORM_S8_UINT:
case PIPE_FORMAT_S8_UINT:
break;
default:
return false;
}
}

return true;
Expand Down
Loading