Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9766 from stenzek/ogl-bbox-memory-barrier
OGL: Force memory barrier when reading back bounding box values
  • Loading branch information
stenzek committed May 29, 2021
2 parents b31d440 + 6393f15 commit b3a414e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Source/Core/VideoBackends/OGL/OGLBoundingBox.cpp
Expand Up @@ -87,12 +87,21 @@ void BoundingBox::Flush()
void BoundingBox::Readback()
{
glBindBuffer(GL_SHADER_STORAGE_BUFFER, s_bbox_buffer_id);

// Using glMapBufferRange to read back the contents of the SSBO is extremely slow
// on nVidia drivers. This is more noticeable at higher internal resolutions.
// Using glGetBufferSubData instead does not seem to exhibit this slowdown.
if (!DriverDetails::HasBug(DriverDetails::BUG_SLOW_GETBUFFERSUBDATA) &&
!static_cast<Renderer*>(g_renderer.get())->IsGLES())
{
// Using glMapBufferRange to read back the contents of the SSBO is extremely slow
// on nVidia drivers. This is more noticeable at higher internal resolutions.
// Using glGetBufferSubData instead does not seem to exhibit this slowdown.
// We also need to ensure the the CPU does not receive stale values which have been updated by
// the GPU. Apparently the buffer here is not coherent on NVIDIA drivers. Not sure if this is a
// driver bug/spec violation or not, one would think that glGetBufferSubData() would invalidate
// any caches as needed, but this path is only used on NVIDIA anyway, so it's fine. A point to
// note is that according to ARB_debug_report, it's moved from video to host memory, which would
// explain why it needs the cache invalidate.
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);

std::array<s32, NUM_BBOX_VALUES> gpu_values;
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(s32) * NUM_BBOX_VALUES,
gpu_values.data());
Expand Down

0 comments on commit b3a414e

Please sign in to comment.