gsdx-ogl: try another implementation for uniform buffer

It is slower but keep it for a bindless trial
This commit is contained in:
Gregory Hainaut 2015-08-15 09:58:13 +02:00
parent 3145031c05
commit 2e9ff045e1
1 changed files with 74 additions and 1 deletions

View File

@ -31,7 +31,7 @@ extern uint64 g_uniform_upload_byte;
class GSUniformBufferOGL {
GLuint buffer; // data object
GLuint index; // GLSL slot
uint32 size; // size of the data
uint32 size; // size of the data
public:
GSUniformBufferOGL(GLuint index, uint32 size) : index(index)
@ -80,3 +80,76 @@ public:
gl_DeleteBuffers(1, &buffer);
}
};
#define UBO_BUFFER_SIZE (4*1024*1024)
class GSUniformBufferStorageOGL {
GLuint buffer; // data object
GLuint index; // GLSL slot
uint32 size; // size of the data
uint8* m_buffer_ptr;
uint32 m_offset;
public:
GSUniformBufferStorageOGL(GLuint index, uint32 size) : index(index)
, size(size), m_offset(0)
{
gl_GenBuffers(1, &buffer);
bind();
allocate();
attach();
}
void bind()
{
if (GLState::ubo != buffer) {
GLState::ubo = buffer;
gl_BindBuffer(GL_UNIFORM_BUFFER, buffer);
}
}
void allocate()
{
const GLbitfield common_flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT /*| GL_MAP_COHERENT_BIT */;
const GLbitfield map_flags = common_flags | GL_MAP_FLUSH_EXPLICIT_BIT;
const GLbitfield create_flags = common_flags /*| GL_CLIENT_STORAGE_BIT */;
GLsizei buffer_size = UBO_BUFFER_SIZE;
gl_BufferStorage(GL_UNIFORM_BUFFER, buffer_size, NULL, create_flags);
m_buffer_ptr = (uint8*) gl_MapBufferRange(GL_UNIFORM_BUFFER, 0, buffer_size, map_flags);
ASSERT(m_buffer_ptr);
}
void attach()
{
// From the opengl manpage:
// glBindBufferBase also binds buffer to the generic buffer binding point specified by target
GLState::ubo = buffer;
//gl_BindBufferBase(GL_UNIFORM_BUFFER, index, buffer);
gl_BindBufferRange(GL_UNIFORM_BUFFER, index, buffer, m_offset, size);
}
void upload(const void* src)
{
#ifdef ENABLE_OGL_DEBUG_MEM_BW
g_uniform_upload_byte += size;
#endif
memcpy(m_buffer_ptr + m_offset, src, size);
attach();
gl_FlushMappedBufferRange(GL_UNIFORM_BUFFER, m_offset, size);
m_offset = (m_offset + size + 255u) & ~0xFF;
if (m_offset >= UBO_BUFFER_SIZE)
m_offset = 0;
}
~GSUniformBufferStorageOGL() {
bind();
gl_UnmapBuffer(GL_UNIFORM_BUFFER);
gl_DeleteBuffers(1, &buffer);
}
};
#undef UBO_BUFFER_SIZE