HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vectorImpl_Dispatch.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_VECTOR_IMPL_DISPATCH_H
8 #define PXR_EXEC_VDF_VECTOR_IMPL_DISPATCH_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/vdf/mask.h"
13 
14 #include <algorithm>
15 #include <type_traits>
16 
18 
19 // This class dispatches copying the vector implementations internal storage
20 // to a call to memcpy or std::copy, depending on what's appropriate for the
21 // specific type.
22 //
23 template < typename T >
25 public:
26  using Memcopyable = std::is_trivially_copyable<T>;
27 
28  // Copy from a raw pointer.
29  static void Copy(T *dest, const T *source, size_t size) {
30  _Copy(dest, source, size, Memcopyable());
31  }
32 
33  // Copy chunks from a raw pointer, given a bitset indicating what to copy.
34  static void Copy(T *dest, const T *source, const VdfMask::Bits &bits) {
35  using View = VdfMask::Bits::PlatformsView;
36  View platforms = bits.GetPlatformsView();
37  for (View::const_iterator it=platforms.begin(), e=platforms.end();
38  it != e; ++it) {
39  if (it.IsSet()) {
40  const size_t index = *it;
41  Copy(dest + index, source + index, it.GetPlatformSize());
42  }
43  }
44  }
45 
46 private:
47  // Overloaded _Copy for types that are not memcpy-able.
48  template <typename U>
49  static void _Copy(
50  U *dest, const U *source, size_t size, const std::false_type &) {
51  std::copy(source, source + size, dest);
52  }
53 
54  // Overloaded _Copy for types that ARE memcpy-able.
55  template <typename U>
56  static void _Copy(
57  U *dest, const U *source, size_t size, const std::true_type &) {
58  memcpy(dest, source, sizeof(T) * size);
59  }
60 };
61 
63 
64 #endif /* PXR_EXEC_VDF_VECTOR_IMPL_DISPATCH_H */
static void Copy(T *dest, const T *source, const VdfMask::Bits &bits)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
static void Copy(T *dest, const T *source, size_t size)
Fast, compressed bit array which is capable of performing logical operations without first decompress...
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
PlatformsView GetPlatformsView() const
GLsizeiptr size
Definition: glcorearb.h:664
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::is_trivially_copyable< T > Memcopyable
View< Mode::Platforms > PlatformsView