@ -10,6 +10,7 @@
# include <CL/opencl.h>
# include <CL/opencl.h>
# elif defined _WIN32
# elif defined _WIN32
# include <CL/cl_gl.h>
# include <CL/cl.h>
# include <CL/cl.h>
# include <CL/opencl.h>
# include <CL/opencl.h>
# include <windows.h>
# include <windows.h>
@ -19,14 +20,13 @@
# include <OpenCL / opencl.h>
# include <OpenCL / opencl.h>
# endif
# endif
# include "TestPlatform.cpp"
# include "Map.h"
# include "Map.h"
# include "Curses.h"
# include "Curses.h"
# include "util.hpp"
# include "util.hpp"
# include "RayCaster.h"
# include "RayCaster.h"
const int WINDOW_X = 150 ;
const int WINDOW_X = 150 ;
const int WINDOW_Y = 150 ;
const int WINDOW_Y = 150 ;
@ -45,43 +45,82 @@ std::string read_file(std::string file_name){
int main ( ) {
int main ( ) {
char buffer [ 256 ] ;
char * val = getcwd ( buffer , sizeof ( buffer ) ) ;
if ( val ) {
std : : cout < < buffer < < std : : endl ;
}
// ===================================================================== //
// ==== Opencl setup
int error = 0 ;
int error = 0 ;
// ===================================================================== //
// ==== Opencl setup
// Get the number of platforms
// Get the number of platforms
cl_uint platformIdCount = 0 ;
cl_uint platform_c ount = 0 ;
clGetPlatformIDs ( 0 , nullptr , & platformIdCount ) ;
clGetPlatformIDs ( 0 , nullptr , & platform _c ount) ;
// Fetch the platforms
// Fetch the platforms
std : : vector < cl_platform_id > platformIds ( platformIdCount ) ;
std : : vector < cl_platform_id > platformIds ( platform_count ) ;
clGetPlatformIDs ( platformIdCount , platformIds . data ( ) , nullptr ) ;
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
// 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 ) ;
std : : vector < cl_device_id > deviceIds ( deviceIdCount ) ;
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 ;
cl_uint deviceIdCount = 0 ;
std : : vector < cl_device_id > deviceIds ;
std : : vector < cl_device_id > deviceIds ;
// Try to get a GPU first
// Try to get a GPU first
error = clGetDeviceIDs ( platformIds [ 0 ] , CL_DEVICE_TYPE_GPU , 0 , nullptr ,
error = clGetDeviceIDs ( platformIds [ 1 ] , CL_DEVICE_TYPE_GPU , 0 , nullptr ,
& deviceIdCount ) ;
& deviceIdCount ) ;
if ( deviceIdCount = = 0 ) {
if ( deviceIdCount = = 0 ) {
std : : cout < < " couldn't aquire a GPU, falling back to CPU " < < std : : endl ;
std : : cout < < " couldn't a c quire a GPU, falling back to CPU" < < std : : endl ;
error = clGetDeviceIDs ( platformIds [ 0 ] , CL_DEVICE_TYPE_CPU , 0 , nullptr , & deviceIdCount ) ;
error = clGetDeviceIDs ( platformIds [ 1 ] , CL_DEVICE_TYPE_CPU , 0 , nullptr , & deviceIdCount ) ;
deviceIds . resize ( 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 {
} else {
std : : cout < < " aquired GPU cl target " < < std : : endl ;
std : : cout < < " a c quired GPU cl target" < < std : : endl ;
deviceIds . resize ( deviceIdCount ) ;
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 ) {
if ( error ! = 0 ) {
std : : cout < < " Err: clGetDeviceIDs returned: " < < error < < std : : endl ;
std : : cout < < " Err: clGetDeviceIDs returned: " < < error < < std : : endl ;
return error ;
return error ;
@ -98,12 +137,16 @@ int main(){
} ;
} ;
# elif defined _WIN32
# elif defined _WIN32
cl_context_properties context_properties [ ] = {
//cl_context_properties context_properties[] = {
CL_GL_CONTEXT_KHR , ( cl_context_properties ) wglGetCurrentContext ( ) ,
// CL_CONTEXT_PLATFORM, (cl_context_properties) platformIds[0],
CL_WGL_HDC_KHR , ( cl_context_properties ) wglGetCurrentDC ( ) ,
// CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
CL_CONTEXT_PLATFORM , ( cl_context_properties ) platform ,
// CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(),
0
// 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
# elif defined TARGET_OS_MAC
CGLContextObj glContext = CGLGetCurrentContext ( ) ;
CGLContextObj glContext = CGLGetCurrentContext ( ) ;
@ -119,12 +162,18 @@ int main(){
// Create our shared context
// Create our shared context
auto context = clCreateContext (
auto context = clCreateContext (
context_properties ,
context_properties ,
deviceIdCount ,
1 ,
deviceIds . data ( ) ,
& deviceIds [ 0 ] ,
nullptr , nullptr ,
nullptr , nullptr ,
& error
& 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 ) {
if ( error ! = 0 ) {
std : : cout < < " Err: clCreateContext returned: " < < error < < std : : endl ;
std : : cout < < " Err: clCreateContext returned: " < < error < < std : : endl ;
return error ;
return error ;