gl_state_tracker: Track state of index buffers

master
ReinUsesLisp 2019-12-31 18:16:58 +07:00
parent a42a6e1a2c
commit a5bfc0d045
4 changed files with 23 additions and 5 deletions

@ -223,7 +223,7 @@ private:
static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024; static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024;
OGLBufferCache buffer_cache; OGLBufferCache buffer_cache;
VertexArrayPushBuffer vertex_array_pushbuffer; VertexArrayPushBuffer vertex_array_pushbuffer{state_tracker};
BindBuffersRangePushBuffer bind_ubo_pushbuffer{GL_UNIFORM_BUFFER}; BindBuffersRangePushBuffer bind_ubo_pushbuffer{GL_UNIFORM_BUFFER};
BindBuffersRangePushBuffer bind_ssbo_pushbuffer{GL_SHADER_STORAGE_BUFFER}; BindBuffersRangePushBuffer bind_ssbo_pushbuffer{GL_SHADER_STORAGE_BUFFER};

@ -6,7 +6,10 @@
#include <limits> #include <limits>
#include <glad/glad.h>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/core.h"
#include "video_core/dirty_flags.h" #include "video_core/dirty_flags.h"
#include "video_core/engines/maxwell_3d.h" #include "video_core/engines/maxwell_3d.h"
@ -85,6 +88,14 @@ public:
void Initialize(); void Initialize();
void BindIndexBuffer(GLuint new_index_buffer) {
if (index_buffer == new_index_buffer) {
return;
}
index_buffer = new_index_buffer;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, new_index_buffer);
}
void NotifyScreenDrawVertexArray() { void NotifyScreenDrawVertexArray() {
auto& flags = system.GPU().Maxwell3D().dirty.flags; auto& flags = system.GPU().Maxwell3D().dirty.flags;
flags[OpenGL::Dirty::VertexFormats] = true; flags[OpenGL::Dirty::VertexFormats] = true;
@ -175,6 +186,8 @@ public:
private: private:
Core::System& system; Core::System& system;
GLuint index_buffer = 0;
}; };
} // namespace OpenGL } // namespace OpenGL

@ -9,6 +9,7 @@
#include <glad/glad.h> #include <glad/glad.h>
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/renderer_opengl/gl_state_tracker.h"
#include "video_core/renderer_opengl/utils.h" #include "video_core/renderer_opengl/utils.h"
namespace OpenGL { namespace OpenGL {
@ -20,7 +21,8 @@ struct VertexArrayPushBuffer::Entry {
GLsizei stride{}; GLsizei stride{};
}; };
VertexArrayPushBuffer::VertexArrayPushBuffer() = default; VertexArrayPushBuffer::VertexArrayPushBuffer(StateTracker& state_tracker)
: state_tracker{state_tracker} {}
VertexArrayPushBuffer::~VertexArrayPushBuffer() = default; VertexArrayPushBuffer::~VertexArrayPushBuffer() = default;
@ -40,10 +42,9 @@ void VertexArrayPushBuffer::SetVertexBuffer(GLuint binding_index, const GLuint*
void VertexArrayPushBuffer::Bind() { void VertexArrayPushBuffer::Bind() {
if (index_buffer) { if (index_buffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *index_buffer); state_tracker.BindIndexBuffer(*index_buffer);
} }
// TODO(Rodrigo): Find a way to ARB_multi_bind this
for (const auto& entry : vertex_buffers) { for (const auto& entry : vertex_buffers) {
glBindVertexBuffer(entry.binding_index, *entry.buffer, entry.offset, entry.stride); glBindVertexBuffer(entry.binding_index, *entry.buffer, entry.offset, entry.stride);
} }

@ -11,9 +11,11 @@
namespace OpenGL { namespace OpenGL {
class StateTracker;
class VertexArrayPushBuffer final { class VertexArrayPushBuffer final {
public: public:
explicit VertexArrayPushBuffer(); explicit VertexArrayPushBuffer(StateTracker& state_tracker);
~VertexArrayPushBuffer(); ~VertexArrayPushBuffer();
void Setup(); void Setup();
@ -28,6 +30,8 @@ public:
private: private:
struct Entry; struct Entry;
StateTracker& state_tracker;
const GLuint* index_buffer{}; const GLuint* index_buffer{};
std::vector<Entry> vertex_buffers; std::vector<Entry> vertex_buffers;
}; };