From 9e67b0a1745e50fe34efedb0a3191b4a27e10724 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Tue, 3 Mar 2009 21:14:33 -0800 Subject: r300-gallium, radeon-gallium: Begin migration to DRI2 state tracker, part 1. s/migration/migrane/ , actually. Anyway, this has working glxinfo... --- src/gallium/drivers/r300/r300_context.c | 7 +- src/gallium/drivers/r300/r300_context.h | 1 - src/gallium/drivers/r300/r300_screen.c | 5 +- src/gallium/drivers/r300/r300_screen.h | 3 +- src/gallium/drivers/r300/r300_winsys.h | 11 +-- src/gallium/winsys/drm/radeon/Makefile | 3 +- src/gallium/winsys/drm/radeon/radeon_buffer.c | 90 ++++++++++++---------- src/gallium/winsys/drm/radeon/radeon_buffer.h | 11 ++- src/gallium/winsys/drm/radeon/radeon_drm.c | 80 +++++++++++++++++++ src/gallium/winsys/drm/radeon/radeon_drm.h | 30 ++++++++ src/gallium/winsys/drm/radeon/radeon_r300.c | 8 +- src/gallium/winsys/drm/radeon/radeon_r300.h | 2 +- .../winsys/drm/radeon/radeon_winsys_softpipe.c | 9 +-- .../winsys/drm/radeon/radeon_winsys_softpipe.h | 2 +- 14 files changed, 190 insertions(+), 72 deletions(-) diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index a981150143..653d919ef1 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -103,7 +103,6 @@ static void r300_destroy_context(struct pipe_context* context) { } struct pipe_context* r300_create_context(struct pipe_screen* screen, - struct pipe_winsys* winsys, struct r300_winsys* r300_winsys) { struct r300_context* r300 = CALLOC_STRUCT(r300_context); @@ -111,9 +110,11 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, if (!r300) return NULL; + /* XXX this could be refactored now? */ r300->winsys = r300_winsys; - r300->context.winsys = winsys; - r300->context.screen = r300_create_screen(winsys, r300_winsys); + + r300->context.winsys = (struct pipe_winsys*)r300_winsys; + r300->context.screen = r300_screen(screen); r300->context.destroy = r300_destroy_context; diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 5247901be5..2be9e2eb33 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -268,7 +268,6 @@ void r300_init_surface_functions(struct r300_context* r300); * We'll just step out in that case... */ #ifndef R300_WINSYS_H struct pipe_context* r300_create_context(struct pipe_screen* screen, - struct pipe_winsys* winsys, struct r300_winsys* r300_winsys); #endif diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index 2fcd504812..e97334463a 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -337,8 +337,7 @@ static void r300_destroy_screen(struct pipe_screen* pscreen) FREE(r300screen); } -struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys, - struct r300_winsys* r300_winsys) +struct pipe_screen* r300_create_screen(struct r300_winsys* r300_winsys) { struct r300_screen* r300screen = CALLOC_STRUCT(r300_screen); struct r300_capabilities* caps = CALLOC_STRUCT(r300_capabilities); @@ -352,7 +351,7 @@ struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys, r300_parse_chipset(caps); r300screen->caps = caps; - r300screen->screen.winsys = winsys; + r300screen->screen.winsys = (struct pipe_winsys*)r300_winsys; r300screen->screen.destroy = r300_destroy_screen; r300screen->screen.get_name = r300_get_name; r300screen->screen.get_vendor = r300_get_vendor; diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h index 6c845144cb..3f52dbc3be 100644 --- a/src/gallium/drivers/r300/r300_screen.h +++ b/src/gallium/drivers/r300/r300_screen.h @@ -61,7 +61,6 @@ r300_transfer(struct pipe_transfer* transfer) } /* Creates a new r300 screen. */ -struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys, - struct r300_winsys* r300_winsys); +struct pipe_screen* r300_create_screen(struct r300_winsys* r300_winsys); #endif /* R300_SCREEN_H */ diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h index 5a3a212892..b7341c4f3a 100644 --- a/src/gallium/drivers/r300/r300_winsys.h +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -33,10 +33,16 @@ extern "C" { #include "pipe/p_defines.h" #include "pipe/p_state.h" +#include "pipe/internal/p_winsys_screen.h" struct radeon_cs; struct r300_winsys { + /* Parent class */ + struct pipe_winsys base; + + /* Opaque Radeon-specific winsys object. */ + void* radeon_winsys; /* PCI ID */ uint32_t pci_id; @@ -47,10 +53,6 @@ struct r300_winsys { /* CS object. This is very much like Intel's batchbuffer. * Fill it full of dwords and relocs and then submit. * Repeat as needed. */ - /* Note: Unlike Mesa's version of this, we don't keep a copy of the CSM - * that was used to create this CS. Is this a good idea? */ - /* Note: The pipe driver doesn't know how to use this. This is purely - * for the winsys. */ struct radeon_cs* cs; /* Check to see if there's room for commands. */ @@ -84,7 +86,6 @@ struct r300_winsys { }; struct pipe_context* r300_create_context(struct pipe_screen* screen, - struct pipe_winsys* winsys, struct r300_winsys* r300_winsys); #ifdef __cplusplus diff --git a/src/gallium/winsys/drm/radeon/Makefile b/src/gallium/winsys/drm/radeon/Makefile index 784686ffb6..8721f2cb5d 100644 --- a/src/gallium/winsys/drm/radeon/Makefile +++ b/src/gallium/winsys/drm/radeon/Makefile @@ -7,15 +7,14 @@ LIBNAME = radeon_dri.so MINIGLX_SOURCES = PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri2/libdri2drm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/r300/libr300.a DRIVER_SOURCES = \ radeon_buffer.c \ - radeon_context.c \ radeon_drm.c \ radeon_r300.c \ - radeon_screen.c \ radeon_winsys_softpipe.c C_SOURCES = \ diff --git a/src/gallium/winsys/drm/radeon/radeon_buffer.c b/src/gallium/winsys/drm/radeon/radeon_buffer.c index 918d2f98e2..79b8f777ca 100644 --- a/src/gallium/winsys/drm/radeon/radeon_buffer.c +++ b/src/gallium/winsys/drm/radeon/radeon_buffer.c @@ -1,5 +1,6 @@ /* * Copyright © 2008 Jérôme Glisse + * 2009 Corbin Simpson * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining @@ -26,10 +27,14 @@ /* * Authors: * Jérôme Glisse + * Corbin Simpson */ #include -#include "dri_util.h" + #include "state_tracker/st_public.h" + +#include "util/u_memory.h" + #include "pipe/p_defines.h" #include "pipe/p_inlines.h" #include "radeon_buffer.h" @@ -38,24 +43,26 @@ #include "radeon_bo.h" #include "radeon_drm.h" + static const char *radeon_get_name(struct pipe_winsys *ws) { - return "RADEON/DRI2"; + return "Radeon/GEM+KMS"; } static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws, - unsigned alignment, - unsigned usage, - unsigned size) + unsigned alignment, + unsigned usage, + unsigned size) { - struct radeon_pipe_winsys *radeon_ws = (struct radeon_pipe_winsys *)ws; + struct radeon_winsys *radeon_ws = (struct radeon_winsys *)ws; struct radeon_pipe_buffer *radeon_buffer; uint32_t domain; - radeon_buffer = calloc(1, sizeof(*radeon_buffer)); + radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer); if (radeon_buffer == NULL) { return NULL; } + radeon_buffer->base.refcount = 1; radeon_buffer->base.alignment = alignment; radeon_buffer->base.usage = usage; @@ -69,21 +76,21 @@ static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws, if (usage & PIPE_BUFFER_USAGE_VERTEX) { domain |= RADEON_GEM_DOMAIN_GTT; } - if (usage & PIPE_BUFFER_USAGE_INDEX) { domain |= RADEON_GEM_DOMAIN_GTT; } - radeon_buffer->bo = radeon_bo_open(radeon_ws->radeon_screen->bom, 0, - size, alignment, domain, 0); + + radeon_buffer->bo = radeon_bo_open(radeon_ws->bom, 0, size, alignment, + domain, 0); if (radeon_buffer->bo == NULL) { - free(radeon_buffer); + FREE(radeon_buffer); } return &radeon_buffer->base; } static struct pipe_buffer *radeon_buffer_user_create(struct pipe_winsys *ws, - void *ptr, - unsigned bytes) + void *ptr, + unsigned bytes) { struct radeon_pipe_buffer *radeon_buffer; @@ -106,21 +113,20 @@ static void radeon_buffer_del(struct pipe_winsys *ws, struct pipe_buffer *buffer } static void *radeon_buffer_map(struct pipe_winsys *ws, - struct pipe_buffer *buffer, - unsigned flags) + struct pipe_buffer *buffer, + unsigned flags) { struct radeon_pipe_buffer *radeon_buffer = (struct radeon_pipe_buffer*)buffer; int write = 0; if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { - /* Remove this when radeon_bo_map supports DONTBLOCK - */ + /* XXX Remove this when radeon_bo_map supports DONTBLOCK */ return NULL; } - if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) { write = 1; } + if (radeon_bo_map(radeon_buffer->bo, write)) return NULL; return radeon_buffer->bo->ptr; @@ -134,59 +140,58 @@ static void radeon_buffer_unmap(struct pipe_winsys *ws, struct pipe_buffer *buff } static void radeon_fence_reference(struct pipe_winsys *ws, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *pfence) + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *pfence) { } static int radeon_fence_signalled(struct pipe_winsys *ws, - struct pipe_fence_handle *pfence, - unsigned flag) + struct pipe_fence_handle *pfence, + unsigned flag) { return 1; } static int radeon_fence_finish(struct pipe_winsys *ws, - struct pipe_fence_handle *pfence, - unsigned flag) + struct pipe_fence_handle *pfence, + unsigned flag) { return 0; } static void radeon_flush_frontbuffer(struct pipe_winsys *pipe_winsys, - struct pipe_surface *pipe_surface, - void *context_private) + struct pipe_surface *pipe_surface, + void *context_private) { /* TODO: call dri2CopyRegion */ } -struct pipe_winsys *radeon_pipe_winsys(struct radeon_screen *radeon_screen) +struct pipe_winsys *radeon_pipe_winsys() { - struct radeon_pipe_winsys *radeon_ws; + struct pipe_winsys *radeon_ws; - radeon_ws = calloc(1, sizeof(struct radeon_pipe_winsys)); + radeon_ws = CALLOC_STRUCT(pipe_winsys); if (radeon_ws == NULL) { return NULL; } - radeon_ws->radeon_screen = radeon_screen; - radeon_ws->winsys.flush_frontbuffer = radeon_flush_frontbuffer; + radeon_ws->flush_frontbuffer = radeon_flush_frontbuffer; - radeon_ws->winsys.buffer_create = radeon_buffer_create; - radeon_ws->winsys.buffer_destroy = radeon_buffer_del; - radeon_ws->winsys.user_buffer_create = radeon_buffer_user_create; - radeon_ws->winsys.buffer_map = radeon_buffer_map; - radeon_ws->winsys.buffer_unmap = radeon_buffer_unmap; + radeon_ws->buffer_create = radeon_buffer_create; + radeon_ws->buffer_destroy = radeon_buffer_del; + radeon_ws->user_buffer_create = radeon_buffer_user_create; + radeon_ws->buffer_map = radeon_buffer_map; + radeon_ws->buffer_unmap = radeon_buffer_unmap; - radeon_ws->winsys.fence_reference = radeon_fence_reference; - radeon_ws->winsys.fence_signalled = radeon_fence_signalled; - radeon_ws->winsys.fence_finish = radeon_fence_finish; + radeon_ws->fence_reference = radeon_fence_reference; + radeon_ws->fence_signalled = radeon_fence_signalled; + radeon_ws->fence_finish = radeon_fence_finish; - radeon_ws->winsys.get_name = radeon_get_name; + radeon_ws->get_name = radeon_get_name; - return &radeon_ws->winsys; + return radeon_ws; } - +#if 0 static struct pipe_buffer *radeon_buffer_from_handle(struct radeon_screen *radeon_screen, uint32_t handle) { @@ -243,3 +248,4 @@ struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_co PIPE_BUFFER_USAGE_GPU_WRITE); return ps; } +#endif \ No newline at end of file diff --git a/src/gallium/winsys/drm/radeon/radeon_buffer.h b/src/gallium/winsys/drm/radeon/radeon_buffer.h index c626c20229..e062308f44 100644 --- a/src/gallium/winsys/drm/radeon/radeon_buffer.h +++ b/src/gallium/winsys/drm/radeon/radeon_buffer.h @@ -40,12 +40,15 @@ struct radeon_pipe_buffer { struct radeon_bo *bo; }; -struct radeon_pipe_winsys { - struct pipe_winsys winsys; - struct radeon_screen *radeon_screen; +struct radeon_winsys { + /* Parent class. */ + struct pipe_winsys base; + + /* Radeon BO manager. This corresponds to void* radeon_winsys in r300_winsys. */ + struct radeon_bo_manager* bom; }; -struct pipe_winsys *radeon_pipe_winsys(struct radeon_screen *radeon_screen); +struct pipe_winsys *radeon_pipe_winsys(); struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_context, uint32_t handle, enum pipe_format format, diff --git a/src/gallium/winsys/drm/radeon/radeon_drm.c b/src/gallium/winsys/drm/radeon/radeon_drm.c index 839b0bf0bd..9cd178f944 100644 --- a/src/gallium/winsys/drm/radeon/radeon_drm.c +++ b/src/gallium/winsys/drm/radeon/radeon_drm.c @@ -27,4 +27,84 @@ * Authors: * Corbin Simpson */ + #include "radeon_drm.h" + +/* Create a pipe_screen. */ +struct pipe_screen* radeon_create_screen(int drmFB, int pciID) +{ + struct radeon_context* radeon = CALLOC_STRUCT(radeon_context); + struct pipe_winsys* winsys = radeon_pipe_winsys(radeon); + + if (getenv("RADEON_SOFTPIPE")) { + return softpipe_create_screen(winsys); + } else { + struct r300_winsys* r300 = radeon_create_r300_winsys(drmFB, winsys); + FREE(winsys); + return r300_create_screen(r300); + } +} + +/* Create a pipe_context. */ +struct pipe_context* radeon_create_context(struct pipe_screen* screen) +{ + if (getenv("RADEON_SOFTPIPE")) { + return radeon_create_softpipe(screen->winsys); + } else { + return r300_create_context(screen, screen->winsys); + } +} + +boolean radeon_buffer_from_texture(struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride) +{ +} + +/* Create a buffer from a handle. */ +/* XXX what's up with name? */ +struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen, + const char* name, + unsigned handle) +{ + struct radeon_bo_manager* bom = ((struct radeon_winsys*)screen->winsys)->bom; + struct radeon_pipe_buffer* radeon_buffer; + struct radeon_bo* bo = NULL; + + bo = radeon_bo_open(bom, handle, 0, 0, 0, 0); + if (bo == NULL) { + return NULL; + } + + radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer); + if (radeon_buffer == NULL) { + radeon_bo_unref(bo); + return NULL; + } + + radeon_buffer->base.refcount = 1; + radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL; + radeon_buffer->bo = bo; + return &radeon_buffer->base; +} + +boolean radeon_handle_from_buffer(struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle) +{ +} + +boolean radeon_global_handle_from_buffer(struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle) +{ +} + +struct drm_api drm_api_hooks = { + .create_screen = radeon_create_screen, + .create_context = radeon_create_context, + .buffer_from_texture = radeon_buffer_from_texture, + .buffer_from_handle = radeon_buffer_from_handle, + .handle_from_buffer = radeon_handle_from_buffer, + .global_handle_from_buffer = radeon_global_handle_from_buffer, +}; \ No newline at end of file diff --git a/src/gallium/winsys/drm/radeon/radeon_drm.h b/src/gallium/winsys/drm/radeon/radeon_drm.h index 8ccbc81895..e434106cb5 100644 --- a/src/gallium/winsys/drm/radeon/radeon_drm.h +++ b/src/gallium/winsys/drm/radeon/radeon_drm.h @@ -30,6 +30,36 @@ #ifndef RADEON_DRM_H #define RADEON_DRM_H +#include "pipe/p_screen.h" + +#include "util/u_memory.h" + #include "state_tracker/drm_api.h" +#include "radeon_buffer.h" +#include "radeon_context.h" +#include "radeon_r300.h" +#include "radeon_screen.h" +#include "radeon_winsys_softpipe.h" + +struct pipe_screen* radeon_create_screen(int drmFB, int pciID); + +struct pipe_context* radeon_create_context(struct pipe_screen* screen); + +boolean radeon_buffer_from_texture(struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride); + +struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen, + const char* name, + unsigned handle); + +boolean radeon_handle_from_buffer(struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle); + +boolean radeon_global_handle_from_buffer(struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle); + #endif diff --git a/src/gallium/winsys/drm/radeon/radeon_r300.c b/src/gallium/winsys/drm/radeon/radeon_r300.c index 8fe2375e34..e9b96b1ee9 100644 --- a/src/gallium/winsys/drm/radeon/radeon_r300.c +++ b/src/gallium/winsys/drm/radeon/radeon_r300.c @@ -75,14 +75,16 @@ static void do_ioctls(struct r300_winsys* winsys, int fd) } -struct r300_winsys* radeon_create_r300_winsys(int fd) +struct r300_winsys* radeon_create_r300_winsys(int fd, struct pipe_winsys* old_winsys) { - struct r300_winsys* winsys = calloc(1, sizeof(struct r300_winsys)); + struct r300_winsys* winsys = CALLOC_STRUCT(r300_winsys); do_ioctls(winsys, fd); + struct radeon_bo_manager* bom = radeon_bo_manager_gem_ctor(fd); struct radeon_cs_manager* csm = radeon_cs_manager_gem_ctor(fd); + winsys->radeon_winsys = bom; winsys->cs = radeon_cs_create(csm, 1024 * 64 / 4); winsys->check_cs = radeon_r300_check_cs; @@ -92,5 +94,7 @@ struct r300_winsys* radeon_create_r300_winsys(int fd) winsys->end_cs = radeon_cs_end; winsys->flush_cs = radeon_r300_flush_cs; + winsys->base = *old_winsys; + return winsys; } diff --git a/src/gallium/winsys/drm/radeon/radeon_r300.h b/src/gallium/winsys/drm/radeon/radeon_r300.h index 8ed95a3a9b..432b7b1833 100644 --- a/src/gallium/winsys/drm/radeon/radeon_r300.h +++ b/src/gallium/winsys/drm/radeon/radeon_r300.h @@ -31,4 +31,4 @@ #include "radeon_buffer.h" -struct r300_winsys* radeon_create_r300_winsys(int fd); +struct r300_winsys* radeon_create_r300_winsys(int fd, struct pipe_winsys* old_winsys); diff --git a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c index 8402e1fa5a..75e975f5e2 100644 --- a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c +++ b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c @@ -29,7 +29,6 @@ * Authors: Keith Whitwell */ #include -#include "imports.h" #include "pipe/p_defines.h" #include "pipe/p_format.h" #include "softpipe/sp_winsys.h" @@ -57,21 +56,19 @@ static boolean radeon_is_format_supported(struct softpipe_winsys *sws, uint form return FALSE; } -struct pipe_context *radeon_create_softpipe(struct radeon_context *radeon_context) +struct pipe_context *radeon_create_softpipe(struct pipe_winsys* winsys) { struct radeon_softpipe_winsys *radeon_sp_ws; struct pipe_screen *pipe_screen; - pipe_screen = softpipe_create_screen(radeon_context->pipe_winsys); + pipe_screen = softpipe_create_screen(winsys); radeon_sp_ws = CALLOC_STRUCT(radeon_softpipe_winsys); if (radeon_sp_ws == NULL) { return NULL; } - radeon_context->pipe_screen = pipe_screen; - radeon_sp_ws->radeon_context = radeon_context; radeon_sp_ws->sp_winsys.is_format_supported = radeon_is_format_supported; return softpipe_create(pipe_screen, - radeon_context->pipe_winsys, + winsys, &radeon_sp_ws->sp_winsys); } diff --git a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h index 519eab769c..093693eddf 100644 --- a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h +++ b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h @@ -32,6 +32,6 @@ #include "radeon_context.h" -struct pipe_context *radeon_create_softpipe(struct radeon_context *radeon_context); +struct pipe_context *radeon_create_softpipe(struct pipe_winsys* winsys); #endif -- cgit v1.2.3