Skip to content

Commit 64e7bdf

Browse files
committed
Implement the rest of PushBuffer
- Generalise uniform post-processing - Add `GLShader.pushSkip` and `GLShader._pushUniforms`. Add `padding` back to the `GLShader` size calculations in material system. - Add GlobalUBOProxy, required for `PushBuffer` to set global uniform values outside of their shaders. - Add `PostProcessGlobalUniforms()`: set `GLShaderManager.globalUniformBlock` to the struct + defines text, which will be the same for all shaders. - GLUniform._global -> _updateType: required for `PushBuffer` to correctly sort uniforms. Also updates `GLShader.WriteUniformsToBuffer()` to use `mode` and `filter` arguments to select the correct uniforms. - Add global UBO in PushBuffer - Post-process shaders to actually add the `globalUniformBlock`, add `SetConstUniforms()` and `SetFrameUniforms()` functions to the core and material system renderers, and add the supporting glsl code. - Fix quake3 fog with material system
1 parent 4995913 commit 64e7bdf

24 files changed

+665
-255
lines changed

src/engine/renderer/GLMemory.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ void GLStagingBuffer::FlushAll() {
117117
FlushStagingCopyQueue();
118118
}
119119

120+
bool GLStagingBuffer::Active() const {
121+
return buffer.id;
122+
}
123+
120124
void GLStagingBuffer::InitGLBuffer() {
121125
buffer.GenBuffer();
122126

@@ -136,6 +140,10 @@ void GLStagingBuffer::FreeGLBuffer() {
136140

137141
void PushBuffer::InitGLBuffers() {
138142
globalUBO.GenBuffer();
143+
144+
globalUBO.BufferStorage( pushBuffer.constUniformsSize + pushBuffer.frameUniformsSize, 1, nullptr );
145+
146+
globalUBO.BindBufferBase();
139147
}
140148

141149
void PushBuffer::FreeGLBuffers() {

src/engine/renderer/GLMemory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class GLBuffer {
175175

176176
void DelBuffer() {
177177
glDeleteBuffers( 1, &id );
178+
id = 0;
178179
mapped = false;
179180
}
180181

@@ -303,6 +304,8 @@ class GLStagingBuffer {
303304
void FlushStagingCopyQueue();
304305
void FlushAll();
305306

307+
bool Active() const;
308+
306309
void InitGLBuffer();
307310
void FreeGLBuffer();
308311

src/engine/renderer/GLUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct GLConfig
123123
bool usingMaterialSystem; // are we using it right now
124124
bool geometryCacheAvailable;
125125
bool usingGeometryCache;
126+
bool pushBufferAvailable;
126127
bool gpuShader4Available;
127128
bool gpuShader5Available;
128129
bool textureGatherAvailable;

src/engine/renderer/Material.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, boo
161161

162162
gl_genericShaderMaterial->SetUniform_DepthScale( pStage->depthFadeValue );
163163

164-
gl_genericShaderMaterial->WriteUniformsToBuffer( materials );
164+
gl_genericShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
165165
}
166166

167167
void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage, bool, bool vertexLit, bool fullbright ) {
@@ -207,7 +207,7 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage,
207207

208208
gl_lightMappingShaderMaterial->SetUniform_SpecularExponent( specExpMin, specExpMax );
209209

210-
gl_lightMappingShaderMaterial->WriteUniformsToBuffer( materials );
210+
gl_lightMappingShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
211211
}
212212

213213
void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
@@ -244,7 +244,7 @@ void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bo
244244
gl_reflectionShaderMaterial->SetUniform_ReliefDepthScale( depthScale );
245245
gl_reflectionShaderMaterial->SetUniform_ReliefOffsetBias( shader->reliefOffsetBias );
246246

247-
gl_reflectionShaderMaterial->WriteUniformsToBuffer( materials );
247+
gl_reflectionShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
248248
}
249249

250250
void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
@@ -255,7 +255,7 @@ void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool,
255255
// u_AlphaThreshold
256256
gl_skyboxShaderMaterial->SetUniform_AlphaTest( GLS_ATEST_NONE );
257257

258-
gl_skyboxShaderMaterial->WriteUniformsToBuffer( materials );
258+
gl_skyboxShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
259259
}
260260

261261
void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
@@ -268,7 +268,7 @@ void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool,
268268
this seems to be the only material system shader that might need it to not be global */
269269
gl_screenShaderMaterial->SetUniform_CurrentMapBindless( BindAnimatedImage( 0, &pStage->bundle[TB_COLORMAP] ) );
270270

271-
gl_screenShaderMaterial->WriteUniformsToBuffer( materials );
271+
gl_screenShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
272272
}
273273

274274
void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
@@ -285,7 +285,7 @@ void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool
285285
// bind u_NormalScale
286286
gl_heatHazeShaderMaterial->SetUniform_NormalScale( normalScale );
287287

288-
gl_heatHazeShaderMaterial->WriteUniformsToBuffer( materials );
288+
gl_heatHazeShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
289289
}
290290

291291
void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
@@ -331,15 +331,15 @@ void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool,
331331

332332
gl_liquidShaderMaterial->SetUniform_NormalScale( normalScale );
333333

334-
gl_liquidShaderMaterial->WriteUniformsToBuffer( materials );
334+
gl_liquidShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
335335
}
336336

337337
void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
338338
// shader_t* shader = pStage->shader;
339339

340340
materials += pStage->bufferOffset;
341341

342-
gl_fogQuake3ShaderMaterial->WriteUniformsToBuffer( materials );
342+
gl_fogQuake3ShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
343343
}
344344

345345
/*
@@ -1621,9 +1621,24 @@ void MaterialSystem::UpdateDynamicSurfaces() {
16211621
GL_CheckErrors();
16221622
}
16231623

1624+
void MaterialSystem::SetConstUniforms() {
1625+
globalUBOProxy->SetUniform_SurfaceDescriptorsCount( surfaceDescriptorsCount );
1626+
uint32_t globalWorkGroupX = surfaceDescriptorsCount % MAX_COMMAND_COUNTERS == 0 ?
1627+
surfaceDescriptorsCount / MAX_COMMAND_COUNTERS : surfaceDescriptorsCount / MAX_COMMAND_COUNTERS + 1;
1628+
1629+
globalUBOProxy->SetUniform_FirstPortalGroup( globalWorkGroupX );
1630+
globalUBOProxy->SetUniform_TotalPortals( totalPortals );
1631+
}
1632+
1633+
void MaterialSystem::SetFrameUniforms() {
1634+
globalUBOProxy->SetUniform_Frame( nextFrame );
1635+
1636+
globalUBOProxy->SetUniform_UseFrustumCulling( r_gpuFrustumCulling.Get() );
1637+
globalUBOProxy->SetUniform_UseOcclusionCulling( r_gpuOcclusionCulling.Get() );
1638+
}
1639+
16241640
void MaterialSystem::UpdateFrameData() {
16251641
gl_clearSurfacesShader->BindProgram();
1626-
gl_clearSurfacesShader->SetUniform_Frame( nextFrame );
16271642
gl_clearSurfacesShader->DispatchCompute( MAX_VIEWS, 1, 1 );
16281643

16291644
GL_CheckErrors();
@@ -1709,15 +1724,9 @@ void MaterialSystem::CullSurfaces() {
17091724
uint32_t globalWorkGroupX = surfaceDescriptorsCount % MAX_COMMAND_COUNTERS == 0 ?
17101725
surfaceDescriptorsCount / MAX_COMMAND_COUNTERS : surfaceDescriptorsCount / MAX_COMMAND_COUNTERS + 1;
17111726
GL_Bind( depthImage );
1712-
gl_cullShader->SetUniform_Frame( nextFrame );
17131727
gl_cullShader->SetUniform_ViewID( view );
1714-
gl_cullShader->SetUniform_SurfaceDescriptorsCount( surfaceDescriptorsCount );
1715-
gl_cullShader->SetUniform_UseFrustumCulling( r_gpuFrustumCulling.Get() );
1716-
gl_cullShader->SetUniform_UseOcclusionCulling( r_gpuOcclusionCulling.Get() );
17171728
gl_cullShader->SetUniform_CameraPosition( origin );
17181729
gl_cullShader->SetUniform_ModelViewMatrix( viewMatrix );
1719-
gl_cullShader->SetUniform_FirstPortalGroup( globalWorkGroupX );
1720-
gl_cullShader->SetUniform_TotalPortals( totalPortals );
17211730
gl_cullShader->SetUniform_ViewWidth( depthImage->width );
17221731
gl_cullShader->SetUniform_ViewHeight( depthImage->height );
17231732
gl_cullShader->SetUniform_SurfaceCommandsOffset( surfaceCommandsCount * ( MAX_VIEWS * nextFrame + view ) );
@@ -1749,7 +1758,6 @@ void MaterialSystem::CullSurfaces() {
17491758
gl_cullShader->DispatchCompute( globalWorkGroupX, 1, 1 );
17501759

17511760
gl_processSurfacesShader->BindProgram();
1752-
gl_processSurfacesShader->SetUniform_Frame( nextFrame );
17531761
gl_processSurfacesShader->SetUniform_ViewID( view );
17541762
gl_processSurfacesShader->SetUniform_SurfaceCommandsOffset( surfaceCommandsCount * ( MAX_VIEWS * nextFrame + view ) );
17551763

src/engine/renderer/Material.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ class MaterialSystem {
362362

363363
void StartFrame();
364364
void EndFrame();
365+
void SetConstUniforms();
366+
void SetFrameUniforms();
365367

366368
void GenerateDepthImages( const int width, const int height, imageParams_t imageParms );
367369

0 commit comments

Comments
 (0)