summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Src/OpenCL.cpp
diff options
context:
space:
mode:
authorSonicadvance1 <sonicadvance1@gmail.com>2009-10-07 02:48:21 +0000
committerSonicadvance1 <sonicadvance1@gmail.com>2009-10-07 02:48:21 +0000
commit0146f3f58f4776661d37495492c8171b1f34717b (patch)
treebeda94a37cf604c69c49c3adc8bbfbbb1a327c4a /Source/Core/Common/Src/OpenCL.cpp
parentf474788e01fff02610af66203f4f0fa5c4f045d7 (diff)
More OpenCL work, got XFB converting which needs more optimization. I haven't checked for FPS changes. My desktop isn't the best to test on anyway (Phenom 1, 32 stream processors). The package check doesn't work for me, so I just checked true if you compile with opencl=true. Requires a bit of cleanup still
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4369 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common/Src/OpenCL.cpp')
-rw-r--r--Source/Core/Common/Src/OpenCL.cpp69
1 files changed, 53 insertions, 16 deletions
diff --git a/Source/Core/Common/Src/OpenCL.cpp b/Source/Core/Common/Src/OpenCL.cpp
index 06f39fb79a..8aebb4e2d3 100644
--- a/Source/Core/Common/Src/OpenCL.cpp
+++ b/Source/Core/Common/Src/OpenCL.cpp
@@ -21,18 +21,19 @@
#include "Common.h"
namespace OpenCL {
-
-cl_context g_context = NULL;
-cl_command_queue g_cmdq = NULL;
+ #if defined(HAVE_OPENCL) && HAVE_OPENCL
+ cl_device_id device_id = NULL;
+ cl_context g_context = NULL;
+ cl_command_queue g_cmdq = NULL;
+ #endif
bool Initialize() {
- if(g_context)
- return false;
#if defined(HAVE_OPENCL) && HAVE_OPENCL
-
+ if(g_context)
+ return false;
int err; // error code returned from api calls
- cl_device_id device_id;
+
// Connect to a compute device
//
@@ -61,13 +62,13 @@ bool Initialize() {
PanicAlert("Error: Failed to create a command commands!\n");
return false;
}
-
+ printf("Initialized OpenCL fine!\n");
return true;
#else
return false;
#endif
}
-
+#if defined(HAVE_OPENCL) && HAVE_OPENCL
cl_context GetInstance() {
return g_context;
}
@@ -76,20 +77,56 @@ cl_command_queue GetCommandQueue() {
return g_cmdq;
}
-cl_program CompileProgram(const char *program, unsigned int size) {
- // TODO
- return NULL;
+cl_program CompileProgram(const char *Kernel) {
+ int err;
+ cl_program program;
+ program = clCreateProgramWithSource(OpenCL::g_context, 1, (const char **) & Kernel, NULL, &err);
+ if (!program)
+ {
+ printf("Error: Failed to create compute program!\n");
+ return NULL;
+ }
+
+ // Build the program executable
+ //
+ err = clBuildProgram(program , 0, NULL, NULL, NULL, NULL);
+ if (err != CL_SUCCESS)
+ {
+ size_t len;
+ char buffer[2048];
+
+ printf("Error: Failed to build program executable!\n");
+ clGetProgramBuildInfo(program , OpenCL::device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
+ printf("%s\n", buffer);
+ return NULL;
+ }
+
+
+ return program;
}
-
+cl_kernel CompileKernel(cl_program program, const char *Function)
+{
+ int err;
+ // Create the compute kernel in the program we wish to run
+ //
+ cl_kernel kernel = clCreateKernel(program, Function, &err);
+ if (!kernel || err != CL_SUCCESS)
+ {
+ printf("Error: Failed to create compute kernel!\n");
+ return NULL;
+ }
+ return kernel;
+}
+#endif
void Destroy() {
- if(!g_context)
- return;
#if defined(HAVE_OPENCL) && HAVE_OPENCL
+ if(!g_context)
+ return;
clReleaseCommandQueue(g_cmdq);
clReleaseContext(g_context);
#endif
}
-}; \ No newline at end of file
+};