Skip to content

Commit 7cadce6

Browse files
unhyperbolicpixar-oss
authored andcommitted
hdPrman: Hydra 2.0 implementation as scene index observer.
The new implementation is only used when HD_PRMAN_EXPERIMENTAL_RILEY_SCENE_INDEX_OBSERVER is set to true and only used for spheres. (Internal change: 2321593) (Internal change: 2321702)
1 parent 1732117 commit 7cadce6

15 files changed

Lines changed: 1151 additions & 3 deletions

third_party/renderman-25/plugin/hdPrman/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ pxr_plugin(${PXR_PACKAGE}
107107
renderSettings
108108
rileyCameraSchema
109109
rileyClippingPlaneSchema
110+
rileyConversionSceneIndexPlugin
110111
rileyCoordinateSystemSchema
111112
rileyDisplacementSchema
112113
rileyDisplayFilterSchema
113114
rileyDisplaySchema
115+
rileyFallbackMaterialSceneIndexPlugin
114116
rileyGeometryInstanceSchema
115117
rileyGeometryPrototypeSchema
116118
rileyIntegratorSchema

third_party/renderman-25/plugin/hdPrman/hdSchemaDefs.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
SCHEMA_NAME = 'RileyParam',
3636
MEMBERS = [
3737
('value', T_SAMPLED, {}),
38-
('role', T_TOKEN, {}),
38+
('role', T_TOKEN,
39+
dict(DOC = '''
40+
Disambiguates what call to RtParamList::SetFOO to use.
41+
42+
Can take values from HdPrimvarRoleTokens and
43+
HdPrmanRileyAdditionalRoleTokens.''')),
3944
],
4045
),
4146

@@ -68,7 +73,12 @@
6873
MEMBERS = [
6974
('value', T_SAMPLED, {}),
7075
('detailType', T_TOKEN, {}),
71-
('role', T_TOKEN, {}),
76+
('role', T_TOKEN,
77+
dict(DOC = '''
78+
Disambiguates what call to RtPrimvarList::SetFOO to use.
79+
80+
Can take values from HdPrimvarRoleTokens and
81+
HdPrmanRileyAdditionalRoleTokens.''')),
7282
],
7383

7484
STATIC_TOKEN_DATASOURCE_BUILDERS = [

third_party/renderman-25/plugin/hdPrman/plugInfo.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@
8686
"loadWithRenderer" : "Prman",
8787
"priority": 0,
8888
"displayName": "Scene Index to convert tet meshes into standard triangle based meshes."
89+
},
90+
"HdPrman_RileyFallbackMaterialSceneIndexPlugin" : {
91+
"bases": ["HdSceneIndexPlugin"],
92+
"loadWithRenderer" : "Prman",
93+
"priority": 0,
94+
"displayName": "Adds fallback material to scene index."
95+
},
96+
"HdPrman_RileyConversionSceneIndexPlugin" : {
97+
"bases": ["HdSceneIndexPlugin"],
98+
"loadWithRenderer" : "Prman",
99+
"priority": 0,
100+
"displayName": "Converts Hydra prims to Riley prims."
89101
}
90102
}
91103
},

third_party/renderman-25/plugin/hdPrman/renderDelegate.cpp

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
#include "hdPrman/terminalSceneIndexObserver.h"
4747
#include "hdPrman/tokens.h"
4848
#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
4956

5057
#include "pxr/imaging/hd/bprim.h"
5158
#include "pxr/imaging/hd/camera.h"
@@ -64,6 +71,115 @@
6471

6572
PXR_NAMESPACE_OPEN_SCOPE
6673

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+
67183
extern TfEnvSetting<bool> HD_PRMAN_ENABLE_QUICKINTEGRATE;
68184

69185
TF_DEFINE_PRIVATE_TOKENS(
@@ -689,11 +805,37 @@ HdPrmanRenderDelegate::SetTerminalSceneIndex(
689805
std::make_unique<HdPrman_TerminalSceneIndexObserver>(
690806
_renderParam, terminalSceneIndex);
691807
}
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
692820
}
693821

694822
void
695823
HdPrmanRenderDelegate::Update()
696824
{
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+
697839
if (!_terminalObserver) {
698840
TF_CODING_ERROR("Invalid terminal scene index observer.");
699841
return;

third_party/renderman-25/plugin/hdPrman/renderDelegate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ class HdPrmanRenderDelegate : public HdRenderDelegate
258258
_terminalObserver;
259259
#endif
260260

261+
struct _RileySceneIndices;
262+
std::unique_ptr<_RileySceneIndices> _rileySceneIndices;
263+
261264
HdResourceRegistrySharedPtr _resourceRegistry;
262265
HdRenderPassSharedPtr _renderPass;
263266
HdRenderSettingDescriptorList _settingDescriptors;

0 commit comments

Comments
 (0)