diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-08-11 16:36:08 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-08-11 16:36:08 +0400 |
commit | 6686f189480c4de3e91f49a76811bf006ed9f9b2 (patch) | |
tree | bb7184c7e0117c2766eeb727448d9460113b705a /intern | |
parent | 18d709022e3ad2208382157a566095c406504d24 (diff) |
Cycles: more opencl tweaks, status is:
* kernel has shading nodes / textures disabled, amd/nvidia opencl
compilers choke on these, need to figure out how to avoid this
* works in cycles_test, not available as option in blender yet
* kernel compiles and runs with opencl 1.1 from intel/amd/nvidia
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/app/cycles_test.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/device/device_opencl.cpp | 45 | ||||
-rw-r--r-- | intern/cycles/kernel/CMakeLists.txt | 18 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_compat_opencl.h | 7 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_types.h | 2 |
5 files changed, 44 insertions, 30 deletions
diff --git a/intern/cycles/app/cycles_test.cpp b/intern/cycles/app/cycles_test.cpp index 2603458f088..698974b6277 100644 --- a/intern/cycles/app/cycles_test.cpp +++ b/intern/cycles/app/cycles_test.cpp @@ -284,7 +284,7 @@ using namespace ccl; int main(int argc, const char **argv) { - path_init(); + path_init("../blender/intern/cycles"); options_parse(argc, argv); diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp index ef416dfb8dc..34c92986f46 100644 --- a/intern/cycles/device/device_opencl.cpp +++ b/intern/cycles/device/device_opencl.cpp @@ -45,7 +45,7 @@ CCL_NAMESPACE_BEGIN class OpenCLDevice : public Device { public: - cl_context cxGPUContext; + cl_context cxContext; cl_command_queue cqCommandQueue; cl_platform_id cpPlatform; cl_device_id cdDevice; @@ -121,18 +121,27 @@ public: OpenCLDevice(bool background_) { background = background_; + vector<cl_platform_id> platform_ids; + cl_uint num_platforms; /* setup device */ - ciErr = clGetPlatformIDs(1, &cpPlatform, NULL); + ciErr = clGetPlatformIDs(0, NULL, &num_platforms); opencl_assert(ciErr); + assert(num_platforms != 0); - ciErr = clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_CPU, 1, &cdDevice, NULL); + platform_ids.resize(num_platforms); + ciErr = clGetPlatformIDs(num_platforms, &platform_ids[0], NULL); opencl_assert(ciErr); - cxGPUContext = clCreateContext(0, 1, &cdDevice, NULL, NULL, &ciErr); + cpPlatform = platform_ids[0]; /* todo: pick specified platform && device */ + + ciErr = clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_ALL, 1, &cdDevice, NULL); + opencl_assert(ciErr); + + cxContext = clCreateContext(0, 1, &cdDevice, NULL, NULL, &ciErr); opencl_assert(ciErr); - cqCommandQueue = clCreateCommandQueue(cxGPUContext, cdDevice, 0, &ciErr); + cqCommandQueue = clCreateCommandQueue(cxContext, cdDevice, 0, &ciErr); opencl_assert(ciErr); /* compile kernel */ @@ -141,15 +150,11 @@ public: string build_options = ""; - //string csource = "../blender/intern/cycles"; - //build_options += "-I " + csource + "/kernel -I " + csource + "/util"; - - build_options += " -I " + path_get("kernel"); /* todo: escape path */ - - build_options += " -Werror"; - build_options += " -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END="; + string csource = "../blender/intern/cycles"; + build_options += "-I " + path_get("kernel") + " -I " + path_get("util"); /* todo: escape path */ + build_options += " -Werror -cl-fast-relaxed-math -cl-strict-aliasing"; - cpProgram = clCreateProgramWithSource(cxGPUContext, 1, (const char **)&source, &source_len, &ciErr); + cpProgram = clCreateProgramWithSource(cxContext, 1, (const char **)&source, &source_len, &ciErr); opencl_assert(ciErr); @@ -178,7 +183,7 @@ public: ckFilmConvertKernel = clCreateKernel(cpProgram, "kernel_ocl_tonemap", &ciErr); opencl_assert(ciErr); - null_mem = (device_ptr)clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, 1, NULL, &ciErr); + null_mem = (device_ptr)clCreateBuffer(cxContext, CL_MEM_READ_ONLY, 1, NULL, &ciErr); } ~OpenCLDevice() @@ -196,7 +201,7 @@ public: clReleaseKernel(ckFilmConvertKernel); clReleaseProgram(cpProgram); clReleaseCommandQueue(cqCommandQueue); - clReleaseContext(cxGPUContext); + clReleaseContext(cxContext); } string description() @@ -213,11 +218,11 @@ public: size_t size = mem.memory_size(); if(type == MEM_READ_ONLY) - mem.device_pointer = (device_ptr)clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, size, NULL, &ciErr); + mem.device_pointer = (device_ptr)clCreateBuffer(cxContext, CL_MEM_READ_ONLY, size, NULL, &ciErr); else if(type == MEM_WRITE_ONLY) - mem.device_pointer = (device_ptr)clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, size, NULL, &ciErr); + mem.device_pointer = (device_ptr)clCreateBuffer(cxContext, CL_MEM_WRITE_ONLY, size, NULL, &ciErr); else - mem.device_pointer = (device_ptr)clCreateBuffer(cxGPUContext, CL_MEM_READ_WRITE, size, NULL, &ciErr); + mem.device_pointer = (device_ptr)clCreateBuffer(cxContext, CL_MEM_READ_WRITE, size, NULL, &ciErr); opencl_assert(ciErr); } @@ -321,7 +326,7 @@ public: opencl_assert(ciErr); - size_t local_size[2] = {1, 1}; + size_t local_size[2] = {8, 8}; size_t global_size[2] = {global_size_round_up(local_size[0], d_w), global_size_round_up(local_size[1], d_h)}; /* run kernel */ @@ -389,7 +394,7 @@ public: opencl_assert(ciErr); - size_t local_size[2] = {1, 1}; + size_t local_size[2] = {8, 8}; size_t global_size[2] = {global_size_round_up(local_size[0], d_w), global_size_round_up(local_size[1], d_h)}; /* run kernel */ diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index bc1f8bd40a5..b6d758369cc 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -72,6 +72,12 @@ SET(svm_headers svm/volume.h ) +SET(util_headers + ../util/util_color.h + ../util/util_math.h + ../util/util_transform.h + ../util/util_types.h) + # CUDA module IF("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") @@ -118,11 +124,13 @@ ENDIF() # OPENCL kernel IF(WITH_CYCLES_OPENCL) - SET(util_headers - ../util/util_color.h - ../util/util_math.h - ../util/util_transform.h - ../util/util_types.h) + #SET(kernel_preprocessed ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl) + #ADD_CUSTOM_COMMAND( + # OUTPUT ${kernel_preprocessed} + # COMMAND gcc -x c++ -E ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cl -I ${CMAKE_CURRENT_SOURCE_DIR}/../util/ -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DWITH_OPENCL -o ${kernel_preprocessed} + # DEPENDS ${kernel_sources} ${util_headers}) + #ADD_CUSTOM_TARGET(cycles_kernel_preprocess ALL DEPENDS ${kernel_preprocessed}) + #INSTALL(FILES ${kernel_preprocessed} DESTINATION ${CYCLES_INSTALL_PATH}/cycles/kernel) INSTALL(FILES kernel.cl ${headers} DESTINATION ${CYCLES_INSTALL_PATH}/cycles/kernel) INSTALL(FILES ${svm_headers} DESTINATION ${CYCLES_INSTALL_PATH}/cycles/kernel/svm) diff --git a/intern/cycles/kernel/kernel_compat_opencl.h b/intern/cycles/kernel/kernel_compat_opencl.h index 0127093d8ce..3d493c61fe4 100644 --- a/intern/cycles/kernel/kernel_compat_opencl.h +++ b/intern/cycles/kernel/kernel_compat_opencl.h @@ -22,7 +22,10 @@ #define __KERNEL_GPU__ #define __KERNEL_OPENCL__ -CCL_NAMESPACE_BEGIN +/* no namespaces in opencl */ +#define CCL_NAMESPACE_BEGIN +#define CCL_NAMESPACE_END +#define WITH_OPENCL /* in opencl all functions are device functions, so leave this empty */ #define __device @@ -104,7 +107,5 @@ __device float kernel_tex_interp_(__global float *data, int width, float x) #include "util_types.h" -CCL_NAMESPACE_END - #endif /* __KERNEL_COMPAT_OPENCL_H__ */ diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index 992a4d95b54..c0cb3fc8a09 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -34,8 +34,8 @@ CCL_NAMESPACE_BEGIN #define __BACKGROUND__ #define __EMISSION__ #define __CAUSTICS_TRICKS__ -#define __SVM__ #ifndef __KERNEL_OPENCL__ +#define __SVM__ #define __TEXTURES__ #endif #define __RAY_DIFFERENTIALS__ |