Skip to content

Commit

Permalink
GL: Removed VAO support.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Jul 21, 2017
1 parent 92a893a commit 38574b6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 263 deletions.
166 changes: 2 additions & 164 deletions src/renderer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3284,11 +3284,6 @@ namespace bgfx { namespace gl

void invalidateCache()
{
if (m_vaoSupport)
{
m_vaoStateCache.invalidate();
}

if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
&& m_samplerObjectSupport)
{
Expand Down Expand Up @@ -3803,7 +3798,6 @@ namespace bgfx { namespace gl
TimerQueryGL m_gpuTimer;
OcclusionQueryGL m_occlusionQuery;

VaoStateCache m_vaoStateCache;
SamplerStateCache m_samplerStateCache;

TextVideoMem m_textVideoMem;
Expand Down Expand Up @@ -4382,8 +4376,6 @@ namespace bgfx { namespace gl
GL_CHECK(glDeleteProgram(m_id) );
m_id = 0;
}

m_vcref.invalidate(s_renderGL->m_vaoStateCache);
}

void ProgramGL::init()
Expand Down Expand Up @@ -4760,16 +4752,12 @@ namespace bgfx { namespace gl
{
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
GL_CHECK(glDeleteBuffers(1, &m_id) );

m_vcref.invalidate(s_renderGL->m_vaoStateCache);
}

void VertexBufferGL::destroy()
{
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
GL_CHECK(glDeleteBuffers(1, &m_id) );

m_vcref.invalidate(s_renderGL->m_vaoStateCache);
}

bool TextureGL::init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint32_t _flags)
Expand Down Expand Up @@ -6423,7 +6411,6 @@ namespace bgfx { namespace gl
GL_CHECK(glBindVertexArray(0) );
GL_CHECK(glDeleteVertexArrays(1, &m_vao) );
m_vao = 0;
m_vaoStateCache.invalidate();
}

m_glctx.makeCurrent(NULL);
Expand Down Expand Up @@ -6500,7 +6487,6 @@ namespace bgfx { namespace gl
: GL_FILL
) );

GLuint currentVao = 0;
bool wasCompute = false;
bool viewHasScissor = false;
Rect viewScissorRect;
Expand Down Expand Up @@ -6648,7 +6634,6 @@ namespace bgfx { namespace gl
if (BGFX_CLEAR_NONE != (clear.m_flags & BGFX_CLEAR_MASK) )
{
clearQuad(_clearQuad, viewState.m_rect, clear, resolutionHeight, _render->m_colorPalette);
currentVao = UINT32_MAX; // clearQuad will mess with VAO, invalidate it.
}

GL_CHECK(glDisable(GL_STENCIL_TEST) );
Expand Down Expand Up @@ -7218,153 +7203,7 @@ namespace bgfx { namespace gl
}
}

if (0 != defaultVao
&& 0 == draw.m_stream[0].m_startVertex
&& 0 == draw.m_instanceDataOffset)
{
bool diffStartVertex = false;
bool diffStreamHandles = false;
for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
; 0 != streamMask
; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask)
)
{
streamMask >>= ntz;
idx += ntz;

if (currentState.m_stream[idx].m_handle.idx != draw.m_stream[idx].m_handle.idx)
{
diffStreamHandles = true;
break;
}

if (currentState.m_stream[idx].m_startVertex != draw.m_stream[idx].m_startVertex)
{
diffStartVertex = true;
break;
}
}

if (programChanged
|| currentState.m_streamMask != draw.m_streamMask
|| currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx
|| currentState.m_instanceDataOffset != draw.m_instanceDataOffset
|| currentState.m_instanceDataStride != draw.m_instanceDataStride
|| currentState.m_instanceDataBuffer.idx != draw.m_instanceDataBuffer.idx
|| diffStartVertex
|| diffStreamHandles)
{
bx::HashMurmur2A murmur;
murmur.begin();

for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
; 0 != streamMask
; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask)
)
{
streamMask >>= ntz;
idx += ntz;

const Stream& stream = draw.m_stream[idx];
murmur.add(stream.m_handle.idx);

if (isValid(stream.m_handle) )
{
const VertexBufferGL& vb = m_vertexBuffers[stream.m_handle.idx];
uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx;
murmur.add(decl);
}

currentState.m_stream[idx].m_handle = stream.m_handle;
currentState.m_stream[idx].m_startVertex = stream.m_startVertex;
}
currentState.m_streamMask = draw.m_streamMask;

murmur.add(draw.m_indexBuffer.idx);
murmur.add(draw.m_instanceDataBuffer.idx);
murmur.add(draw.m_instanceDataOffset);
murmur.add(draw.m_instanceDataStride);
murmur.add(programIdx);
uint32_t hash = murmur.end();

currentState.m_indexBuffer = draw.m_indexBuffer;
currentState.m_instanceDataOffset = draw.m_instanceDataOffset;
currentState.m_instanceDataStride = draw.m_instanceDataStride;

GLuint id = m_vaoStateCache.find(hash);
if (UINT32_MAX != id)
{
currentVao = id;
GL_CHECK(glBindVertexArray(id) );
}
else
{
id = m_vaoStateCache.add(hash);
currentVao = id;
GL_CHECK(glBindVertexArray(id) );

program.add(hash);

program.bindAttributesBegin();
for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
; 0 != streamMask
; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask)
)
{
streamMask >>= ntz;
idx += ntz;

const Stream& stream = draw.m_stream[idx];

if (isValid(stream.m_handle) )
{
VertexBufferGL& vb = m_vertexBuffers[stream.m_handle.idx];
vb.add(hash);

uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx;
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) );
program.bindAttributes(m_vertexDecls[decl], stream.m_startVertex);
}

if (isValid(draw.m_instanceDataBuffer) )
{
VertexBufferGL& instanceVb = m_vertexBuffers[draw.m_instanceDataBuffer.idx];
instanceVb.add(hash);
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, instanceVb.m_id) );
program.bindInstanceData(draw.m_instanceDataStride, draw.m_instanceDataOffset);
}
}
program.bindAttributesEnd();

if (isValid(draw.m_indexBuffer) )
{
IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx];
ib.add(hash);
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib.m_id) );
}
else
{
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
}
}
}
}
else
{
if (0 != defaultVao
&& 0 != currentVao)
{
GL_CHECK(glBindVertexArray(defaultVao) );
currentState.m_streamMask = 0;
for (size_t ii = 0; ii < BGFX_CONFIG_MAX_VERTEX_STREAMS; ++ii)
{
currentState.m_stream[ii].m_handle.idx = kInvalidHandle;
}
currentState.m_indexBuffer.idx = kInvalidHandle;
bindAttribs = true;
currentVao = 0;
}

bool diffStreamHandles = false;
for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
; 0 != streamMask
Expand Down Expand Up @@ -7777,9 +7616,8 @@ namespace bgfx { namespace gl

pos++;
tvm.printf(10, pos++, 0x8e, " State cache: ");
tvm.printf(10, pos++, 0x8e, " VAO | Sampler ");
tvm.printf(10, pos++, 0x8e, " %6d | %6d "
, m_vaoStateCache.getCount()
tvm.printf(10, pos++, 0x8e, " Sampler ");
tvm.printf(10, pos++, 0x8e, " %6d "
, m_samplerStateCache.getCount()
);

Expand Down
99 changes: 0 additions & 99 deletions src/renderer_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,87 +995,6 @@ namespace bgfx { namespace gl
#define GL_IMPORT(_optional, _proto, _func, _import) extern _proto _func
#include "glimports.h"

class VaoStateCache
{
public:
GLuint add(uint32_t _hash)
{
invalidate(_hash);

GLuint arrayId;
GL_CHECK(glGenVertexArrays(1, &arrayId) );

m_hashMap.insert(stl::make_pair(_hash, arrayId) );

return arrayId;
}

GLuint find(uint32_t _hash)
{
HashMap::iterator it = m_hashMap.find(_hash);
if (it != m_hashMap.end() )
{
return it->second;
}

return UINT32_MAX;
}

void invalidate(uint32_t _hash)
{
GL_CHECK(glBindVertexArray(0) );

HashMap::iterator it = m_hashMap.find(_hash);
if (it != m_hashMap.end() )
{
GL_CHECK(glDeleteVertexArrays(1, &it->second) );
m_hashMap.erase(it);
}
}

void invalidate()
{
GL_CHECK(glBindVertexArray(0) );

for (HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it)
{
GL_CHECK(glDeleteVertexArrays(1, &it->second) );
}
m_hashMap.clear();
}

uint32_t getCount() const
{
return uint32_t(m_hashMap.size() );
}

private:
typedef stl::unordered_map<uint32_t, GLuint> HashMap;
HashMap m_hashMap;
};

class VaoCacheRef
{
public:
void add(uint32_t _hash)
{
m_vaoSet.insert(_hash);
}

void invalidate(VaoStateCache& _vaoCache)
{
for (VaoSet::iterator it = m_vaoSet.begin(), itEnd = m_vaoSet.end(); it != itEnd; ++it)
{
_vaoCache.invalidate(*it);
}

m_vaoSet.clear();
}

typedef stl::unordered_set<uint32_t> VaoSet;
VaoSet m_vaoSet;
};

class SamplerStateCache
{
public:
Expand Down Expand Up @@ -1171,14 +1090,8 @@ namespace bgfx { namespace gl

void destroy();

void add(uint32_t _hash)
{
m_vcref.add(_hash);
}

GLuint m_id;
uint32_t m_size;
VaoCacheRef m_vcref;
uint16_t m_flags;
};

Expand Down Expand Up @@ -1225,16 +1138,10 @@ namespace bgfx { namespace gl

void destroy();

void add(uint32_t _hash)
{
m_vcref.add(_hash);
}

GLuint m_id;
GLenum m_target;
uint32_t m_size;
VertexDeclHandle m_decl;
VaoCacheRef m_vcref;
};

struct TextureGL
Expand Down Expand Up @@ -1363,11 +1270,6 @@ namespace bgfx { namespace gl
}
}

void add(uint32_t _hash)
{
m_vcref.add(_hash);
}

GLuint m_id;

uint8_t m_unboundUsedAttrib[Attrib::Count]; // For tracking unbound used attributes between begin()/end().
Expand All @@ -1382,7 +1284,6 @@ namespace bgfx { namespace gl
UniformBuffer* m_constantBuffer;
PredefinedUniform m_predefined[PredefinedUniform::Count];
uint8_t m_numPredefined;
VaoCacheRef m_vcref;
};

struct TimerQueryGL
Expand Down

0 comments on commit 38574b6

Please sign in to comment.