mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:42:58 +02:00
exploring optimization in Backend for bffer bindings
This commit is contained in:
parent
b8e93ec688
commit
1123ba2b0a
9 changed files with 41 additions and 8 deletions
|
@ -239,6 +239,7 @@ public:
|
||||||
virtual GLuint getFramebufferID(const FramebufferPointer& framebuffer) = 0;
|
virtual GLuint getFramebufferID(const FramebufferPointer& framebuffer) = 0;
|
||||||
virtual GLuint getTextureID(const TexturePointer& texture) final;
|
virtual GLuint getTextureID(const TexturePointer& texture) final;
|
||||||
virtual GLuint getBufferID(const Buffer& buffer) = 0;
|
virtual GLuint getBufferID(const Buffer& buffer) = 0;
|
||||||
|
virtual GLuint getBufferIDUnsafe(const Buffer& buffer) = 0;
|
||||||
virtual GLuint getQueryID(const QueryPointer& query) = 0;
|
virtual GLuint getQueryID(const QueryPointer& query) = 0;
|
||||||
|
|
||||||
virtual GLFramebuffer* syncGPUObject(const Framebuffer& framebuffer) = 0;
|
virtual GLFramebuffer* syncGPUObject(const Framebuffer& framebuffer) = 0;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "GLBackend.h"
|
#include "GLBackend.h"
|
||||||
#include "GLShared.h"
|
#include "GLShared.h"
|
||||||
#include "GLInputFormat.h"
|
#include "GLInputFormat.h"
|
||||||
|
#include "GLBuffer.h"
|
||||||
|
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
using namespace gpu::gl;
|
using namespace gpu::gl;
|
||||||
|
@ -39,14 +40,20 @@ void GLBackend::do_setInputBuffer(const Batch& batch, size_t paramOffset) {
|
||||||
BufferPointer buffer = batch._buffers.get(batch._params[paramOffset + 2]._uint);
|
BufferPointer buffer = batch._buffers.get(batch._params[paramOffset + 2]._uint);
|
||||||
uint32 channel = batch._params[paramOffset + 3]._uint;
|
uint32 channel = batch._params[paramOffset + 3]._uint;
|
||||||
|
|
||||||
if (channel < getNumInputBuffers()) {
|
// if (channel < getNumInputBuffers()) {
|
||||||
bool isModified = false;
|
bool isModified = false;
|
||||||
if (_input._buffers[channel] != buffer) {
|
if (_input._buffers[channel] != buffer) {
|
||||||
_input._buffers[channel] = buffer;
|
_input._buffers[channel] = buffer;
|
||||||
|
|
||||||
GLuint vbo = 0;
|
GLuint vbo = 0;
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
vbo = getBufferID((*buffer));
|
// vbo = getBufferID((*buffer));
|
||||||
|
// vbo = getBufferIDUnsafe((*buffer));
|
||||||
|
auto* object = Backend::getGPUObject<GLBuffer>((*buffer));
|
||||||
|
|
||||||
|
if (object) {
|
||||||
|
vbo = object->_buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_input._bufferVBOs[channel] = vbo;
|
_input._bufferVBOs[channel] = vbo;
|
||||||
|
|
||||||
|
@ -66,7 +73,7 @@ void GLBackend::do_setInputBuffer(const Batch& batch, size_t paramOffset) {
|
||||||
if (isModified) {
|
if (isModified) {
|
||||||
_input._invalidBuffers.set(channel);
|
_input._invalidBuffers.set(channel);
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::initInput() {
|
void GLBackend::initInput() {
|
||||||
|
@ -128,7 +135,7 @@ void GLBackend::do_setIndexBuffer(const Batch& batch, size_t paramOffset) {
|
||||||
if (indexBuffer != _input._indexBuffer) {
|
if (indexBuffer != _input._indexBuffer) {
|
||||||
_input._indexBuffer = indexBuffer;
|
_input._indexBuffer = indexBuffer;
|
||||||
if (indexBuffer) {
|
if (indexBuffer) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getBufferID(*indexBuffer));
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getBufferIDUnsafe(*indexBuffer));
|
||||||
} else {
|
} else {
|
||||||
// FIXME do we really need this? Is there ever a draw call where we care that the element buffer is null?
|
// FIXME do we really need this? Is there ever a draw call where we care that the element buffer is null?
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
@ -145,7 +152,7 @@ void GLBackend::do_setIndirectBuffer(const Batch& batch, size_t paramOffset) {
|
||||||
if (buffer != _input._indirectBuffer) {
|
if (buffer != _input._indirectBuffer) {
|
||||||
_input._indirectBuffer = buffer;
|
_input._indirectBuffer = buffer;
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, getBufferID(*buffer));
|
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, getBufferIDUnsafe(*buffer));
|
||||||
} else {
|
} else {
|
||||||
// FIXME do we really need this? Is there ever a draw call where we care that the element buffer is null?
|
// FIXME do we really need this? Is there ever a draw call where we care that the element buffer is null?
|
||||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
|
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
|
||||||
|
|
|
@ -172,6 +172,8 @@ void GLBackend::bindUniformBuffer(uint32_t slot, const BufferPointer& buffer, GL
|
||||||
|
|
||||||
// Sync BufferObject
|
// Sync BufferObject
|
||||||
auto* object = syncGPUObject(*bufferState.buffer);
|
auto* object = syncGPUObject(*bufferState.buffer);
|
||||||
|
// auto glBO = getBufferIDUnsafe(*buffer);
|
||||||
|
|
||||||
if (object) {
|
if (object) {
|
||||||
glBindBufferRange(GL_UNIFORM_BUFFER, slot, object->_buffer, bufferState.offset, bufferState.size);
|
glBindBufferRange(GL_UNIFORM_BUFFER, slot, object->_buffer, bufferState.offset, bufferState.size);
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,25 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename GLBufferType>
|
||||||
|
static GLuint getIdUnsafe(GLBackend& backend, const Buffer& buffer) {
|
||||||
|
GLBufferType* object = Backend::getGPUObject<GLBufferType>(buffer);
|
||||||
|
|
||||||
|
if (object) {
|
||||||
|
return object->_buffer;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const GLuint& _buffer { _id };
|
const GLuint& _buffer { _id };
|
||||||
const GLuint _size;
|
const GLuint _size;
|
||||||
const Stamp _stamp;
|
const Stamp _stamp;
|
||||||
|
|
||||||
~GLBuffer();
|
~GLBuffer();
|
||||||
|
|
||||||
virtual void transfer() = 0;
|
virtual void transfer() {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GLBuffer(const std::weak_ptr<GLBackend>& backend, const Buffer& buffer, GLuint id);
|
GLBuffer(const std::weak_ptr<GLBackend>& backend, const Buffer& buffer, GLuint id);
|
||||||
|
|
|
@ -134,6 +134,7 @@ protected:
|
||||||
GLFramebuffer* syncGPUObject(const Framebuffer& framebuffer) override;
|
GLFramebuffer* syncGPUObject(const Framebuffer& framebuffer) override;
|
||||||
|
|
||||||
GLuint getBufferID(const Buffer& buffer) override;
|
GLuint getBufferID(const Buffer& buffer) override;
|
||||||
|
GLuint getBufferIDUnsafe(const Buffer& buffer) override;
|
||||||
GLuint getResourceBufferID(const Buffer& buffer);
|
GLuint getResourceBufferID(const Buffer& buffer);
|
||||||
GLBuffer* syncGPUObject(const Buffer& buffer) override;
|
GLBuffer* syncGPUObject(const Buffer& buffer) override;
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,10 @@ GLuint GL41Backend::getBufferID(const Buffer& buffer) {
|
||||||
return GL41Buffer::getId<GL41Buffer>(*this, buffer);
|
return GL41Buffer::getId<GL41Buffer>(*this, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLuint GL41Backend::getBufferIDUnsafe(const Buffer& buffer) {
|
||||||
|
return GL41Backend::getBufferID(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
GLuint GL41Backend::getResourceBufferID(const Buffer& buffer) {
|
GLuint GL41Backend::getResourceBufferID(const Buffer& buffer) {
|
||||||
auto* object = GL41Buffer::sync<GL41Buffer>(*this, buffer);
|
auto* object = GL41Buffer::sync<GL41Buffer>(*this, buffer);
|
||||||
if (object) {
|
if (object) {
|
||||||
|
|
|
@ -235,6 +235,7 @@ protected:
|
||||||
GLFramebuffer* syncGPUObject(const Framebuffer& framebuffer) override;
|
GLFramebuffer* syncGPUObject(const Framebuffer& framebuffer) override;
|
||||||
|
|
||||||
GLuint getBufferID(const Buffer& buffer) override;
|
GLuint getBufferID(const Buffer& buffer) override;
|
||||||
|
GLuint getBufferIDUnsafe(const Buffer& buffer) override;
|
||||||
GLBuffer* syncGPUObject(const Buffer& buffer) override;
|
GLBuffer* syncGPUObject(const Buffer& buffer) override;
|
||||||
|
|
||||||
GLTexture* syncGPUObject(const TexturePointer& texture) override;
|
GLTexture* syncGPUObject(const TexturePointer& texture) override;
|
||||||
|
|
|
@ -51,6 +51,11 @@ GLuint GL45Backend::getBufferID(const Buffer& buffer) {
|
||||||
return GL45Buffer::getId<GL45Buffer>(*this, buffer);
|
return GL45Buffer::getId<GL45Buffer>(*this, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLuint GL45Backend::getBufferIDUnsafe(const Buffer& buffer) {
|
||||||
|
//return GL45Buffer::getId<GL45Buffer>(*this, buffer);
|
||||||
|
return GL45Buffer::getIdUnsafe<GL45Buffer>(*this, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
GLBuffer* GL45Backend::syncGPUObject(const Buffer& buffer) {
|
GLBuffer* GL45Backend::syncGPUObject(const Buffer& buffer) {
|
||||||
return GL45Buffer::sync<GL45Buffer>(*this, buffer);
|
return GL45Buffer::sync<GL45Buffer>(*this, buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,10 +417,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
const Data& get(uint32 offset) const {
|
const Data& get(uint32 offset) const {
|
||||||
if (offset >= _items.size()) {
|
/* if (offset >= _items.size()) {
|
||||||
static const Data EMPTY;
|
static const Data EMPTY;
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}*/
|
||||||
return (_items.data() + offset)->_data;
|
return (_items.data() + offset)->_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue