MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GlBuffer

Class GlBuffer

tensorflow/lite/delegates/gpu/gl/gl_buffer.h:37–113  ·  view source on GitHub ↗

Buffer is an RAII wrapper for OpenGL buffer object. See https://www.khronos.org/opengl/wiki/Buffer_Object for more information. Buffer is moveable but not copyable.

Source from the content-addressed store, hash-verified

35//
36// Buffer is moveable but not copyable.
37class GlBuffer {
38 public:
39 // @param has_ownership indicates that GlBuffer is responsible for
40 // corresponding GL buffer deletion.
41 GlBuffer(GLenum target, GLuint id, size_t bytes_size, size_t offset,
42 bool has_ownership)
43 : target_(target),
44 id_(id),
45 bytes_size_(bytes_size),
46 offset_(offset),
47 has_ownership_(has_ownership) {}
48
49 // Creates invalid buffer.
50 GlBuffer() : GlBuffer(GL_INVALID_ENUM, GL_INVALID_INDEX, 0, 0, false) {}
51
52 // Move-only
53 GlBuffer(GlBuffer&& buffer);
54 GlBuffer& operator=(GlBuffer&& buffer);
55 GlBuffer(const GlBuffer&) = delete;
56 GlBuffer& operator=(const GlBuffer&) = delete;
57
58 ~GlBuffer();
59
60 // Reads data from buffer into CPU memory. Data should point to a region that
61 // has at least bytes_size available.
62 template <typename T>
63 Status Read(absl::Span<T> data) const;
64
65 // Writes data to a buffer.
66 template <typename T>
67 Status Write(absl::Span<const T> data);
68
69 // Maps GPU memory to CPU address space and calls reader that may read from
70 // that memory.
71 template <typename T>
72 Status MappedRead(
73 const std::function<Status(absl::Span<const T>)>& reader) const;
74
75 // Maps GPU memory to CPU address space and calls writer that may write into
76 // that memory.
77 template <typename T>
78 Status MappedWrite(const std::function<Status(absl::Span<T>)>& writer);
79
80 Status MakeView(size_t offset, size_t bytes_size, GlBuffer* gl_buffer);
81
82 // Makes a copy without ownership of the buffer.
83 GlBuffer MakeRef();
84
85 // Binds a buffer to an index.
86 Status BindToIndex(uint32_t index) const;
87
88 // Releases the ownership of the buffer object.
89 void Release() { has_ownership_ = false; }
90
91 size_t bytes_size() const { return bytes_size_; }
92
93 const GLenum target() const { return target_; }
94

Callers 5

BindBufferToTensorMethod · 0.85
MakeViewMethod · 0.85
MakeRefMethod · 0.85
AddMethod · 0.85
CreateSharedGlBufferMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected