|
46 | 46 | #include "hdPrman/terminalSceneIndexObserver.h" |
47 | 47 | #include "hdPrman/tokens.h" |
48 | 48 | #include "hdPrman/volume.h" |
| 49 | +#include "hdPrman/sceneIndexObserverApi.h" |
| 50 | + |
| 51 | +#ifdef HDPRMAN_USE_SCENE_INDEX_OBSERVER |
| 52 | +#include "hdPrman/rileyPrimFactory.h" |
| 53 | +#include "pxr/imaging/hdsi/primManagingSceneIndexObserver.h" |
| 54 | +#include "pxr/imaging/hdsi/primTypeNoticeBatchingSceneIndex.h" |
| 55 | +#endif |
49 | 56 |
|
50 | 57 | #include "pxr/imaging/hd/bprim.h" |
51 | 58 | #include "pxr/imaging/hd/camera.h" |
|
64 | 71 |
|
65 | 72 | PXR_NAMESPACE_OPEN_SCOPE |
66 | 73 |
|
| 74 | +#ifdef HDPRMAN_USE_SCENE_INDEX_OBSERVER |
| 75 | + |
| 76 | +TF_DEFINE_ENV_SETTING(HD_PRMAN_EXPERIMENTAL_RILEY_SCENE_INDEX_OBSERVER, false, |
| 77 | + "Enable scene index observer calling the Riley API for " |
| 78 | + "the prims in the terminal scene index. This is scene " |
| 79 | + "index observer is the first step towards a future " |
| 80 | + "Hydra 2.0 implementation. " |
| 81 | + "See HdPrmanRenderDelegate::_RileySceneIndices for more."); |
| 82 | + |
| 83 | +#endif |
| 84 | + |
| 85 | +// \class HdPrmanRenderDelegate::_RileySceneIndices. |
| 86 | +// |
| 87 | +// Holds the scene indices and scene index observers past the terminal scene |
| 88 | +// index coming from the render index. The Hydra 2.0 implementation also |
| 89 | +// relies on several plugin scene indices inserted by the render index (only if |
| 90 | +// HD_PRMAN_EXPERIMENTAL_RILEY_SCENE_INDEX_OBSERVER is true). |
| 91 | +// |
| 92 | +// Overall, the scene indices are as follows: |
| 93 | +// |
| 94 | +// 1. HdPrman_RileyFallbackMaterialSceneIndexPlugin |
| 95 | +// Adds a hard-coded riley material at GetFallbackMaterialPath(). |
| 96 | +// |
| 97 | +// 2. HdPrman_RileyConversionSceneIndexPlugin |
| 98 | +// |
| 99 | +// Converts some hydra prims to riley prims (following, e.g., |
| 100 | +// HdPrmanRileyGeometryPrototypeSchema). |
| 101 | +// |
| 102 | +// Note that we can have some hydra prims be handled by converting them to |
| 103 | +// riley prims in this scene index and others go through emulation and |
| 104 | +// the Hydra 1.0 path. |
| 105 | +// |
| 106 | +// For example, the scene index converts a sphere to a |
| 107 | +// riley:geometryPrototype and riley:geometryInstance. These prims will |
| 108 | +// be observed (see later) by |
| 109 | +// HdPrmanRenderDelegate::_RileySceneIndices::_primManagingSceneIndexObserver |
| 110 | +// which will issue the corresponding riley Create/Modify/Delete calls. |
| 111 | +// Because the original sphere has been converted to different prim types, |
| 112 | +// there is no instantiation of HdPrman_Sphere. |
| 113 | +// Also, note that we do not report riley:geometryPrototype or |
| 114 | +// riley:geometryInstance by any |
| 115 | +// HdPrmanRenderDelegate::GetSupported[RSB]primTypes(). |
| 116 | +// |
| 117 | +// Another example is mesh. The scene index does not convert a mesh. |
| 118 | +// mesh is reported by HdPrmanRenderDelegate::GetSupportedRprimTypes(). |
| 119 | +// Thus, HdSceneIndexAdapterSceneDelegate will call _InsertRprim for |
| 120 | +// a mesh and thus we instantiate HdPrman_mesh. |
| 121 | +// |
| 122 | +// The conversion scene index is also the terminal scene index in the render |
| 123 | +// index. However, _RileySceneIndices continues the chain of filtering scene |
| 124 | +// indices and observers as follows: |
| 125 | +// |
| 126 | +// 3. HdsiPrimTypeNoticeBatchingSceneIndex _noticeBatchingSceneIndex |
| 127 | +// |
| 128 | +// This scene index postpones any prim messages until we sync. |
| 129 | +// During sync (more precisely, in HdPrmanRenderDelegate::Update()), it |
| 130 | +// sorts and batches the messages to fulfill dependencies between prims. |
| 131 | +// E.g. the Riley::CreateGeometryInstance call needs the result of |
| 132 | +// Riley::CreateGeometryPrototype, so this scene index sends out the |
| 133 | +// messages for riley:geometryInstance first. |
| 134 | +// |
| 135 | +// 4. HdsiPrimManagingSceneIndexObserver _primManagingSceneIndexObserver |
| 136 | +// |
| 137 | +// This observer calls, e.g., Riley::Create/Modify/DeleteGeometryInstance |
| 138 | +// in response to add/modify/delete prim messages. |
| 139 | +// |
| 140 | +struct HdPrmanRenderDelegate::_RileySceneIndices |
| 141 | +{ |
| 142 | +#ifdef HDPRMAN_USE_SCENE_INDEX_OBSERVER |
| 143 | + _RileySceneIndices( |
| 144 | + HdSceneIndexBaseRefPtr const &terminalSceneIndex, |
| 145 | + HdPrman_RenderParam * const renderParam) |
| 146 | + : _noticeBatchingSceneIndex( |
| 147 | + HdsiPrimTypeNoticeBatchingSceneIndex::New( |
| 148 | + terminalSceneIndex, |
| 149 | + HdPrman_RileyPrimFactory:: |
| 150 | + GetPrimTypeNoticeBatchingSceneIndexInputArgs())) |
| 151 | + , _primManagingSceneIndexObserver( |
| 152 | + HdsiPrimManagingSceneIndexObserver::New( |
| 153 | + _noticeBatchingSceneIndex, |
| 154 | + _Args(renderParam))) |
| 155 | + { |
| 156 | + } |
| 157 | + |
| 158 | + static |
| 159 | + HdContainerDataSourceHandle |
| 160 | + _Args(HdPrman_RenderParam * const renderParam) |
| 161 | + { |
| 162 | + using DataSource = |
| 163 | + HdRetainedTypedSampledDataSource< |
| 164 | + HdsiPrimManagingSceneIndexObserver::PrimFactoryBaseHandle>; |
| 165 | + |
| 166 | + return |
| 167 | + HdRetainedContainerDataSource::New( |
| 168 | + HdsiPrimManagingSceneIndexObserverTokens->primFactory, |
| 169 | + DataSource::New( |
| 170 | + std::make_shared<HdPrman_RileyPrimFactory>(renderParam))); |
| 171 | + } |
| 172 | + |
| 173 | + void Update() |
| 174 | + { |
| 175 | + _noticeBatchingSceneIndex->Flush(); |
| 176 | + } |
| 177 | + |
| 178 | + HdsiPrimTypeNoticeBatchingSceneIndexRefPtr _noticeBatchingSceneIndex; |
| 179 | + HdsiPrimManagingSceneIndexObserverRefPtr _primManagingSceneIndexObserver; |
| 180 | +#endif |
| 181 | +}; |
| 182 | + |
67 | 183 | extern TfEnvSetting<bool> HD_PRMAN_ENABLE_QUICKINTEGRATE; |
68 | 184 |
|
69 | 185 | TF_DEFINE_PRIVATE_TOKENS( |
@@ -689,11 +805,37 @@ HdPrmanRenderDelegate::SetTerminalSceneIndex( |
689 | 805 | std::make_unique<HdPrman_TerminalSceneIndexObserver>( |
690 | 806 | _renderParam, terminalSceneIndex); |
691 | 807 | } |
| 808 | + |
| 809 | +#ifdef HDPRMAN_USE_SCENE_INDEX_OBSERVER |
| 810 | + if (terminalSceneIndex) { |
| 811 | + if (TfGetEnvSetting(HD_PRMAN_EXPERIMENTAL_RILEY_SCENE_INDEX_OBSERVER)) { |
| 812 | + if (!_rileySceneIndices) { |
| 813 | + _rileySceneIndices = |
| 814 | + std::make_unique<_RileySceneIndices>( |
| 815 | + terminalSceneIndex, _renderParam.get()); |
| 816 | + } |
| 817 | + } |
| 818 | + } |
| 819 | +#endif |
692 | 820 | } |
693 | 821 |
|
694 | 822 | void |
695 | 823 | HdPrmanRenderDelegate::Update() |
696 | 824 | { |
| 825 | +#ifdef HDPRMAN_USE_SCENE_INDEX_OBSERVER |
| 826 | + if (_rileySceneIndices) { |
| 827 | + // We need to set some paths before any riley Create call can |
| 828 | + // be issued - otherwise, we get a crash. |
| 829 | + // |
| 830 | + // TODO: There should be a designated prim in the scene index |
| 831 | + // to communicate the global riley options. |
| 832 | + // |
| 833 | + _renderParam->SetRileyOptions(); |
| 834 | + |
| 835 | + _rileySceneIndices->Update(); |
| 836 | + } |
| 837 | +#endif |
| 838 | + |
697 | 839 | if (!_terminalObserver) { |
698 | 840 | TF_CODING_ERROR("Invalid terminal scene index observer."); |
699 | 841 | return; |
|
0 commit comments