Skip to content

Commit

Permalink
Merged cuda_rendering branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Dade916 committed Apr 22, 2020
2 parents fe4575c + 56e1e5a commit 0b62099
Show file tree
Hide file tree
Showing 146 changed files with 2,377 additions and 1,773 deletions.
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,16 @@ if (NOT OPENIMAGEIO_FOUND)
MESSAGE(FATAL_ERROR "--> Could not locate required OpenImageIO files - Please check ${OPENIMAGEIO_SEARCH_PATH}")
endif()

if (NOT OPENCL_FOUND AND NOT LUXRAYS_DISABLE_OPENCL)
MESSAGE(ERROR "--> Could not locate required OpenCL files, disabling OpenCL support - Please check ${OPENCL_SEARCH_PATH}")
SET(LUXRAYS_DISABLE_OPENCL 1)
if (NOT OPENCL_FOUND AND LUXRAYS_ENABLE_OPENCL)
MESSAGE(FATAL_ERROR "--> Could not locate required OpenCL files, disabling OpenCL support - Please check ${OPENCL_SEARCH_PATH}")
endif()

if (NOT CUDA_FOUND AND LUXRAYS_ENABLE_CUDA)
MESSAGE(FATAL_ERROR "--> Could not locate required CUDA files - Please check ${CUDA_TOOLKIT_ROOT_DIR}")
if (NOT OPENGL_FOUND AND LUXRAYS_ENABLE_OPENCL)
MESSAGE(FATAL_ERROR "--> Could not locate required OpenGL files, disabling OpenCL support, disabling samples build")
endif()

if (NOT OPENGL_FOUND AND NOT LUXRAYS_DISABLE_OPENCL)
MESSAGE(ERROR "--> Could not locate required OpenGL files, disabling OpenCL support, disabling samples build")
SET(LUXRAYS_DISABLE_OPENCL 1)
if ((NOT CUDA_FOUND AND LUXRAYS_ENABLE_CUDA) OR (LUXRAYS_ENABLE_CUDA AND NOT LUXRAYS_ENABLE_OPENCL))
MESSAGE(FATAL_ERROR "--> CUDA support requires to enable OpenCL support too")
endif()

if (NOT EMBREE_FOUND)
Expand All @@ -141,8 +139,8 @@ endif()
#
################################################################################

if (LUXRAYS_DISABLE_OPENCL)
ADD_DEFINITIONS("-DLUXRAYS_DISABLE_OPENCL")
if (LUXRAYS_ENABLE_OPENCL)
ADD_DEFINITIONS("-DLUXRAYS_ENABLE_OPENCL")
endif()

if (LUXRAYS_ENABLE_CUDA)
Expand Down
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if (OPENGL_FOUND)
endif ()

# OpenCL
if (NOT LUXRAYS_DISABLE_OPENCL)
if (LUXRAYS_ENABLE_OPENCL)
set(OPENCL_ROOT "${OPENCL_SEARCH_PATH}")
find_package(OpenCL)

Expand Down
4 changes: 2 additions & 2 deletions cmake/SpecializedConfig/Config_Dade.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ SET(CMAKE_LIBRARY_PATH "/home/david/projects/luxcorerender/LinuxCompile/target-6
SET(Blosc_USE_STATIC_LIBS "ON")

# Note: CUDA requires to have enabled OpenCL support too
#SET(LUXRAYS_ENABLE_CUDA TRUE)
#SET(LUXRAYS_DISABLE_OPENCL TRUE)
SET(LUXRAYS_ENABLE_CUDA TRUE)
SET(LUXRAYS_ENABLE_OPENCL TRUE)
#SET(BUILD_LUXCORE_DLL TRUE)

#SET(CMAKE_BUILD_TYPE "Debug")
Expand Down
2 changes: 1 addition & 1 deletion cmake/SpecializedConfig/Config_Linux-Static.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SET(CMAKE_INCLUDE_PATH "${LuxRays_SOURCE_DIR}/../target-64-sse2/include;${LuxRay
SET(CMAKE_LIBRARY_PATH "${LuxRays_SOURCE_DIR}/../target-64-sse2/lib;${LuxRays_SOURCE_DIR}/../target-64-sse2")
SET(Blosc_USE_STATIC_LIBS "ON")

#SET(LUXRAYS_DISABLE_OPENCL TRUE)
#SET(LUXRAYS_ENABLE_OPENCL TRUE)
#SET(BUILD_LUXCORE_DLL TRUE)

#SET(CMAKE_BUILD_TYPE "Debug")
Expand Down
7 changes: 5 additions & 2 deletions include/luxcore/luxcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ CPP_EXPORT CPP_API void KernelCacheFill(const luxrays::Properties &config, void
* properties currently supported are:
* - version.number\n
* The LuxCore version. As string with "major.minor" version format.
* - compile.LUXRAYS_DISABLE_OPENCL\n
* true or false if the sources has been compiled with LUXRAYS_DISABLE_OPENCL and
* - compile.LUXRAYS_ENABLE_OPENCL and compile.LUXRAYS_DISABLE_OPENCL\n
* true or false if the sources has been compiled with LUXRAYS_ENABLE_OPENCL and
* OpenCL rendering engines are available or not.
* - compile.LUXRAYS_ENABLE_CUDA\n
* true or false if the sources has been compiled with LUXRAYS_ENABLE_CUDA and
* CUDA support is available or not.
* - compile.LUXCORE_DISABLE_EMBREE_BVH_BUILDER\n
* true or false if the sources has been compiled with LUXCORE_DISABLE_EMBREE_BVH_BUILDER and
* Embree BVH builder is used for OpenCL or not. This is now always false.
Expand Down
22 changes: 11 additions & 11 deletions include/luxrays/accelerators/bvh.cl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#line 2 "bvh_kernel.cl"
#line 2 "bvh.cl"

/***************************************************************************
* Copyright 1998-2020 by authors (see AUTHORS.txt) *
Expand Down Expand Up @@ -120,8 +120,8 @@ void Accelerator_Intersect(
const uint stopNode = BVHNodeData_GetSkipIndex(accelNodePage0[0].nodeData); // Non-existent
#endif

const float3 rayOrig = (float3)(ray->o.x, ray->o.y, ray->o.z);
const float3 rayDir = (float3)(ray->d.x, ray->d.y, ray->d.z);
const float3 rayOrig = MAKE_FLOAT3(ray->o.x, ray->o.y, ray->o.z);
const float3 rayDir = MAKE_FLOAT3(ray->d.x, ray->d.y, ray->d.z);
const float mint = ray->mint;
float maxt = ray->maxt;

Expand All @@ -146,16 +146,16 @@ void Accelerator_Intersect(
const float4 data1 = *data;

//const uint nodeData = node->nodeData;
const uint nodeData = as_uint(data1.s2);
const uint nodeData = as_uint(data1.z);
if (BVHNodeData_IsLeaf(nodeData)) {
// It is a leaf, check the triangle

//const uint i0 = node->triangleLeaf.v[0];
//const uint i1 = node->triangleLeaf.v[1];
//const uint i2 = node->triangleLeaf.v[2];
const uint v0 = as_uint(data0.s0);
const uint v1 = as_uint(data0.s1);
const uint v2 = as_uint(data0.s2);
const uint v0 = as_uint(data0.x);
const uint v1 = as_uint(data0.y);
const uint v2 = as_uint(data0.z);

#if (BVH_VERTS_PAGE_COUNT == 1)
// Fast path for when there is only one memory page
Expand All @@ -180,8 +180,8 @@ void Accelerator_Intersect(
#endif

//const uint triangleIndex = node->triangleLeaf.triangleIndex;
const uint meshIndex = as_uint(data0.s3);
const uint triangleIndex = as_uint(data1.s0);
const uint meshIndex = as_uint(data0.w);
const uint triangleIndex = as_uint(data1.x);

Triangle_Intersect(rayOrig, rayDir, mint, &maxt, &hitMeshIndex, &hitTriangleIndex,
&b1, &b2, meshIndex, triangleIndex, p0, p1, p2);
Expand All @@ -194,8 +194,8 @@ void Accelerator_Intersect(
// It is a node, check the bounding box
//const float3 pMin = VLOAD3F(&node->bvhNode.bboxMin[0]);
//const float3 pMax = VLOAD3F(&node->bvhNode.bboxMax[0]);
const float3 pMin = (float3)(data0.s0, data0.s1, data0.s2);
const float3 pMax = (float3)(data0.s3, data1.s0, data1.s1);
const float3 pMin = MAKE_FLOAT3(data0.x, data0.y, data0.z);
const float3 pMax = MAKE_FLOAT3(data0.w, data1.x, data1.y);

if (BBox_IntersectP(pMin, pMax, rayOrig, invRayDir, mint, maxt)) {
#if (BVH_NODES_PAGE_COUNT == 1)
Expand Down
13 changes: 8 additions & 5 deletions include/luxrays/accelerators/bvhaccel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace luxrays {

class HardwareIntersectionDevice;

// BVHAccel Declarations
class BVHAccel : public Accelerator {
public:
Expand All @@ -36,7 +38,10 @@ class BVHAccel : public Accelerator {
virtual ~BVHAccel();

virtual AcceleratorType GetType() const { return ACCEL_BVH; }
virtual OpenCLKernel *NewOpenCLKernel(OpenCLIntersectionDevice *device) const;

virtual bool HasDataParallelSupport(const IntersectionDevice &device) const;
virtual HardwareIntersectionKernel *NewHardwareIntersectionKernel(HardwareIntersectionDevice &device) const;

virtual void Init(const std::deque<const Mesh *> &meshes,
const u_longlong totalVertexCount,
const u_longlong totalTriangleCount);
Expand All @@ -45,11 +50,9 @@ class BVHAccel : public Accelerator {

static BVHParams ToBVHParams(const Properties &props);

friend class BVHKernel;
friend class MBVHKernel;
friend class MBVHAccel;
#if !defined(LUXRAYS_DISABLE_OPENCL)
friend class OpenCLBVHKernel;
friend class OpenCLMBVHKernel;
#endif

private:
BVHParams params;
Expand Down
6 changes: 4 additions & 2 deletions include/luxrays/accelerators/embreeaccel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ class EmbreeAccel : public Accelerator {

virtual AcceleratorType GetType() const { return ACCEL_EMBREE; }

virtual OpenCLKernel *NewOpenCLKernel(OpenCLIntersectionDevice *device) const { return NULL; }
virtual bool CanRunOnOpenCLDevice(OpenCLIntersectionDevice *device) const {
virtual bool HasDataParallelSupport(const IntersectionDevice &device) const {
return false;
}
virtual HardwareIntersectionKernel *NewHardwareIntersectionKernel(HardwareIntersectionDevice &device) const {
return nullptr;
}

virtual void Init(const std::deque<const Mesh *> &meshes,
const u_longlong totalVertexCount,
Expand Down
30 changes: 15 additions & 15 deletions include/luxrays/accelerators/mbvh.cl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#line 2 "mbvh_kernel.cl"
#line 2 "mbvh.cl"

/***************************************************************************
* Copyright 1998-2020 by authors (see AUTHORS.txt) *
Expand Down Expand Up @@ -152,8 +152,8 @@ void Accelerator_Intersect(

uint currentMeshOffset = 0;

const float3 rootRayOrig = (float3)(ray->o.x, ray->o.y, ray->o.z);
const float3 rootRayDir = (float3)(ray->d.x, ray->d.y, ray->d.z);
const float3 rootRayOrig = MAKE_FLOAT3(ray->o.x, ray->o.y, ray->o.z);
const float3 rootRayDir = MAKE_FLOAT3(ray->d.x, ray->d.y, ray->d.z);
const float mint = ray->mint;
float maxt = ray->maxt;
#if defined(MBVH_HAS_MOTIONSYSTEMS)
Expand Down Expand Up @@ -213,17 +213,17 @@ void Accelerator_Intersect(
const float4 data1 = *data;

//const uint nodeData = node->nodeData;
const uint nodeData = as_uint(data1.s2);
const uint nodeData = as_uint(data1.z);
if (BVHNodeData_IsLeaf(nodeData)) {
if (insideLeafTree) {
// I'm inside a leaf tree, I have to check the triangle

//const uint i0 = node->triangleLeaf.v[0];
//const uint i1 = node->triangleLeaf.v[1];
//const uint i2 = node->triangleLeaf.v[2];
const uint v0 = as_uint(data0.s0);
const uint v1 = as_uint(data0.s1);
const uint v2 = as_uint(data0.s2);
const uint v0 = as_uint(data0.x);
const uint v1 = as_uint(data0.y);
const uint v2 = as_uint(data0.z);

#if (MBVH_VERTS_PAGE_COUNT == 1)
// Fast path for when there is only one memory page
Expand All @@ -249,8 +249,8 @@ void Accelerator_Intersect(

//const uint meshIndex = node->triangleLeaf.meshIndex + currentMeshOffset;
//const uint triangleIndex = node->triangleLeaf.triangleIndex;
const uint meshIndex = as_uint(data0.s3) + currentMeshOffset;
const uint triangleIndex = as_uint(data1.s0);
const uint meshIndex = as_uint(data0.w) + currentMeshOffset;
const uint triangleIndex = as_uint(data1.x);
Triangle_Intersect(currentRayOrig, currentRayDir, mint, &maxt, &hitMeshIndex, &hitTriangleIndex, &b1, &b2,
meshIndex, triangleIndex, p0, p1, p2);
#if (MBVH_NODES_PAGE_COUNT == 1)
Expand All @@ -265,7 +265,7 @@ void Accelerator_Intersect(

#if defined(MBVH_HAS_TRANSFORMATIONS)
//const uint transformIndex = node->bvhLeaf.transformIndex;
const uint transformIndex = as_int(data0.s1);
const uint transformIndex = as_int(data0.y);
if (transformIndex != NULL_INDEX) {
// Transform ray origin and direction
__global const Matrix4x4* restrict m = &leafTransformations[transformIndex];
Expand All @@ -276,7 +276,7 @@ void Accelerator_Intersect(

#if defined(MBVH_HAS_MOTIONSYSTEMS)
//const uint motionIndex = node->bvhLeaf.motionIndex;
const uint motionIndex = as_int(data0.s2);
const uint motionIndex = as_int(data0.z);
if (motionIndex != NULL_INDEX) {
// Transform ray origin and direction
Matrix4x4 m;
Expand All @@ -287,10 +287,10 @@ void Accelerator_Intersect(
#endif

//currentMeshOffset = node->bvhLeaf.meshOffsetIndex;
currentMeshOffset = as_int(data0.s3);
currentMeshOffset = as_int(data0.w);

//const uint leafIndex = node->bvhLeaf.leafIndex;
const uint leafIndex = as_int(data0.s0);
const uint leafIndex = as_int(data0.x);
#if (MBVH_NODES_PAGE_COUNT == 1)
currentRootNode = currentNode + 1;
currentNode = leafIndex;
Expand All @@ -317,8 +317,8 @@ void Accelerator_Intersect(
// It is a node, check the bounding box
//const float3 pMin = VLOAD3F(&node->bvhNode.bboxMin[0]);
//const float3 pMax = VLOAD3F(&node->bvhNode.bboxMax[0]);
const float3 pMin = (float3)(data0.s0, data0.s1, data0.s2);
const float3 pMax = (float3)(data0.s3, data1.s0, data1.s1);
const float3 pMin = MAKE_FLOAT3(data0.x, data0.y, data0.z);
const float3 pMax = MAKE_FLOAT3(data0.w, data1.x, data1.y);

if (BBox_IntersectP(pMin, pMax, currentRayOrig, 1.f / currentRayDir, mint, maxt)) {
#if (MBVH_NODES_PAGE_COUNT == 1)
Expand Down
11 changes: 7 additions & 4 deletions include/luxrays/accelerators/mbvhaccel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace luxrays {

class HardwareIntersectionDevice;

// MBVHAccel Declarations
class MBVHAccel : public Accelerator {
public:
Expand All @@ -36,7 +38,10 @@ class MBVHAccel : public Accelerator {
virtual ~MBVHAccel();

virtual AcceleratorType GetType() const { return ACCEL_MBVH; }
virtual OpenCLKernel *NewOpenCLKernel(OpenCLIntersectionDevice *device) const;

virtual bool HasDataParallelSupport(const IntersectionDevice &device) const;
virtual HardwareIntersectionKernel *NewHardwareIntersectionKernel(HardwareIntersectionDevice &device) const;

virtual void Init(const std::deque<const Mesh *> &meshes,
const u_longlong totalVertexCount,
const u_longlong totalTriangleCount);
Expand All @@ -46,9 +51,7 @@ class MBVHAccel : public Accelerator {

virtual bool Intersect(const Ray *ray, RayHit *hit) const;

#if !defined(LUXRAYS_DISABLE_OPENCL)
friend class OpenCLMBVHKernel;
#endif
friend class MBVHKernel;

private:
static bool MeshPtrCompare(const Mesh *, const Mesh *);
Expand Down
9 changes: 5 additions & 4 deletions include/luxrays/core/accelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ typedef enum {
ACCEL_AUTO, ACCEL_BVH, ACCEL_MBVH, ACCEL_EMBREE
} AcceleratorType;

class OpenCLKernel;
class OpenCLIntersectionDevice;
class IntersectionDevice;
class HardwareIntersectionDevice;
class HardwareIntersectionKernel;

class Accelerator {
public:
Expand All @@ -42,8 +43,8 @@ class Accelerator {

virtual AcceleratorType GetType() const = 0;

virtual OpenCLKernel *NewOpenCLKernel(OpenCLIntersectionDevice *device) const = 0;
virtual bool CanRunOnOpenCLDevice(OpenCLIntersectionDevice *device) const { return true; }
virtual bool HasDataParallelSupport(const IntersectionDevice &device) const = 0;
virtual HardwareIntersectionKernel *NewHardwareIntersectionKernel(HardwareIntersectionDevice &device) const = 0;

virtual void Init(const std::deque<const Mesh *> &meshes, const u_longlong totalVertexCount, const u_longlong totalTriangleCount) = 0;
virtual bool DoesSupportUpdate() const { return false; }
Expand Down
2 changes: 1 addition & 1 deletion include/luxrays/core/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Context {
void SetVerbose(const bool v) { verbose = v; }
bool IsVerbose() const { return verbose; }

#if !defined(LUXRAYS_DISABLE_OPENCL)
#if defined(LUXRAYS_ENABLE_OPENCL)
friend class OpenCLIntersectionDevice;
#endif

Expand Down
Loading

0 comments on commit 0b62099

Please sign in to comment.