Gallium 3D: pipe loader

git-svn-id: svn://kolibrios.org@3847 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2013-08-03 16:19:22 +00:00
parent 57d92e4a1f
commit c398fbbf20
8 changed files with 421 additions and 36 deletions

View File

@ -0,0 +1,83 @@
/**************************************************************************
*
* Copyright 2012 Francisco Jerez
* 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 "pipe_loader_priv.h"
#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_string.h"
#include "util/u_dl.h"
#define MODULE_PREFIX "pipe_"
static int (*backends[])(struct pipe_loader_device **, int) = {
#ifdef HAVE_PIPE_LOADER_DRM
&pipe_loader_drm_probe,
#endif
&pipe_loader_sw_probe
};
int
pipe_loader_probe(struct pipe_loader_device **devs, int ndev)
{
int i, n = 0;
for (i = 0; i < Elements(backends); i++)
n += backends[i](&devs[n], MAX2(0, ndev - n));
return n;
}
void
pipe_loader_release(struct pipe_loader_device **devs, int ndev)
{
int i;
for (i = 0; i < ndev; i++)
devs[i]->ops->release(&devs[i]);
}
struct pipe_screen *
pipe_loader_create_screen(struct pipe_loader_device *dev,
const char *library_paths)
{
return dev->ops->create_screen(dev, library_paths);
}
struct util_dl_library *
pipe_loader_find_module(struct pipe_loader_device *dev,
const char *library_paths)
{
struct util_dl_library *lib;
const char *next;
char path[PATH_MAX];
int len, ret;
lib = load_library("g3dsoft.drv");
return lib;
}

View File

@ -0,0 +1,140 @@
/**************************************************************************
*
* Copyright 2012 Francisco Jerez
* 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.
*
**************************************************************************/
/**
* \file Library that provides device enumeration and creation of
* winsys/pipe_screen instances.
*/
#ifndef PIPE_LOADER_H
#define PIPE_LOADER_H
#include "pipe/p_compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
struct pipe_screen;
enum pipe_loader_device_type {
PIPE_LOADER_DEVICE_SOFTWARE,
PIPE_LOADER_DEVICE_PCI,
NUM_PIPE_LOADER_DEVICE_TYPES
};
/**
* A device known to the pipe loader.
*/
struct pipe_loader_device {
enum pipe_loader_device_type type;
union {
struct {
int vendor_id;
int chip_id;
} pci;
} u; /**< Discriminated by \a type */
const char *driver_name;
const struct pipe_loader_ops *ops;
};
/**
* Get a list of known devices.
*
* \param devs Array that will be filled with pointers to the devices
* available in the system.
* \param ndev Maximum number of devices to return.
* \return Number of devices available in the system.
*/
int
pipe_loader_probe(struct pipe_loader_device **devs, int ndev);
/**
* Create a pipe_screen for the specified device.
*
* \param dev Device the screen will be created for.
* \param library_paths Colon-separated list of filesystem paths that
* will be used to look for the pipe driver
* module that handles this device.
*/
struct pipe_screen *
pipe_loader_create_screen(struct pipe_loader_device *dev,
const char *library_paths);
/**
* Release resources allocated for a list of devices.
*
* Should be called when the specified devices are no longer in use to
* release any resources allocated by pipe_loader_probe.
*
* \param devs Devices to release.
* \param ndev Number of devices to release.
*/
void
pipe_loader_release(struct pipe_loader_device **devs, int ndev);
/**
* Get a list of known software devices.
*
* This function is platform-specific.
*
* \sa pipe_loader_probe
*/
int
pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev);
#ifdef HAVE_PIPE_LOADER_DRM
/**
* Get a list of known DRM devices.
*
* This function is platform-specific.
*
* \sa pipe_loader_probe
*/
int
pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev);
/**
* Initialize a DRM device in an already opened fd.
*
* This function is platform-specific.
*
* \sa pipe_loader_probe
*/
boolean
pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd);
#endif
#ifdef __cplusplus
}
#endif
#endif /* PIPE_LOADER_H */

View File

@ -0,0 +1,47 @@
/**************************************************************************
*
* Copyright 2012 Francisco Jerez
* 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.
*
**************************************************************************/
#ifndef PIPE_LOADER_PRIV_H
#define PIPE_LOADER_PRIV_H
#include "pipe_loader.h"
struct pipe_loader_ops {
struct pipe_screen *(*create_screen)(struct pipe_loader_device *dev,
const char *library_paths);
void (*release)(struct pipe_loader_device **dev);
};
/**
* Open the pipe driver module that handles a specified device.
*/
struct util_dl_library *
pipe_loader_find_module(struct pipe_loader_device *dev,
const char *library_paths);
#endif /* PIPE_LOADER_PRIV_H */

View File

@ -0,0 +1,111 @@
/**************************************************************************
*
* Copyright 2012 Francisco Jerez
* 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 "pipe_loader_priv.h"
#include "util/u_memory.h"
#include "util/u_dl.h"
#include "target-helpers/inline_sw_helper.h"
#include "sw/kos_sw_winsys.h"
struct pipe_loader_sw_device {
struct pipe_loader_device base;
struct util_dl_library *lib;
struct sw_winsys *ws;
};
#define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
static struct pipe_loader_ops pipe_loader_sw_ops;
static struct sw_winsys *(*backends[])() = {
#ifdef HAVE_WINSYS_XLIB
x11_sw_create,
#endif
kos_create_sw_winsys
};
int
pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev)
{
int i;
for (i = 0; i < Elements(backends); i++) {
if (i < ndev) {
struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
sdev->base.driver_name = "swrast";
sdev->base.ops = &pipe_loader_sw_ops;
sdev->ws = backends[i]();
devs[i] = &sdev->base;
}
}
return i;
}
static void
pipe_loader_sw_release(struct pipe_loader_device **dev)
{
struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(*dev);
// if (sdev->lib)
// util_dl_close(sdev->lib);
FREE(sdev);
*dev = NULL;
}
static struct pipe_screen *
pipe_loader_sw_create_screen(struct pipe_loader_device *dev,
const char *library_paths)
{
struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
struct pipe_screen *(*init)(struct sw_winsys *);
printf("%s\n",__FUNCTION__);
if (!sdev->lib)
sdev->lib = pipe_loader_find_module(dev, library_paths);
if (!sdev->lib)
return NULL;
init = (void *)get_proc_address(sdev->lib, "swrast_create_screen");
printf("swrast_create_screen %p\n", init);
if (!init)
return NULL;
return init(sdev->ws);
}
static struct pipe_loader_ops pipe_loader_sw_ops = {
.create_screen = pipe_loader_sw_create_screen,
.release = pipe_loader_sw_release
};

View File

@ -0,0 +1,23 @@
#include "target-helpers/inline_sw_helper.h"
#include "target-helpers/inline_debug_helper.h"
#include "state_tracker/drm_driver.h"
PUBLIC struct pipe_screen *
swrast_create_screen(struct sw_winsys *ws);
PUBLIC
DRM_DRIVER_DESCRIPTOR("swrast", NULL, NULL, NULL)
struct pipe_screen *
swrast_create_screen(struct sw_winsys *ws)
{
struct pipe_screen *screen;
ws = kos_create_sw_winsys();
if (ws == NULL)
return NULL;
screen = softpipe_create_screen(ws);
return screen;
}

View File

@ -32,27 +32,6 @@
#include "target-helpers/inline_debug_helper.h" #include "target-helpers/inline_debug_helper.h"
#include "target-helpers/inline_sw_helper.h" #include "target-helpers/inline_sw_helper.h"
#include <kos32sys.h> #include <kos32sys.h>
//#include <windows.h>
/*
static LRESULT CALLBACK
window_proc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
*/
static struct { static struct {
void (* draw)(void); void (* draw)(void);
@ -68,6 +47,8 @@ graw_create_window_and_screen(int x,
{ {
struct sw_winsys *winsys = NULL; struct sw_winsys *winsys = NULL;
struct pipe_screen *screen = NULL; struct pipe_screen *screen = NULL;
struct pipe_loader_device *dev;
int ret;
if (format != PIPE_FORMAT_B8G8R8X8_UNORM) if (format != PIPE_FORMAT_B8G8R8X8_UNORM)
goto fail; goto fail;
@ -76,7 +57,11 @@ graw_create_window_and_screen(int x,
if (winsys == NULL) if (winsys == NULL)
goto fail; goto fail;
screen = sw_screen_create(winsys); /* find a hardware device */
ret = pipe_loader_probe(&dev, 1);
/* init a pipe screen */
screen = pipe_loader_create_screen(dev, "drivers");
if (screen == NULL) if (screen == NULL)
goto fail; goto fail;

View File

@ -210,10 +210,6 @@ kos_sw_displaytarget_display(struct sw_winsys *winsys,
struct sw_displaytarget *dt, struct sw_displaytarget *dt,
void *context_private) void *context_private)
{ {
/* nasty:
*/
// HDC hDC = (HDC)context_private;
kos_sw_display(winsys, dt); kos_sw_display(winsys, dt);
} }