summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Rusin <zack@tungstengraphics.com>2008-12-14 15:03:36 -0500
committerZack Rusin <zack@tungstengraphics.com>2008-12-14 15:04:28 -0500
commit45271ef0958b258dbdec4783096fb95f09a692e3 (patch)
treeec194a5dda4ce73e64119609738ca22ffd60ec78
parent02989ed1213af9b924e202b017fb6671682e8fe1 (diff)
a little nicer scheme of creating devices
-rw-r--r--src/api_device.cpp2
-rw-r--r--src/device.cpp47
-rw-r--r--src/device.h19
3 files changed, 35 insertions, 33 deletions
diff --git a/src/api_device.cpp b/src/api_device.cpp
index 775cdfe..1428897 100644
--- a/src/api_device.cpp
+++ b/src/api_device.cpp
@@ -49,7 +49,7 @@ create_cpu_device(cl_device_id * devices,
cl_uint * num_devices,
cl_uint num_entries)
{
- Device *device = new Device(CL_DEVICE_TYPE_CPU);
+ Device *device = Device::create(CL_DEVICE_TYPE_CPU);
devices[0] = (cl_device_id)device;
*num_devices = 1;
diff --git a/src/device.cpp b/src/device.cpp
index 94ec7e8..31b318c 100644
--- a/src/device.cpp
+++ b/src/device.cpp
@@ -12,35 +12,19 @@
#include "softpipe/sp_winsys.h"
-
-Device::Device(cl_uint type)
- : m_type(type)
+Device * Device::create(cl_uint type)
{
- switch(m_type) {
- case CL_DEVICE_TYPE_CPU:
- createCpuDevice();
+ switch(type) {
+ case CL_DEVICE_TYPE_CPU: {
+ struct pipe_winsys *ws = cpu_winsys();
+ struct pipe_screen *screen =
+ softpipe_create_screen(ws);
+ return new Device(CL_DEVICE_TYPE_CPU, ws, screen);
+ }
break;
case CL_DEVICE_TYPE_GPU:
- createGpuDevice();
break;
case CL_DEVICE_TYPE_ACCELERATOR:
- createAcceleratorDevice();
- break;
- }
-}
-
-void Device::createCpuDevice()
-{
- m_winsys = cpu_winsys();
- m_screen = softpipe_create_screen(m_winsys);
-}
-
-void Device::createGpuDevice()
-{
-}
-
-void Device::createAcceleratorDevice()
-{
#ifdef GALLIUM_CELL
if (!getenv("GALLIUM_NOCELL")) {
struct cell_winsys *cws = cell_get_winsys(pixelformat);
@@ -49,6 +33,9 @@ void Device::createAcceleratorDevice()
pipe = cell_create_context(screen, cws);
}
#endif
+ break;
+ }
+ return 0;
}
cl_int Device::info(cl_device_info opcode,
@@ -164,3 +151,15 @@ cl_int Device::info(cl_device_info opcode,
return CL_SUCCESS;
}
+
+Device::Device(cl_uint type, struct pipe_winsys *ws,
+ struct pipe_screen *screen)
+ : m_winsys(ws), m_screen(screen)
+{
+ m_info.type = type;
+ fillInfo();
+}
+
+void Device::fillInfo()
+{
+}
diff --git a/src/device.h b/src/device.h
index 3fe4e85..fa83bf2 100644
--- a/src/device.h
+++ b/src/device.h
@@ -1,6 +1,8 @@
#ifndef DEVICE_H
#define DEVICE_H
+#include "deviceinfo.h"
+
#include "OpenCL/cl.h"
struct pipe_screen;
@@ -10,8 +12,8 @@ struct pipe_winsys;
class Device
{
public:
- Device(cl_uint type);
-
+ static Device *create(cl_uint type);
+public:
inline cl_uint type() const;
inline struct pipe_screen *screen() const;
inline struct pipe_winsys *winsys() const;
@@ -22,19 +24,20 @@ public:
size_t * paramValueSizeRet) const;
private:
- void createCpuDevice();
- void createGpuDevice();
- void createAcceleratorDevice();
+ Device(cl_uint type, struct pipe_winsys *ws,
+ struct pipe_screen *screen);
+ void fillInfo();
+
private:
- const cl_uint m_type;
+ DeviceInfo m_info;
- struct pipe_screen *m_screen;
struct pipe_winsys *m_winsys;
+ struct pipe_screen *m_screen;
};
inline cl_uint Device::type() const
{
- return m_type;
+ return m_info.type;
}
inline struct pipe_screen *Device::screen() const