7#ifndef PXR_EXEC_EF_PAGE_CACHE_BASED_EXECUTOR_H
8#define PXR_EXEC_EF_PAGE_CACHE_BASED_EXECUTOR_H
14#include "pxr/exec/ef/loftedOutputSet.h"
27PXR_NAMESPACE_OPEN_SCOPE
41 template <
typename>
class EngineType,
42 typename DataManagerType>
55 _engine(*this, &this->_dataManager),
56 _cacheStorage(cacheStorage),
86 const VdfMask &mask)
const override;
91 const VdfMask &mask)
const override;
100 const VdfRequest &computeRequest,
105 bool _IsCaching()
const;
113 bool _InvalidateOutput(
115 const VdfMask &invalidationMask)
override;
119 virtual bool _PreProcessInvalidation(
120 const VdfMaskedOutputVector &invalidationRequest,
121 VdfMaskedOutputVector *processedRequest);
124 void _ClearDataForOutput(
129 EngineType<DataManagerType> _engine;
145template <
template <
typename>
class EngineType,
typename DataManagerType>
154 Base::SetOutputValue(output, value, mask);
159 if (_cacheStorage->_IsKeyOutput(output, mask)) {
160 _currentCache = _cacheStorage->_GetOrCreateCache(value);
164template <
template <
typename>
class EngineType,
typename DataManagerType>
169 _loftedOutputs.RemoveAllOutputsForNode(node);
173template <
template <
typename>
class EngineType,
typename DataManagerType>
184 Base::_dataManager.GetInputValue(connection, mask)) {
193template <
template <
typename>
class EngineType,
typename DataManagerType>
205 Base::_dataManager.GetOutputValueForReading(
206 Base::_dataManager.GetDataHandle(output.
GetId()), mask)) {
211 return _GetPageCacheValue(output, mask);
214template <
template <
typename>
class EngineType,
typename DataManagerType>
218 const VdfRequest &computeRequest,
222 if (computeRequest.IsEmpty()) {
230 _loftedOutputs.Resize(*schedule.
GetNetwork());
234 if (
TF_VERIFY(_currentCache) && _IsCaching()) {
235 const DataManagerType &dataManager = Base::_dataManager;
236 const VdfRequest &cacheableRequest =
237 _cacheStorage->GetCacheableRequest(computeRequest);
238 VdfRequest::IndexedView cacheableView(cacheableRequest);
243 schedule, computeRequest, errorLogger,
244 [&dataManager, &cacheableView, cache, storage]
249 const VdfVector *value = dataManager.GetOutputValueForReading(
252 if (!value || !cacheableView.Get(requestedIndex)) {
258 Ef_OutputValueCache::SharedAccess access(cache);
259 if (access.GetValue(*mo.GetOutput(), mo.GetMask())) {
266 storage->_Commit(mo, *value, &access);
272 _engine.RunSchedule(schedule, computeRequest, errorLogger);
276template <
template <
typename>
class EngineType,
typename DataManagerType>
281 _cacheStorage->IsEnabled() &&
285template <
template <
typename>
class EngineType,
typename DataManagerType>
297 if (!_currentCache) {
305 if (
const VdfVector *cachedValue = cacheAccess.GetValue(output, mask)) {
308 if (_loftedOutputs.Add(output, mask)) {
311 Base::_TouchOutput(output);
323template <
template <
typename>
class EngineType,
typename DataManagerType>
327 const VdfMask &invalidationMask)
330 if (Base::_InvalidateOutput(output, invalidationMask)) {
333 _loftedOutputs.Remove(
345template <
template <
typename>
class EngineType,
typename DataManagerType>
348 const VdfMaskedOutputVector &invalidationRequest,
349 VdfMaskedOutputVector *processedRequest)
353 const size_t numLoftedOutputs = _loftedOutputs.GetSize();
354 if (numLoftedOutputs == 0) {
362 _cacheStorage->_FindDependencies(invalidationRequest);
371 processedRequest->reserve(
372 invalidationRequest.size() +
373 std::min(numLoftedOutputs, deps.size()));
378 _loftedOutputs.CollectLoftedDependencies(deps, processedRequest);
379 if (processedRequest->empty()) {
386 processedRequest->insert(
387 processedRequest->end(),
388 invalidationRequest.begin(), invalidationRequest.end());
397template <
template <
typename>
class EngineType,
typename DataManagerType>
402 Base::_ClearDataForOutput(outputId, nodeId);
403 _loftedOutputs.Remove(outputId, nodeId,
VdfMask());
407template <
template <
typename>
class EngineType,
typename DataManagerType>
411 _loftedOutputs.Clear();
414PXR_NAMESPACE_CLOSE_SCOPE
Tracks the set of lofted outputs (outputs whose values were sourced from the page cache during evalua...
An accessor that provides exclusive read/write access to the cache.
This accessor grants shared read access to the cache, preventing any concurrent write access.
An output-to-value storage for caching.
Executes a VdfNetwork to compute a requested set of values.
virtual const VdfVector * _GetOutputValueForReading(const VdfOutput &output, const VdfMask &mask) const override
Returns an output value for reading.
virtual const VdfVector * _GetInputValue(const VdfConnection &connection, const VdfMask &mask) const override
Returns value for the cache that flows across connection.
virtual void _ClearData()
Virtual implementation of the ClearData call.
virtual ~EfPageCacheBasedExecutor()
Destructor.
void WillDeleteNode(const VdfNode &node)
Removes any internal references to node upon deleting the node from the VdfNetwork.
EfPageCacheBasedExecutor(EfPageCacheStorage *cacheStorage)
Constructor.
virtual void SetOutputValue(const VdfOutput &output, const VdfVector &value, const VdfMask &mask)
Set an output value.
Manages a page cache and provides methods for invalidation of cached values.
static EF_API bool HasReachedMemoryLimit()
Returns true, if the upper memory limit has been reached, and the object is no longer allowed to allo...
A class that fully represents a connection between two VdfNodes.
const VdfOutput & GetSourceOutput() const
Returns the output (ie. source) for this connection.
Base class for executors that use a data manager.
A client may instantiate an object of this class and set it in an executor, to collect errors that ma...
A VdfMask is placed on connections to specify the data flowing through them.
Class to hold on to an externally owned output and a mask.
VdfOutput * GetOutput() const
Returns the VdfOutput.
const VdfMask & GetMask() const
Returns the VdfMask.
This is the base class for all nodes in a VdfNetwork.
VdfId GetId() const
Returns the unique id of this node in its network.
A VdfOutput represents an output on a node.
const VdfNode & GetNode() const
Returns the owning node for this output.
VdfId GetId() const
The unique id of this output.
Contains a specification of how to execute a particular VdfNetwork.
const VdfNetwork * GetNetwork() const
Returns the network for this schedule.
This class is used to abstract away knowledge of the cache data used for each node.
uint64_t VdfId
The unique identifier type for Vdf objects.
std::unordered_map< const VdfOutput *, VdfMask, TfHash > VdfOutputToMaskMap
A map from output pointer to mask.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.