Fixed TAA jittering bug

This commit is contained in:
Robert Beckebans 2022-04-19 21:56:30 +02:00
parent 51405a3e8f
commit a7623165b5
13 changed files with 124 additions and 83 deletions

View file

@ -527,15 +527,15 @@ void idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings::AdjustFi
}
case SYSTEM_FIELD_ANTIALIASING:
{
// RB: disabled 16x MSAA
// RB: disabled 8x, 16x MSAA because they are too expensive at 4k resolutions
static const int numValues = 5;
static const int values[numValues] =
{
ANTI_ALIASING_NONE,
ANTI_ALIASING_SMAA_1X,
ANTI_ALIASING_TAA,
ANTI_ALIASING_TAA_SMAA_1X,
ANTI_ALIASING_MSAA_2X,
ANTI_ALIASING_MSAA_4X,
ANTI_ALIASING_MSAA_8X
};
// RB end
r_antiAliasing.SetInteger( AdjustOption( r_antiAliasing.GetInteger(), values, numValues, adjustAmount ) );
@ -662,13 +662,13 @@ idSWFScriptVar idMenuScreen_Shell_SystemOptions::idMenuDataSource_SystemSettings
static const char* values[numValues] =
{
"None",
"SMAA 1X",
"TAA",
"TAA + SMAA 1X",
"MSAA 2X",
"MSAA 4X",
"MSAA 8X"
};
compile_time_assert( numValues == ( ANTI_ALIASING_MSAA_8X + 1 ) );
compile_time_assert( numValues == ( ANTI_ALIASING_MSAA_4X + 1 ) );
return values[ r_antiAliasing.GetInteger() ];
}

View file

@ -309,7 +309,7 @@ float idConsoleLocal::DrawFPS( float y )
{
// start smaller
int32 statsWindowWidth = 320;
int32 statsWindowHeight = 270;
int32 statsWindowHeight = 280;
if( com_showFPS.GetInteger() > 2 )
{
@ -355,13 +355,13 @@ float idConsoleLocal::DrawFPS( float y )
static const char* aaValues[aaNumValues] =
{
"None",
"SMAA 1X",
"TAA",
"TAA + SMAA 1X",
"MSAA 2X",
"MSAA 4X",
"MSAA 8X"
};
compile_time_assert( aaNumValues == ( ANTI_ALIASING_MSAA_8X + 1 ) );
compile_time_assert( aaNumValues == ( ANTI_ALIASING_MSAA_4X + 1 ) );
const char* aaMode = aaValues[ r_antiAliasing.GetInteger() ];

View file

@ -477,7 +477,7 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef )
// for motion blurred anti-aliasing
float jitterx, jittery;
if( r_useTemporalAA.GetBool() )
if( R_UseTemporalAA() )
{
idVec2 jitter = tr.backend.GetCurrentPixelOffset();
jitterx = jitter.x;

View file

@ -45,25 +45,6 @@ If you have questions concerning this license or the applicable additional terms
#define DEFAULT_SIZE 16
static uint GetMSAASamples()
{
switch( r_antiAliasing.GetInteger() )
{
case ANTI_ALIASING_MSAA_2X:
return 2;
case ANTI_ALIASING_MSAA_4X:
return 4;
case ANTI_ALIASING_MSAA_8X:
return 8;
default:
return 1;
}
}
/*
==================
idImage::MakeDefault
@ -260,7 +241,7 @@ static void R_LdrNativeImage( idImage* image, nvrhi::ICommandList* commandList )
static void R_DepthImage( idImage* image, nvrhi::ICommandList* commandList )
{
uint sampleCount = GetMSAASamples();
uint sampleCount = R_GetMSAASamples();
image->GenerateImage( NULL, renderSystem->GetWidth(), renderSystem->GetHeight(), TF_NEAREST, TR_CLAMP, TD_DEPTH_STENCIL, nullptr, true, false, sampleCount );
}
@ -268,11 +249,16 @@ static void R_DepthImage( idImage* image, nvrhi::ICommandList* commandList )
// RB begin
static void R_HDR_RGBA16FImage_ResNative_MSAAOpt( idImage* image, nvrhi::ICommandList* commandList )
{
uint sampleCount = GetMSAASamples();
uint sampleCount = R_GetMSAASamples();
image->GenerateImage( NULL, renderSystem->GetWidth(), renderSystem->GetHeight(), TF_NEAREST, TR_CLAMP, TD_RGBA16F, nullptr, true, sampleCount == 1, sampleCount );
}
static void R_HDR_RG16FImage_ResNative( idImage* image, nvrhi::ICommandList* commandList )
{
image->GenerateImage( NULL, renderSystem->GetWidth(), renderSystem->GetHeight(), TF_NEAREST, TR_CLAMP, TD_RG16F, nullptr, true );
}
static void R_HDR_RGBA16FImage_ResNative( idImage* image, nvrhi::ICommandList* commandList )
{
image->GenerateImage( NULL, renderSystem->GetWidth(), renderSystem->GetHeight(), TF_NEAREST, TR_CLAMP, TD_RGBA16F, nullptr, true );
@ -345,7 +331,7 @@ static void R_AmbientOcclusionImage_ResNative( idImage* image, nvrhi::ICommandLi
static void R_GeometryBufferImage_ResNative( idImage* image, nvrhi::ICommandList* commandList )
{
uint sampleCount = GetMSAASamples();
uint sampleCount = R_GetMSAASamples();
image->GenerateImage( NULL, renderSystem->GetWidth(), renderSystem->GetHeight(), TF_LINEAR, TR_CLAMP, TD_RGBA16F, nullptr, true, false, sampleCount );
}
@ -1074,7 +1060,7 @@ void idImageManager::CreateIntrinsicImages()
currentRenderHDRImage64 = globalImages->ImageFromFunction( "_currentRenderHDR64", R_HDR_RGBA16FImage_Res64 );
ldrImage = globalImages->ImageFromFunction( "_currentRenderLDR", R_LdrNativeImage );
taaMotionVectorsImage = ImageFromFunction( "_taaMotionVectors", R_HDR_RGBA16FImage_ResNative ); // RB: could be shared with _currentNormals.zw
taaMotionVectorsImage = ImageFromFunction( "_taaMotionVectors", R_HDR_RG16FImage_ResNative ); // RB: could be shared with _currentNormals.zw
taaResolvedImage = ImageFromFunction( "_taaResolved", R_HDR_RGBA16FImage_ResNative_UAV );
taaFeedback1Image = ImageFromFunction( "_taaFeedback1", R_HDR_RGBA16SImage_ResNative_UAV );
taaFeedback2Image = ImageFromFunction( "_taaFeedback2", R_HDR_RGBA16SImage_ResNative_UAV );

View file

@ -86,8 +86,8 @@ void Framebuffer::Init()
void Framebuffer::CheckFramebuffers()
{
int screenWidth = renderSystem->GetWidth();
int screenHeight = renderSystem->GetHeight();
//int screenWidth = renderSystem->GetWidth();
//int screenHeight = renderSystem->GetHeight();
}
void Framebuffer::Shutdown()

View file

@ -1036,7 +1036,6 @@ void idRenderBackend::CheckCVars()
{
case ANTI_ALIASING_MSAA_2X:
case ANTI_ALIASING_MSAA_4X:
case ANTI_ALIASING_MSAA_8X:
if( r_antiAliasing.GetInteger() > 0 )
{
//glEnable( GL_MULTISAMPLE );
@ -1053,6 +1052,12 @@ void idRenderBackend::CheckCVars()
Framebuffer::ResizeFramebuffers();
}
if( taaPass )
{
delete taaPass;
taaPass = NULL;
}
r_antiAliasing.ClearModified();
}

View file

@ -111,13 +111,6 @@ void TemporalAntiAliasingPass::Init(
break;
}
case ANTI_ALIASING_MSAA_8X:
{
auto taaResolveShaderInfo = renderProgManager.GetProgramInfo( BUILTIN_TAA_RESOLVE_MSAA_8X );
m_TemporalAntiAliasingCS = taaResolveShaderInfo.cs;
break;
}
default:
{
auto taaResolveShaderInfo = renderProgManager.GetProgramInfo( BUILTIN_TAA_RESOLVE );
@ -280,10 +273,12 @@ void TemporalAntiAliasingPass::TemporalResolve(
TemporalAntiAliasingConstants taaConstants = {};
const float marginSize = 1.f;
taaConstants.inputViewOrigin = idVec2( viewportInput.minX, viewportInput.minY );
taaConstants.inputViewSize = idVec2( viewportInput.width(), viewportInput.height() );
// RB: TODO figure out why 1 pixel is missing and the old code for resolving _currentImage adds 1 pixel to each side
taaConstants.inputViewSize = idVec2( viewportInput.width() + 1, viewportInput.height() + 1 );
taaConstants.outputViewOrigin = idVec2( viewportOutput.minX, viewportOutput.minY );
taaConstants.outputViewSize = idVec2( viewportOutput.width(), viewportOutput.height() );
taaConstants.inputPixelOffset.Set( 0, 0 ); // TODO = viewInput->GetPixelOffset();
taaConstants.outputViewSize = idVec2( viewportOutput.width() + 1, viewportOutput.height() + 1 );
//taaConstants.inputPixelOffset.Set( 0, 0 ); // TODO = viewInput->GetPixelOffset();
taaConstants.inputPixelOffset = GetCurrentPixelOffset();
taaConstants.outputTextureSizeInv = 1.0f / idVec2( float( renderSystem->GetWidth() ), float( renderSystem->GetHeight() ) );
taaConstants.inputOverOutputViewSize = taaConstants.inputViewSize / taaConstants.outputViewSize;
taaConstants.outputOverInputViewSize = taaConstants.outputViewSize / taaConstants.inputViewSize;

View file

@ -5445,7 +5445,7 @@ void idRenderBackend::DrawMotionVectors()
return;
}
if( !r_useTemporalAA.GetBool() && r_motionBlur.GetInteger() <= 0 )
if( !R_UseTemporalAA() && r_motionBlur.GetInteger() <= 0 )
{
return;
}
@ -5561,7 +5561,7 @@ void idRenderBackend::TemporalAAPass( const viewDef_t* _viewDef )
return;
}
if( !r_useTemporalAA.GetBool() )
if( !R_UseTemporalAA() )
{
return;
}
@ -5851,7 +5851,8 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
return;
}
if( r_useSSAO.GetInteger() <= 0 || r_useSSAO.GetInteger() > 1 )
// FIXME: the hierarchical depth buffer does not work with the MSAA depth texture source
if( r_useSSAO.GetInteger() <= 0 || r_useSSAO.GetInteger() > 1 || R_GetMSAASamples() > 1 )
{
return;
}
@ -5890,16 +5891,22 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
#if defined( USE_NVRHI )
renderLog.OpenBlock( "Render_HiZ" );
commonPasses.BlitTexture(
commandList,
globalFramebuffers.csDepthFBO[0]->GetApiObject(),
globalImages->currentDepthImage->GetTextureHandle(),
&bindingCache );
//if( R_GetMSAASamples() > 1 )
//{
// commandList->resolveTexture( globalImages->hierarchicalZbufferImage->GetTextureHandle(), nvrhi::AllSubresources, globalImages->currentDepthImage->GetTextureHandle(), nvrhi::AllSubresources );
//}
//else
{
commonPasses.BlitTexture(
commandList,
globalFramebuffers.csDepthFBO[0]->GetApiObject(),
globalImages->currentDepthImage->GetTextureHandle(),
&bindingCache );
}
hiZGenPass->Dispatch( commandList, MAX_HIERARCHICAL_ZBUFFERS );
renderLog.CloseBlock();
#else
renderLog.OpenBlock( "Render_HiZ", colorDkGrey );
@ -6882,14 +6889,27 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste
// resolve the screen
#if defined( USE_NVRHI )
renderLog.OpenBlock( "Blit to _currentRender" );
BlitParameters blitParms;
nvrhi::IFramebuffer* currentFB = ( nvrhi::IFramebuffer* )currentFrameBuffer->GetApiObject();
blitParms.sourceTexture = currentFB->getDesc().colorAttachments[0].texture;
blitParms.targetFramebuffer = globalFramebuffers.postProcFBO->GetApiObject(); // _currentRender image
blitParms.targetViewport = nvrhi::Viewport( renderSystem->GetWidth(), renderSystem->GetHeight() );
commonPasses.BlitTexture( commandList, blitParms, &bindingCache );
//if( currentFrameBuffer->GetApiObject()->getDesc().colorAttachments.begin().)
if( R_GetMSAASamples() > 1 )
{
renderLog.OpenBlock( "Resolve to _currentRender" );
commandList->resolveTexture( globalImages->currentRenderImage->GetTextureHandle(), nvrhi::AllSubresources, globalImages->currentRenderHDRImage->GetTextureHandle(), nvrhi::AllSubresources );
}
else
{
renderLog.OpenBlock( "Blit to _currentRender" );
BlitParameters blitParms;
nvrhi::IFramebuffer* currentFB = ( nvrhi::IFramebuffer* )currentFrameBuffer->GetApiObject();
blitParms.sourceTexture = currentFB->getDesc().colorAttachments[0].texture;
blitParms.targetFramebuffer = globalFramebuffers.postProcFBO->GetApiObject(); // _currentRender image
blitParms.targetViewport = nvrhi::Viewport( renderSystem->GetWidth(), renderSystem->GetHeight() );
commonPasses.BlitTexture( commandList, blitParms, &bindingCache );
}
renderLog.CloseBlock();
#else
@ -6970,13 +6990,22 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste
Tonemap( _viewDef );
#else
ToneMappingParameters parms;
if( r_useTemporalAA.GetBool() )
if( R_UseTemporalAA() )
{
toneMapPass->SimpleRender( commandList, parms, viewDef, globalImages->taaResolvedImage->GetTextureHandle(), globalFramebuffers.ldrFBO->GetApiObject() );
}
else
{
toneMapPass->SimpleRender( commandList, parms, viewDef, globalImages->currentRenderHDRImage->GetTextureHandle(), globalFramebuffers.ldrFBO->GetApiObject() );
if( R_GetMSAASamples() > 1 )
{
commandList->resolveTexture( globalImages->taaResolvedImage->GetTextureHandle(), nvrhi::AllSubresources, globalImages->currentRenderHDRImage->GetTextureHandle(), nvrhi::AllSubresources );
toneMapPass->SimpleRender( commandList, parms, viewDef, globalImages->taaResolvedImage->GetTextureHandle(), globalFramebuffers.ldrFBO->GetApiObject() );
}
else
{
toneMapPass->SimpleRender( commandList, parms, viewDef, globalImages->currentRenderHDRImage->GetTextureHandle(), globalFramebuffers.ldrFBO->GetApiObject() );
}
}
#endif
}

View file

@ -1302,6 +1302,10 @@ INITIALIZATION
====================================================================
*/
bool R_UseTemporalAA();
uint R_GetMSAASamples();
void R_SetNewMode( const bool fullInit );
void R_SetColorMappings();

View file

@ -229,8 +229,6 @@ void PC_EndNamedEvent( nvrhi::ICommandList* commandList )
{
qvkCmdDebugMarkerEndEXT( vkcontext.commandBuffer[ vkcontext.frameParity ] );
}
#elif defined(USE_NVRHI)
// SP: nvrhi debugging
#else
// only do this if RBDOOM-3-BFG was started by RenderDoc or some similar tool
if( glConfig.gremedyStringMarkerAvailable && glConfig.khronosDebugAvailable )

View file

@ -64,8 +64,7 @@ enum renderLogMainBlock_t
/*
================================================
idRenderLog stubbed version for the SPUs and high
performance rendering in retail builds.
idRenderLog
// Performance Events abstraction layer for OpenGL, Vulkan, DX12
// see https://devblogs.nvidia.com/best-practices-gpu-performance-events/
@ -84,14 +83,6 @@ private:
idStaticList<nvrhi::TimerQueryHandle, MRB_TOTAL_QUERIES> timerQueries;
idStaticList<bool, MRB_TOTAL_QUERIES> timerUsed;
//idArray< idArray< nvrhi::TimerQueryHandle, MRB_TOTAL_QUERIES >, NUM_FRAME_DATA > timerQueries;
// GPU timestamp queries
//idArray< uint32, NUM_FRAME_DATA > queryIndex;
//idArray< idArray< uint64, NUM_TIMESTAMP_QUERIES >, NUM_FRAME_DATA > queryResults;
//idArray< VkQueryPool, NUM_FRAME_DATA > queryPools;
#endif
public:

View file

@ -104,10 +104,10 @@ enum graphicsDriverType_t
enum antiAliasingMode_t
{
ANTI_ALIASING_NONE,
ANTI_ALIASING_SMAA_1X,
ANTI_ALIASING_TAA,
ANTI_ALIASING_TAA_SMAA_1X,
ANTI_ALIASING_MSAA_2X,
ANTI_ALIASING_MSAA_4X,
ANTI_ALIASING_MSAA_8X
};
// CPU counters and timers

View file

@ -80,7 +80,7 @@ idCVar r_glDriver( "r_glDriver", "", CVAR_RENDERER, "\"opengl32\", etc." );
#endif
// SRS end
// RB: disabled 16x MSAA
idCVar r_antiAliasing( "r_antiAliasing", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, " 0 = None\n 1 = SMAA 1x\n 2 = MSAA 2x\n 3 = MSAA 4x\n 4 = MSAA 8x\n", 0, ANTI_ALIASING_MSAA_8X );
idCVar r_antiAliasing( "r_antiAliasing", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, " 0 = None\n 1 = TAA 1x\n 2 = TAA + SMAA 1x\n 3 = MSAA 2x\n 4 = MSAA 4x\n", 0, ANTI_ALIASING_MSAA_4X );
// RB end
idCVar r_vidMode( "r_vidMode", "0", CVAR_ARCHIVE | CVAR_RENDERER | CVAR_INTEGER, "fullscreen video mode number" );
idCVar r_displayRefresh( "r_displayRefresh", "0", CVAR_RENDERER | CVAR_INTEGER | CVAR_NOCHEAT, "optional display refresh rate option for vid mode", 0.0f, 240.0f );
@ -349,6 +349,42 @@ const char* skyDirection[6] = { "_forward", "_back", "_left", "_right", "_up", "
DeviceManager* deviceManager;
#endif
bool R_UseTemporalAA()
{
if( !r_useTemporalAA.GetBool() )
{
return false;
}
switch( r_antiAliasing.GetInteger() )
{
case ANTI_ALIASING_TAA:
return true;
case ANTI_ALIASING_TAA_SMAA_1X:
return true;
default:
return false;
}
}
uint R_GetMSAASamples()
{
switch( r_antiAliasing.GetInteger() )
{
case ANTI_ALIASING_MSAA_2X:
return 2;
case ANTI_ALIASING_MSAA_4X:
return 4;
default:
return 1;
}
}
/*
=============================
R_SetNewMode
@ -443,9 +479,6 @@ void R_SetNewMode( const bool fullInit )
case ANTI_ALIASING_MSAA_4X:
parms.multiSamples = 4;
break;
case ANTI_ALIASING_MSAA_8X:
parms.multiSamples = 8;
break;
default:
parms.multiSamples = 1;