Skip to content

Commit f96877f

Browse files
authored
Update pipelines (#79)
* Enable custom direction basis and optimize data types * Add ray load * Remove TIndex array from PRD * Correct numBoundaryHits * Add option to precompute all normals * Fix type * Small fixes * Bump version * Remove unnecessary enums
1 parent ea4ff7b commit f96877f

24 files changed

Lines changed: 187 additions & 130 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22
project(
33
ViennaRay
44
LANGUAGES CXX
5-
VERSION 3.6.0)
5+
VERSION 3.6.1)
66

77
# --------------------------------------------------------------------------------------------------------
88
# Library switches

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ We recommend using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to consum
6363
* Installation with CPM
6464

6565
```cmake
66-
CPMAddPackage("gh:viennatools/viennaray@3.6.0")
66+
CPMAddPackage("gh:viennatools/viennaray@3.6.1")
6767
```
6868

6969
* With a local installation

gpu/examples/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ configure_file(Resources/trenchMesh.dat ${CMAKE_CURRENT_BINARY_DIR}/trenchMesh.d
77
add_dependencies(ViennaRay-GPU_Examples ${target_name})
88

99
add_gpu_executable(GPU_trenchDisks target_name trenchDisks.cpp)
10-
configure_file(${CMAKE_SOURCE_DIR}/examples/trench/trenchGrid3D.dat ${CMAKE_CURRENT_BINARY_DIR}/trenchGrid3D.dat COPYONLY)
10+
configure_file(${CMAKE_SOURCE_DIR}/examples/trench/trenchGrid3D.dat
11+
${CMAKE_CURRENT_BINARY_DIR}/trenchGrid3D.dat COPYONLY)
1112
add_dependencies(ViennaRay-GPU_Examples ${target_name})
1213

1314
add_gpu_executable(GPU_trenchLines target_name trenchLines.cpp)

gpu/include/raygBoundary.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ __device__ __inline__ void reflectFromBoundary(viennaray::gpu::PerRayData *prd,
1616
const int D) {
1717
using namespace viennacore;
1818
const unsigned int primID = optixGetPrimitiveIndex();
19+
prd->numBoundaryHits++;
1920

2021
if constexpr (std::is_same<SBTData, viennaray::gpu::HitSBTDataDisk>::value) {
2122
prd->pos =
@@ -32,7 +33,6 @@ __device__ __inline__ void reflectFromBoundary(viennaray::gpu::PerRayData *prd,
3233
unsigned dim = primID / 4;
3334
prd->dir[dim] -= 2 * prd->dir[dim];
3435
prd->pos[dim] = hsd->vertex[hsd->index[primID][0]][dim];
35-
prd->numBoundaryHits++;
3636
} else if constexpr (std::is_same<SBTData,
3737
viennaray::gpu::HitSBTDataLine>::value) {
3838
prd->pos = prd->pos + prd->dir * (optixGetRayTmax());
@@ -47,6 +47,7 @@ applyPeriodicBoundary(viennaray::gpu::PerRayData *prd, const SBTData *hsd,
4747
const int D) {
4848
using namespace viennacore;
4949
const unsigned int primID = optixGetPrimitiveIndex();
50+
prd->numBoundaryHits++;
5051

5152
if constexpr (std::is_same<SBTData, viennaray::gpu::HitSBTDataDisk>::value) {
5253
prd->pos =
@@ -66,7 +67,6 @@ applyPeriodicBoundary(viennaray::gpu::PerRayData *prd, const SBTData *hsd,
6667
prd->pos = prd->pos + prd->dir * optixGetRayTmax();
6768
unsigned dim = primID / 4;
6869
prd->pos[dim] = hsd->vertex[hsd->index[primID ^ 2][0]][dim];
69-
prd->numBoundaryHits++;
7070
} else if constexpr (std::is_same<SBTData,
7171
viennaray::gpu::HitSBTDataLine>::value) {
7272
prd->pos = prd->pos + prd->dir * (optixGetRayTmax());

gpu/include/raygLaunchParams.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,34 @@ __both__ __forceinline__ unsigned callableIndex(unsigned p, CallableSlot s) {
1515

1616
struct LaunchParams {
1717
float *resultBuffer;
18+
1819
float rayWeightThreshold = 0.1f;
20+
float tThreshold = 0.5f;
21+
1922
unsigned int seed = 0;
20-
unsigned int numElements;
21-
unsigned int *dataPerParticle; // to determine result buffer index
2223
bool periodicBoundary = false;
23-
unsigned int maxBoundaryHits = 100;
24-
unsigned int particleIdx = 0;
25-
unsigned particleType = 0;
26-
float gridDelta = 1.f;
27-
float tThreshold = 0.5f;
2824

29-
int D = 3; // Dimension
25+
unsigned int numElements; // to determine result buffer index
26+
unsigned int *dataPerParticle; // to determine result buffer index
27+
28+
unsigned maxBoundaryHits = 100;
29+
uint8_t particleIdx = 0;
30+
uint8_t particleType = 0;
31+
uint8_t D = 3; // Dimension
3032

31-
// std::unordered_map<int, float> sticking;
32-
int *materialIds;
33-
float *materialSticking;
3433
float sticking = 1.f;
3534
float cosineExponent = 1.f;
35+
int *materialIds;
36+
float *materialSticking;
3637
void *customData;
3738

3839
// source plane params
39-
struct {
40+
struct SourcePlane {
4041
viennacore::Vec2Df minPoint;
4142
viennacore::Vec2Df maxPoint;
4243
float planeHeight;
4344
std::array<viennacore::Vec3Df, 3> directionBasis;
45+
bool customDirectionBasis = false;
4446
} source;
4547

4648
OptixTraversableHandle traversable;

gpu/include/raygLineGeometry.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ template <typename NumericType, int D = 3> struct LineGeometry {
1515
// geometry
1616
CudaBuffer geometryNodesBuffer;
1717
CudaBuffer geometryLinesBuffer;
18+
CudaBuffer geometryNormalsBuffer;
1819

1920
// boundary
2021
CudaBuffer boundaryNodesBuffer;
@@ -52,6 +53,7 @@ template <typename NumericType, int D = 3> struct LineGeometry {
5253
// upload the model to the device: the builder
5354
geometryNodesBuffer.allocUpload(mesh.nodes);
5455
geometryLinesBuffer.allocUpload(mesh.lines);
56+
geometryNormalsBuffer.allocUpload(mesh.normals);
5557

5658
// create local variables, because we need a *pointer* to the
5759
// device pointers

gpu/include/raygMesh.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ using namespace viennacore;
1313
struct LineMesh {
1414
std::vector<Vec3Df> nodes;
1515
std::vector<Vec2D<unsigned>> lines;
16+
std::vector<Vec3Df> normals;
1617

1718
Vec3Df minimumExtent;
1819
Vec3Df maximumExtent;
@@ -22,6 +23,7 @@ struct LineMesh {
2223
struct TriangleMesh {
2324
std::vector<Vec3Df> nodes;
2425
std::vector<Vec3D<unsigned>> triangles;
26+
std::vector<Vec3Df> normals;
2527

2628
Vec3Df minimumExtent;
2729
Vec3Df maximumExtent;

gpu/include/raygPerRayData.hpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,31 @@
1212

1313
namespace viennaray::gpu {
1414

15+
// Per-ray data structure associated with each ray. Should be kept small to
16+
// optimize memory usage and performance.
1517
struct PerRayData {
16-
float rayWeight = 1.f;
18+
// Position and direction
1719
viennacore::Vec3Df pos;
1820
viennacore::Vec3Df dir;
1921

22+
// Simulation specific data
23+
float rayWeight = 1.f;
24+
float energy = 0.f;
25+
float load = 0.f;
26+
27+
// RNG
2028
RNGState RNGstate;
2129

22-
float energy = 0.f;
30+
// Hit data
2331
unsigned int numBoundaryHits = 0;
24-
25-
unsigned primID = 0;
26-
float tMin = 1e20f;
32+
unsigned int primID = 0; // primID of closest hit
33+
float tMin = 1e20f; // distance to closest hit
2734

2835
// Variables for neighbor intersections (overlapping disks and lines)
29-
int TIndex[MAX_NEIGHBORS]; // Indices of neighbor hits
30-
int ISCount = 0; // Number of hits starting from 1
31-
int tempCount = 0; // total intersections recorded
32-
float tValues[MAX_NEIGHBORS]; // all intersection distances
33-
int primIDs[MAX_NEIGHBORS]; // their primitive IDs
36+
uint8_t ISCount = 0; // Number of hits starting from 1
37+
uint8_t totalCount = 0; // total intersections recorded
38+
float tValues[MAX_NEIGHBORS]; // all intersection distances
39+
unsigned int primIDs[MAX_NEIGHBORS]; // their primitive IDs
3440
bool hitFromBack = false;
3541
};
3642

gpu/include/raygRNG.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ __device__ __inline__ float getNextRand(viennaray::gpu::RNGState *state) {
3737
}
3838

3939
__device__ __inline__ float getNormalDistRand(viennaray::gpu::RNGState *state) {
40-
float u0 = curand_uniform(state);
41-
float u1 = curand_uniform(state);
42-
float r = sqrtf(-2.f * logf(u0));
43-
float theta = 2.f * M_PIf * u1;
40+
float4 u0 = curand_uniform4(state);
41+
float r = sqrtf(-2.f * logf(u0.x));
42+
float theta = 2.f * M_PIf * u0.y;
4443
return r * sinf(theta);
4544
}
4645
#endif

gpu/include/raygReflection.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ using namespace viennaray::gpu;
1313
#ifdef __CUDACC__
1414
__device__ __inline__ viennacore::Vec3Df
1515
computeNormal(const void *sbtData, const unsigned int primID) {
16+
using namespace viennacore;
1617
const HitSBTDataBase *baseData =
1718
reinterpret_cast<const HitSBTDataBase *>(sbtData);
1819
switch (baseData->geometryType) {
1920
case 0: {
20-
using namespace viennacore;
21+
// Triangles
2122
const HitSBTDataTriangle *sbt =
2223
reinterpret_cast<const HitSBTDataTriangle *>(sbtData);
2324
const Vec3D<unsigned> &index = sbt->index[primID];
@@ -27,12 +28,11 @@ computeNormal(const void *sbtData, const unsigned int primID) {
2728
return Normalize<float, 3>(CrossProduct<float>(B - A, C - A));
2829
} break;
2930
case 1: {
30-
const HitSBTDataDisk *sbt =
31-
reinterpret_cast<const HitSBTDataDisk *>(sbtData);
32-
return sbt->normal[primID];
31+
// Disks
32+
return baseData->normal[primID];
3333
} break;
3434
case 2: {
35-
using namespace viennacore;
35+
// Lines
3636
const HitSBTDataLine *sbt =
3737
reinterpret_cast<const HitSBTDataLine *>(sbtData);
3838
Vec3Df p0 = sbt->nodes[sbt->lines[primID][0]];
@@ -48,6 +48,11 @@ computeNormal(const void *sbtData, const unsigned int primID) {
4848
}
4949
}
5050

51+
__device__ __forceinline__ viennacore::Vec3Df
52+
getNormal(const void *sbtData, const unsigned int primID) {
53+
return reinterpret_cast<const HitSBTDataBase *>(sbtData)->normal[primID];
54+
}
55+
5156
static __device__ __forceinline__ void
5257
specularReflection(viennaray::gpu::PerRayData *prd,
5358
const viennacore::Vec3Df &geoNormal) {
@@ -163,7 +168,7 @@ PickRandomPointOnUnitSphere(viennaray::gpu::RNGState *state) {
163168

164169
static __device__ void diffuseReflection(viennaray::gpu::PerRayData *prd,
165170
const viennacore::Vec3Df &geoNormal,
166-
const int D) {
171+
const uint8_t D) {
167172
using namespace viennacore;
168173
#ifndef VIENNARAY_TEST
169174
prd->pos = prd->pos + prd->tMin * prd->dir;
@@ -178,7 +183,7 @@ static __device__ void diffuseReflection(viennaray::gpu::PerRayData *prd,
178183
}
179184

180185
static __device__ void diffuseReflection(viennaray::gpu::PerRayData *prd,
181-
const int D) {
186+
const uint8_t D) {
182187
using namespace viennacore;
183188

184189
const viennaray::gpu::HitSBTDataDisk *sbtData =
@@ -190,7 +195,7 @@ static __device__ void diffuseReflection(viennaray::gpu::PerRayData *prd,
190195
static __device__ __forceinline__ void
191196
conedCosineReflection(viennaray::gpu::PerRayData *prd,
192197
const viennacore::Vec3Df &geomNormal,
193-
const float maxConeAngle, const int D) {
198+
const float maxConeAngle, const uint8_t D) {
194199
using namespace viennacore;
195200

196201
// TODO: Is this needed? Done in the CPU version

0 commit comments

Comments
 (0)