Skip to content

Commit

Permalink
Automatically restart HdPrman render on ReloadResource.
Browse files Browse the repository at this point in the history
Move HdPrman resource registry into Hdx so we can dirty the scene version on interactive context.

(Internal change: 2040376)
  • Loading branch information
lumonix authored and pixar-oss committed Feb 7, 2020
1 parent e8783aa commit dcfb209
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
1 change: 0 additions & 1 deletion third_party/renderman-23/plugin/hdPrman/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pxr_shared_library(${PXR_PACKAGE}
points
renderDelegate
renderPass
resourceRegistry
rixStrings
volume
xcpt
Expand Down
6 changes: 4 additions & 2 deletions third_party/renderman-23/plugin/hdPrman/renderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "hdPrman/renderDelegate.h"
#include "hdPrman/renderParam.h"
#include "hdPrman/renderPass.h"
#include "hdPrman/resourceRegistry.h"
#include "hdPrman/volume.h"

#include "pxr/imaging/hd/tokens.h"
Expand Down Expand Up @@ -102,7 +101,10 @@ void
HdPrmanRenderDelegate::_Initialize()
{
_renderParam = std::make_shared<HdPrman_RenderParam>(_context);
_resourceRegistry = boost::make_shared<HdPrman_ResourceRegistry>(_context);

// Initialize default resource registry. HdxPrman may override this with its
// resource registry during HdxPrmanRenderDelegate::_Initialize.
_resourceRegistry.reset(new HdResourceRegistry());

std::string integrator = HdPrmanIntegratorTokens->PxrPathTracer;
const std::string interactiveIntegrator =
Expand Down
1 change: 1 addition & 0 deletions third_party/renderman-23/plugin/hdxPrman/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pxr_plugin(${PXR_PACKAGE}
renderBuffer
renderDelegate
renderPass
resourceRegistry

CPPFILES
rendererPlugin
Expand Down
4 changes: 4 additions & 0 deletions third_party/renderman-23/plugin/hdxPrman/renderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "renderBuffer.h"
#include "renderParam.h"
#include "renderPass.h"
#include "resourceRegistry.h"
#include "context.h"

#include "hdPrman/instancer.h"
Expand Down Expand Up @@ -68,6 +69,9 @@ HdxPrmanRenderDelegate::_Initialize(std::shared_ptr<HdPrman_Context> context)
_interactiveContext);
_interactiveContext->Begin(this);
}

_resourceRegistry = boost::make_shared<HdxPrman_ResourceRegistry>(
_interactiveContext);
}

HdxPrmanRenderDelegate::~HdxPrmanRenderDelegate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,33 @@
//
#include "pxr/imaging/hd/tokens.h"
#include "RixRiCtl.h"
#include "hdPrman/resourceRegistry.h"
#include "resourceRegistry.h"
#include "context.h"


PXR_NAMESPACE_OPEN_SCOPE

HdPrman_ResourceRegistry::HdPrman_ResourceRegistry(
std::shared_ptr<HdPrman_Context> const& context)
HdxPrman_ResourceRegistry::HdxPrman_ResourceRegistry(
std::shared_ptr<HdxPrman_InteractiveContext> const& context)
: _context(context)
{
}

HdPrman_ResourceRegistry::~HdPrman_ResourceRegistry()
HdxPrman_ResourceRegistry::~HdxPrman_ResourceRegistry()
{
}

void
HdPrman_ResourceRegistry::ReloadResource(
HdxPrman_ResourceRegistry::ReloadResource(
TfToken const& resourceType,
std::string const& path)
{
if (resourceType == HdResourceTypeTokens->texture) {
_context->ri->InvalidateTexture(RtUString(path.c_str()));
}

_context->StopRender();
_context->sceneVersion.fetch_add(1);
}

PXR_NAMESPACE_CLOSE_SCOPE
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,35 @@
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef EXT_RMANPKG_23_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_RESOURCE_REGISTRY_H
#define EXT_RMANPKG_23_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_RESOURCE_REGISTRY_H
#ifndef EXT_RMANPKG_23_0_PLUGIN_RENDERMAN_PLUGIN_HDX_PRMAN_RESOURCE_REGISTRY_H
#define EXT_RMANPKG_23_0_PLUGIN_RENDERMAN_PLUGIN_HDX_PRMAN_RESOURCE_REGISTRY_H

#include "pxr/pxr.h"
#include "pxr/imaging/hd/resourceRegistry.h"
#include "hdPrman/api.h"
#include "hdPrman/context.h"
#include "context.h"

PXR_NAMESPACE_OPEN_SCOPE

/// HdPrman's implementation of the hydra resource registry.
/// HdxPrman's implementation of the hydra resource registry.
/// Renderman manages its resources internally, but uses the HdResourceRegistry
/// to respond to certain resource changes, such as texture reloading.
class HdPrman_ResourceRegistry final : public HdResourceRegistry {
class HdxPrman_ResourceRegistry final : public HdResourceRegistry {
public:
HDPRMAN_API
HdPrman_ResourceRegistry(std::shared_ptr<HdPrman_Context> const& context);
HdxPrman_ResourceRegistry(
std::shared_ptr<HdxPrman_InteractiveContext> const& context);

HDPRMAN_API
virtual ~HdPrman_ResourceRegistry();
virtual ~HdxPrman_ResourceRegistry();

HDPRMAN_API
void ReloadResource(
TfToken const& resourceType,
std::string const& path) override;

private:
std::shared_ptr<HdPrman_Context> _context;
std::shared_ptr<HdxPrman_InteractiveContext> _context;
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down

0 comments on commit dcfb209

Please sign in to comment.