Skip to content

Commit 4b840fd

Browse files
committed
Add the remaining code for the 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.
1 parent e976371 commit 4b840fd

20 files changed

+212
-14
lines changed

src/engine/renderer/GLMemory.cpp

Lines changed: 4 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

src/engine/renderer/GLMemory.h

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

178178
void DelBuffer() {
179179
glDeleteBuffers( 1, &id );
180+
id = 0;
180181
mapped = false;
181182
}
182183

@@ -305,6 +306,8 @@ class GLStagingBuffer {
305306
void FlushStagingCopyQueue();
306307
void FlushAll();
307308

309+
bool Active() const;
310+
308311
void InitGLBuffer();
309312
void FreeGLBuffer();
310313

src/engine/renderer/Material.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,9 +1495,24 @@ void MaterialSystem::UpdateDynamicSurfaces() {
14951495
GL_CheckErrors();
14961496
}
14971497

1498+
void MaterialSystem::SetConstUniforms() {
1499+
globalUBOProxy->SetUniform_SurfaceDescriptorsCount( surfaceDescriptorsCount );
1500+
uint32_t globalWorkGroupX = surfaceDescriptorsCount % MAX_COMMAND_COUNTERS == 0 ?
1501+
surfaceDescriptorsCount / MAX_COMMAND_COUNTERS : surfaceDescriptorsCount / MAX_COMMAND_COUNTERS + 1;
1502+
1503+
globalUBOProxy->SetUniform_FirstPortalGroup( globalWorkGroupX );
1504+
globalUBOProxy->SetUniform_TotalPortals( totalPortals );
1505+
}
1506+
1507+
void MaterialSystem::SetFrameUniforms() {
1508+
globalUBOProxy->SetUniform_Frame( nextFrame );
1509+
1510+
globalUBOProxy->SetUniform_UseFrustumCulling( r_gpuFrustumCulling.Get() );
1511+
globalUBOProxy->SetUniform_UseOcclusionCulling( r_gpuOcclusionCulling.Get() );
1512+
}
1513+
14981514
void MaterialSystem::UpdateFrameData() {
14991515
gl_clearSurfacesShader->BindProgram( 0 );
1500-
gl_clearSurfacesShader->SetUniform_Frame( nextFrame );
15011516
gl_clearSurfacesShader->DispatchCompute( MAX_VIEWS, 1, 1 );
15021517

15031518
GL_CheckErrors();
@@ -1582,15 +1597,9 @@ void MaterialSystem::CullSurfaces() {
15821597
uint32_t globalWorkGroupX = surfaceDescriptorsCount % MAX_COMMAND_COUNTERS == 0 ?
15831598
surfaceDescriptorsCount / MAX_COMMAND_COUNTERS : surfaceDescriptorsCount / MAX_COMMAND_COUNTERS + 1;
15841599
GL_Bind( depthImage );
1585-
gl_cullShader->SetUniform_Frame( nextFrame );
15861600
gl_cullShader->SetUniform_ViewID( view );
1587-
gl_cullShader->SetUniform_SurfaceDescriptorsCount( surfaceDescriptorsCount );
1588-
gl_cullShader->SetUniform_UseFrustumCulling( r_gpuFrustumCulling.Get() );
1589-
gl_cullShader->SetUniform_UseOcclusionCulling( r_gpuOcclusionCulling.Get() );
15901601
gl_cullShader->SetUniform_CameraPosition( origin );
15911602
gl_cullShader->SetUniform_ModelViewMatrix( viewMatrix );
1592-
gl_cullShader->SetUniform_FirstPortalGroup( globalWorkGroupX );
1593-
gl_cullShader->SetUniform_TotalPortals( totalPortals );
15941603
gl_cullShader->SetUniform_ViewWidth( depthImage->width );
15951604
gl_cullShader->SetUniform_ViewHeight( depthImage->height );
15961605
gl_cullShader->SetUniform_SurfaceCommandsOffset( surfaceCommandsCount * ( MAX_VIEWS * nextFrame + view ) );
@@ -1622,7 +1631,6 @@ void MaterialSystem::CullSurfaces() {
16221631
gl_cullShader->DispatchCompute( globalWorkGroupX, 1, 1 );
16231632

16241633
gl_processSurfacesShader->BindProgram( 0 );
1625-
gl_processSurfacesShader->SetUniform_Frame( nextFrame );
16261634
gl_processSurfacesShader->SetUniform_ViewID( view );
16271635
gl_processSurfacesShader->SetUniform_SurfaceCommandsOffset( surfaceCommandsCount * ( MAX_VIEWS * nextFrame + view ) );
16281636

src/engine/renderer/Material.h

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

360360
void StartFrame();
361361
void EndFrame();
362+
void SetConstUniforms();
363+
void SetFrameUniforms();
362364

363365
void GenerateDepthImages( const int width, const int height, imageParams_t imageParms );
364366

src/engine/renderer/gl_shader.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,12 @@ void GLShaderManager::InitShader( GLShader* shader ) {
13501350
ShaderDescriptor* desc = FindShader( shader->_name, shaderType.mainText, shaderType.GLType, shaderType.headers,
13511351
uniqueMacros, compileMacros, true );
13521352

1353+
if ( desc && glConfig2.pushBufferAvailable ) {
1354+
desc->shaderSource = RemoveUniformsFromShaderText( desc->shaderSource, shader->_pushUniforms );
1355+
1356+
desc->shaderSource.insert( shaderType.offset, globalUniformBlock );
1357+
}
1358+
13531359
if ( desc && glConfig2.usingMaterialSystem && shader->_useMaterialSystem ) {
13541360
desc->shaderSource = ShaderPostProcess( shader, desc->shaderSource, shaderType.offset );
13551361
}
@@ -1605,7 +1611,7 @@ void GLShaderManager::PostProcessGlobalUniforms() {
16051611
GLuint padding;
16061612
std::vector<GLUniform*>* uniforms = &( ( GLShader* ) globalUBOProxy )->_uniforms;
16071613
std::vector<GLUniform*> constUniforms =
1608-
ProcessUniforms( GLUniform::CONST, GLUniform::CONST, false, *uniforms, size, padding );
1614+
ProcessUniforms( GLUniform::CONST, GLUniform::CONST, !glConfig2.usingBindlessTextures, *uniforms, size, padding );
16091615

16101616
GenerateUniformStructDefinesText( constUniforms, padding, 0, "globalUniforms", uniformStruct, uniformDefines );
16111617

@@ -1614,7 +1620,7 @@ void GLShaderManager::PostProcessGlobalUniforms() {
16141620
pushBuffer.constUniformsSize = size + padding;
16151621

16161622
std::vector<GLUniform*> frameUniforms =
1617-
ProcessUniforms( GLUniform::FRAME, GLUniform::FRAME, false, *uniforms, size, padding );
1623+
ProcessUniforms( GLUniform::FRAME, GLUniform::FRAME, !glConfig2.usingBindlessTextures, *uniforms, size, padding );
16181624

16191625
GenerateUniformStructDefinesText( frameUniforms, padding, paddingCount, "globalUniforms", uniformStruct, uniformDefines );
16201626

@@ -2250,7 +2256,7 @@ void GLShader::PostProcessUniforms() {
22502256
if ( glConfig2.pushBufferAvailable && !pushSkip ) {
22512257
GLuint unused;
22522258
_pushUniforms = gl_shaderManager.ProcessUniforms( GLUniform::CONST, GLUniform::FRAME,
2253-
false, _uniforms, unused, unused );
2259+
!glConfig2.usingBindlessTextures, _uniforms, unused, unused );
22542260
}
22552261
}
22562262

src/engine/renderer/glsl_source/cameraEffects_fp.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222

2323
/* cameraEffects_fp.glsl */
2424

25+
#define CAMERAEFFECTS_GLSL
26+
2527
uniform sampler2D u_CurrentMap;
2628

2729
#if defined(r_colorGrading)
@@ -69,6 +71,8 @@ DECLARE_OUTPUT(vec4)
6971

7072
void main()
7173
{
74+
#insert material_fp
75+
7276
// calculate the screen texcoord in the 0.0 to 1.0 range
7377
vec2 st = gl_FragCoord.st / r_FBufSize;
7478

src/engine/renderer/glsl_source/depthReduction_cp.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

3535
/* depthReduction_cp.glsl */
3636

37+
#define DEPTHMAP_GLSL
38+
3739
#insert common_cp
3840

3941
// Keep this to 8x8 because we don't want extra shared mem etc. to be allocated, and to minimize wasted lanes
@@ -48,6 +50,8 @@ uniform uint u_ViewHeight;
4850
uniform bool u_InitialDepthLevel;
4951

5052
void main() {
53+
#insert material_fp
54+
5155
const uint globalInvocationID = GLOBAL_INVOCATION_ID;
5256

5357
const ivec2 position = ivec2( gl_GlobalInvocationID.xy );

src/engine/renderer/glsl_source/depthtile1_fp.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

3535
/* depthtile1_fp.glsl */
3636

37+
#define DEPTHMAP_GLSL
38+
3739
uniform sampler2D u_DepthMap;
3840
IN(flat) vec3 unprojectionParams;
3941

@@ -63,6 +65,8 @@ float min16(in vec4 data0, in vec4 data1, in vec4 data2, in vec4 data3)
6365
}
6466
void main()
6567
{
68+
#insert material_fp
69+
6670
vec2 st = gl_FragCoord.st * 4.0 * pixelScale;
6771
vec4 depth[4], mask[4];
6872

src/engine/renderer/glsl_source/depthtile2_fp.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

3535
/* depthtile2_fp.glsl */
3636

37+
#define DEPTHTILE1_GLSL
38+
3739
uniform sampler2D u_DepthTile1;
3840

3941
#if __VERSION__ > 120
@@ -44,6 +46,8 @@ out vec4 outputColor;
4446

4547
void main()
4648
{
49+
#insert material_fp
50+
4751
vec2 st = gl_FragCoord.st * r_tileStep;
4852
float x, y;
4953
vec4 accum = vec4( 0.0, 99999.0, 0.0, 0.0 );

src/engine/renderer/glsl_source/fogGlobal_fp.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2424

2525
#insert common
2626

27+
#define DEPTHMAP_GLSL
28+
2729
uniform sampler2D u_ColorMap; // fog texture
2830
uniform sampler2D u_DepthMap;
2931

@@ -40,6 +42,8 @@ out vec4 outputColor;
4042

4143
void main()
4244
{
45+
#insert material_fp
46+
4347
// calculate the screen texcoord in the 0.0 to 1.0 range
4448
vec2 st = gl_FragCoord.st / r_FBufSize;
4549

0 commit comments

Comments
 (0)