Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tsd/apps/interactive/mpiViewer/DistributedSceneController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void DistributedSceneController::shutdown()
MPI_Barrier(MPI_COMM_WORLD);

auto d = m_anari.device;
m_ctx->anari.releaseRenderIndex(d);
m_ctx->anari.releaseRenderIndex(m_ctx->tsd.scene, d);
anari::release(d, m_anari.hdriLight);
anari::release(d, m_anari.renderer);
anari::release(d, m_anari.camera);
Expand Down Expand Up @@ -291,4 +291,4 @@ void DistributedSceneController::executeFrame_render()
MPI_Barrier(MPI_COMM_WORLD);
}

} // namespace tsd::mpi_viewer
} // namespace tsd::mpi_viewer
14 changes: 9 additions & 5 deletions tsd/apps/interactive/network/client/tsdRemoteViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Application : public TSDApplication
void connect();
void disconnect();

std::unique_ptr<tsd::network::NetworkUpdateDelegate> m_updateDelegate;
tsd::network::NetworkUpdateDelegate *m_updateDelegate{nullptr};
tsd::ui::imgui::RemoteViewport *m_viewport{nullptr};
std::shared_ptr<tsd::network::NetworkClient> m_client;
std::string m_host{"127.0.0.1"};
Expand All @@ -52,8 +52,9 @@ Application::Application()

m_client = std::make_shared<tsd::network::NetworkClient>();

m_updateDelegate = std::make_unique<tsd::network::NetworkUpdateDelegate>(
&ctx->tsd.scene, m_client.get());
m_updateDelegate =
ctx->tsd.scene.updateDelegate().emplace<tsd::network::NetworkUpdateDelegate>(
&ctx->tsd.scene, m_client.get());

ctx->tsd.animationMgr.setTimeChangedCallback([this](float time) {
if (m_timeUpdatesEnabled)
Expand Down Expand Up @@ -100,11 +101,14 @@ Application::Application()
m_timeUpdatesEnabled = true;
});

ctx->tsd.scene.setUpdateDelegate(m_updateDelegate.get());
ctx->tsd.sceneLoadComplete = false;
}

Application::~Application() = default;
Application::~Application()
{
if (m_updateDelegate)
appContext()->tsd.scene.updateDelegate().erase(m_updateDelegate);
}

anari_viewer::WindowArray Application::setupWindows()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void DistributedRenderServer::run(short port)
}

m_camera = {};
m_ctx.anari.releaseRenderIndex(m_device);
m_ctx.anari.releaseRenderIndex(m_ctx.tsd.scene, m_device);
m_ctx.anari.releaseAllDevices();

MPI_Barrier(MPI_COMM_WORLD);
Expand Down Expand Up @@ -256,7 +256,7 @@ void DistributedRenderServer::setup_ANARIDevice()
return v.get<int32_t>() == myRank;
return true; // no mpiRank tag → global (camera, renderer, etc.)
});
m_ctx.anari.getUpdateDelegate().signalObjectFilteringChanged();
m_ctx.tsd.scene.updateDelegate().signalObjectFilteringChanged();

m_camera = scene.defaultCamera();
m_renderers = scene.renderersOfDevice(m_libName).empty()
Expand Down
2 changes: 1 addition & 1 deletion tsd/apps/interactive/network/server/RenderServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void RenderServer::run(short port)
m_server->removeAllHandlers();

m_camera = {};
m_ctx.anari.releaseRenderIndex(m_device);
m_ctx.anari.releaseRenderIndex(m_ctx.tsd.scene, m_device);
m_ctx.anari.releaseAllDevices();
}

Expand Down
8 changes: 3 additions & 5 deletions tsd/apps/tutorial/tsdTutorialMultiRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,15 @@ int main()

// Setup render indexes //

tsd::rendering::MultiUpdateDelegate ud;
auto &ud = scene.updateDelegate();

auto *rIdx1 = ud.emplace<tsd::rendering::RenderIndexFlatRegistry>(
scene, deviceName, device);
auto *rIdx2 = ud.emplace<tsd::rendering::RenderIndexFlatRegistry>(
scene, deviceName, device);

rIdx1->populate(false);
rIdx2->populate(false);

scene.setUpdateDelegate(&ud);
rIdx1->populate();
rIdx2->populate();

// Create camera //

Expand Down
1 change: 0 additions & 1 deletion tsd/src/anari_tsd/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ void Device::initDevice()
libraryName.c_str());

state->deviceName = libraryName;
state->scene->setUpdateDelegate(&state->anari.getUpdateDelegate());
}
}

Expand Down
2 changes: 1 addition & 1 deletion tsd/src/anari_tsd/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ World::~World()
{
auto *s = deviceState();
if (!s->usingExternalScene())
s->anari.releaseRenderIndex(s->device);
s->anari.releaseRenderIndex(*s->scene, s->device);
s->scene->removeLayer(m_layerName);
}

Expand Down
59 changes: 46 additions & 13 deletions tsd/src/tsd/app/ANARIDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// tsd_rendering
#include "tsd/rendering/index/RenderIndexAllLayers.hpp"
#include "tsd/rendering/index/RenderIndexFlatRegistry.hpp"
// std
#include <cassert>

namespace tsd::app {

Expand Down Expand Up @@ -146,48 +148,79 @@ tsd::rendering::RenderIndex *ANARIDeviceManager::acquireRenderIndex(
tsd::scene::Scene &c, tsd::core::Token n, anari::Device d)
{
auto &liveIdx = m_rIdxs[d];
if (liveIdx.scene && liveIdx.scene != &c) {
tsd::core::logError(
"ANARIDeviceManager::acquireRenderIndex() scene mismatch for device %p"
" (existing=%p, requested=%p)",
(void *)d,
(void *)liveIdx.scene,
(void *)&c);
return nullptr;
Comment thread
jeffamstutz marked this conversation as resolved.
}

if (liveIdx.refCount == 0) {
liveIdx.scene = &c;
switch (renderIndexKind()) {
case RenderIndexKind::FLAT:
liveIdx.idx =
m_delegate.emplace<tsd::rendering::RenderIndexFlatRegistry>(c, n, d);
c.updateDelegate().emplace<tsd::rendering::RenderIndexFlatRegistry>(
c, n, d);
break;
case RenderIndexKind::ALL_LAYERS:
default:
liveIdx.idx =
m_delegate.emplace<tsd::rendering::RenderIndexAllLayers>(c, n, d);
c.updateDelegate().emplace<tsd::rendering::RenderIndexAllLayers>(
c, n, d);
break;
}
liveIdx.idx->populate(false);
liveIdx.idx->populate();
}
liveIdx.refCount++;
return liveIdx.idx;
}

void ANARIDeviceManager::releaseRenderIndex(anari::Device d)
void ANARIDeviceManager::releaseRenderIndex(
tsd::scene::Scene &c, anari::Device d)
{
auto &liveIdx = m_rIdxs[d];
auto itr = m_rIdxs.find(d);
if (itr == m_rIdxs.end())
return;

auto &liveIdx = itr->second;
if (liveIdx.scene && liveIdx.scene != &c) {
tsd::core::logError(
"ANARIDeviceManager::releaseRenderIndex() scene mismatch for device %p"
" (existing=%p, requested=%p)",
(void *)d,
(void *)liveIdx.scene,
(void *)&c);
return;
Comment thread
jeffamstutz marked this conversation as resolved.
}

if (liveIdx.refCount == 0)
return;
else if (liveIdx.refCount == 1)
m_delegate.erase(liveIdx.idx);
liveIdx.refCount--;
if (--liveIdx.refCount == 0) {
c.updateDelegate().erase(liveIdx.idx);
m_rIdxs.erase(itr);
}
}

void ANARIDeviceManager::releaseAllDevices()
{
for (auto &itr : m_rIdxs) {
auto &liveIdx = itr.second;
if (liveIdx.scene && liveIdx.idx)
liveIdx.scene->updateDelegate().erase(liveIdx.idx);
}
m_rIdxs.clear();

for (auto &d : m_loadedDevices) {
if (d.second)
anari::release(d.second, d.second);
}
m_loadedDevices.clear();
}

tsd::scene::MultiUpdateDelegate &ANARIDeviceManager::getUpdateDelegate()
{
return m_delegate;
}

void ANARIDeviceManager::setRenderIndexKind(RenderIndexKind k)
{
m_settings.renderIndexKind = k;
Expand Down
12 changes: 5 additions & 7 deletions tsd/src/tsd/app/ANARIDeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ using DeviceInitParam = std::pair<std::string, tsd::core::Any>;

/*
* Manages the lifecycle of ANARI devices and their associated RenderIndex
* instances; loads libraries on demand, reference-counts render indices per
* device, and fans update delegate signals to all active render indices.
* instances; loads libraries on demand and reference-counts one scene-owned
* RenderIndex per ANARI device.
*
* Example:
* ANARIDeviceManager mgr;
* auto device = mgr.loadDevice("visrtx");
* auto *idx = mgr.acquireRenderIndex(scene, deviceToken, device);
* mgr.releaseRenderIndex(device);
* mgr.releaseRenderIndex(scene, device);
*/
struct ANARIDeviceManager
{
Expand All @@ -45,11 +45,9 @@ struct ANARIDeviceManager
const anari::Extensions *loadDeviceExtensions(const std::string &libName);
tsd::rendering::RenderIndex *acquireRenderIndex(
tsd::scene::Scene &c, tsd::core::Token deviceName, anari::Device device);
void releaseRenderIndex(anari::Device device);
void releaseRenderIndex(tsd::scene::Scene &c, anari::Device device);
void releaseAllDevices();

tsd::scene::MultiUpdateDelegate &getUpdateDelegate();

void setRenderIndexKind(RenderIndexKind k);
RenderIndexKind renderIndexKind() const;

Expand All @@ -60,11 +58,11 @@ struct ANARIDeviceManager
const bool *m_verboseFlag{nullptr};
struct LiveAnariIndex
{
tsd::scene::Scene *scene{nullptr};
int refCount{0};
tsd::rendering::RenderIndex *idx{nullptr};
};
std::map<anari::Device, LiveAnariIndex> m_rIdxs;
tsd::scene::MultiUpdateDelegate m_delegate;
std::map<std::string, anari::Device> m_loadedDevices;
std::map<std::string, anari::Extensions> m_loadedDeviceExtensions;
std::vector<std::string> m_libraryList;
Expand Down
13 changes: 5 additions & 8 deletions tsd/src/tsd/app/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ namespace tsd::app {

TSDState::TSDState() : animationMgr(&scene) {}

Context::Context() : anari(&m_logging.verbose)
{
tsd.scene.setUpdateDelegate(&anari.getUpdateDelegate());
}
Context::Context() : anari(&m_logging.verbose) {}

Context::~Context()
{
Expand Down Expand Up @@ -248,7 +245,7 @@ void Context::setSelected(tsd::scene::LayerNodeRef node)
void Context::setSelected(const std::vector<tsd::scene::LayerNodeRef> &nodes)
{
tsd.selectedNodes = nodes;
anari.getUpdateDelegate().signalObjectFilteringChanged();
tsd.scene.updateDelegate().signalObjectFilteringChanged();
}

void Context::setSelected(const tsd::scene::Object *obj)
Expand Down Expand Up @@ -304,15 +301,15 @@ void Context::addToSelection(tsd::scene::LayerNodeRef node)
}

tsd.selectedNodes.push_back(node);
anari.getUpdateDelegate().signalObjectFilteringChanged();
tsd.scene.updateDelegate().signalObjectFilteringChanged();
}

void Context::removeFromSelection(tsd::scene::LayerNodeRef node)
{
auto it = std::find(tsd.selectedNodes.begin(), tsd.selectedNodes.end(), node);
if (it != tsd.selectedNodes.end()) {
tsd.selectedNodes.erase(it);
anari.getUpdateDelegate().signalObjectFilteringChanged();
tsd.scene.updateDelegate().signalObjectFilteringChanged();
}
}

Expand All @@ -326,7 +323,7 @@ void Context::clearSelected()
{
if (!tsd.selectedNodes.empty()) {
tsd.selectedNodes.clear();
anari.getUpdateDelegate().signalObjectFilteringChanged();
tsd.scene.updateDelegate().signalObjectFilteringChanged();
}
}
std::vector<tsd::scene::LayerNodeRef> Context::getParentOnlySelectedNodes()
Expand Down
7 changes: 5 additions & 2 deletions tsd/src/tsd/app/renderAnimationSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ void renderAnimationSequence(Context &ctx,
}
anari::commitParameters(d, d);

auto renderIndex =
std::make_unique<tsd::rendering::RenderIndexAllLayers>(scene, libName, d);
auto *renderIndex =
scene.updateDelegate().emplace<tsd::rendering::RenderIndexAllLayers>(
scene, libName, d);
renderIndex->populate();

// Validate camera — resolve index //
Expand All @@ -78,6 +79,7 @@ void renderAnimationSequence(Context &ctx,
if (!cameraRef) {
tsd::core::logError(
"[renderAnimationSequence] No camera at index %zu", camIdx);
scene.updateDelegate().erase(renderIndex);
anari::release(d, d);
return;
}
Expand Down Expand Up @@ -189,6 +191,7 @@ void renderAnimationSequence(Context &ctx,

// Restore animation state //
animMgr.setAnimationFrame(savedFrame);
scene.updateDelegate().erase(renderIndex);
}

} // namespace tsd::app
7 changes: 2 additions & 5 deletions tsd/src/tsd/rendering/index/RenderIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void RenderIndex::logCacheInfo() const
logStatus(" renderers: %zu", m_cache.renderer.size());
}

void RenderIndex::populate(bool setAsUpdateDelegate)
void RenderIndex::populate()
{
m_cache.clear();

Expand All @@ -108,9 +108,6 @@ void RenderIndex::populate(bool setAsUpdateDelegate)
createANARICacheObjects(db.camera, m_cache.camera);
createANARICacheObjects(db.renderer, m_cache.renderer);

if (setAsUpdateDelegate)
m_ctx->setUpdateDelegate(this);

updateWorld();
}

Expand Down Expand Up @@ -223,7 +220,7 @@ void RenderIndex::signalRemoveAllObjects()
void RenderIndex::signalInvalidateCachedObjects()
{
signalRemoveAllObjects();
populate(false); // always 'false' as this may already be the delegate
populate();
updateWorld();
}

Expand Down
7 changes: 5 additions & 2 deletions tsd/src/tsd/rendering/index/RenderIndex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct RenderToAnariObjectsVisitor;
* subclasses decide how layers are mapped to world instances.
*
* Example:
* auto idx = std::make_unique<RenderIndexAllLayers>(scene, device);
* auto idx = scene.updateDelegate().emplace<RenderIndexAllLayers>(
* scene, deviceName, device);
* idx->populate();
* anari::World world = idx->world();
*/
Expand All @@ -42,7 +43,9 @@ struct RenderIndex : public BaseUpdateDelegate

void logCacheInfo() const;

void populate(bool setAsUpdateDelegate = true);
// Bootstrap or fully rebuild this index from the current Scene snapshot.
// This does not register the index as a Scene update delegate.
void populate();

virtual void setFilterFunction(RenderIndexFilterFcn f);
virtual bool isFlat() const = 0;
Expand Down
Loading
Loading