Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.10.0 - Tessellation, async compute & copy, object picking, magnifier, instanced draw + LODs #170

Merged
merged 205 commits into from
Jan 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
205 commits
Select commit Hold shift + click to select a range
a0a7b9d
Bump the version to 0.10.0
vilbeyli May 23, 2022
69dff05
Use const qualifier for the imgui userdata cast in ui rendering
vilbeyli May 28, 2022
d94399a
MagnifierPS outputting to swapchain
vilbeyli May 29, 2022
af6f391
Fix compiler warnings
vilbeyli May 29, 2022
92a0a10
Fix linear sampler in the magnifier shader
vilbeyli May 29, 2022
140bdef
Update magnifier UI labels, remove unused code
vilbeyli May 29, 2022
8cdea10
Instanced bounding box rendering. GPU: 2.4ms -> 0.7ms
vilbeyli May 23, 2022
dad66c2
Instanced shadow map mesh rendering
vilbeyli May 24, 2022
bf38e58
Instanced rendering for ZPrePass and ForwardLightingPass
vilbeyli May 24, 2022
1dfd568
Multi-thread shadow frustum instanced mesh command recording
vilbeyli May 24, 2022
aefe018
Fix non-instanced rendering path -- the batching is way too slow due …
vilbeyli May 24, 2022
e84f899
[Optimization] reuse the instance data memory instead of re-allocatin…
vilbeyli May 30, 2022
c19de74
Move worker thread context memory into Scene object and now condition…
vilbeyli May 30, 2022
3f917fe
Threaded game object bounding box build
vilbeyli May 30, 2022
4447b2e
Fix culling partitioning bug + resize mesh bounding box containers up…
vilbeyli Jun 1, 2022
971e74b
Threaded mesh bounding box building
vilbeyli Jun 1, 2022
3dd1cd7
Optimize counting game object meshes: no longer chase scattered data …
vilbeyli Jun 2, 2022
b591668
[Threading] refactor the culling work to be more parallel and in phase
vilbeyli Jun 3, 2022
5b4e8ab
fix incorrect order of multi-threaded frustum cull results
vilbeyli Jun 4, 2022
135ddb9
Threaded bounding box instance data batching
vilbeyli Jun 4, 2022
10466ea
fix one off errors for work distribution during culling worker param …
vilbeyli Jun 4, 2022
ac9598d
[Perf] save 21% from CollectInstanceData for scene view meshes by rem…
vilbeyli Jun 4, 2022
87cf3ac
[Optimization] move frustum cull check into SSE - saves 200us, 11% in…
vilbeyli Jun 6, 2022
e57a346
[Optimization] avoid copying the quaternion in Transform::matWorldTra…
vilbeyli Jun 6, 2022
97041bb
Fix out of bounds access in instanced rendering batching
vilbeyli Jun 6, 2022
d1d680a
add CPU marker to the texture upload thread
vilbeyli Jun 6, 2022
300810e
Avoid looking into models umap and use the worker context to store ma…
vilbeyli Jun 6, 2022
54a25b2
Revert "add CPU marker to the texture upload thread"
vilbeyli Jun 6, 2022
ffbb3df
[Optimziation] cache transforms for bounding boxes (good for quick th…
vilbeyli Jun 6, 2022
7c7e0f0
Fix single threaded code paths
vilbeyli Jun 6, 2022
b9852ba
Fix motion vector rendering -> update the _previous position of Trans…
vilbeyli Jun 7, 2022
b8f1f46
[Threading] do not thread if there's too little work + fix frustum cu…
vilbeyli Jun 7, 2022
b49f6a6
Fix warnings, scoped marker labels
vilbeyli Jun 7, 2022
7a15380
Test fixing CI/CD agent's internal compiler error...
vilbeyli Jun 7, 2022
bcc4d5f
Fix out of bounds memcpy on shadow mesh command recording and the ran…
vilbeyli Jun 8, 2022
b4d015c
Fix bounding box instanced rendering instance data container size mis…
vilbeyli Jun 9, 2022
9a10fae
Add markers to loading
vilbeyli Jun 9, 2022
619633f
Add pix markers to Renderer
vilbeyli Jun 9, 2022
99031fe
CPU/GPU Markers: formatted print macro
vilbeyli Jun 11, 2022
4886a38
[StressTestScene] optimize material + gameobject generation with prea…
vilbeyli Jun 11, 2022
919c66e
[Threading] fix thread-unsafe map entry generation in scene createamt…
vilbeyli Jun 11, 2022
36eced4
[Threading] MT game object creation phase 1: ranges and worker threads
vilbeyli Jun 11, 2022
824b27a
Remove erronous additional FramePacing() call
vilbeyli Jun 11, 2022
de2f2be
[Threading] Assimp MT mesh processing -- need to threadify based on N…
vilbeyli Jun 11, 2022
4b0ea42
[Threading] adjust load worker counts
vilbeyli Jun 12, 2022
3242438
[Threading] defer assimp importer cleanup to a mesh laod worker and s…
vilbeyli Jun 12, 2022
b25b93f
[UI] Add imgui backend, separate UI files into own folder
vilbeyli Jun 20, 2022
e53c23d
[UI] add the missing imgui backend initialization code
vilbeyli Jun 20, 2022
656aa15
[Threading] Texture loading threading bottleneck resolved, but env ma…
vilbeyli Jun 20, 2022
d545c9a
Fix broken mip mapping for >32bpp imges
vilbeyli Jun 20, 2022
58e8bbe
circumvent MSVC compiler error for MSBuild v14.32-17.2
vilbeyli Aug 7, 2022
0cc438d
Fix app exit instability
vilbeyli Aug 16, 2022
464c88f
Fix HDR post processing settings when the main monitor is not the HDR…
vilbeyli Aug 17, 2022
1d1bda5
fix the logic for querying the registry for monitor info
vilbeyli Nov 6, 2022
a93f877
fix compiler error -- missing string include in model.h
vilbeyli Feb 4, 2024
4e9019d
attenuate light brightness for light rendering pass
vilbeyli Feb 4, 2024
605b4f7
polish graphics settings UI, remove CAS
vilbeyli Feb 5, 2024
03579fb
remove the 100x multiplier for emissive
vilbeyli Feb 5, 2024
8617a47
hook in uv scale offset + multiplicative roughness/metallic/emissive …
vilbeyli Feb 7, 2024
c5bb961
material editor + texture viewer
vilbeyli Feb 7, 2024
710ce52
named threads
vilbeyli Feb 7, 2024
0d9ff92
light editor
vilbeyli Feb 7, 2024
23730e5
fix texture viewer + move debug window into graphics settings tab
vilbeyli Feb 8, 2024
8e0cbff
fix roughness & metallic values with textured objects
vilbeyli Feb 9, 2024
1c46d08
blend the bounding box & bounds visualizations
vilbeyli Feb 9, 2024
5aad4f2
object id pass. updated memory pools to do handle management
vilbeyli Feb 11, 2024
00f537e
object picker
vilbeyli Feb 11, 2024
6e2249a
async copy queue for objectID readback
vilbeyli Feb 12, 2024
f3f49f2
simple outline rendering
vilbeyli Feb 13, 2024
bf5c28e
sync gpu-cpu for readback on deman, as late as possible (1 frame late)
vilbeyli Feb 13, 2024
e743661
fix picking incorrect coord
vilbeyli Feb 13, 2024
bf0bca3
fix material editor table layout (rows now take full width)
vilbeyli Feb 13, 2024
385096a
update cmakelists to include objectid render pass & outline shader
vilbeyli Feb 13, 2024
88e09ba
fix race condition around model data, mtx lock when building game obj…
vilbeyli Feb 14, 2024
30e8019
fix object picking
vilbeyli Feb 14, 2024
4992cdb
limit loading screen frame rate to 16
vilbeyli Feb 14, 2024
6e92068
add cpu markers to various initializatoin functions
vilbeyli Feb 14, 2024
6b336ef
better looking outline using stencil
vilbeyli Feb 15, 2024
6b0501c
fix warnings
vilbeyli Feb 15, 2024
f273575
fix device lost on window resize
vilbeyli Feb 16, 2024
cff1629
decouple depth prepass from object pass, move constant buffer copy in…
vilbeyli Feb 16, 2024
21d3f8c
fix model loader roughness/metallic issue
vilbeyli Feb 16, 2024
ee5f95b
material editor only shows selected object's materials
vilbeyli Feb 16, 2024
45d5da2
async compute depth resolve, downsample, ssao
vilbeyli Feb 17, 2024
4913827
rearrange objID pass and depth prepass to start async compute earlier
vilbeyli Feb 17, 2024
0c9ac1b
generate LOD meshes
vilbeyli Feb 17, 2024
948d1d8
fix thread hang if there's no async compute command recording
vilbeyli Feb 17, 2024
35dd5ee
add animation to stresstest scene
vilbeyli Feb 17, 2024
d3d3a6e
LODs for shadow meshes & some builtin geometry
vilbeyli Feb 18, 2024
aeb3316
fix compiler error
vilbeyli Feb 18, 2024
84dba92
add LODs for main view, but they seem rather buggy (force LOD0)
vilbeyli Feb 18, 2024
31c7e8d
execute and wait on swapchain on worker thread
vilbeyli Feb 18, 2024
f2d7a40
use SSE for AABB screen projection
vilbeyli Feb 19, 2024
9ce3392
threaded scene mesh instance data recording + reduce thread syncs
vilbeyli Feb 20, 2024
78a36c4
first attempt to remove additional copy for instance data. still need…
vilbeyli Feb 22, 2024
944340b
fix device removed on skybox rendering
vilbeyli Feb 25, 2024
b752400
[Stability] fix sync issues with command lists & async queues. add to…
vilbeyli Feb 26, 2024
cc0771d
[Threading] distribute mainview instance data collection to threads w…
vilbeyli Feb 26, 2024
e1a5077
[Threading] final tuning on CPU work distribution
vilbeyli Mar 1, 2024
248bba0
fix light bounds rendering
vilbeyli Mar 1, 2024
373cd6e
Add per-vertex axis visualization shader using GS
vilbeyli Mar 3, 2024
74d3977
parameterize debug viz local vertex axis length
vilbeyli Mar 4, 2024
bd182a9
fix empty scene errors, specify shader model in shader compilation
vilbeyli Mar 7, 2024
ba2963a
[Terrain] heightmap displacement in VS, restructure code
vilbeyli Mar 8, 2024
1200ef5
terrain pixel shader, displacement through material
vilbeyli Mar 8, 2024
a566298
hello tessellation shaders
vilbeyli Mar 9, 2024
2c51f6f
tessellation shader parameters in UI
vilbeyli Mar 11, 2024
bf0d1fe
add rough frustum culling to tessellated meshes
vilbeyli Mar 16, 2024
e913b55
move tessellation into material, remove terrain, fix warnings
vilbeyli Mar 17, 2024
d02ba9d
optimized & multithreaded shader + PSO compilation
vilbeyli Mar 18, 2024
cd64992
fix PSO mapping
vilbeyli Mar 19, 2024
01564fb
optimize load times, parallelize tasks. now sub 1s load
vilbeyli Mar 19, 2024
268ddc1
make tessellation common between depth prepass and lighting pass
vilbeyli Mar 21, 2024
87b44d5
enable displacement
vilbeyli Mar 24, 2024
f247b10
fix selection pass
vilbeyli Mar 24, 2024
666d02a
UI: object transform editor
vilbeyli Mar 25, 2024
97b1186
update camera controls: now only orbit OR fly cam, changed through GU…
vilbeyli Mar 25, 2024
c50a9b6
fix unintended depth rejects in wireframe rendering mode
vilbeyli Mar 25, 2024
e1fd0f2
update ui window keybinds, layouts
vilbeyli Mar 25, 2024
f26cd9c
fix reflections / normals
vilbeyli Mar 25, 2024
7fa95af
fix directional map shadows
vilbeyli Mar 25, 2024
8cc60e4
cleanup
vilbeyli Mar 26, 2024
2b76a0d
Merge pull request #165 from vilbeyli/hdr
vilbeyli Mar 26, 2024
13ecdfc
cleanup
vilbeyli Mar 26, 2024
feac2e7
fix GPU memory leak when resizing window
vilbeyli Mar 28, 2024
546a4d6
fix texture cache
vilbeyli Mar 28, 2024
5325008
fix shutdown issue with gpu resources still in flight
vilbeyli Mar 29, 2024
c4daa52
fix deadlock caused by texture upload signaling failure
vilbeyli Mar 29, 2024
072957b
fix threading issues with scene loading (deadlock on update workers)
vilbeyli Mar 29, 2024
84d0c8b
fix camera controller deserialization
vilbeyli Mar 29, 2024
a82efb7
fix heap corruption during mip generation
vilbeyli Mar 29, 2024
1b3e117
upgrade DXCompiler to 1.8.2403.1
vilbeyli Mar 30, 2024
5e37595
upgrade all sahders to SM6
vilbeyli Mar 30, 2024
b70614d
quad tessellation + broken frustum culling
vilbeyli Apr 2, 2024
0bd2a0e
update vqutils: .exr support
vilbeyli Apr 2, 2024
100cb87
remove terrain
vilbeyli Apr 5, 2024
1082218
adaptive tessellation
vilbeyli Apr 6, 2024
846def6
GS-based frustum & face culling for tessellation pipeline
vilbeyli Apr 7, 2024
67c6bff
fix shader warnings
vilbeyli Apr 9, 2024
d68191d
generic tessellation shaders, unified root signature for all shadow P…
vilbeyli Apr 9, 2024
fdb00d7
split mesh generator into own file
vilbeyli Apr 11, 2024
e81d2ca
[Multithreading] refactor main & shadow view culling, unify functions…
vilbeyli Apr 13, 2024
185e0ba
tessellation support for shadow pass draw calls
vilbeyli Apr 13, 2024
4d6973c
fix build
vilbeyli Apr 13, 2024
b3e6889
fix texture download script after origin updates links
vilbeyli Apr 13, 2024
e5595f3
update PBR assets, fix download script
vilbeyli Apr 14, 2024
b99a882
fix object id pass crashing
vilbeyli Apr 14, 2024
f377330
object id pass supports tessellation
vilbeyli Apr 14, 2024
7b79bec
outline pass supportes tessellated geometry
vilbeyli Apr 15, 2024
a007eef
fix tessellated shadow geometry being incorrectly instanced
vilbeyli May 5, 2024
5fc0eac
fix directional map shadows for tessellated geometry, make static res…
vilbeyli May 6, 2024
9010277
fix missing VB/IB data upon scene reload
vilbeyli May 9, 2024
8a8a559
WIP vertex buffer data packing
vilbeyli May 9, 2024
8f32098
Create FUNDING.yml
vilbeyli Jun 9, 2024
eb90299
Merge pull request #167 from vilbeyli/funding
vilbeyli Jun 9, 2024
e58eca9
[funding] add ko-fi and buy me a coffee links
vilbeyli Nov 19, 2024
685b517
[funding] fix ko-fi and buy me a coffee links
vilbeyli Nov 19, 2024
d394ace
[build] fix GenerateProjectFiles.bat relative path execution
vilbeyli Nov 20, 2024
be18042
update dx compiler to latest version 1.8.2407
vilbeyli Nov 24, 2024
6ff1263
dont crash when models/textures are not downloaded
vilbeyli Nov 24, 2024
7a4f3a7
fix crash on rare case where object picking has incorrect index
vilbeyli Nov 24, 2024
d8d4754
fix toggling enabled for directional light
vilbeyli Nov 24, 2024
dc3eb04
adjust directional light viewport for stress test level
vilbeyli Dec 15, 2024
b65e237
[UI] prevent incompatible tessellation settings to be chosen, prevent…
vilbeyli Dec 15, 2024
8d73a53
[UI] prevent excessing shadowing light count when light type is changed
vilbeyli Dec 15, 2024
9ccfed6
fix shader reflection memory leak
vilbeyli Dec 15, 2024
ee10eac
clear load-time resources that are no longer needed
vilbeyli Dec 16, 2024
6c9d849
suppress d3d12 warnings that are non-issues
vilbeyli Dec 16, 2024
99f4631
change to standalone 7z
vilbeyli Dec 16, 2024
800cb98
fix out-of-bounds access for materials when selected index is invalid
vilbeyli Dec 16, 2024
7bd17be
[UI] fix scene control label for F1 key
vilbeyli Dec 19, 2024
551872a
fix sync issue when loading environment map (wait for swapchain)
vilbeyli Dec 20, 2024
a2fc3fa
optimize PSO compilation around descriptor/task param management
vilbeyli Dec 20, 2024
9c8f2e9
update libs/vqutils to fix debug compiler error
vilbeyli Dec 21, 2024
e6c3dde
reduce substr() calls in GetIncludeFileName()
vilbeyli Dec 21, 2024
ac8a80f
Remove busy-wait for mesh generation, use signals instead. also add m…
vilbeyli Dec 21, 2024
00b286a
fix meshgen deadlock
vilbeyli Dec 22, 2024
a1e3d82
fix depth prepass barrier transitions and device lost when MSAA toggled
vilbeyli Dec 31, 2024
3984988
fix Renderer threading issue with mTextures read/write
vilbeyli Dec 31, 2024
cb225b6
fix SSR barrier transition issues
vilbeyli Jan 1, 2025
0656a7a
fix assertions & odd behavior with object picking when user clicks on…
vilbeyli Jan 1, 2025
2956c76
enable mesh shader support check on gfx device
vilbeyli Jan 1, 2025
02ce02f
enable enhanced barrier support check on gfx device
vilbeyli Jan 1, 2025
8d7fe16
fix enhanced barrier check logic, use options12
vilbeyli Jan 2, 2025
1d41374
fix missing normalize() in reading normal map helper function
vilbeyli Jan 2, 2025
8af3428
further proof up mTextures thread safe access
vilbeyli Jan 2, 2025
8de38c5
fix BRDF LUT barrier before/after SSR pass
vilbeyli Jan 2, 2025
ea44b20
fix light bounds rendering w/ MSAA off & reflections off
vilbeyli Jan 6, 2025
8b382b3
clean up the debug rendering code, add comments
vilbeyli Jan 6, 2025
ccf3afc
downgrade PBR textures to 2K since 4K was overkill
vilbeyli Jan 6, 2025
4f2bad2
add mip bias to normal maps through material interface & ui
vilbeyli Jan 6, 2025
9ca4f7a
change the startup scene to default instead of stress test
vilbeyli Jan 6, 2025
b7ef62a
update readme with screenshots
vilbeyli Jan 6, 2025
d4f7457
correct image annotation
vilbeyli Jan 6, 2025
2b4d871
update readme: tessellation gif + correct .bat name
vilbeyli Jan 9, 2025
c0a7460
remove area lights from default scene
vilbeyli Jan 9, 2025
4985907
fix textures in stress test scene
vilbeyli Jan 9, 2025
0674625
fix textures in stress test scene
vilbeyli Jan 9, 2025
48d0bb4
fix renderer instability w/ light frustum rendering & cmd recording
vilbeyli Jan 11, 2025
30b06cf
fix material & light editor GUI instabilities
vilbeyli Jan 11, 2025
8c26c7d
update key bindings text in GUI
vilbeyli Jan 11, 2025
af2b5ba
update models submodule to get the sponza texture map fix
vilbeyli Jan 11, 2025
dd35623
update README: add debug draw mode gif
vilbeyli Jan 11, 2025
3604c6f
update README: add magnifier gif
vilbeyli Jan 12, 2025
ec89902
update README: add instanced draw + LODs gif
vilbeyli Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Optimziation] cache transforms for bounding boxes (good for quick th…
…read access)
vilbeyli committed Jun 6, 2022
commit ffbb3df338709fd73e9eb2d4710c6552e3a2643f
29 changes: 12 additions & 17 deletions Source/Engine/Culling.cpp
Original file line number Diff line number Diff line change
@@ -140,17 +140,13 @@ void FFrustumCullWorkerContext::AllocInputMemoryIfNecessary(size_t sz)
SCOPED_CPU_MARKER("AllocMem");
vFrustumPlanes.resize(sz);
vBoundingBoxLists.resize(sz);
vGameObjectPointerLists.resize(sz);
vMaterialIDLists.resize(sz);
}
}
void FFrustumCullWorkerContext::ClearMemory()
{
vFrustumPlanes.clear();
vBoundingBoxLists.clear();
vGameObjectPointerLists.clear();
vCulledBoundingBoxIndexListPerView.clear();
vMaterialIDLists.clear();
NumValidInputElements = 0;
}

@@ -165,8 +161,6 @@ void FFrustumCullWorkerContext::AddWorkerItem(
SCOPED_CPU_MARKER("FFrustumCullWorkerContext::AddWorkerItem()");
vFrustumPlanes[i] = FrustumPlaneSet;
vBoundingBoxLists[i] = vBoundingBoxList;
vGameObjectPointerLists[i] = pGameObjects;
vMaterialIDLists[i] = vMaterials;
}

void FFrustumCullWorkerContext::ProcessWorkItems_SingleThreaded()
@@ -296,19 +290,17 @@ void FFrustumCullWorkerContext::Process(size_t iRangeBegin, size_t iRangeEnd)
for (size_t iWork = iRangeBegin; iWork <= iRangeEnd; ++iWork)
{
{
{
SCOPED_CPU_MARKER("Clear");
vCulledBoundingBoxIndexListPerView[iWork].clear();
}
SCOPED_CPU_MARKER("Clear");
vCulledBoundingBoxIndexListPerView[iWork].clear();
}

SCOPED_CPU_MARKER("CullFrustum");
// process bounding box list per frustum
for (size_t bb = 0; bb < vBoundingBoxLists[iWork].size(); ++bb)
SCOPED_CPU_MARKER("CullFrustum");
// process bounding box list per frustum
for (size_t bb = 0; bb < vBoundingBoxLists[iWork].size(); ++bb)
{
if (IsBoundingBoxIntersectingFrustum(vFrustumPlanes[iWork], vBoundingBoxLists[iWork][bb]))
{
if (IsBoundingBoxIntersectingFrustum(vFrustumPlanes[iWork], vBoundingBoxLists[iWork][bb]))
{
vCulledBoundingBoxIndexListPerView[iWork].push_back(bb); // grows as we go (no pre-alloc)
}
vCulledBoundingBoxIndexListPerView[iWork].push_back(bb); // grows as we go (no pre-alloc)
}
}
}
@@ -625,6 +617,7 @@ void SceneBoundingBoxHierarchy::BuildMeshBoundingBox(const GameObject* pObj, siz
mMeshBoundingBoxMeshIDMapping[iMesh] = mesh;
mMeshBoundingBoxMaterialIDMapping[iMesh] = mat;
mMeshBoundingBoxGameObjectPointerMapping[iMesh] = pObj;
mMeshTransforms[iMesh] = *mpTransforms.at(pObj->mTransformID);
++iMesh;
bAtLeastOneMesh = true;
}
@@ -669,6 +662,7 @@ void SceneBoundingBoxHierarchy::Clear()
mMeshBoundingBoxes.clear();
mMeshBoundingBoxMeshIDMapping.clear();
mMeshBoundingBoxMaterialIDMapping.clear();
mMeshTransforms.clear();
mMeshBoundingBoxGameObjectPointerMapping.clear();
mGameObjectBoundingBoxGameObjectPointerMapping.clear();
}
@@ -701,6 +695,7 @@ void SceneBoundingBoxHierarchy::ResizeGameMeshBoxContainer(size_t size)
mMeshBoundingBoxes.resize(size);
mMeshBoundingBoxMeshIDMapping.resize(size);
mMeshBoundingBoxMaterialIDMapping.resize(size);
mMeshTransforms.resize(size);
mMeshBoundingBoxGameObjectPointerMapping.resize(size);
}

4 changes: 0 additions & 4 deletions Source/Engine/Culling.h
Original file line number Diff line number Diff line change
@@ -151,10 +151,6 @@ struct FFrustumCullWorkerContext : public FThreadWorkerContext
// store the index of the surviving bounding box in a list, per view frustum
/*out*/ std::vector<IndexList_t> vCulledBoundingBoxIndexListPerView;
// Hot Data ------------------------------------------------------------------------------------------------------------

// Cold Data : used after culling
/*in */ std::vector<std::vector<const GameObject*>> vGameObjectPointerLists; // Associates BoundingBoxes with pGameObjects
/*in */ std::vector<std::vector<MaterialID>> vMaterialIDLists; // Associates BoundingBoxes with MaterialIDs

//std::vector<int> vLightMovementTypeID; // index to access light type vectors: [0]:static, [1]:stationary, [2]:dynamic

153 changes: 65 additions & 88 deletions Source/Engine/Scene/Scene.cpp
Original file line number Diff line number Diff line change
@@ -624,32 +624,35 @@ void Scene::GatherFrustumCullParameters(const FSceneView& SceneView, FSceneShado
mFrustumCullWorkerContext.AddWorkerItem(FrustumPlanesets[i], BVH.mMeshBoundingBoxes, BVH.mMeshBoundingBoxGameObjectPointerMapping, i);
#else
{
SCOPED_CPU_MARKER("DispatchWorkers");
mFrustumCullWorkerContext.AllocInputMemoryIfNecessary(FrustumPlanesets.size());
mFrustumCullWorkerContext.NumValidInputElements = FrustumPlanesets.size();

const std::vector<std::pair<size_t, size_t>> vRanges = PartitionWorkItemsIntoRanges(FrustumPlanesets.size(), UpdateWorkerThreadPool.GetThreadPoolSize()+1);
size_t currRange = 0;
for (const std::pair<size_t, size_t>& Range : vRanges)
{
if (currRange == 0)
SCOPED_CPU_MARKER("DispatchWorkers");
size_t currRange = 0;
for (const std::pair<size_t, size_t>& Range : vRanges)
{
++currRange; // skip the first range, and do it on this thread after dispatches
continue;
if (currRange == 0)
{
++currRange; // skip the first range, and do it on this thread after dispatches
continue;
}
const size_t& iBegin = Range.first;
const size_t& iEnd = Range.second; // inclusive
assert(iBegin <= iEnd); // ensure work context bounds
UpdateWorkerThreadPool.AddTask([Range, &FrustumPlanesets, &BVH, this]()
{
SCOPED_CPU_MARKER_C("UpdateWorker", 0xFF0000FF);
for (size_t i = Range.first; i <= Range.second; ++i)
mFrustumCullWorkerContext.AddWorkerItem(FrustumPlanesets[i]
, BVH.mMeshBoundingBoxes
, BVH.mMeshBoundingBoxGameObjectPointerMapping
, BVH.mMeshBoundingBoxMaterialIDMapping
, i
);
});
}
const size_t& iBegin = Range.first;
const size_t& iEnd = Range.second; // inclusive
assert(iBegin <= iEnd); // ensure work context bounds
UpdateWorkerThreadPool.AddTask([Range, &FrustumPlanesets, &BVH, this]()
{
SCOPED_CPU_MARKER_C("UpdateWorker", 0xFF0000FF);
for (size_t i = Range.first; i <= Range.second; ++i)
mFrustumCullWorkerContext.AddWorkerItem(FrustumPlanesets[i]
, BVH.mMeshBoundingBoxes
, BVH.mMeshBoundingBoxGameObjectPointerMapping
, BVH.mMeshBoundingBoxMaterialIDMapping
, i
);
});
}

for (size_t i = vRanges[0].first; i <= vRanges[0].second; ++i)
@@ -861,60 +864,10 @@ static void MarkInstanceDataStale(std::unordered_map < MaterialID, std::unordere
}
}
}
static void CollectInstanceData(
std::unordered_map<MaterialID, std::unordered_map<MeshID, FSceneView::FMeshInstanceData>>& MaterialMeshInstanceDataLookup
, const std::vector<const GameObject*>& MeshBoundingBoxGameObjectPointers
, const std::vector<MeshID >& MeshBoundingBoxMeshIDMapping
, const std::vector<MaterialID >& mMeshBoundingBoxMaterialIDMapping
, const std::vector<size_t >& CulledBoundingBoxIndexList_Msh
, size_t iBegin
, size_t iEnd
, const DirectX::XMMATRIX matViewProj
, const DirectX::XMMATRIX matViewProjHistory
, const std::vector<Transform*>& mpTransforms
, const ModelLookup_t& mModels
)
{
SCOPED_CPU_MARKER("CollectInstanceData");
for (size_t i = iBegin; i < iEnd; ++i)
{
const size_t BBIndex = CulledBoundingBoxIndexList_Msh[i];
assert(BBIndex < MeshBoundingBoxMeshIDMapping.size());
MeshID meshID = MeshBoundingBoxMeshIDMapping[BBIndex];

// read game object data
const GameObject* pGameObject = MeshBoundingBoxGameObjectPointers[BBIndex];
Transform* const& pTF = mpTransforms.at(pGameObject->mTransformID);
const XMMATRIX matWorld = pTF->matWorldTransformation();
const XMMATRIX matWorldHistory = pTF->matWorldTransformationPrev();
const XMMATRIX matNormal = pTF->NormalMatrix(matWorld);

MaterialID matID = mMeshBoundingBoxMaterialIDMapping[BBIndex];

{
//SCOPED_CPU_MARKER("WriteMap");
//
// record instance data
FSceneView::FMeshInstanceData& d = MaterialMeshInstanceDataLookup[matID][meshID];

// if we're seeing this materia/mesh combo the first time,
// allocate some memory for instance data, enough for 1 batch
if (d.InstanceData.empty() || d.InstanceData.size() == d.NumValidData)
{
SCOPED_CPU_MARKER("MemAlloc");
d.InstanceData.resize(d.InstanceData.empty() ? MAX_INSTANCE_COUNT__SCENE_MESHES : d.InstanceData.size() * 2);
}

d.InstanceData[d.NumValidData++] = { matWorld, matWorld * matViewProj, matWorldHistory * matViewProjHistory, matNormal };
}
}

}
void Scene::BatchInstanceData_SceneMeshes(
std::vector<MeshRenderCommand_t>* pMeshRenderCommands
, std::unordered_map < MaterialID, std::unordered_map<MeshID, FSceneView::FMeshInstanceData>>& MaterialMeshInstanceDataLookup
, const std::vector<const GameObject*>& MeshBoundingBoxGameObjectPointers
, const std::vector<MaterialID>& MeshBoundingBoxMaterialIDs
, const std::vector<size_t>& CulledBoundingBoxIndexList_Msh
, const DirectX::XMMATRIX& matViewProj
, const DirectX::XMMATRIX& matViewProjHistory
@@ -925,18 +878,43 @@ void Scene::BatchInstanceData_SceneMeshes(
#if RENDER_INSTANCED_SCENE_MESHES
MarkInstanceDataStale(MaterialMeshInstanceDataLookup);

CollectInstanceData(MaterialMeshInstanceDataLookup
, MeshBoundingBoxGameObjectPointers
, mBoundingBoxHierarchy.mMeshBoundingBoxMeshIDMapping
, MeshBoundingBoxMaterialIDs
, CulledBoundingBoxIndexList_Msh
, 0
, CulledBoundingBoxIndexList_Msh.size()
, matViewProj
, matViewProjHistory
, mpTransforms
, mModels
);
{
SCOPED_CPU_MARKER("CollectInstanceData");
const std::vector<MeshID>& MeshBB_MeshID = mBoundingBoxHierarchy.mMeshBoundingBoxMeshIDMapping;
const std::vector<MaterialID>& MeshBB_MatID = mBoundingBoxHierarchy.mMeshBoundingBoxMaterialIDMapping;
const std::vector<Transform>& MeshBB_Transforms = mBoundingBoxHierarchy.mMeshTransforms;

const size_t iBegin = 0;
const size_t iEnd = CulledBoundingBoxIndexList_Msh.size();
for (size_t i = iBegin; i < iEnd; ++i)
{
const size_t BBIndex = CulledBoundingBoxIndexList_Msh[i];
assert(BBIndex < MeshBB_MeshID.size());
MeshID meshID = MeshBB_MeshID[BBIndex];

// read game object data
const Transform& tf = MeshBB_Transforms[BBIndex];
const XMMATRIX matWorld = tf.matWorldTransformation();
const XMMATRIX matWorldHistory = tf.matWorldTransformationPrev();
const XMMATRIX matNormal = tf.NormalMatrix(matWorld);

MaterialID matID = MeshBB_MatID[BBIndex];
{
// record instance data
FSceneView::FMeshInstanceData& d = MaterialMeshInstanceDataLookup[matID][meshID];

// if we're seeing this materia/mesh combo the first time,
// allocate some memory for instance data, enough for 1 batch
if (d.InstanceData.empty() || d.InstanceData.size() == d.NumValidData)
{
SCOPED_CPU_MARKER("MemAlloc");
d.InstanceData.resize(d.InstanceData.empty() ? MAX_INSTANCE_COUNT__SCENE_MESHES : d.InstanceData.size() * 2);
}

d.InstanceData[d.NumValidData++] = { matWorld, matWorld * matViewProj, matWorldHistory * matViewProjHistory, matNormal };
}
}
}

int NumInstancedRenderCommands = 0;
{
@@ -1074,10 +1052,11 @@ void Scene::BatchInstanceData_ShadowMeshes(size_t iFrustum, FSceneShadowView::FS
assert(BBIndex < mBoundingBoxHierarchy.mMeshBoundingBoxMeshIDMapping.size());
MeshID meshID = mBoundingBoxHierarchy.mMeshBoundingBoxMeshIDMapping[BBIndex];

const GameObject* pGameObject = mFrustumCullWorkerContext.vGameObjectPointerLists[iFrustum][BBIndex];
Transform* const& pTF = mpTransforms.at(pGameObject->mTransformID);

XMMATRIX matWorld = pTF->matWorldTransformation();

const GameObject* pGameObject = mBoundingBoxHierarchy.mMeshBoundingBoxGameObjectPointerMapping[BBIndex];

Transform const TF = mBoundingBoxHierarchy.mMeshTransforms[BBIndex];
XMMATRIX matWorld = TF.matWorldTransformation();

FSceneShadowView::FShadowView::FShadowMeshInstanceData& d = pShadowView->ShadowMeshInstanceDataLookup[meshID];

@@ -1190,8 +1169,6 @@ void Scene::BatchInstanceData(FSceneView& SceneView, ThreadPool& UpdateWorkerThr
SCOPED_CPU_MARKER_C("UpdateWorker", 0xFF0000FF);
BatchInstanceData_SceneMeshes(&SceneView.meshRenderCommands
, SceneView.MaterialMeshInstanceDataLookup
, mFrustumCullWorkerContext.vGameObjectPointerLists[0]
, mFrustumCullWorkerContext.vMaterialIDLists[0]
, mFrustumCullWorkerContext.vCulledBoundingBoxIndexListPerView[0]
, SceneView.viewProj
, SceneView.viewProjPrev
5 changes: 2 additions & 3 deletions Source/Engine/Scene/Scene.h
Original file line number Diff line number Diff line change
@@ -269,7 +269,8 @@ class SceneBoundingBoxHierarchy
std::vector<FBoundingBox> mMeshBoundingBoxes;
std::vector<MeshID> mMeshBoundingBoxMeshIDMapping;
std::vector<MaterialID> mMeshBoundingBoxMaterialIDMapping;
std::vector<const GameObject*> mMeshBoundingBoxGameObjectPointerMapping;
std::vector<Transform> mMeshTransforms;
std::vector<const GameObject*> mMeshBoundingBoxGameObjectPointerMapping;
//------------------------------------------------------

// scene data container references
@@ -353,8 +354,6 @@ class Scene
void BatchInstanceData_SceneMeshes(
std::vector<MeshRenderCommand_t>* pMeshRenderCommands
, std::unordered_map < MaterialID, std::unordered_map<MeshID, FSceneView::FMeshInstanceData>>& MaterialMeshInstanceDataLookup
, const std::vector<const GameObject*>& MeshBoundingBoxGameObjectPointers
, const std::vector<MaterialID>& MeshBoundingBoxMaterialIDs
, const std::vector<size_t>& CulledBoundingBoxIndexList_Msh
, const DirectX::XMMATRIX& matViewProj
, const DirectX::XMMATRIX& matViewProjHistory