Skip to content

Commit 9396fb5

Browse files
committed
Only update PushBuffer if any uniform has actually changed
Also mutualises `uniformFirewall` and `currentValue` and removes a bunch of unneeded code.
1 parent 7d721d2 commit 9396fb5

File tree

5 files changed

+135
-363
lines changed

5 files changed

+135
-363
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ GLShaderManager::~GLShaderManager()
231231
= default;
232232

233233
void GLShaderManager::FreeAll() {
234+
for ( const std::unique_ptr<GLShader>& shader : _shaders ) {
235+
if ( shader.get()->uniformStorage ) {
236+
Z_Free( shader.get()->uniformStorage );
237+
}
238+
}
239+
234240
_shaders.clear();
235241

236242
deformShaderCount = 0;
@@ -249,8 +255,8 @@ void GLShaderManager::FreeAll() {
249255
Z_Free( program.uniformBlockIndexes );
250256
}
251257

252-
if ( program.uniformFirewall ) {
253-
Z_Free( program.uniformFirewall );
258+
if ( program.uniformStorage ) {
259+
Z_Free( program.uniformStorage );
254260
}
255261
}
256262

@@ -279,7 +285,7 @@ void GLShaderManager::UpdateShaderProgramUniformLocations( GLShader* shader, Sha
279285
shaderProgram->uniformLocations = ( GLint* ) Z_Malloc( sizeof( GLint ) * numUniforms );
280286

281287
// create buffer for uniform firewall
282-
shaderProgram->uniformFirewall = ( byte* ) Z_Malloc( uniformSize );
288+
shaderProgram->uniformStorage = ( uint32_t* ) Z_Malloc( uniformSize );
283289

284290
// update uniforms
285291
for (GLUniform *uniform : shader->_uniforms)
@@ -1284,10 +1290,16 @@ void GLShaderManager::InitShader( GLShader* shader ) {
12841290
for ( std::size_t i = 0; i < shader->_uniforms.size(); i++ ) {
12851291
GLUniform* uniform = shader->_uniforms[i];
12861292
uniform->SetLocationIndex( i );
1287-
uniform->SetFirewallIndex( shader->_uniformStorageSize );
1288-
shader->_uniformStorageSize += uniform->GetSize();
1293+
uniform->SetUniformStorageOffset( shader->_uniformStorageSize );
1294+
1295+
const uint32_t size = uniform->_components ? uniform->_std430Size * uniform->_components : uniform->_std430Size;
1296+
shader->_uniformStorageSize += size;
12891297
}
12901298

1299+
shader->_uniformStorageSize *= sizeof( uint32_t );
1300+
1301+
shader->uniformStorage = ( uint32_t* ) Z_Malloc( shader->_uniformStorageSize );
1302+
12911303
for ( std::size_t i = 0; i < shader->_uniformBlocks.size(); i++ ) {
12921304
GLUniformBlock* uniformBlock = shader->_uniformBlocks[i];
12931305
uniformBlock->SetLocationIndex( i );
@@ -2150,10 +2162,6 @@ bool GLCompileMacro_USE_BSP_SURFACE::HasConflictingMacros(size_t permutation, co
21502162
return false;
21512163
}
21522164

2153-
uint32_t* GLUniform::WriteToBuffer( uint32_t* buffer ) {
2154-
return buffer;
2155-
}
2156-
21572165
void GLShader::RegisterUniform( GLUniform* uniform ) {
21582166
_uniforms.push_back( uniform );
21592167
}
@@ -2208,7 +2216,7 @@ GLuint GLShaderManager::SortUniforms( std::vector<GLUniform*>& uniforms ) {
22082216
}
22092217

22102218
if ( alignmentConsume & 3 ) {
2211-
tmpUniform->_std430Size += alignmentConsume;
2219+
tmpUniform->_nextUniformOffset += alignmentConsume;
22122220
}
22132221

22142222
if ( uniforms.size() ) {
@@ -2458,6 +2466,8 @@ void GLShader::WriteUniformsToBuffer( uint32_t* buffer, const Mode mode, const i
24582466
bufPtr = uniform->WriteToBuffer( bufPtr );
24592467
}
24602468
}
2469+
2470+
uniformsUpdated = false;
24612471
}
24622472

24632473
GLShader_generic::GLShader_generic() :

0 commit comments

Comments
 (0)