Debian Codegraph @

Source/Core/VideoBackends/OGL/OGLStreamBuffer.h

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <memory>
8 #include <utility>
9
10 #include "Common/CommonTypes.h"
11 #include "Common/GL/GLExtensions/GLExtensions.h"
12
13 namespace OGL
14 {
15 class StreamBuffer
16 {
17 public:
18 static std::unique_ptr<StreamBuffer> Create(u32 type, u32 size);
19 virtual ~StreamBuffer();
20
21 u32 GetGLBufferId() const { return m_buffer; }
22 u32 GetSize() const { return m_size; }
23 u32 GetCurrentOffset() const { return m_iterator; }
24
25 /* This mapping function will return a pair of:
26 * - the pointer to the mapped buffer
27 * - the offset into the real GPU buffer (always multiple of stride)
28 * On mapping, the maximum of size for allocation has to be set.
29 * The size really pushed into this fifo only has to be known on Unmapping.
30 * Mapping invalidates the current buffer content,
31 * so it isn't allowed to access the old content any more.
32 */
33 virtual std::pair<u8*, u32> Map(u32 size) = 0;
34 virtual void Unmap(u32 used_size) = 0;
35
36 std::pair<u8*, u32> Map(u32 size, u32 stride)
37 {
38 u32 padding = m_iterator % stride;
39 if (padding)
40 {
41 m_iterator += stride - padding;
42 }
43 return Map(size);
44 }
45
46 const u32 m_buffer;
47
48 protected:
49 StreamBuffer(u32 type, u32 size);
50 void CreateFences();
51 void DeleteFences();
52 void AllocMemory(u32 size);
53
54 const u32 m_buffertype;
55 const u32 m_size;
56
57 u32 m_iterator;
58 u32 m_used_iterator;
59 u32 m_free_iterator;
60
61 private:
62 static constexpr int SYNC_POINTS = 16;
63 int Slot(u32 x) const { return x >> m_bit_per_slot; }
64 const int m_bit_per_slot;
65
66 std::array<GLsync, SYNC_POINTS> m_fences{};
67 };
68 } // namespace OGL