Skip to content

Commit b355201

Browse files
committed
Add PushBuffer
Adds `PushBuffer` class, `pushBuffer` global, and the supporting code for `glconfig2`.
1 parent 6ad2144 commit b355201

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-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
@@ -329,6 +329,28 @@ class GLStagingBuffer {
329329
GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_INVALIDATE_BUFFER_BIT );
330330
};
331331

332+
struct PushBuffer {
333+
uint32_t constUniformsSize;
334+
uint32_t frameUniformsSize;
335+
uint32_t globalUBOSize;
336+
uint32_t* globalUBOData;
337+
338+
uint32_t pushStart = UINT32_MAX;
339+
uint32_t pushEnd = 0;
340+
341+
uint32_t sector = 0;
342+
const uint32_t MAX_SECTORS = 1024;
343+
344+
GLUBO globalUBO = GLUBO( "globalUniforms", BufferBind::GLOBAL_DATA, 0, 0 );
345+
346+
void InitGLBuffers();
347+
void FreeGLBuffers();
348+
349+
uint32_t* MapGlobalUniformData( const int updateType );
350+
void PushGlobalUniforms();
351+
};
352+
332353
extern GLStagingBuffer stagingBuffer;
354+
extern PushBuffer pushBuffer;
333355

334-
#endif // GLMEMORY_H
356+
#endif // GLMEMORY_H

src/engine/renderer/tr_public.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct glconfig2_t
118118
bool usingMaterialSystem; // are we using it right now
119119
bool geometryCacheAvailable;
120120
bool usingGeometryCache;
121+
bool pushBufferAvailable;
121122
bool gpuShader4Available;
122123
bool gpuShader5Available;
123124
bool textureGatherAvailable;

src/engine/sys/sdl_glimp.cpp

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

25392539
glConfig2.geometryCacheAvailable = glConfig2.vertexAttribBindingAvailable && glConfig2.directStateAccessAvailable;
25402540

2541+
glConfig2.pushBufferAvailable =
2542+
glConfig2.directStateAccessAvailable
2543+
&& glConfig2.explicitUniformLocationAvailable
2544+
&& glConfig2.uniformBufferObjectAvailable;
2545+
25412546
glConfig2.materialSystemAvailable =
25422547
glConfig2.bindlessTexturesAvailable
25432548
&& glConfig2.computeShaderAvailable

0 commit comments

Comments
 (0)