Loading...
Searching...
No Matches
vectorImpl_Dispatch.h
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
17PXR_NAMESPACE_OPEN_SCOPE
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//
23template < typename T >
24class Vdf_VectorImplDispatch {
25public:
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) {
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
46private:
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
62PXR_NAMESPACE_CLOSE_SCOPE
63
64#endif /* PXR_EXEC_VDF_VECTOR_IMPL_DISPATCH_H */
Fast, compressed bit array which is capable of performing logical operations without first decompress...
View< Mode::Platforms > PlatformsView
Returns an iteratable view for the bits that steps over all platforms.