@@ -725,6 +725,36 @@ void MaterialSystem::GenerateWorldCommandBuffer( std::vector<MaterialSurface>& s
725725 GL_CheckErrors ();
726726}
727727
728+ void MaterialSystem::BindBuffers () {
729+ materialsUBO.BindBufferBase ();
730+ texDataBuffer.BindBufferBase ( texDataBufferType, texDataBindingPoint );
731+ lightMapDataUBO.BindBufferBase ();
732+
733+ if ( glConfig2.realtimeLighting ) {
734+ // UBOs are actually completely independent of shaders since we set the binding points explicitly here
735+ gl_lightMappingShaderMaterial->SetUniformBlock_Lights ( tr.dlightUBO );
736+ }
737+
738+ culledCommandsBuffer.BindBuffer ( GL_DRAW_INDIRECT_BUFFER );
739+ atomicCommandCountersBuffer.BindBuffer ( GL_PARAMETER_BUFFER_ARB );
740+
741+ atomicCommandCountersBuffer.BindBufferBase ( GL_SHADER_STORAGE_BUFFER, Util::ordinal ( BufferBind::COMMAND_COUNTERS_STORAGE ) );
742+
743+ surfaceDescriptorsSSBO.BindBufferBase ();
744+ surfaceCommandsSSBO.BindBufferBase ();
745+ culledCommandsBuffer.BindBufferBase ( GL_SHADER_STORAGE_BUFFER );
746+ surfaceBatchesUBO.BindBufferBase ();
747+ atomicCommandCountersBuffer.BindBufferBase ( GL_ATOMIC_COUNTER_BUFFER );
748+
749+ if ( totalPortals > 0 ) {
750+ portalSurfacesSSBO.BindBufferBase ();
751+ }
752+
753+ if ( r_materialDebug.Get () ) {
754+ debugSSBO.BindBufferBase ();
755+ }
756+ }
757+
728758void MaterialSystem::GenerateDepthImages ( const int width, const int height, imageParams_t imageParms ) {
729759 imageParms.bits ^= ( IF_NOPICMIP | IF_PACKED_DEPTH24_STENCIL8 );
730760 imageParms.bits |= IF_ONECOMP32F;
@@ -812,8 +842,6 @@ void BindShaderLightMapping( Material* material ) {
812842 }
813843
814844 if ( glConfig2.realtimeLighting ) {
815- gl_lightMappingShaderMaterial->SetUniformBlock_Lights ( tr.dlightUBO );
816-
817845 // bind u_LightTiles
818846 gl_lightMappingShaderMaterial->SetUniform_LightTilesBindless (
819847 GL_BindToTMU ( BIND_LIGHTTILES, tr.lighttileRenderImage )
@@ -1471,14 +1499,10 @@ void MaterialSystem::UpdateDynamicSurfaces() {
14711499}
14721500
14731501void MaterialSystem::UpdateFrameData () {
1474- atomicCommandCountersBuffer.BindBufferBase ( GL_SHADER_STORAGE_BUFFER, Util::ordinal ( BufferBind::COMMAND_COUNTERS_STORAGE ) );
1475-
14761502 gl_clearSurfacesShader->BindProgram ( 0 );
14771503 gl_clearSurfacesShader->SetUniform_Frame ( nextFrame );
14781504 gl_clearSurfacesShader->DispatchCompute ( MAX_VIEWS, 1 , 1 );
14791505
1480- atomicCommandCountersBuffer.UnBindBufferBase ( GL_SHADER_STORAGE_BUFFER, Util::ordinal ( BufferBind::COMMAND_COUNTERS_STORAGE ) );
1481-
14821506 GL_CheckErrors ();
14831507}
14841508
@@ -1530,29 +1554,15 @@ void MaterialSystem::DepthReduction() {
15301554
15311555 glMemoryBarrier ( GL_SHADER_IMAGE_ACCESS_BARRIER_BIT );
15321556 }
1557+
1558+ GL_CheckErrors ();
15331559}
15341560
15351561void MaterialSystem::CullSurfaces () {
15361562 if ( r_gpuOcclusionCulling.Get () ) {
15371563 DepthReduction ();
15381564 }
15391565
1540- surfaceDescriptorsSSBO.BindBufferBase ();
1541- surfaceCommandsSSBO.BindBufferBase ();
1542- culledCommandsBuffer.BindBufferBase ( GL_SHADER_STORAGE_BUFFER );
1543- surfaceBatchesUBO.BindBufferBase ();
1544- atomicCommandCountersBuffer.BindBufferBase ( GL_ATOMIC_COUNTER_BUFFER );
1545-
1546- if ( totalPortals > 0 ) {
1547- portalSurfacesSSBO.BindBufferBase ();
1548- }
1549-
1550- if ( r_materialDebug.Get () ) {
1551- debugSSBO.BindBufferBase ();
1552- }
1553-
1554- GL_CheckErrors ();
1555-
15561566 for ( uint32_t view = 0 ; view < frames[nextFrame].viewCount ; view++ ) {
15571567 vec3_t origin;
15581568 frustum_t * frustum = &frames[nextFrame].viewFrames [view].frustum ;
@@ -1623,20 +1633,6 @@ void MaterialSystem::CullSurfaces() {
16231633 gl_processSurfacesShader->DispatchCompute ( totalBatchCount, 1 , 1 );
16241634 }
16251635
1626- surfaceDescriptorsSSBO.UnBindBufferBase ();
1627- surfaceCommandsSSBO.UnBindBufferBase ();
1628- culledCommandsBuffer.UnBindBufferBase ( GL_SHADER_STORAGE_BUFFER );
1629- surfaceBatchesUBO.UnBindBufferBase ();
1630- atomicCommandCountersBuffer.UnBindBufferBase ( GL_ATOMIC_COUNTER_BUFFER );
1631-
1632- if ( totalPortals > 0 ) {
1633- portalSurfacesSSBO.UnBindBufferBase ();
1634- }
1635-
1636- if ( r_materialDebug.Get () ) {
1637- debugSSBO.UnBindBufferBase ();
1638- }
1639-
16401636 GL_CheckErrors ();
16411637}
16421638
@@ -1855,7 +1851,6 @@ void MaterialSystem::AddPortalSurfaces() {
18551851 return ;
18561852 }
18571853
1858- portalSurfacesSSBO.BindBufferBase ();
18591854 PortalSurface* portalSurfs = ( PortalSurface* ) portalSurfacesSSBO.GetCurrentAreaData ();
18601855 viewCount = 0 ;
18611856 // This will recursively find potentially visible portals in each view based on the data read back from the GPU
@@ -1894,8 +1889,6 @@ void MaterialSystem::RenderMaterials( const shaderSort_t fromSort, const shaderS
18941889 frameStart = false ;
18951890 }
18961891
1897- materialsUBO.BindBufferBase ();
1898-
18991892 geometryCache.Bind ();
19001893
19011894 for ( MaterialPack& materialPack : materialPacks ) {
@@ -2026,13 +2019,6 @@ void MaterialSystem::RenderMaterial( Material& material, const uint32_t viewID )
20262019 }
20272020 material.texturesResident = true ;
20282021
2029- culledCommandsBuffer.BindBuffer ( GL_DRAW_INDIRECT_BUFFER );
2030-
2031- atomicCommandCountersBuffer.BindBuffer ( GL_PARAMETER_BUFFER_ARB );
2032-
2033- texDataBuffer.BindBufferBase ( texDataBufferType, texDataBindingPoint );
2034- lightMapDataUBO.BindBufferBase ();
2035-
20362022 if ( r_showGlobalMaterials.Get () && material.sort != 0
20372023 && ( material.shaderBinder == BindShaderLightMapping || material.shaderBinder == BindShaderGeneric3D ) ) {
20382024 vec3_t color;
@@ -2143,13 +2129,6 @@ void MaterialSystem::RenderMaterial( Material& material, const uint32_t viewID )
21432129 }
21442130 }
21452131
2146- culledCommandsBuffer.UnBindBuffer ( GL_DRAW_INDIRECT_BUFFER );
2147-
2148- atomicCommandCountersBuffer.UnBindBuffer ( GL_PARAMETER_BUFFER_ARB );
2149-
2150- texDataBuffer.UnBindBufferBase ( texDataBufferType, texDataBindingPoint );
2151- lightMapDataUBO.UnBindBufferBase ();
2152-
21532132 if ( material.usePolygonOffset ) {
21542133 glDisable ( GL_POLYGON_OFFSET_FILL );
21552134 }
0 commit comments