Skip to content

Commit

Permalink
fix curve aux leak
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Dec 3, 2024
1 parent 629cd71 commit 3316a44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
5 changes: 3 additions & 2 deletions zenovis/src/optx/RenderEngineOptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ struct GraphicsManager {
}
}

loadCurveGroup(points, widths, normals, strands, curveTypeEnum, mtlid);
auto abcpath = ud.get2<std::string>("abcpath_0", "Default");
loadCurveGroup(points, widths, normals, strands, curveTypeEnum, mtlid, abcpath);
return;
}

Expand Down Expand Up @@ -1352,7 +1353,7 @@ struct RenderEngineOptx : RenderEngine, zeno::disable_copy {
cachedCurvesMaterials[mtid] = { ctype };
}

for (auto& ele : curveGroupCache) {
for (auto& [key, ele] : curveGroupCache) {

auto ctype = ele->curveType;
auto mtlid = ele->mtlid;
Expand Down
22 changes: 15 additions & 7 deletions zenovis/xinxinoptix/hair/optixHair.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ struct HairState
// Aux data
CurveGroupAux aux {};

~HairState() {
cudaFree( reinterpret_cast<void*>( aux.strand_u.data ) );
aux.strand_u.data = 0;
cudaFree( reinterpret_cast<void*>( aux.strand_i.data ) );
aux.strand_i.data = 0;
cudaFree( reinterpret_cast<void*>( aux.strand_info.data ) );
aux.strand_info.data = 0;
}

public:

void makeHairGAS(OptixDeviceContext contex);
Expand Down Expand Up @@ -169,11 +178,11 @@ inline void prepareHairs(OptixDeviceContext context) {
}
}

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

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

auto cg = std::make_shared<CurveGroup>();
cg->mtlid = mtlid;
Expand All @@ -184,14 +193,14 @@ inline void loadCurveGroup(std::vector<float3>& points, std::vector<float>& widt
cg->normals = std::move(normals);
cg->strands = std::move(strands);

curveGroupCache.push_back(cg);
curveGroupCache[key] = cg;
}

inline void prepareCurveGroup(OptixDeviceContext context) {

curveGroupStateCache.clear();

for (auto& ele : curveGroupCache) {
for (auto& [key, ele] : curveGroupCache) {
auto state = std::make_shared<HairState>();

state->curveGroup = ele;
Expand All @@ -200,8 +209,7 @@ inline void prepareCurveGroup(OptixDeviceContext context) {
state->mtid = ele->mtlid;

state->makeCurveGroupGAS(context);

curveGroupStateCache.push_back(state);
curveGroupStateCache[key] = state;
}

curveGroupCache.clear();
Expand Down
5 changes: 1 addition & 4 deletions zenovis/xinxinoptix/optixPathTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,12 +1214,9 @@ void updateRootIAS()
}
}

for (size_t i=0; i<curveGroupStateCache.size(); ++i) {

auto& ele = curveGroupStateCache[i];
for (auto& [key, ele] : curveGroupStateCache) {

OptixInstance opinstance {};

auto shader_mark = (uint)ele->curveType + 3;

auto combinedID = ele->mtid + ":" + std::to_string(shader_mark);
Expand Down

0 comments on commit 3316a44

Please sign in to comment.