@@ -62,7 +62,7 @@ class HnMaterial final : public pxr::HdMaterial
6262{
6363public:
6464 static HnMaterial* Create (const pxr::SdfPath& id);
65- static HnMaterial* CreateFallback (HnTextureRegistry& TexRegistry, const USD_Renderer& UsdRenderer );
65+ static HnMaterial* CreateFallback (HnRenderDelegate& RenderDelegate );
6666
6767 ~HnMaterial ();
6868
@@ -78,8 +78,8 @@ class HnMaterial final : public pxr::HdMaterial
7878 // / Creates an SRB cache that should be passed to UpdateSRB().
7979 static RefCntAutoPtr<IObject> CreateSRBCache ();
8080
81- bool UpdateSRB (HnRenderDelegate& RendererDelegate );
82- void BindMaterialAttribsBuffer (HnRenderDelegate& RendererDelegate );
81+ bool UpdateSRB (HnRenderDelegate& RenderDelegate );
82+ void BindMaterialAttribsBuffer (HnRenderDelegate& RenderDelegate );
8383
8484 IShaderResourceBinding* GetSRB () const { return m_SRB; }
8585 IShaderResourceBinding* GetSRB (Uint32 PrimitiveAttribsOffset) const
@@ -88,10 +88,11 @@ class HnMaterial final : public pxr::HdMaterial
8888 m_PrimitiveAttribsVar->SetBufferOffset (PrimitiveAttribsOffset);
8989 return m_SRB;
9090 }
91- void SetMaterialAttribsBufferOffset (Uint32 Offset ) const
91+ void ApplyMaterialAttribsBufferOffset ( ) const
9292 {
9393 VERIFY_EXPR (m_MaterialAttribsVar != nullptr );
94- m_MaterialAttribsVar->SetBufferOffset (Offset);
94+ VERIFY_EXPR (m_PBRMaterialAttribsBufferOffset != ~0u );
95+ m_MaterialAttribsVar->SetBufferOffset (m_PBRMaterialAttribsBufferOffset);
9596 }
9697 void SetJointsBufferOffset (Uint32 Offset) const
9798 {
@@ -132,7 +133,12 @@ class HnMaterial final : public pxr::HdMaterial
132133 }
133134
134135 Uint32 GetPBRPrimitiveAttribsBufferRange () const { return m_PBRPrimitiveAttribsBufferRange; }
135- Uint32 GetPBRMaterailAttribsBufferRange () const { return m_PBRMaterialAttribsBufferRange; }
136+ Uint32 GetPBRMaterialAttribsSize () const { return m_PBRMaterialAttribsSize; }
137+ Uint32 GetPBRMaterialAttribsBufferOffset () const
138+ {
139+ VERIFY_EXPR (m_PBRMaterialAttribsBufferOffset != ~0u );
140+ return m_PBRMaterialAttribsBufferOffset;
141+ }
136142
137143private:
138144 HnMaterial (pxr::SdfPath const & id);
@@ -142,15 +148,14 @@ class HnMaterial final : public pxr::HdMaterial
142148 // \remarks Sync() is not called on fallback material,
143149 // but we need to initialize default textures,
144150 // so we have to use this special constructor.
145- HnMaterial (HnTextureRegistry& TexRegistry, const USD_Renderer& UsdRenderer );
151+ HnMaterial (HnRenderDelegate& RenderDelegate );
146152
147153 // A mapping from the texture name to the texture coordinate set index in m_TexCoords array (e.g. "diffuseColor" -> 0)
148154 // The same index is set in m_ShaderTextureAttribs[].UVSelector for the corresponding texture.
149155 // The name of the primvar that contains the texture coordinates is given by m_TexCoords[index].PrimVarName (e.g. "st0").
150156 using TexNameToCoordSetMapType = std::unordered_map<pxr::TfToken, size_t , pxr::TfToken::HashFunctor>;
151157 void AllocateTextures (const HnMaterialNetwork& Network,
152- HnTextureRegistry& TexRegistry,
153- const USD_Renderer& UsdRenderer);
158+ HnRenderDelegate& RenderDelegate);
154159 void InitTextureAttribs (const HnMaterialNetwork& Network,
155160 HnTextureRegistry& TexRegistry,
156161 const USD_Renderer& UsdRenderer,
@@ -161,6 +166,7 @@ class HnMaterial final : public pxr::HdMaterial
161166 HnTextureRegistry::TextureHandleSharedPtr GetDefaultTexture (HnTextureRegistry& TexRegistry, const pxr::TfToken& Name);
162167
163168 void ProcessMaterialNetwork (const HnMaterialNetwork& Network);
169+ void AllocateBufferSpace (HnRenderDelegate& RenderDelegate);
164170
165171private:
166172 pxr::TfToken m_Tag;
@@ -175,6 +181,7 @@ class HnMaterial final : public pxr::HdMaterial
175181 GLTF::Material m_MaterialData;
176182
177183 std::atomic<bool > m_TextureAddressingAttribsDirty{false };
184+ std::atomic<bool > m_GPUDataDirty{true };
178185
179186 // The names of the primvars that contain unique texture coordinate sets for this material (e.g. "st0", "st1").
180187 // The index in this array for texture N is given by m_ShaderTextureAttribs[N].UVSelector.
@@ -184,11 +191,24 @@ class HnMaterial final : public pxr::HdMaterial
184191 Uint32 m_PBRPrimitiveAttribsBufferRange = 0 ;
185192
186193 // The range that is used to bind the cbMaterialAttribs buffer.
194+ // This is the maximum of all material attribs buffer sizes for
195+ // all materials that use the same SRB.
187196 Uint32 m_PBRMaterialAttribsBufferRange = 0 ;
188197
198+ PBR_Renderer::PSO_FLAGS m_PSOFlags = PBR_Renderer::PSO_FLAG_NONE;
199+
200+ // Material attribs shader data size in bytes.
201+ Uint32 m_PBRMaterialAttribsSize = 0 ;
202+
203+ // The offset in the cbMaterialAttribs buffer.
204+ Uint32 m_PBRMaterialAttribsBufferOffset = ~0u ;
205+
189206 // Current texture storage version
190207 Uint32 m_TexRegistryStorageVersion = 0 ;
191208
209+ // Current material attribs buffer version
210+ Uint32 m_MaterialAttribsBufferVersion = ~0u ;
211+
192212 ShaderTextureIndexingIdType m_ShaderTextureIndexingId = 0 ;
193213};
194214
0 commit comments