From 36ee752697c489b8cee4f78f884cb34179b6a8f6 Mon Sep 17 00:00:00 2001 From: iaomw Date: Tue, 27 Aug 2024 20:13:58 +0800 Subject: [PATCH] minor update --- zenovis/xinxinoptix/hair/optixHair.cpp | 37 +++++++++++++++++++++----- zenovis/xinxinoptix/hair/optixHair.h | 32 +++++++++------------- zenovis/xinxinoptix/optixSphere.cpp | 2 +- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/zenovis/xinxinoptix/hair/optixHair.cpp b/zenovis/xinxinoptix/hair/optixHair.cpp index 23b5870d91..ffef6b0bf0 100644 --- a/zenovis/xinxinoptix/hair/optixHair.cpp +++ b/zenovis/xinxinoptix/hair/optixHair.cpp @@ -37,11 +37,15 @@ #include "Util.h" #include "optixHair.h" +#include +#include + void HairState::makeCurveGroupGAS(OptixDeviceContext context, const std::vector& points, const std::vector& widths, const std::vector& normals, - const std::vector& strands) { + const std::vector& strands) +{ xinxinoptix::raii devicePoints; { @@ -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; @@ -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; } diff --git a/zenovis/xinxinoptix/hair/optixHair.h b/zenovis/xinxinoptix/hair/optixHair.h index 00c3b48b57..27a8629340 100644 --- a/zenovis/xinxinoptix/hair/optixHair.h +++ b/zenovis/xinxinoptix/hair/optixHair.h @@ -60,10 +60,9 @@ struct CurveGroup { struct HairState { std::shared_ptr pHair; + std::shared_ptr curveGroup; sutil::Aabb aabb; - std::shared_ptr curveGroup; - zeno::CurveType curveType; std::string mtid; @@ -83,11 +82,7 @@ void makeCurveGroupGAS(OptixDeviceContext context, const std::vector& normals, const std::vector& 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 strandU(zeno::CurveType curveType, const std::vector& m_strands); std::vector strandInfo(zeno::CurveType curveType, const std::vector& m_strands); @@ -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 curveGroupCache; +inline std::vector> curveGroupCache; inline std::vector> curveGroupStateCache; inline void loadCurveGroup(const std::vector& points, const std::vector& widths, const std::vector& normals, const std::vector& strands, zeno::CurveType curveType, std::string mtlid) { - CurveGroup cg; - cg.mtlid = mtlid; - cg.curveType = curveType; + auto cg = std::make_shared(); + 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); } @@ -179,10 +173,10 @@ inline void prepareCurveGroup(OptixDeviceContext context) { for (auto& ele : curveGroupCache) { auto state = std::make_shared(); - state->curveGroup = std::make_shared(ele); + state->curveGroup = ele; - state->curveType = ele.curveType; - state->mtid = ele.mtlid; + state->curveType = ele->curveType; + state->mtid = ele->mtlid; state->makeCurveGroupGAS(context); diff --git a/zenovis/xinxinoptix/optixSphere.cpp b/zenovis/xinxinoptix/optixSphere.cpp index 99138f043a..62473368e8 100644 --- a/zenovis/xinxinoptix/optixSphere.cpp +++ b/zenovis/xinxinoptix/optixSphere.cpp @@ -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( &d_vertex_buffer ), sizeof( float3 ) ) );