Skip to content

Commit 140678a

Browse files
committed
Only update PushBuffer if any uniform has actually changed
1 parent 1e2423c commit 140678a

File tree

4 files changed

+134
-349
lines changed

4 files changed

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

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

2148-
uint32_t* GLUniform::WriteToBuffer( uint32_t* buffer ) {
2149-
return buffer;
2150-
}
2151-
21522160
void GLShader::RegisterUniform( GLUniform* uniform ) {
21532161
_uniforms.push_back( uniform );
21542162
}
@@ -2203,7 +2211,7 @@ GLuint GLShaderManager::SortUniforms( std::vector<GLUniform*>& uniforms ) {
22032211
}
22042212

22052213
if ( alignmentConsume & 3 ) {
2206-
tmpUniform->_std430Size += alignmentConsume;
2214+
tmpUniform->_nextUniformOffset += alignmentConsume;
22072215
}
22082216

22092217
if ( uniforms.size() ) {
@@ -2453,6 +2461,8 @@ void GLShader::WriteUniformsToBuffer( uint32_t* buffer, const Mode mode, const i
24532461
bufPtr = uniform->WriteToBuffer( bufPtr );
24542462
}
24552463
}
2464+
2465+
uniformsUpdated = false;
24562466
}
24572467

24582468
GLShader_generic::GLShader_generic() :

0 commit comments

Comments
 (0)