summaryrefslogtreecommitdiff
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorGravatar Ameer J2023-08-13 21:38:23 -0400
committerGravatar Ameer J2023-08-13 23:17:47 -0500
commit48b87d64de42d83577860db668ef97ec6424554d (patch)
tree121014bed1a741e6211028f732d9379d1fbb7544 /src/video_core/renderer_opengl
parentMerge pull request #11880 from abouvier/unbundle-stb (diff)
downloadyuzu-48b87d64de42d83577860db668ef97ec6424554d.tar.gz
yuzu-48b87d64de42d83577860db668ef97ec6424554d.tar.xz
yuzu-48b87d64de42d83577860db668ef97ec6424554d.zip
gl_staging_buffer_pool: Refactor allocation variables into a struct
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp45
-rw-r--r--src/video_core/renderer_opengl/gl_staging_buffer_pool.h13
2 files changed, 28 insertions, 30 deletions
diff --git a/src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp b/src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp
index bbb06e51f..49121a775 100644
--- a/src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp
+++ b/src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp
@@ -32,12 +32,12 @@ StagingBufferMap StagingBuffers::RequestMap(size_t requested_size, bool insert_f
32 MICROPROFILE_SCOPE(OpenGL_BufferRequest); 32 MICROPROFILE_SCOPE(OpenGL_BufferRequest);
33 33
34 const size_t index = RequestBuffer(requested_size); 34 const size_t index = RequestBuffer(requested_size);
35 OGLSync* const sync = insert_fence ? &syncs[index] : nullptr; 35 OGLSync* const sync = insert_fence ? &allocs[index].sync : nullptr;
36 sync_indices[index] = insert_fence ? ++current_sync_index : 0; 36 allocs[index].sync_index = insert_fence ? ++current_sync_index : 0;
37 return StagingBufferMap{ 37 return StagingBufferMap{
38 .mapped_span = std::span(maps[index], requested_size), 38 .mapped_span = std::span(allocs[index].map, requested_size),
39 .sync = sync, 39 .sync = sync,
40 .buffer = buffers[index].handle, 40 .buffer = allocs[index].buffer.handle,
41 }; 41 };
42} 42}
43 43
@@ -45,46 +45,41 @@ size_t StagingBuffers::RequestBuffer(size_t requested_size) {
45 if (const std::optional<size_t> index = FindBuffer(requested_size); index) { 45 if (const std::optional<size_t> index = FindBuffer(requested_size); index) {
46 return *index; 46 return *index;
47 } 47 }
48 48 StagingBufferAlloc alloc;
49 OGLBuffer& buffer = buffers.emplace_back(); 49 alloc.buffer.Create();
50 buffer.Create();
51 const auto next_pow2_size = Common::NextPow2(requested_size); 50 const auto next_pow2_size = Common::NextPow2(requested_size);
52 glNamedBufferStorage(buffer.handle, next_pow2_size, nullptr, 51 glNamedBufferStorage(alloc.buffer.handle, next_pow2_size, nullptr,
53 storage_flags | GL_MAP_PERSISTENT_BIT); 52 storage_flags | GL_MAP_PERSISTENT_BIT);
54 maps.push_back(static_cast<u8*>(glMapNamedBufferRange(buffer.handle, 0, next_pow2_size, 53 alloc.map = static_cast<u8*>(glMapNamedBufferRange(alloc.buffer.handle, 0, next_pow2_size,
55 map_flags | GL_MAP_PERSISTENT_BIT))); 54 map_flags | GL_MAP_PERSISTENT_BIT));
56 syncs.emplace_back(); 55 alloc.size = next_pow2_size;
57 sync_indices.emplace_back(); 56 allocs.emplace_back(std::move(alloc));
58 sizes.push_back(next_pow2_size); 57 return allocs.size() - 1;
59
60 ASSERT(syncs.size() == buffers.size() && buffers.size() == maps.size() &&
61 maps.size() == sizes.size());
62
63 return buffers.size() - 1;
64} 58}
65 59
66std::optional<size_t> StagingBuffers::FindBuffer(size_t requested_size) { 60std::optional<size_t> StagingBuffers::FindBuffer(size_t requested_size) {
67 size_t known_unsignaled_index = current_sync_index + 1; 61 size_t known_unsignaled_index = current_sync_index + 1;
68 size_t smallest_buffer = std::numeric_limits<size_t>::max(); 62 size_t smallest_buffer = std::numeric_limits<size_t>::max();
69 std::optional<size_t> found; 63 std::optional<size_t> found;
70 const size_t num_buffers = sizes.size(); 64 const size_t num_buffers = allocs.size();
71 for (size_t index = 0; index < num_buffers; ++index) { 65 for (size_t index = 0; index < num_buffers; ++index) {
72 const size_t buffer_size = sizes[index]; 66 StagingBufferAlloc& alloc = allocs[index];
67 const size_t buffer_size = alloc.size;
73 if (buffer_size < requested_size || buffer_size >= smallest_buffer) { 68 if (buffer_size < requested_size || buffer_size >= smallest_buffer) {
74 continue; 69 continue;
75 } 70 }
76 if (syncs[index].handle != 0) { 71 if (alloc.sync.handle != 0) {
77 if (sync_indices[index] >= known_unsignaled_index) { 72 if (alloc.sync_index >= known_unsignaled_index) {
78 // This fence is later than a fence that is known to not be signaled 73 // This fence is later than a fence that is known to not be signaled
79 continue; 74 continue;
80 } 75 }
81 if (!syncs[index].IsSignaled()) { 76 if (!alloc.sync.IsSignaled()) {
82 // Since this fence hasn't been signaled, it's safe to assume all later 77 // Since this fence hasn't been signaled, it's safe to assume all later
83 // fences haven't been signaled either 78 // fences haven't been signaled either
84 known_unsignaled_index = std::min(known_unsignaled_index, sync_indices[index]); 79 known_unsignaled_index = std::min(known_unsignaled_index, alloc.sync_index);
85 continue; 80 continue;
86 } 81 }
87 syncs[index].Release(); 82 alloc.sync.Release();
88 } 83 }
89 smallest_buffer = buffer_size; 84 smallest_buffer = buffer_size;
90 found = index; 85 found = index;
diff --git a/src/video_core/renderer_opengl/gl_staging_buffer_pool.h b/src/video_core/renderer_opengl/gl_staging_buffer_pool.h
index 60f72d3a0..5b229d0b6 100644
--- a/src/video_core/renderer_opengl/gl_staging_buffer_pool.h
+++ b/src/video_core/renderer_opengl/gl_staging_buffer_pool.h
@@ -38,11 +38,14 @@ struct StagingBuffers {
38 38
39 std::optional<size_t> FindBuffer(size_t requested_size); 39 std::optional<size_t> FindBuffer(size_t requested_size);
40 40
41 std::vector<OGLSync> syncs; 41 struct StagingBufferAlloc {
42 std::vector<OGLBuffer> buffers; 42 OGLSync sync;
43 std::vector<u8*> maps; 43 OGLBuffer buffer;
44 std::vector<size_t> sizes; 44 u8* map;
45 std::vector<size_t> sync_indices; 45 size_t size;
46 size_t sync_index;
47 };
48 std::vector<StagingBufferAlloc> allocs;
46 GLenum storage_flags; 49 GLenum storage_flags;
47 GLenum map_flags; 50 GLenum map_flags;
48 size_t current_sync_index = 0; 51 size_t current_sync_index = 0;