HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
16 
17 #include "pxr/base/tf/mallocTag.h"
18 #include "pxr/base/tf/token.h"
19 #include "pxr/base/tf/type.h"
20 
22 
23 // Manually implemented vtable+typeinfo block for VdfOutputSpec.
25 {
26  using AllocateCacheFn = VdfVector* (*)();
27  using ResizeCacheFn = void (*)(VdfVector *, const VdfMask::Bits &);
28 
32 };
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 ///
36 /// A VdfOuptutSpec describes an output connector. It stores typing
37 /// information and the connector's name.
38 ///
40 {
41 public:
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 
55  /// Returns the name of this spec's type.
56  VDF_API
57  std::string GetTypeName() const;
58 
59  /// Returns the type of this spec
60  TfType GetType() const { return _typeinfo->type; }
61 
62  /// Returns the name of this connector.
63  const TfToken &GetName() const { return _name; }
64 
65  /// Allocate a new VdfVector with this spec's type.
66  VDF_API
67  VdfVector *AllocateCache() const;
68 
69  /// Resize an existing VdfVector to accomodate all the data set in the bits.
70  VDF_API
71  void ResizeCache(VdfVector *vector, const VdfMask::Bits &bits) const;
72 
73  /// Returns true, if two output specs are equal.
74  ///
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 
82  /// Returns a hash for this instance.
83  VDF_API
84  size_t GetHash() const;
85 
86 private:
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.
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 
125 private:
126  const Vdf_OutputSpecTypeInfo *_typeinfo;
127  TfToken _name;
128 };
129 
131 
132 #endif
bool operator==(const VdfOutputSpec &rhs) const
Definition: outputSpec.h:75
VDF_API VdfVector * AllocateCache() const
Allocate a new VdfVector with this spec's type.
void
Definition: png.h:1083
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
VDF_API ~VdfOutputSpec()
ResizeCacheFn resizeCache
Definition: outputSpec.h:31
#define VDF_API
Definition: api.h:25
Fast, compressed bit array which is capable of performing logical operations without first decompress...
TF_MALLOC_TAG_NEW("Vdf","new VdfOutputSpec")
VDF_API size_t GetHash() const
Returns a hash for this instance.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Definition: token.h:70
void(*)(VdfVector *, const VdfMask::Bits &) ResizeCacheFn
Definition: outputSpec.h:27
static VdfOutputSpec * New(const TfToken &name)
Definition: outputSpec.h:45
GLuint const GLchar * name
Definition: glcorearb.h:786
VdfVector *(*)( AllocateCacheFn)
Definition: outputSpec.h:26
TfType GetType() const
Returns the type of this spec.
Definition: outputSpec.h:60
AllocateCacheFn allocateCache
Definition: outputSpec.h:30
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
const TfToken & GetName() const
Returns the name of this connector.
Definition: outputSpec.h:63
bool operator!=(const VdfOutputSpec &rhs) const
Definition: outputSpec.h:78
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.
void Resize(size_t size)
Definition: vector.h:218