Skip to content

Commit

Permalink
implement flush texture using render delegate commands (#1341)
Browse files Browse the repository at this point in the history
* implement flush texture using render delegate commands

* add a rendersetting parameter to act as a trigger to flush the textures
  • Loading branch information
cpichard authored Nov 21, 2022
1 parent b0f7860 commit 9750c63
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions common/constant_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ ASTR(filename);
ASTR(filters);
ASTR(filterwidth);
ASTR(flat);
ASTR(flush_textures);
ASTR(focus_distance);
ASTR(format);
ASTR(fov);
Expand Down
4 changes: 4 additions & 0 deletions render_delegate/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ struct HdArnoldConfig {
///
std::string osl_includepath; ///< OSL includepath.

/// ask for flush texture cache
///
bool flush_textures;

private:
/// Constructor for reading the values from the environment variables.
HDARNOLD_API
Expand Down
30 changes: 29 additions & 1 deletion render_delegate/render_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const SupportedRenderSettings& _GetSupportedRenderSettings()
static const auto& config = HdArnoldConfig::GetInstance();
static const SupportedRenderSettings data{
// Global settings to control rendering
{str::t_flush_textures, {"Flush textures", config.flush_textures}},
{str::t_enable_progressive_render, {"Enable Progressive Render", config.enable_progressive_render}},
{str::t_progressive_min_AA_samples,
{"Progressive Render Minimum AA Samples", config.progressive_min_AA_samples}},
Expand Down Expand Up @@ -654,6 +655,12 @@ void HdArnoldRenderDelegate::_SetRenderSetting(const TfToken& _key, const VtValu
if (value.IsHolding<GfVec2i>()) {
_resolution = value.UncheckedGet<GfVec2i>();
}
} else if (key == str::t_flush_textures) {
_renderParam->Pause();
// Flush texture
AiUniverseCacheFlush(_universe, AI_CACHE_TEXTURE);
// Restart the render
_renderParam->Resume();
} else {
auto* optionsEntry = AiNodeGetNodeEntry(_options);
// Sometimes the Render Delegate receives parameters that don't exist
Expand Down Expand Up @@ -769,7 +776,7 @@ VtValue HdArnoldRenderDelegate::GetRenderSetting(const TfToken& _key) const
{
TfToken key;
_RemoveArnoldGlobalPrefix(_key, key);

if (key == str::t_flush_textures) return VtValue(false);
if (key == str::t_enable_gpu_rendering) {
return VtValue(AiNodeGetStr(_options, str::render_device) == str::GPU);
} else if (key == str::t_enable_progressive_render) {
Expand Down Expand Up @@ -1506,5 +1513,26 @@ void HdArnoldRenderDelegate::ClearCryptomatteDrivers()
_cryptomatteDrivers.clear();
}

#if PXR_VERSION >= 2108
HdCommandDescriptors HdArnoldRenderDelegate::GetCommandDescriptors() const
{
HdCommandDescriptors descriptors;
descriptors.emplace_back(TfToken("flush_texture"), "Flush textures");
return descriptors;
}

bool HdArnoldRenderDelegate::InvokeCommand(const TfToken& command, const HdCommandArgs& args)
{
if (command == TfToken("flush_texture")) {
// Pause render
_renderParam->Pause();
// Flush texture
AiUniverseCacheFlush(_universe, AI_CACHE_TEXTURE);
// Restart the render
_renderParam->Resume();
}
return false;
}
#endif // PXR_VERSION

PXR_NAMESPACE_CLOSE_SCOPE
11 changes: 11 additions & 0 deletions render_delegate/render_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,17 @@ class HdArnoldRenderDelegate final : public HdRenderDelegate {
GfVec2i GetResolution() const {return _resolution;}

bool IsBatchContext() const {return _isBatch;}

#if PXR_VERSION >= 2108
/// Get the descriptors for the commands supported by this render delegate.
HDARNOLD_API
virtual HdCommandDescriptors GetCommandDescriptors() const override;

/// Invoke a HdArnoldRenderDelegate command
HDARNOLD_API
virtual bool InvokeCommand(const TfToken& command, const HdCommandArgs& args = HdCommandArgs()) override;
#endif

private:
HdArnoldRenderDelegate(const HdArnoldRenderDelegate&) = delete;
HdArnoldRenderDelegate& operator=(const HdArnoldRenderDelegate&) = delete;
Expand Down

0 comments on commit 9750c63

Please sign in to comment.