@ -3,14 +3,6 @@
CLCaster : : CLCaster ( ) { }
CLCaster : : CLCaster ( ) { }
CLCaster : : ~ CLCaster ( ) {
CLCaster : : ~ CLCaster ( ) {
// Causes sigabrt??
//release_map();
//release_camera();
//release_octree();
//clReleaseKernel(kernel_map.at("raycaster"));
//clReleaseProgram()
//release_viewport();
delete [ ] viewport_matrix ;
delete [ ] viewport_matrix ;
delete [ ] viewport_image ;
delete [ ] viewport_image ;
@ -64,11 +56,10 @@ bool CLCaster::init() {
return false ;
return false ;
}
}
if ( ! compile_kernel ( " ../kernels/ray_caster_kernel.cl " , true , " raycaster " ) ) {
if ( ! create_settings_buffer ( ) ) {
Logger : : log ( " Failed to compile the kernel " , Logger : : LogLevel : : ERROR , __LINE__ , __FILE__ ) ;
Logger : : log ( " Failed to create settings buffer " , Logger : : LogLevel : : ERROR , __LINE__ , __FILE__ ) ;
std : : cin . get ( ) ; // hang the output window so we can read the error
return false ;
return false ;
}
}
srand ( time ( nullptr ) ) ;
srand ( time ( nullptr ) ) ;
@ -117,8 +108,8 @@ bool CLCaster::assign_octree(std::shared_ptr<Map> map) {
return false ;
return false ;
if ( ! create_buffer ( " octree_attachment_buffer " , map - > octree . buffer_size * sizeof ( uint64_t ) , map - > octree . attachment_buffer ) )
if ( ! create_buffer ( " octree_attachment_buffer " , map - > octree . buffer_size * sizeof ( uint64_t ) , map - > octree . attachment_buffer ) )
return false ;
return false ;
if ( ! create_buffer ( " settings_buffer " , sizeof ( uint64_t ) , & map - > octree . root_index ) )
return false ;
add_to_settings_buffer ( " octree_root_index " , " OCTREE_ROOT_INDEX " , ( int64_t * ) & map - > octree . root_index ) ;
return true ;
return true ;
}
}
@ -134,8 +125,6 @@ bool CLCaster::release_octree()
return false ;
return false ;
if ( ! release_buffer ( " octree_attachment_buffer " ) )
if ( ! release_buffer ( " octree_attachment_buffer " ) )
return false ;
return false ;
if ( ! release_buffer ( " settings_buffer " ) )
return false ;
return true ;
return true ;
}
}
@ -166,6 +155,12 @@ bool CLCaster::release_camera() {
bool CLCaster : : validate ( ) {
bool CLCaster : : validate ( ) {
if ( ! compile_kernel ( " ../kernels/ray_caster_kernel.cl " , true , " raycaster " ) ) {
Logger : : log ( " Failed to compile the kernel " , Logger : : LogLevel : : ERROR , __LINE__ , __FILE__ ) ;
std : : cin . get ( ) ; // hang the output window so we can read the error
return false ;
}
Logger : : log ( " Validating OpenCL kernel args " , Logger : : LogLevel : : INFO ) ;
Logger : : log ( " Validating OpenCL kernel args " , Logger : : LogLevel : : INFO ) ;
// Check to make sure everything has been entered
// Check to make sure everything has been entered
@ -278,7 +273,7 @@ bool CLCaster::create_viewport(int width, int height, float v_fov, float h_fov)
}
}
}
}
if ( ! create_buffer ( " viewport_matrix " , sizeof ( float ) * 4 * view_res . x * view_res . y , viewport_matrix , CL_MEM_USE_HOST_PTR ))
if ( ! create_buffer ( " viewport_matrix " , sizeof ( float ) * 4 * view_res . x * view_res . y , viewport_matrix ))
return false ;
return false ;
// Create the image that opencl's rays write to
// Create the image that opencl's rays write to
@ -635,7 +630,6 @@ bool CLCaster::create_shared_context()
0
0
} ;
} ;
# elif defined TARGET_OS_MAC
# elif defined TARGET_OS_MAC
CGLContextObj glContext = CGLGetCurrentContext ( ) ;
CGLContextObj glContext = CGLGetCurrentContext ( ) ;
@ -648,8 +642,6 @@ bool CLCaster::create_shared_context()
# endif
# endif
// Create our shared context
// Create our shared context
context = clCreateContext (
context = clCreateContext (
context_properties ,
context_properties ,
@ -719,7 +711,6 @@ bool CLCaster::compile_kernel(std::string kernel_source, bool is_path, std::stri
return false ;
return false ;
}
}
std : : stringstream build_string_stream ;
std : : stringstream build_string_stream ;
// walk the settings index's and add them to the defines
// walk the settings index's and add them to the defines
@ -727,7 +718,6 @@ bool CLCaster::compile_kernel(std::string kernel_source, bool is_path, std::stri
build_string_stream < < " -D " < < define . first < < " = " < < define . second ;
build_string_stream < < " -D " < < define . first < < " = " < < define . second ;
}
}
//build_string_stream << "-DOCTDIM=" << std::to_string(Application::MAP_X);
build_string_stream < < " -cl-finite-math-only -cl-fast-relaxed-math -cl-unsafe-math-optimizations " ;
build_string_stream < < " -cl-finite-math-only -cl-fast-relaxed-math -cl-unsafe-math-optimizations " ;
std : : string build_string = build_string_stream . str ( ) ;
std : : string build_string = build_string_stream . str ( ) ;
@ -1177,14 +1167,63 @@ std::string CLCaster::cl_err_lookup(int error_code) {
}
}
void CLCaster : : set D efine( std : : string name , std : : string value ) {
void CLCaster : : set _d efine( std : : string name , std : : string value ) {
defines_map [ name ] = value ;
defines_map [ name ] = value ;
}
}
void CLCaster : : remove D efine( std : : string name ) {
void CLCaster : : remove _d efine( std : : string name ) {
defines_map . erase ( name ) ;
defines_map . erase ( name ) ;
}
}
bool CLCaster : : add_to_settings_buffer ( std : : string setting_name , std : : string define_accessor_name , int64_t * value ) {
bool success = true ;
if ( settings_buffer = = nullptr ) {
Logger : : log ( " Trying to push settings to an uninitialized settings buffer " , Logger : : LogLevel : : ERROR , __LINE__ , __FILE__ ) ;
success = false ;
} else if ( defines_map . count ( define_accessor_name ) ) {
Logger : : log ( " Define name already present in the defines map " , Logger : : LogLevel : : ERROR , __LINE__ , __FILE__ ) ;
success = false ;
} else {
if ( settings_buffer_position < SETTINGS_BUFFER_SIZE ) {
defines_map [ define_accessor_name ] = std : : to_string ( settings_buffer_position ) ;
settings_buffer [ settings_buffer_position ] = * value ;
settings_buffer_position + + ;
} else {
Logger : : log ( " Settings buffer has reached the maximum size of " + std : : to_string ( SETTINGS_BUFFER_SIZE ) + " elements " , Logger : : LogLevel : : ERROR , __LINE__ , __FILE__ ) ;
success = false ;
}
}
return success ;
}
bool CLCaster : : create_settings_buffer ( ) {
settings_buffer = new int64_t [ SETTINGS_BUFFER_SIZE ] ;
if ( ! create_buffer ( " settings_buffer " , sizeof ( int64_t ) * SETTINGS_BUFFER_SIZE , settings_buffer , CL_MEM_USE_HOST_PTR ) )
return false ;
return true ;
}
bool CLCaster : : remove_from_settings_buffer ( std : : string setting_name ) {
Logger : : log ( " remove_from_settings_buffer() not implimented " , Logger : : LogLevel : : WARN , __LINE__ , __FILE__ ) ;
return false ;
}
bool CLCaster : : release_settings_buffer ( ) {
if ( ! release_buffer ( " settings_buffer " ) )
return false ;
return true ;
}
CLCaster : : device : : device ( cl_device_id device_id , cl_platform_id platform_id ) {
CLCaster : : device : : device ( cl_device_id device_id , cl_platform_id platform_id ) {
@ -1237,26 +1276,25 @@ CLCaster::device::device(const device& d) {
void CLCaster : : device : : print ( std : : ostream & stream ) const {
void CLCaster : : device : : print ( std : : ostream & stream ) const {
stream < < " \n \t Device ID : " < < device_id < < std : : endl ;
stream < < " \n \t Device ID : " < < device_id < < std : : endl ;
stream < < " \t Device Name : " < < data . device_name < < std : : endl ;
stream < < " \t Platform ID : " < < platform_id < < std : : endl ;
stream < < " \t Platform ID : " < < platform_id < < std : : endl ;
stream < < " \t Device Name : " < < data . device_name < < std : : endl ;
stream < < " \t Platform Name : " < < data . platform_name < < std : : endl ;
stream < < " \t Platform Name : " < < data . platform_name < < std : : endl ;
stream < < " \t Device Type : " ;
stream < < " \t OpenCL Version : " < < data . opencl_version < < std : : endl ;
if ( data . device_type = = CL_DEVICE_TYPE_CPU )
stream < < " \t Supports sharing : " < < std : : boolalpha < < cl_gl_sharing < < std : : endl ;
stream < < " CPU " < < std : : endl ;
stream < < " \t Device Type : " ;
if ( data . device_type = = CL_DEVICE_TYPE_C PU)
else if ( data . device_type = = CL_DEVICE_TYPE_G PU)
stream < < " C PU" < < std : : endl ;
stream < < " G PU" < < std : : endl ;
else if ( data . device_type = = CL_DEVICE_TYPE_ GPU )
else if ( data . device_type = = CL_DEVICE_TYPE_ ACCELERATOR )
stream < < " GPU " < < std : : endl ;
stream < < " Accelerator " < < std : : endl ;
else if ( data . device_type = = CL_DEVICE_TYPE_ACCELERATOR )
stream < < " \t OpenCL Version : " < < data . opencl_version < < std : : endl ;
stream < < " Accelerator " < < std : : endl ;
stream < < " \t Supports sharing : " < < std : : boolalpha < < cl_gl_sharing < < std : : endl ;
stream < < " \t Is Little Endian : " < < std : : boolalpha < < is_little_endian < < std : : endl ;
stream < < " \t Is Little Endian : " < < std : : boolalpha < < is_little_endian < < std : : endl ;
stream < < " \t Clock Frequency : " < < data . clock_frequency < < std : : endl ;
stream < < " \t Clock Frequency : " < < data . clock_frequency < < std : : endl ;
stream < < " \t Compute Units : " < < data . compute_units < < std : : endl ;
stream < < " \t Compute Units : " < < data . compute_units < < std : : endl ;