Skip to content
Snippets Groups Projects
Commit 39c97f1b authored by ReinUsesLisp's avatar ReinUsesLisp
Browse files

gl_stream_buffer: Use InvalidateBufferData instead unmap and map

Making the stream buffer resident increases GPU usage significantly on
some games. This seems to be addressed invalidating the stream buffer
with InvalidateBufferData instead of using a Unmap + Map (with
invalidation flags).
parent 41a40903
No related branches found
No related tags found
No related merge requests found
...@@ -57,30 +57,21 @@ std::tuple<u8*, GLintptr, bool> OGLStreamBuffer::Map(GLsizeiptr size, GLintptr a ...@@ -57,30 +57,21 @@ std::tuple<u8*, GLintptr, bool> OGLStreamBuffer::Map(GLsizeiptr size, GLintptr a
bool invalidate = false; bool invalidate = false;
if (buffer_pos + size > buffer_size) { if (buffer_pos + size > buffer_size) {
MICROPROFILE_SCOPE(OpenGL_StreamBuffer);
glInvalidateBufferData(gl_buffer.handle);
buffer_pos = 0; buffer_pos = 0;
invalidate = true; invalidate = true;
glUnmapNamedBuffer(gl_buffer.handle);
}
if (invalidate) {
static const GLbitfield flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT |
GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT;
MICROPROFILE_SCOPE(OpenGL_StreamBuffer);
mapped_ptr = static_cast<u8*>(
glMapNamedBufferRange(gl_buffer.handle, buffer_pos, buffer_size - buffer_pos, flags));
mapped_offset = buffer_pos;
} }
return std::make_tuple(mapped_ptr + buffer_pos - mapped_offset, buffer_pos, invalidate); return std::make_tuple(mapped_ptr + buffer_pos, buffer_pos, invalidate);
} }
void OGLStreamBuffer::Unmap(GLsizeiptr size) { void OGLStreamBuffer::Unmap(GLsizeiptr size) {
ASSERT(size <= mapped_size); ASSERT(size <= mapped_size);
if (size > 0) { if (size > 0) {
glFlushMappedNamedBufferRange(gl_buffer.handle, buffer_pos - mapped_offset, size); glFlushMappedNamedBufferRange(gl_buffer.handle, buffer_pos, size);
} }
buffer_pos += size; buffer_pos += size;
......
...@@ -48,7 +48,6 @@ private: ...@@ -48,7 +48,6 @@ private:
GLuint64EXT gpu_address = 0; GLuint64EXT gpu_address = 0;
GLintptr buffer_pos = 0; GLintptr buffer_pos = 0;
GLsizeiptr buffer_size = 0; GLsizeiptr buffer_size = 0;
GLintptr mapped_offset = 0;
GLsizeiptr mapped_size = 0; GLsizeiptr mapped_size = 0;
u8* mapped_ptr = nullptr; u8* mapped_ptr = nullptr;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment