Refactored and commented the Hardware Caster. Cleaned up many small things

This commit is contained in:
MitchellHansen
2017-03-18 17:15:25 -07:00
parent 50c6d68944
commit 3aaffce566
9 changed files with 131 additions and 70 deletions

View File

@@ -1,9 +1,4 @@
#include "LightController.h"
#include "LightHandle.h"
#include <numeric>
#include <SFML/System/Time.hpp>
LightController::LightController(std::shared_ptr<Hardware_Caster> raycaster) : packed_data_array(reserved_count), open_list(reserved_count) {

View File

@@ -93,7 +93,6 @@ int main() {
// ni.listen_for_clients(5000);
// ni.stop_listening_for_clients();
// =============================
// Map _map(sf::Vector3i(0, 0, 0));
// _map.generate_octree();
@@ -109,12 +108,6 @@ int main() {
ImGui::SFML::Init(window);
window.resetGLStates();
/*GL_Testing t;
t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT);
t.compile_shader("../shaders/passthrough.vert", GL_Testing::Shader_Type::VERTEX);
t.create_program();
t.create_buffers();*/
// Start up the raycaster
std::shared_ptr<Hardware_Caster> raycaster(new Hardware_Caster());
@@ -155,33 +148,24 @@ int main() {
std::shared_ptr<LightHandle> handle(light_controller.create_light(prototype));
// Load in the spritesheet texture
sf::Texture spritesheet;
spritesheet.loadFromFile("../assets/textures/minecraft_tiles.png");
//spritesheet.getNativeHandle();
raycaster->create_texture_atlas(&spritesheet, sf::Vector2i(16, 16));
// Checks to see if proper data was uploaded, then sets the kernel args
// ALL DATA LOADING MUST BE FINISHED
raycaster->validate();
// ========== DEBUG ==========
fps_counter fps;
// ===========================
Input input_handler;
camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyHeld);
camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed);
camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::MouseMoved);
//handle->subscribe_to_publisher(&ni, vr::Event::EventType::JoystickMoved);
WindowHandler win_hand(&window);
win_hand.subscribe_to_publisher(&input_handler, vr::Event::EventType::Closed);
// 16.6 milliseconds (60FPS)
float step_size = 0.0166f;
double frame_time = 0.0,
elapsed_time = 0.0,
@@ -192,6 +176,7 @@ int main() {
// The sfml imgui wrapper I'm using requires Update be called with sf::Time
// Might modify it to also accept seconds
sf::Clock sf_delta_clock;
fps_counter fps;
while (window.isOpen()) {

View File

@@ -16,10 +16,6 @@ int Hardware_Caster::init() {
if(vr_assert(error, "aquire_platform_and_device"))
return error;
error = check_cl_khr_gl_sharing();
if(vr_assert(error, "check_cl_khr_gl_sharing"))
return error;
error = create_shared_context();
if (vr_assert(error, "create_shared_context"))
return error;
@@ -265,7 +261,7 @@ void Hardware_Caster::test_edit_viewport(int width, int height, float v_fov, flo
ray.y,
ray.z,
0
);
);
}
}
}
@@ -294,9 +290,9 @@ int Hardware_Caster::acquire_platform_and_device() {
cl_uint deviceIdCount = 0;
error = clGetDeviceIDs(plt_buf[i], CL_DEVICE_TYPE_ALL, 0, nullptr, &deviceIdCount);
// Check to see if we even have opencl on this machine
// Check to see if we even have OpenCL on this machine
if (deviceIdCount == 0) {
std::cout << "There appears to be no platforms supporting opencl" << std::endl;
std::cout << "There appears to be no platforms supporting OpenCL" << std::endl;
return OPENCL_NOT_SUPPORTED;
}
@@ -318,6 +314,40 @@ int Hardware_Caster::acquire_platform_and_device() {
clGetDeviceInfo(d.id, CL_DEVICE_TYPE, sizeof(cl_device_type), &d.type, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(cl_uint), &d.clock_frequency, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &d.comp_units, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_EXTENSIONS, 1024, &d.extensions, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_NAME, 256, &d.name, NULL);
std::cout << "Device: " << q << std::endl;
std::cout << "Device Name : " << d.name << std::endl;
std::cout << "Platform ID : " << d.platform << std::endl;
std::cout << "Device Version : " << d.version << std::endl;
std::cout << "Device Type : ";
if (d.type == CL_DEVICE_TYPE_CPU)
std::cout << "CPU" << std::endl;
else if (d.type == CL_DEVICE_TYPE_GPU)
std::cout << "GPU" << std::endl;
else if (d.type == CL_DEVICE_TYPE_ACCELERATOR)
std::cout << "Accelerator" << std::endl;
std::cout << "Max clock frequency : " << d.clock_frequency << std::endl;
std::cout << "Max compute units : " << d.comp_units << std::endl;
std::cout << "cl_khr_gl_sharing supported: ";
if (std::string(d.extensions).find("cl_khr_gl_sharing") == std::string::npos &&
std::string(d.extensions).find("cl_APPLE_gl_sharing") == std::string::npos) {
std::cout << "False" << std::endl;
}
std::cout << "True" << std::endl;
d.cl_gl_sharing = true;
std::cout << "Extensions supported: " << std::endl;
std::cout << std::string(d.extensions) << std::endl;
std::cout << " ===================================================================================== " << std::endl;
plt_ids.at(d.platform).push_back(d);
}
@@ -342,13 +372,22 @@ int Hardware_Caster::acquire_platform_and_device() {
// Upon success of a condition, set the current best device values
// If the current device is not a GPU and we are comparing it to a GPU
if (device.type == CL_DEVICE_TYPE_GPU && current_best_device.type != CL_DEVICE_TYPE_GPU) {
current_best_device = device;
}
else if (device.comp_units > current_best_device.comp_units) {
// Get the unit with the higher compute units
if (device.comp_units > current_best_device.comp_units) {
current_best_device = device;
}
else if (current_best_device.type != CL_DEVICE_TYPE_GPU && device.clock_frequency > current_best_device.clock_frequency) {
// If we are comparing CPU to CPU get the one with the best clock
if (current_best_device.type != CL_DEVICE_TYPE_GPU && device.clock_frequency > current_best_device.clock_frequency) {
current_best_device = device;
}
if (current_best_device.cl_gl_sharing == false && device.cl_gl_sharing == true) {
current_best_device = device;
}
}
@@ -357,6 +396,15 @@ int Hardware_Caster::acquire_platform_and_device() {
platform_id = current_best_device.platform;
device_id = current_best_device.id;
std::cout << std::endl;
std::cout << "Selected Platform : " << platform_id << std::endl;
std::cout << "Selected Device : " << device_id << std::endl;
std::cout << "Selected Name : " << current_best_device.name << std::endl;
if (current_best_device.cl_gl_sharing == false) {
std::cout << "This device does not support the cl_khr_gl_sharing extension" << std::endl;
return RayCaster::SHARING_NOT_SUPPORTED;
}
return 1;
};
@@ -431,24 +479,7 @@ int Hardware_Caster::create_command_queue() {
}
}
int Hardware_Caster::check_cl_khr_gl_sharing() {
// Test for sharing
size_t ext_str_size = 1024;
char *ext_str = new char[ext_str_size];
clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, ext_str_size, ext_str, &ext_str_size);
std::cout << std::string(ext_str);
if (std::string(ext_str).find("cl_khr_gl_sharing") == std::string::npos &&
std::string(ext_str).find("cl_APPLE_gl_sharing") == std::string::npos) {
std::cout << "No support for the cl_khr_gl_sharing extension";
delete ext_str;
return RayCaster::SHARING_NOT_SUPPORTED;
}
delete ext_str;
return 1;
}
int Hardware_Caster::compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name) {