@ -10,6 +10,7 @@
# include <CL/opencl.h>
# elif defined _WIN32
# include <CL/cl_gl.h>
# include <CL/cl.h>
# include <CL/opencl.h>
# include <windows.h>
@ -19,14 +20,13 @@
# include <OpenCL / opencl.h>
# endif
# include "TestPlatform.cpp"
# include "Map.h"
# include "Curses.h"
# include "util.hpp"
# include "RayCaster.h"
const int WINDOW_X = 150 ;
const int WINDOW_Y = 150 ;
@ -45,43 +45,82 @@ std::string read_file(std::string file_name){
int main ( ) {
char buffer [ 256 ] ;
char * val = getcwd ( buffer , sizeof ( buffer ) ) ;
if ( val ) {
std : : cout < < buffer < < std : : endl ;
}
int error = 0 ;
// ===================================================================== //
// ==== Opencl setup
int error = 0 ;
// Get the number of platforms
cl_uint platform_count = 0 ;
clGetPlatformIDs ( 0 , nullptr , & platform_count ) ;
// Fetch the platforms
std : : vector < cl_platform_id > platformIds ( platform_count ) ;
clGetPlatformIDs ( platform_count , platformIds . data ( ) , nullptr ) ;
// Print out this machines info
std : : cout < < " ============ Hardware info ================= " < < std : : endl ;
for ( unsigned int i = 0 ; i < platform_count ; i + + ) {
std : : cout < < " --Platform: " < < i < < std : : endl ;
char platform [ 128 ] ;
char version [ 128 ] ;
clGetPlatformInfo ( platformIds [ i ] , CL_PLATFORM_NAME , 128 , platform , NULL ) ;
clGetPlatformInfo ( platformIds [ i ] , CL_PLATFORM_VERSION , 128 , version , NULL ) ;
std : : cout < < platform < < " \n " ;
std : : cout < < version < < " \n \n " ;
// get the number of devices, fetch them, choose the first one
cl_uint deviceIdCount = 0 ;
error = clGetDeviceIDs ( platformIds [ i ] , CL_DEVICE_TYPE_ALL , 0 , nullptr , & deviceIdCount ) ;
// Get the number of platforms
cl_uint platformIdCount = 0 ;
clGetPlatformIDs ( 0 , nullptr , & platformIdCount ) ;
std : : vector < cl_device_id > deviceIds ( deviceIdCount ) ;
// Fetch the platforms
std : : vector < cl_platform_id > platformIds ( platformIdCount ) ;
clGetPlatformIDs ( platformIdCount , platformIds . data ( ) , nullptr ) ;
for ( int q = 0 ; q < deviceIdCount ; q + + ) {
std : : cout < < " ++++Device " < < q < < std : : endl ;
error = clGetDeviceIDs ( platformIds [ i ] , CL_DEVICE_TYPE_ALL , deviceIdCount , deviceIds . data ( ) , NULL ) ;
clGetDeviceInfo ( deviceIds [ q ] , CL_DEVICE_NAME , 128 , platform , NULL ) ;
clGetDeviceInfo ( deviceIds [ q ] , CL_DEVICE_VERSION , 128 , version , NULL ) ;
std : : cout < < platform < < " \n " ;
std : : cout < < version < < " \n \n " ;
}
}
std : : cout < < " ============================================ " < < std : : endl ;
cl_uint deviceIdCount = 0 ;
std : : vector < cl_device_id > deviceIds ;
// Try to get a GPU first
error = clGetDeviceIDs ( platformIds [ 1 ] , CL_DEVICE_TYPE_GPU , 0 , nullptr ,
& deviceIdCount ) ;
// get the number of devices, fetch them, choose the first one
cl_uint deviceIdCount = 0 ;
std : : vector < cl_device_id > deviceIds ;
// Try to get a GPU first
error = clGetDeviceIDs ( platformIds [ 0 ] , CL_DEVICE_TYPE_GPU , 0 , nullptr ,
& deviceIdCount ) ;
if ( deviceIdCount = = 0 ) {
std : : cout < < " couldn't aquire a GPU, falling back to CPU " < < std : : endl ;
error = clGetDeviceIDs ( platformIds [ 0 ] , CL_DEVICE_TYPE_CPU , 0 , nullptr , & deviceIdCount ) ;
std : : cout < < " couldn't acquire a GPU, falling back to CPU " < < std : : endl ;
error = clGetDeviceIDs ( platformIds [ 1 ] , CL_DEVICE_TYPE_CPU , 0 , nullptr , & deviceIdCount ) ;
deviceIds . resize ( deviceIdCount ) ;
error = clGetDeviceIDs ( platformIds [ 0 ] , CL_DEVICE_TYPE_CPU , deviceIdCount , deviceIds . data ( ) , NULL ) ;
error = clGetDeviceIDs ( platformIds [ 1 ] , CL_DEVICE_TYPE_CPU , deviceIdCount , deviceIds . data ( ) , NULL ) ;
} else {
std : : cout < < " aquired GPU cl target " < < std : : endl ;
std : : cout < < " a c quired GPU cl target" < < std : : endl ;
deviceIds . resize ( deviceIdCount ) ;
clGetDeviceIDs ( platformIds [ 0 ] , CL_DEVICE_TYPE_GPU , deviceIdCount , deviceIds . data ( ) , nullptr ) ;
clGetDeviceIDs ( platformIds [ 1 ] , CL_DEVICE_TYPE_GPU , deviceIdCount , deviceIds . data ( ) , nullptr ) ;
}
if ( error ! = 0 ) {
std : : cout < < " Err: clGetDeviceIDs returned: " < < error < < std : : endl ;
return error ;
@ -98,12 +137,16 @@ int main(){
} ;
# elif defined _WIN32
cl_context_properties context_properties [ ] = {
CL_GL_CONTEXT_KHR , ( cl_context_properties ) wglGetCurrentContext ( ) ,
CL_WGL_HDC_KHR , ( cl_context_properties ) wglGetCurrentDC ( ) ,
CL_CONTEXT_PLATFORM , ( cl_context_properties ) platform ,
0
} ;
//cl_context_properties context_properties[] = {
// CL_CONTEXT_PLATFORM, (cl_context_properties) platformIds[0],
// CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
// CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(),
// 0
//};
HGLRC hGLRC = wglGetCurrentContext ( ) ;
HDC hDC = wglGetCurrentDC ( ) ;
cl_context_properties context_properties [ ] = { CL_CONTEXT_PLATFORM , ( cl_context_properties ) platformIds [ 1 ] , CL_GL_CONTEXT_KHR , ( cl_context_properties ) hGLRC , CL_WGL_HDC_KHR , ( cl_context_properties ) hDC , 0 } ;
# elif defined TARGET_OS_MAC
CGLContextObj glContext = CGLGetCurrentContext ( ) ;
@ -117,13 +160,19 @@ int main(){
# endif
// Create our shared context
auto context = clCreateContext (
context_properties ,
deviceIdCount ,
deviceIds . data ( ) ,
nullptr , nullptr ,
& error
) ;
auto context = clCreateContext (
context_properties ,
1 ,
& deviceIds [ 0 ] ,
nullptr , nullptr ,
& error
) ;
//cl_device_id devices[32];
//size_t size;
//clGetGLContextInfoKHR(context_properties, CL_DEVICES_FOR_GL_CONTEXT_KHR,
// 32 * sizeof(cl_device_id), devices, &size);
if ( error ! = 0 ) {
std : : cout < < " Err: clCreateContext returned: " < < error < < std : : endl ;