Skip to content

Commit f648c4c

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 a6b2a20 commit f648c4c

File tree

4 files changed

+134
-362
lines changed

4 files changed

+134
-362
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)
@@ -1280,10 +1286,16 @@ void GLShaderManager::InitShader( GLShader* shader ) {
12801286
for ( std::size_t i = 0; i < shader->_uniforms.size(); i++ ) {
12811287
GLUniform* uniform = shader->_uniforms[i];
12821288
uniform->SetLocationIndex( i );
1283-
uniform->SetFirewallIndex( shader->_uniformStorageSize );
1284-
shader->_uniformStorageSize += uniform->GetSize();
1289+
uniform->SetUniformStorageOffset( shader->_uniformStorageSize );
1290+
1291+
const uint32_t size = uniform->_components ? uniform->_std430Size * uniform->_components : uniform->_std430Size;
1292+
shader->_uniformStorageSize += size;
12851293
}
12861294

1295+
shader->_uniformStorageSize *= sizeof( uint32_t );
1296+
1297+
shader->uniformStorage = ( uint32_t* ) Z_Malloc( shader->_uniformStorageSize );
1298+
12871299
for ( std::size_t i = 0; i < shader->_uniformBlocks.size(); i++ ) {
12881300
GLUniformBlock* uniformBlock = shader->_uniformBlocks[i];
12891301
uniformBlock->SetLocationIndex( i );
@@ -2146,10 +2158,6 @@ bool GLCompileMacro_USE_BSP_SURFACE::HasConflictingMacros(size_t permutation, co
21462158
return false;
21472159
}
21482160

2149-
uint32_t* GLUniform::WriteToBuffer( uint32_t* buffer ) {
2150-
return buffer;
2151-
}
2152-
21532161
void GLShader::RegisterUniform( GLUniform* uniform ) {
21542162
_uniforms.push_back( uniform );
21552163
}
@@ -2204,7 +2212,7 @@ GLuint GLShaderManager::SortUniforms( std::vector<GLUniform*>& uniforms ) {
22042212
}
22052213

22062214
if ( alignmentConsume & 3 ) {
2207-
tmpUniform->_std430Size += alignmentConsume;
2215+
tmpUniform->_nextUniformOffset += alignmentConsume;
22082216
}
22092217

22102218
if ( uniforms.size() ) {
@@ -2454,6 +2462,8 @@ void GLShader::WriteUniformsToBuffer( uint32_t* buffer, const Mode mode, const i
24542462
bufPtr = uniform->WriteToBuffer( bufPtr );
24552463
}
24562464
}
2465+
2466+
uniformsUpdated = false;
24572467
}
24582468

24592469
GLShader_generic::GLShader_generic() :

0 commit comments

Comments
 (0)