Skip to content

Commit

Permalink
promote cacheid type to long int and fix update of the stage counter (A…
Browse files Browse the repository at this point in the history
  • Loading branch information
cpichard authored Jun 27, 2024
1 parent 5e2e35c commit f3002b6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [usd#1661](https://github.com/Autodesk/arnold-usd/issues/1661) - In the procedural the subdivision meshes will use the normals generated by the subdivision algorithm instead of the normal primvar.
- [usd#1919](https://github.com/Autodesk/arnold-usd/issues/1919) - Fix rendering multiple frames with husk.
- [usd#1952](https://github.com/Autodesk/arnold-usd/issues/1952) - Don't write camera aperture parameters if they're already set
- [usd#1902](https://github.com/Autodesk/arnold-usd/issues/1902) - Fix invalid Cache ID sporadic error

## Pending bugfix release
- [usd#1940](https://github.com/Autodesk/arnold-usd/issues/1940) - Incorrect handling of shaders referenced in multiple materials
Expand Down
2 changes: 1 addition & 1 deletion libs/common/procedural_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void ProceduralReader::Read(const std::string &filename,
_overrides = nullptr; // clear the overrides pointer. Note that we don't own this array
}

bool ProceduralReader::Read(int cacheId, const std::string &path)
bool ProceduralReader::Read(long int cacheId, const std::string &path)
{
if (!GetNodes().empty()) {
return true;
Expand Down
6 changes: 3 additions & 3 deletions libs/common/procedural_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ class ProceduralReader {

const std::string &GetFilename() const { return _filename; }
const AtArray *GetOverrides() const { return _overrides; }
int GetCacheId() const {return _cacheId;}
long int GetCacheId() const {return _cacheId;}
void SetInteractive(bool b) {_interactive = b;}
bool GetInteractive() const {return _interactive;}

void Read(const std::string &filename,
AtArray *overrides, const std::string &path = "");

bool Read(int cacheId, const std::string &path = "");
bool Read(long int cacheId, const std::string &path = "");
virtual void Update() {} // Update scene for interactive changes
protected:
std::string _filename;
AtArray *_overrides = nullptr;
int _cacheId = 0; // usdStage cacheID used with a StageCache
long int _cacheId = 0; // usdStage cacheID used with a StageCache
bool _interactive = false; // interactive readers can update Arnold when the usdStage changes
};
16 changes: 12 additions & 4 deletions libs/translator/reader/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace {


static AtMutex s_globalReaderMutex;
static std::unordered_map<int, int> s_cacheRefCount;
static std::unordered_map<long int, int> s_cacheRefCount;
UsdArnoldReader::UsdArnoldReader()
: _procParent(nullptr),
_universe(nullptr),
Expand Down Expand Up @@ -1039,8 +1039,8 @@ void UsdArnoldReader::InitCacheId()
UsdStageCache::Id id = stageCache.Insert(_stage);
// now our reader will have a cacheID
_cacheId = id.ToLongInt();
// there's one ref count for this cache ID, for the current proc
s_cacheRefCount[_cacheId] = 1;
// stageCache.Insert can return an existing stage, so we increase the ref count for that stage in case it exists
s_cacheRefCount[_cacheId]++;
}
// Return a AtNode representing a whole part of the scene hierarchy, as needed e.g. for instancing.
// In this case, we create a nested procedural and give it an "object_path" so that it only represents
Expand Down Expand Up @@ -1069,7 +1069,15 @@ AtNode *UsdArnoldReader::CreateNestedProc(const char *objectPath, UsdArnoldReade
cacheIdIter->second++;
}

AiNodeSetInt(proto, str::cache_id, _cacheId);

// The current USD stageCache implementation use an ID counter which starts at 9223000 and increase it everytime a stage is added.
// So it should most likely stay in the integer range. But if the implementation changes, we need to make sure we catch it.
// We could/should probably store it as string. TBD
if (_cacheId <= std::numeric_limits<int>::max() && _cacheId >= std::numeric_limits<int>::min()) {
AiNodeSetInt(proto, str::cache_id, static_cast<int>(_cacheId));
} else {
AiMsgWarning("[usd] Cache ID is larger that what can be stored in arnold parameter %ld", _cacheId);
}
AiNodeSetStr(proto, str::object_path, AtString(objectPath));
AiNodeSetFlt(proto, str::frame, time.frame); // give it the desired frame
AiNodeSetFlt(proto, str::motion_start, time.motionStart);
Expand Down
4 changes: 2 additions & 2 deletions plugins/procedural/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,15 @@ std::string USDLibraryPath()

extern "C"
{
DLLEXPORT void WriteUsdStageCache ( const AtUniverse* universe, int cacheId, const AtParamValueMap* params )
DLLEXPORT void WriteUsdStageCache ( const AtUniverse* universe, long int cacheId, const AtParamValueMap* params )
{
// Get the UsdStageCache, it's common to all libraries linking against the same USD libs
UsdStageCache &stageCache = UsdUtilsStageCache::Get();
UsdStageCache::Id id = UsdStageCache::Id::FromLongInt(cacheId);
// Retrieve the UsdStage associated to this cache ID.
UsdStageRefPtr stage = (id.IsValid()) ? stageCache.Find(id) : nullptr;
if (!stage) {
AiMsgError("[usd] Cache ID not valid %d", cacheId);
AiMsgError("[usd] Cache ID not valid %ld", cacheId);
return;
}
// Create an Arnold-USD writer, that can write an Arnold univers to a UsdStage
Expand Down

0 comments on commit f3002b6

Please sign in to comment.