Skip Masked Occlusion Culling on non-SSE2 CPUs

This commit is contained in:
Robert Beckebans 2024-08-27 11:41:39 +02:00
parent 930c968fa9
commit c4e39bdc1c
6 changed files with 42 additions and 12 deletions

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.10)
project(RBDoom3BFG)
@ -428,7 +428,10 @@ if(NOT APPLE)
add_subdirectory(tools/compilers)
endif()
add_subdirectory(libs/moc)
if(USE_INTRINSICS_SSE)
add_subdirectory(libs/moc)
set(MASKED_OCCLUSION_LIBRARY MaskedOcclusionCulling)
endif()
file(GLOB NATVIS_SOURCES .natvis)
@ -1670,9 +1673,9 @@ endif()
# needs to come after nvrhi_d3d11 etc. for link order
target_link_libraries(RBDoom3BFG nvrhi)
target_link_libraries(RBDoom3BFG ShaderMakeBlob MaskedOcclusionCulling)
target_link_libraries(RBDoom3BFG ShaderMakeBlob ${MASKED_OCCLUSION_LIBRARY})
add_subdirectory(shaders)
add_dependencies(Shaders ShaderMake)
add_dependencies(RBDoom3BFG Shaders MaskedOcclusionCulling)
add_dependencies(RBDoom3BFG Shaders ${MASKED_OCCLUSION_LIBRARY})

View file

@ -1045,10 +1045,12 @@ public:
idRenderBackend backend;
#if defined(USE_INTRINSICS_SSE)
MaskedOcclusionCulling* maskedOcclusionCulling;
idVec4 maskedUnitCubeVerts[8];
idVec4 maskedZeroOneCubeVerts[8];
unsigned int maskedZeroOneCubeIndexes[36];
#endif
private:
bool bInitialized;

View file

@ -33,7 +33,10 @@ If you have questions concerning this license or the applicable additional terms
#pragma hdrstop
#include "imgui.h"
#include "../libs/moc/MaskedOcclusionCulling.h"
#if defined(USE_INTRINSICS_SSE)
#include "../libs/moc/MaskedOcclusionCulling.h"
#endif
#include "RenderCommon.h"
@ -1790,12 +1793,14 @@ void idRenderSystemLocal::Clear()
envprobeJobs.Clear();
lightGridJobs.Clear();
#if defined(USE_INTRINSICS_SSE)
// destroy occlusion culling object and free hierarchical z-buffer
if( maskedOcclusionCulling != NULL )
{
MaskedOcclusionCulling::Destroy( maskedOcclusionCulling );
maskedOcclusionCulling = NULL;
}
#endif
}
/*
@ -1943,6 +1948,7 @@ static srfTriangles_t* R_MakeZeroOneCubeTris()
}
// RB begin
#if defined(USE_INTRINSICS_SSE)
static void R_MakeZeroOneCubeTrisForMaskedOcclusionCulling()
{
const float low = 0.0f;
@ -2055,6 +2061,7 @@ static void R_MakeUnitCubeTrisForMaskedOcclusionCulling()
verts[6].w = 1;
verts[7].w = 1;
}
#endif
static srfTriangles_t* R_MakeZeroOneSphereTris()
{
@ -2291,12 +2298,14 @@ void idRenderSystemLocal::Init()
omitSwapBuffers = true;
}
#if defined(USE_INTRINSICS_SSE)
// Flush denorms to zero to avoid performance issues with small values
_mm_setcsr( _mm_getcsr() | 0x8040 );
maskedOcclusionCulling = MaskedOcclusionCulling::Create();
R_MakeZeroOneCubeTrisForMaskedOcclusionCulling();
R_MakeUnitCubeTrisForMaskedOcclusionCulling();
#endif
// make sure the command buffers are ready to accept the first screen update
SwapCommandBuffers( NULL, NULL, NULL, NULL, NULL, NULL );

View file

@ -30,7 +30,9 @@ If you have questions concerning this license or the applicable additional terms
#include "precompiled.h"
#pragma hdrstop
#include "../libs/moc/MaskedOcclusionCulling.h"
#if defined(USE_INTRINSICS_SSE)
#include "../libs/moc/MaskedOcclusionCulling.h"
#endif
#include "RenderCommon.h"
@ -269,6 +271,7 @@ static void R_AddSingleLight( viewLight_t* vLight )
const bool viewInsideLight = !idRenderMatrix::CullPointToMVP( light->baseLightProject, viewDef->renderView.vieworg, true );
// RB: test surface visibility by drawing the triangles of the bounds
#if defined(USE_INTRINSICS_SSE)
// FIXME spot light projections are too short
if( r_useMaskedOcclusionCulling.GetBool() && !viewInsideLight && !viewDef->isMirror && !viewDef->isSubview )
@ -360,6 +363,7 @@ static void R_AddSingleLight( viewLight_t* vLight )
}
}
}
#endif
// RB end
// RB: calculate shadow LOD similar to Q3A .md3 LOD code

View file

@ -30,7 +30,9 @@ If you have questions concerning this license or the applicable additional terms
#include "precompiled.h"
#pragma hdrstop
#include "../libs/moc/MaskedOcclusionCulling.h"
#if defined(USE_INTRINSICS_SSE)
#include "../libs/moc/MaskedOcclusionCulling.h"
#endif
#include "RenderCommon.h"
#include "Model_local.h"
@ -675,6 +677,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
// RB: added check wether GPU skinning is available at all
const bool gpuSkinned = ( tri->staticModelWithJoints != NULL && r_useGPUSkinning.GetBool() );
#if defined(USE_INTRINSICS_SSE)
idRenderMatrix cullSurfaceProject;
idRenderMatrix::InverseOffsetScaleForBounds( renderMatrix_identity, tri->bounds, cullSurfaceProject );
@ -774,7 +777,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
}
#endif
}
#endif // #if defined(USE_INTRINSICS_SSE)

View file

@ -29,7 +29,9 @@ If you have questions concerning this license or the applicable additional terms
#include "precompiled.h"
#pragma hdrstop
#include "../libs/moc/MaskedOcclusionCulling.h"
#if defined(USE_INTRINSICS_SSE)
#include "../libs/moc/MaskedOcclusionCulling.h"
#endif
#include "RenderCommon.h"
#include "Model_local.h"
@ -109,6 +111,7 @@ and shadows are generated, since dynamic models will typically be lit by
two or more lights.
===================
*/
#if defined(USE_INTRINSICS_SSE)
void R_RenderSingleModel( viewEntity_t* vEntity )
{
// we will add all interaction surfs here, to be chained to the lights in later serial code
@ -322,6 +325,7 @@ void R_RenderSingleModel( viewEntity_t* vEntity )
//--------------------------
const float* shaderRegisters = NULL;
drawSurf_t* baseDrawSurf = NULL;
if( surfaceDirectlyVisible && shader->IsDrawn() && shader->Coverage() == MC_OPAQUE && !renderEntity->weaponDepthHack && renderEntity->modelDepthHack == 0.0f )
//if( surfaceDirectlyVisible && shader->IsDrawn() && !renderEntity->weaponDepthHack && renderEntity->modelDepthHack == 0.0f )
{
@ -477,6 +481,7 @@ void R_RenderSingleModel( viewEntity_t* vEntity )
}
}
}
#endif
//REGISTER_PARALLEL_JOB( R_AddSingleModel, "R_AddSingleModel" );
@ -491,6 +496,9 @@ void R_FillMaskedOcclusionBufferWithModels( viewDef_t* viewDef )
{
SCOPED_PROFILE_EVENT( "R_FillMaskedOcclusionBufferWithModels" );
tr.viewDef->viewEntitys = R_SortViewEntities( tr.viewDef->viewEntitys );
#if defined(USE_INTRINSICS_SSE)
if( !r_useMaskedOcclusionCulling.GetBool() )
{
return;
@ -505,8 +513,6 @@ void R_FillMaskedOcclusionBufferWithModels( viewDef_t* viewDef )
tr.maskedOcclusionCulling->SetNearClipPlane( zNear );
tr.maskedOcclusionCulling->ClearBuffer();
tr.viewDef->viewEntitys = R_SortViewEntities( tr.viewDef->viewEntitys );
//-------------------------------------------------
// Go through each view entity that is either visible to the view, or to
// any light that intersects the view (for shadows).
@ -538,8 +544,10 @@ void R_FillMaskedOcclusionBufferWithModels( viewDef_t* viewDef )
R_RenderSingleModel( vEntity );
}
}
#endif
}
#if defined(USE_INTRINSICS_SSE)
static void TonemapDepth( float* depth, unsigned char* image, int w, int h )
{
// Find min/max w coordinate (discard cleared pixels)
@ -599,4 +607,5 @@ CONSOLE_COMMAND( maskShot, "Dumping masked occlusion culling buffer", NULL )
R_WritePNG( "screenshots/soft_occlusion_buffer.png", image, 3, width, height, "fs_basepath" );
delete[] image;
}
}
#endif