that was a pain. Got it working on windows again. MSVC was being really

picky about a few errors. Good thing though, I'm not really sure why
clang + osx let me be that lax with memory
master
MitchellHansen 8 years ago
parent 9c99f9edd0
commit f487895f9f

@ -25,6 +25,7 @@ struct device {
cl_uint clock_frequency; cl_uint clock_frequency;
char version[128]; char version[128];
cl_platform_id platform; cl_platform_id platform;
cl_uint comp_units;
}; };
class CL_Wrapper { class CL_Wrapper {

@ -48,17 +48,17 @@ __kernel void min_kern(
// Setup the voxel coords from the camera origin // Setup the voxel coords from the camera origin
int3 voxel = { int3 voxel = {
floorf(cam_pos->x), floor(cam_pos->x),
floorf(cam_pos->y), floor(cam_pos->y),
floorf(cam_pos->z) floor(cam_pos->z)
}; };
// Delta T is the units a ray must travel along an axis in order to // Delta T is the units a ray must travel along an axis in order to
// traverse an integer split // traverse an integer split
float3 delta_t = { float3 delta_t = {
fabsf(1.0f / ray_dir.x), fabs(1.0f / ray_dir.x),
fabsf(1.0f / ray_dir.y), fabs(1.0f / ray_dir.y),
fabsf(1.0f / ray_dir.z) fabs(1.0f / ray_dir.z)
}; };
// Intersection T is the collection of the next intersection points // Intersection T is the collection of the next intersection points

@ -44,10 +44,11 @@ int CL_Wrapper::acquire_platform_and_device(){
d.id = deviceIds[q]; d.id = deviceIds[q];
clGetDeviceInfo(d.id, CL_DEVICE_PLATFORM, 128, &d.platform, NULL); clGetDeviceInfo(d.id, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), &d.platform, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_VERSION, 128, &d.version, NULL); clGetDeviceInfo(d.id, CL_DEVICE_VERSION, sizeof(char) * 128, &d.version, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_TYPE, 128, &d.type, NULL); clGetDeviceInfo(d.id, CL_DEVICE_TYPE, sizeof(cl_device_type), &d.type, NULL);
clGetDeviceInfo(d.id, CL_DEVICE_MAX_CLOCK_FREQUENCY, 128, &d.clock_frequency, 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);
plt_ids.at(d.platform).push_back(d); plt_ids.at(d.platform).push_back(d);
} }
@ -58,7 +59,8 @@ int CL_Wrapper::acquire_platform_and_device(){
// falling back to the cpu with the fastest clock if we weren't able to find one // falling back to the cpu with the fastest clock if we weren't able to find one
device current_best_device; device current_best_device;
current_best_device.clock_frequency = 0; // Set this to 0 so the first run always selects a new device current_best_device.type = -1; // Set this to -1 so the first run always selects a new device
for (auto kvp: plt_ids){ for (auto kvp: plt_ids){
@ -72,7 +74,10 @@ int CL_Wrapper::acquire_platform_and_device(){
if (device.type == CL_DEVICE_TYPE_GPU && current_best_device.type != CL_DEVICE_TYPE_GPU){ if (device.type == CL_DEVICE_TYPE_GPU && current_best_device.type != CL_DEVICE_TYPE_GPU){
current_best_device = device; current_best_device = device;
} }
else if (device.clock_frequency > current_best_device.clock_frequency){ else 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){
current_best_device = device; current_best_device = device;
} }
} }
@ -108,7 +113,7 @@ int CL_Wrapper::create_shared_context() {
//}; //};
HGLRC hGLRC = wglGetCurrentContext(); HGLRC hGLRC = wglGetCurrentContext();
HDC hDC = wglGetCurrentDC(); 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 }; cl_context_properties context_properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform_id, 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
@ -206,6 +211,8 @@ int CL_Wrapper::compile_kernel(std::string kernel_source, bool is_path, std::str
return -1; return -1;
kernel_map.emplace(std::make_pair(kernel_name, kernel)); kernel_map.emplace(std::make_pair(kernel_name, kernel));
return 1;
} }
int CL_Wrapper::set_kernel_arg( int CL_Wrapper::set_kernel_arg(
@ -228,6 +235,7 @@ int CL_Wrapper::set_kernel_arg(
int CL_Wrapper::store_buffer(cl_mem buffer, std::string buffer_name){ int CL_Wrapper::store_buffer(cl_mem buffer, std::string buffer_name){
buffer_map.emplace(std::make_pair(buffer_name, buffer)); buffer_map.emplace(std::make_pair(buffer_name, buffer));
return 1;
} }
int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){ int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
@ -246,7 +254,7 @@ int CL_Wrapper::run_kernel(std::string kernel_name, const int work_size){
if (assert(error, "clEnqueueNDRangeKernel")) if (assert(error, "clEnqueueNDRangeKernel"))
return -1; return -1;
return 1;
} }

@ -1,13 +1,16 @@
#pragma once #pragma once
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <OpenCL/cl_ext.h>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#ifdef linux #ifdef linux
#elif defined _WIN32 #elif defined _WIN32
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl_gl.h>
#include <CL/cl.h>
#include <CL/opencl.h>
#elif defined TARGET_OS_MAC #elif defined TARGET_OS_MAC
# include <OpenGL/OpenGL.h> # include <OpenGL/OpenGL.h>
@ -111,6 +114,21 @@ inline int query_platform_devices() {
clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL); clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL);
fprintf(stdout, "%s\n", buf); fprintf(stdout, "%s\n", buf);
//cl_device_type a;
//clGetDeviceInfo(devices[i], CL_DEVICE_TYPE, 128, &a, NULL);
//std::cout << a << std::endl;
//cl_uint b;
//clGetDeviceInfo(devices[i], CL_DEVICE_MAX_CLOCK_FREQUENCY, 128, &b, NULL);
//std::cout << b << std::endl;
//cl_uint c;
//clGetDeviceInfo(devices[i], CL_DEVICE_MAX_COMPUTE_UNITS, 128, &c, NULL);
//std::cout << c << std::endl;
std::cout << devices[i] << std::endl;
} }
free(devices); free(devices);

@ -9,9 +9,12 @@
#include <CL/opencl.h> #include <CL/opencl.h>
#elif defined _WIN32 #elif defined _WIN32
#include <windows.h>
#include <CL/cl_gl.h> #include <CL/cl_gl.h>
#include <CL/cl.h> #include <CL/cl.h>
#include <CL/opencl.h> #include <CL/opencl.h>
#include <GL/GL.h>
#include <windows.h> #include <windows.h>
#elif defined TARGET_OS_MAC #elif defined TARGET_OS_MAC
@ -66,12 +69,13 @@ int main() {
sf::Texture t; sf::Texture t;
CL_Wrapper c; CL_Wrapper c;
query_platform_devices();
c.acquire_platform_and_device(); c.acquire_platform_and_device();
c.create_shared_context(); c.create_shared_context();
c.create_command_queue(); c.create_command_queue();
c.compile_kernel("../kernels/kernel.c", true, "hello"); //c.compile_kernel("../kernels/kernel.cl", true, "hello");
c.compile_kernel("../kernels/minimal_kernel.c", true, "min_kern"); c.compile_kernel("../kernels/minimal_kernel.cl", true, "min_kern");
sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z); sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z);
Map* map = new Map(map_dim); Map* map = new Map(map_dim);
@ -101,7 +105,7 @@ int main() {
// SFML 2.4 has Vector4 datatypes....... // SFML 2.4 has Vector4 datatypes.......
float view_matrix[view_res.x * view_res.y * 4]; float* view_matrix = new float[WINDOW_X * WINDOW_Y * 4];
for (int y = -view_res.y / 2; y < view_res.y / 2; y++) { for (int y = -view_res.y / 2; y < view_res.y / 2; y++) {
for (int x = -view_res.x / 2; x < view_res.x / 2; x++) { for (int x = -view_res.x / 2; x < view_res.x / 2; x++) {

Loading…
Cancel
Save