Skip to content

Commit 096daaa

Browse files
committed
Add PushBuffer
Adds `PushBuffer` class, `pushBuffer` global, and the supporting code for `glconfig2`.
1 parent 2b80fa9 commit 096daaa

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

src/engine/renderer/BufferBind.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ namespace BufferBind {
4242
MATERIALS = 0,
4343
TEX_DATA = 1,
4444
LIGHTMAP_DATA = 2,
45-
LIGHTS = 3,
45+
GLOBAL_DATA = 3,
46+
LIGHTS = 4,
4647

47-
SURFACE_BATCHES = 4,
48+
SURFACE_BATCHES = 5,
4849

4950
// SSBO
5051
SURFACE_DESCRIPTORS = 0,

src/engine/renderer/GLMemory.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3737

3838
#include "GLMemory.h"
3939

40+
#include "gl_shader.h"
41+
4042
// 128 MB, should be enough to fit anything in BAR without going overboard
4143
const GLsizeiptr GLStagingBuffer::SIZE = 128 * 1024 * 1024 / sizeof( uint32_t );
4244

4345
GLStagingBuffer stagingBuffer;
46+
PushBuffer pushBuffer;
4447

4548
void GLBufferCopy( GLBuffer* src, GLBuffer* dst, GLintptr srcOffset, GLintptr dstOffset, GLsizeiptr size ) {
4649
glCopyNamedBufferSubData( src->id, dst->id,
@@ -130,3 +133,32 @@ void GLStagingBuffer::FreeGLBuffer() {
130133
current = 0;
131134
last = 0;
132135
}
136+
137+
void PushBuffer::InitGLBuffers() {
138+
globalUBO.GenBuffer();
139+
}
140+
141+
void PushBuffer::FreeGLBuffers() {
142+
globalUBO.DelBuffer();
143+
}
144+
145+
uint32_t* PushBuffer::MapGlobalUniformData( const int updateType ) {
146+
switch ( updateType ) {
147+
case GLUniform::CONST:
148+
globalUBOData = stagingBuffer.MapBuffer( constUniformsSize );
149+
stagingBuffer.QueueStagingCopy( &globalUBO, 0 );
150+
break;
151+
case GLUniform::FRAME:
152+
globalUBOData = stagingBuffer.MapBuffer( frameUniformsSize );
153+
stagingBuffer.QueueStagingCopy( &globalUBO, constUniformsSize );
154+
break;
155+
default:
156+
ASSERT_UNREACHABLE();
157+
}
158+
159+
return globalUBOData;
160+
}
161+
162+
void PushBuffer::PushGlobalUniforms() {
163+
stagingBuffer.FlushAll();
164+
}

src/engine/renderer/GLMemory.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,28 @@ class GLStagingBuffer {
321321
GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_INVALIDATE_BUFFER_BIT );
322322
};
323323

324+
struct PushBuffer {
325+
uint32_t constUniformsSize;
326+
uint32_t frameUniformsSize;
327+
uint32_t globalUBOSize;
328+
uint32_t* globalUBOData;
329+
330+
uint32_t pushStart = UINT32_MAX;
331+
uint32_t pushEnd = 0;
332+
333+
uint32_t sector = 0;
334+
const uint32_t MAX_SECTORS = 1024;
335+
336+
GLUBO globalUBO = GLUBO( "globalUniforms", BufferBind::GLOBAL_DATA, 0, 0 );
337+
338+
void InitGLBuffers();
339+
void FreeGLBuffers();
340+
341+
uint32_t* MapGlobalUniformData( const int updateType );
342+
void PushGlobalUniforms();
343+
};
344+
324345
extern GLStagingBuffer stagingBuffer;
346+
extern PushBuffer pushBuffer;
325347

326-
#endif // GLMEMORY_H
348+
#endif // GLMEMORY_H

src/engine/renderer/tr_public.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct GLConfig
135135
bool usingMaterialSystem; // are we using it right now
136136
bool geometryCacheAvailable;
137137
bool usingGeometryCache;
138+
bool pushBufferAvailable;
138139
bool gpuShader4Available;
139140
bool gpuShader5Available;
140141
bool textureGatherAvailable;

src/engine/sys/sdl_glimp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,11 @@ static void GLimp_InitExtensions()
25292529

25302530
glConfig.geometryCacheAvailable = glConfig.vertexAttribBindingAvailable && glConfig.directStateAccessAvailable;
25312531

2532+
glConfig.pushBufferAvailable =
2533+
glConfig.directStateAccessAvailable
2534+
&& glConfig.explicitUniformLocationAvailable
2535+
&& glConfig.uniformBufferObjectAvailable;
2536+
25322537
glConfig.materialSystemAvailable =
25332538
glConfig.bindlessTexturesAvailable
25342539
&& glConfig.computeShaderAvailable
@@ -2538,6 +2543,7 @@ static void GLimp_InitExtensions()
25382543
&& glConfig.gpuShader4Available
25392544
&& glConfig.indirectParametersAvailable
25402545
&& glConfig.multiDrawIndirectAvailable
2546+
&& glConfig.pushBufferAvailable
25412547
&& glConfig.shaderAtomicCountersAvailable
25422548
&& glConfig.shaderDrawParametersAvailable
25432549
&& glConfig.shaderImageLoadStoreAvailable

0 commit comments

Comments
 (0)