Skip to content

Commit 7e0dd2b

Browse files
committed
MSAA clean-up and fixes
1 parent 7066d19 commit 7e0dd2b

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

src/engine/renderer/Material.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ void BindShaderHeatHaze( Material* material ) {
10621062
gl_heatHazeShaderMaterial->SetUniform_DeformEnable( true );
10631063

10641064
// draw to background image
1065-
TransitionMSAAToMain();
1065+
TransitionMSAAToMain( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
10661066

10671067
R_BindFBO( tr.mainFBO[1 - backEnd.currentMainFBO] );
10681068
}
@@ -2240,7 +2240,7 @@ void MaterialSystem::RenderMaterial( Material& material, const uint32_t viewID )
22402240

22412241
RenderIndirect( material, viewID );
22422242

2243-
TransitionMainToMSAA();
2243+
TransitionMainToMSAA( GL_COLOR_BUFFER_BIT );
22442244
}
22452245

22462246
if ( r_showTris->integer

src/engine/renderer/tr_backend.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,42 +199,36 @@ GLuint64 GL_BindToTMU( int unit, image_t *image )
199199
return 0;
200200
}
201201

202-
static void BlitFBOToMSAA( FBO_t* fbo ) {
203-
glState.currentFBO = nullptr;
204-
202+
static void BlitFBOToMSAA( FBO_t* fbo, const GLbitfield mask ) {
205203
R_BindFBO( GL_READ_FRAMEBUFFER, fbo );
206204
R_BindFBO( GL_DRAW_FRAMEBUFFER, tr.msaaFBO );
207205
glBlitFramebuffer( 0, 0, fbo->width, fbo->height, 0, 0, tr.msaaFBO->width, tr.msaaFBO->height,
208-
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST );
206+
mask, GL_NEAREST );
209207

210-
glState.currentFBO = nullptr;
211208
R_BindFBO( GL_DRAW_FRAMEBUFFER, fbo );
212209
glState.currentFBO = fbo;
213210
}
214211

215-
static void BlitMSAAToFBO( FBO_t* fbo ) {
216-
glState.currentFBO = nullptr;
217-
212+
static void BlitMSAAToFBO( FBO_t* fbo, const GLbitfield mask ) {
218213
R_BindFBO( GL_READ_FRAMEBUFFER, tr.msaaFBO );
219214
R_BindFBO( GL_DRAW_FRAMEBUFFER, fbo );
220215
glBlitFramebuffer( 0, 0, tr.msaaFBO->width, tr.msaaFBO->height, 0, 0, fbo->width, fbo->height,
221-
GL_COLOR_BUFFER_BIT /* | GL_DEPTH_BUFFER_BIT */, GL_NEAREST );
216+
mask, GL_NEAREST );
222217

223-
glState.currentFBO = nullptr;
224218
R_BindFBO( GL_READ_FRAMEBUFFER, fbo );
225219
glState.currentFBO = fbo;
226220
}
227221

228-
void TransitionMainToMSAA() {
222+
void TransitionMainToMSAA( const GLbitfield mask ) {
229223
if ( glConfig.MSAA ) {
230-
BlitFBOToMSAA( tr.mainFBO[backEnd.currentMainFBO] );
224+
BlitFBOToMSAA( tr.mainFBO[backEnd.currentMainFBO], mask );
231225
R_BindFBO( tr.msaaFBO );
232226
}
233227
}
234228

235-
void TransitionMSAAToMain() {
229+
void TransitionMSAAToMain( const GLbitfield mask ) {
236230
if ( glConfig.MSAA ) {
237-
BlitMSAAToFBO( tr.mainFBO[backEnd.currentMainFBO] );
231+
BlitMSAAToFBO( tr.mainFBO[backEnd.currentMainFBO], mask );
238232
}
239233
}
240234

@@ -1309,6 +1303,8 @@ static void RenderDepthTiles()
13091303
{
13101304
RB_PrepareForSamplingDepthMap();
13111305
}
1306+
1307+
TransitionMSAAToMain( GL_DEPTH_BUFFER_BIT );
13121308

13131309
// 1st step
13141310
R_BindFBO( tr.depthtile1FBO );
@@ -1500,7 +1496,7 @@ void RB_RenderBloom()
15001496
GL_BindToTMU( 0, tr.currentRenderImage[backEnd.currentMainFBO] )
15011497
);
15021498

1503-
TransitionMSAAToMain();
1499+
TransitionMSAAToMain( GL_COLOR_BUFFER_BIT );
15041500

15051501
R_BindFBO( tr.contrastRenderFBO );
15061502
GL_ClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
@@ -1566,7 +1562,7 @@ void RB_RenderBloom()
15661562
GL_PopMatrix();
15671563
}
15681564

1569-
TransitionMainToMSAA();
1565+
TransitionMainToMSAA( GL_COLOR_BUFFER_BIT );
15701566

15711567
GL_CheckErrors();
15721568
}
@@ -1588,7 +1584,7 @@ void RB_RenderMotionBlur()
15881584

15891585
gl_motionblurShader->BindProgram();
15901586

1591-
TransitionMSAAToMain();
1587+
TransitionMSAAToMain( GL_COLOR_BUFFER_BIT );
15921588

15931589
// Swap main FBOs
15941590
gl_motionblurShader->SetUniform_ColorMapBindless(
@@ -1605,7 +1601,7 @@ void RB_RenderMotionBlur()
16051601

16061602
Tess_InstantScreenSpaceQuad();
16071603

1608-
TransitionMainToMSAA();
1604+
TransitionMainToMSAA( GL_COLOR_BUFFER_BIT );
16091605

16101606
GL_CheckErrors();
16111607
}
@@ -1627,6 +1623,8 @@ void RB_RenderSSAO()
16271623

16281624
RB_PrepareForSamplingDepthMap();
16291625

1626+
TransitionMSAAToMain( GL_DEPTH_BUFFER_BIT );
1627+
16301628
GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO );
16311629
GL_Cull( cullType_t::CT_TWO_SIDED );
16321630

@@ -2856,7 +2854,7 @@ static void RB_RenderPostProcess()
28562854
materialSystem.EndFrame();
28572855
}
28582856

2859-
TransitionMSAAToMain();
2857+
TransitionMSAAToMain( GL_COLOR_BUFFER_BIT );
28602858

28612859
RB_FXAA();
28622860

src/engine/renderer/tr_fbo.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,8 @@ void R_InitFBOs()
280280
if ( glConfig.MSAA ) {
281281
tr.msaaFBO = R_CreateFBO( "msaa", width, height );
282282
R_BindFBO( tr.msaaFBO );
283-
GL_CheckErrors();
284283
R_AttachFBOTexture2D( GL_TEXTURE_2D_MULTISAMPLE, tr.currentRenderImageMSAA->texnum, 0 );
285-
GL_CheckErrors();
286284
R_AttachFBOTexturePackedDepthStencilMSAA( tr.currentDepthImageMSAA->texnum );
287-
GL_CheckErrors();
288285
R_CheckFBO( tr.msaaFBO );
289286
}
290287

src/engine/renderer/tr_local.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,8 +2917,8 @@ inline bool checkGLErrors()
29172917
GLuint64 GL_BindToTMU( int unit, image_t *image );
29182918
void GL_BindNullProgram();
29192919

2920-
void TransitionMainToMSAA();
2921-
void TransitionMSAAToMain();
2920+
void TransitionMainToMSAA( const GLbitfield mask );
2921+
void TransitionMSAAToMain( const GLbitfield mask );
29222922
void BindMSAAOrMainFBO();
29232923

29242924
void GL_SetDefaultState();

src/engine/renderer/tr_shade.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,11 +891,21 @@ void Render_generic3D( shaderStage_t *pStage )
891891
bool hasDepthFade = pStage->hasDepthFade;
892892
bool needDepthMap = pStage->hasDepthFade;
893893

894-
if ( needDepthMap )
894+
const bool needMSAATransion = needDepthMap && backEnd.dirtyDepthBuffer;
895+
896+
if ( needDepthMap && backEnd.dirtyDepthBuffer && glConfig.textureBarrierAvailable )
895897
{
896898
RB_PrepareForSamplingDepthMap();
897899
}
898900

901+
if ( needMSAATransion ) {
902+
TransitionMSAAToMain( GL_DEPTH_BUFFER_BIT );
903+
904+
if ( glConfig.MSAA ) {
905+
R_BindFBO( GL_DRAW_FRAMEBUFFER, tr.msaaFBO );
906+
}
907+
}
908+
899909
// choose right shader program ----------------------------------
900910
ProcessShaderGeneric3D( pStage );
901911
gl_genericShader->BindProgram();
@@ -1465,7 +1475,7 @@ void Render_heatHaze( shaderStage_t *pStage )
14651475
}
14661476

14671477
// draw to background image
1468-
TransitionMSAAToMain();
1478+
TransitionMSAAToMain( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
14691479
R_BindFBO( tr.mainFBO[ 1 - backEnd.currentMainFBO ] );
14701480

14711481
// bind u_NormalMap
@@ -1501,7 +1511,7 @@ void Render_heatHaze( shaderStage_t *pStage )
15011511
gl_heatHazeShader->SetUniform_DeformMagnitude( 0.0f );
15021512
Tess_DrawElements();
15031513

1504-
TransitionMainToMSAA();
1514+
TransitionMainToMSAA( GL_COLOR_BUFFER_BIT );
15051515

15061516
GL_CheckErrors();
15071517
}

0 commit comments

Comments
 (0)