Skip to content

Commit 4fce8e5

Browse files
committed
Add PushBuffer
Adds `PushBuffer` class, `pushBuffer` global, and the supporting code for `glconfig2`.
1 parent b63d64f commit 4fce8e5

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: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838

3939
#include "common/Common.h"
4040
#include "GL/glew.h"
41+
4142
#include "tr_local.h"
4243
#include "BufferBind.h"
4344

@@ -318,6 +319,28 @@ class GLStagingBuffer {
318319
GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_INVALIDATE_BUFFER_BIT );
319320
};
320321

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

323-
#endif // GLMEMORY_H
346+
#endif // GLMEMORY_H

src/engine/renderer/tr_public.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct glconfig2_t
120120
bool usingMaterialSystem; // are we using it right now
121121
bool geometryCacheAvailable;
122122
bool usingGeometryCache;
123+
bool pushBufferAvailable;
123124
bool gpuShader4Available;
124125
bool gpuShader5Available;
125126
bool textureGatherAvailable;

src/engine/sys/sdl_glimp.cpp

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

25922592
glConfig2.geometryCacheAvailable = glConfig2.vertexAttribBindingAvailable && glConfig2.directStateAccessAvailable;
25932593

2594+
glConfig2.pushBufferAvailable =
2595+
glConfig2.directStateAccessAvailable
2596+
&& glConfig2.explicitUniformLocationAvailable
2597+
&& glConfig2.uniformBufferObjectAvailable;
2598+
25942599
glConfig2.materialSystemAvailable =
25952600
glConfig2.bindlessTexturesAvailable
25962601
&& glConfig2.computeShaderAvailable

0 commit comments

Comments
 (0)