Loading...
Searching...
No Matches
outputSpec.h
Go to the documentation of this file.
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_VDF_OUTPUT_SPEC_H
8#define PXR_EXEC_VDF_OUTPUT_SPEC_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
16
18#include "pxr/base/tf/token.h"
19#include "pxr/base/tf/type.h"
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23// Manually implemented vtable+typeinfo block for VdfOutputSpec.
24struct Vdf_OutputSpecTypeInfo
25{
26 using AllocateCacheFn = VdfVector* (*)();
27 using ResizeCacheFn = void (*)(VdfVector *, const VdfMask::Bits &);
28
29 TfType type;
30 AllocateCacheFn allocateCache;
31 ResizeCacheFn resizeCache;
32};
33
40{
41public:
42 TF_MALLOC_TAG_NEW("Vdf", "new VdfOutputSpec");
43
44 template <typename T>
45 static VdfOutputSpec *New(const TfToken &name) {
46 return new VdfOutputSpec(_GenerateTypeInfo<T>(), name);
47 }
48
49 VDF_API
50 static VdfOutputSpec *New(TfType type, const TfToken &name);
51
52 VDF_API
54
56 VDF_API
57 std::string GetTypeName() const;
58
60 TfType GetType() const { return _typeinfo->type; }
61
63 const TfToken &GetName() const { return _name; }
64
66 VDF_API
68
70 VDF_API
71 void ResizeCache(VdfVector *vector, const VdfMask::Bits &bits) const;
72
75 bool operator==(const VdfOutputSpec &rhs) const {
76 return GetType() == rhs.GetType() && _name == rhs._name;
77 }
78 bool operator!=(const VdfOutputSpec &rhs) const {
79 return !(*this == rhs);
80 }
81
83 VDF_API
84 size_t GetHash() const;
85
86private:
87
89 const Vdf_OutputSpecTypeInfo *typeinfo,
90 const TfToken &name)
91 : _typeinfo(typeinfo)
92 , _name(name)
93 {}
94
95 template <typename T>
96 static VdfVector *_AllocateCache() {
97 return new VdfTypedVector<T>();
98 }
99
100 template <typename T>
101 static void _ResizeCache(VdfVector *cache, const VdfMask::Bits &bits) {
102 cache->Resize<T>(bits);
103 }
104
105 // Return a pointer to a static vtable+typeinfo block.
106 template <typename T>
107 static const Vdf_OutputSpecTypeInfo * _GenerateTypeInfo() {
108 static const Vdf_OutputSpecTypeInfo ti = {
109 TfType::Find<T>(), _AllocateCache<T>, _ResizeCache<T>
110 };
111 return &ti;
112 }
113
114 // Register a type for runtime manufacturing.
115 // Only VdfExecutionTypeRegistry should register types.
116 friend class VdfExecutionTypeRegistry;
117 VDF_API
118 static void _RegisterType(const Vdf_OutputSpecTypeInfo *);
119
120 template <typename T>
121 static void _RegisterType() {
122 _RegisterType(_GenerateTypeInfo<T>());
123 }
124
125private:
126 const Vdf_OutputSpecTypeInfo *_typeinfo;
127 TfToken _name;
128};
129
130PXR_NAMESPACE_CLOSE_SCOPE
131
132#endif
Fast, compressed bit array which is capable of performing logical operations without first decompress...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
Manages low-level value type functionality used within execution.
A VdfOuptutSpec describes an output connector.
Definition: outputSpec.h:40
VDF_API size_t GetHash() const
Returns a hash for this instance.
VDF_API VdfVector * AllocateCache() const
Allocate a new VdfVector with this spec's type.
TfType GetType() const
Returns the type of this spec.
Definition: outputSpec.h:60
VDF_API std::string GetTypeName() const
Returns the name of this spec's type.
VDF_API void ResizeCache(VdfVector *vector, const VdfMask::Bits &bits) const
Resize an existing VdfVector to accomodate all the data set in the bits.
const TfToken & GetName() const
Returns the name of this connector.
Definition: outputSpec.h:63
bool operator==(const VdfOutputSpec &rhs) const
Returns true, if two output specs are equal.
Definition: outputSpec.h:75
A VdfTypedVector implements a VdfVector with a specific type.
Definition: typedVector.h:23
This class is used to abstract away knowledge of the cache data used for each node.
Definition: vector.h:56
void Resize(size_t size)
Allocates space for size number of elements.
Definition: vector.h:218
#define TF_MALLOC_TAG_NEW(name1, name2)
Enable lib/tf memory management.
Definition: mallocTag.h:475
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...