Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Aug 27, 2024
1 parent 3012e01 commit 36ee752
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
37 changes: 30 additions & 7 deletions zenovis/xinxinoptix/hair/optixHair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@
#include "Util.h"
#include "optixHair.h"

#include <tbb/task.h>
#include <tbb/task_group.h>

void HairState::makeCurveGroupGAS(OptixDeviceContext context,
const std::vector<float3>& points,
const std::vector<float>& widths,
const std::vector<float3>& normals,
const std::vector<uint>& strands) {
const std::vector<uint>& strands)
{

xinxinoptix::raii<CUdeviceptr> devicePoints;
{
Expand Down Expand Up @@ -134,11 +138,33 @@ void HairState::makeCurveGroupGAS(OptixDeviceContext context,
accelBuildOptions.operation = OPTIX_BUILD_OPERATION_BUILD;

xinxinoptix::buildXAS(context, accelBuildOptions, buildInput, gasBuffer, gasHandle);

makeAuxData(strands);
return;
}

void HairState::makeCurveGroupGAS(OptixDeviceContext context) {
if (nullptr == curveGroup && nullptr == pHair) { return; }

tbb::task_group tgroup;

tgroup.run([&]() {
if (nullptr != pHair) {
makeCurveGroupGAS(context, pHair->points(), pHair->widths(), {}, pHair->strands());
} else {
makeCurveGroupGAS(context, curveGroup->points, curveGroup->widths, curveGroup->normals, curveGroup->strands);
}
});

tgroup.run([&]() {
if (nullptr != pHair) {
makeAuxData(pHair->strands());
} else {
makeAuxData(curveGroup->strands);
}
});

tgroup.wait();
}

void HairState::makeHairGAS(OptixDeviceContext context)
{
auto pState = this;
Expand All @@ -147,11 +173,8 @@ void HairState::makeHairGAS(OptixDeviceContext context)
pState->gasHandle = 0;
pState->gasBuffer.reset();

auto& points = pHair->points();
auto& widths = pHair->widths();
auto& strands = pHair->strands();
makeCurveGroupGAS(context);

makeCurveGroupGAS(context, points, widths, {}, strands);
return;
}

Expand Down
32 changes: 13 additions & 19 deletions zenovis/xinxinoptix/hair/optixHair.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ struct CurveGroup {
struct HairState
{
std::shared_ptr<Hair> pHair;
std::shared_ptr<CurveGroup> curveGroup;
sutil::Aabb aabb;

std::shared_ptr<CurveGroup> curveGroup;

zeno::CurveType curveType;
std::string mtid;

Expand All @@ -83,11 +82,7 @@ void makeCurveGroupGAS(OptixDeviceContext context,
const std::vector<float3>& normals,
const std::vector<uint>& strands);

inline void makeCurveGroupGAS(OptixDeviceContext context) {
if (nullptr == curveGroup) { return; }

makeCurveGroupGAS(context, curveGroup->points, curveGroup->widths, curveGroup->normals, curveGroup->strands);
}
void makeCurveGroupGAS(OptixDeviceContext context);

std::vector<float2> strandU(zeno::CurveType curveType, const std::vector<uint>& m_strands);
std::vector<uint2> strandInfo(zeno::CurveType curveType, const std::vector<uint>& m_strands);
Expand Down Expand Up @@ -149,25 +144,24 @@ inline void prepareHairs(OptixDeviceContext context) {
hair_cache.clear();

for (auto& [key, state] : geo_hair_map) {

state->makeHairGAS(context);
}
}

inline std::vector<CurveGroup> curveGroupCache;
inline std::vector<std::shared_ptr<CurveGroup>> curveGroupCache;
inline std::vector<std::shared_ptr<HairState>> curveGroupStateCache;

inline void loadCurveGroup(const std::vector<float3>& points, const std::vector<float>& widths, const std::vector<float3>& normals, const std::vector<uint>& strands,
zeno::CurveType curveType, std::string mtlid) {

CurveGroup cg;
cg.mtlid = mtlid;
cg.curveType = curveType;
auto cg = std::make_shared<CurveGroup>();
cg->mtlid = mtlid;
cg->curveType = curveType;

cg.points = points;
cg.widths = widths;
cg.normals = normals;
cg.strands = strands;
cg->points = std::move(points);
cg->widths = std::move(widths);
cg->normals = std::move(normals);
cg->strands = std::move(strands);

curveGroupCache.push_back(cg);
}
Expand All @@ -179,10 +173,10 @@ inline void prepareCurveGroup(OptixDeviceContext context) {
for (auto& ele : curveGroupCache) {
auto state = std::make_shared<HairState>();

state->curveGroup = std::make_shared<CurveGroup>(ele);
state->curveGroup = ele;

state->curveType = ele.curveType;
state->mtid = ele.mtlid;
state->curveType = ele->curveType;
state->mtid = ele->mtlid;

state->makeCurveGroupGAS(context);

Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/optixSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void buildUniformedSphereGAS(const OptixDeviceContext& context, OptixTraversabl
OPTIX_BUILD_FLAG_ALLOW_RANDOM_INSTANCE_ACCESS;

float3 sphereVertex = make_float3( 0.f, 0.f, 0.f );
float sphereRadius = 1.0f;
float sphereRadius = 0.5f;

CUdeviceptr d_vertex_buffer{};
CUDA_CHECK( cudaMalloc( reinterpret_cast<void**>( &d_vertex_buffer ), sizeof( float3 ) ) );
Expand Down

0 comments on commit 36ee752

Please sign in to comment.