resurrected multithreaded rendering

This commit is contained in:
turanszkij
2019-06-30 01:45:49 +01:00
parent f2673802fa
commit 97f3d7032e
13 changed files with 155 additions and 117 deletions
+12 -12
View File
@@ -119,7 +119,7 @@ void MainComponent::Run()
}
wiProfiler::BeginFrame();
wiProfiler::BeginRange("CPU Frame", wiProfiler::DOMAIN_CPU);
auto range = wiProfiler::BeginRange("CPU Frame", wiProfiler::DOMAIN_CPU);
deltaTime = float(std::max(0.0, timer.elapsed() / 1000.0));
timer.record();
@@ -133,7 +133,7 @@ void MainComponent::Run()
fadeManager.Update(dt);
// Fixed time update:
wiProfiler::BeginRange("Fixed Update", wiProfiler::DOMAIN_CPU);
auto range = wiProfiler::BeginRange("Fixed Update", wiProfiler::DOMAIN_CPU);
{
if (frameskip)
{
@@ -156,18 +156,18 @@ void MainComponent::Run()
FixedUpdate();
}
}
wiProfiler::EndRange(); // Fixed Update
wiProfiler::EndRange(range); // Fixed Update
// Variable-timed update:
wiProfiler::BeginRange("Update", wiProfiler::DOMAIN_CPU);
range = wiProfiler::BeginRange("Update", wiProfiler::DOMAIN_CPU);
Update(dt);
wiProfiler::EndRange(); // Update
wiProfiler::EndRange(range); // Update
wiInputManager::Update();
wiProfiler::BeginRange("Render", wiProfiler::DOMAIN_CPU);
range = wiProfiler::BeginRange("Render", wiProfiler::DOMAIN_CPU);
Render();
wiProfiler::EndRange(); // Render
wiProfiler::EndRange(range); // Render
}
else
{
@@ -175,13 +175,13 @@ void MainComponent::Run()
deltaTimeAccumulator = 0;
}
wiProfiler::EndRange(); // CPU Frame
wiProfiler::EndRange(range); // CPU Frame
wiProfiler::BeginRange("Compose", wiProfiler::DOMAIN_CPU);
range = wiProfiler::BeginRange("Compose", wiProfiler::DOMAIN_CPU);
wiRenderer::GetDevice()->PresentBegin();
Compose();
wiRenderer::GetDevice()->PresentEnd();
wiProfiler::EndRange(); // Compose
wiProfiler::EndRange(range); // Compose
wiRenderer::EndFrame();
@@ -220,12 +220,12 @@ void MainComponent::Render()
{
wiLua::GetGlobal()->Render();
wiProfiler::BeginRange("GPU Frame", wiProfiler::DOMAIN_GPU, GRAPHICSTHREAD_IMMEDIATE);
auto range = wiProfiler::BeginRange("GPU Frame", wiProfiler::DOMAIN_GPU, GRAPHICSTHREAD_IMMEDIATE);
if (GetActivePath() != nullptr)
{
GetActivePath()->Render();
}
wiProfiler::EndRange(GRAPHICSTHREAD_IMMEDIATE); // GPU Frame
wiProfiler::EndRange(range); // GPU Frame
}
void MainComponent::Compose()
+7 -7
View File
@@ -270,7 +270,7 @@ void RenderPath3D::RenderFrameSetUp(GRAPHICSTHREAD threadID) const
}
void RenderPath3D::RenderReflections(GRAPHICSTHREAD threadID) const
{
wiProfiler::BeginRange("Reflection rendering", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Reflection rendering", wiProfiler::DOMAIN_GPU, threadID);
if (wiRenderer::IsRequestedReflectionRendering())
{
@@ -309,7 +309,7 @@ void RenderPath3D::RenderReflections(GRAPHICSTHREAD threadID) const
}
}
wiProfiler::EndRange(); // Reflection Rendering
wiProfiler::EndRange(range); // Reflection Rendering
}
void RenderPath3D::RenderShadows(GRAPHICSTHREAD threadID) const
{
@@ -641,14 +641,14 @@ void RenderPath3D::RenderTransparents(const Texture2D& dstSceneRT, RENDERPASS re
// Transparent scene
{
wiProfiler::BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID);
device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, threadID);
device->BindResource(PS, &rtSceneCopy, TEXSLOT_RENDERPATH_REFRACTION, threadID);
device->BindResource(PS, &rtWaterRipple, TEXSLOT_RENDERPATH_WATERRIPPLES, threadID);
wiRenderer::DrawScene_Transparent(wiRenderer::GetCamera(), renderPass, threadID, getHairParticlesEnabled(), true);
wiProfiler::EndRange(threadID); // Transparent Scene
wiProfiler::EndRange(range); // Transparent Scene
}
wiRenderer::DrawLightVisualizers(wiRenderer::GetCamera(), threadID);
@@ -689,7 +689,7 @@ void RenderPath3D::RenderTransparents(const Texture2D& dstSceneRT, RENDERPASS re
RenderParticles(true, GRAPHICSTHREAD_IMMEDIATE);
RenderParticles(true, threadID);
}
void RenderPath3D::TemporalAAResolve(const Texture2D& srcdstSceneRT, const Texture2D& srcGbuffer1, GRAPHICSTHREAD threadID) const
{
@@ -701,7 +701,7 @@ void RenderPath3D::TemporalAAResolve(const Texture2D& srcdstSceneRT, const Textu
wiRenderer::BindGBufferTextures(nullptr, &srcGbuffer1, nullptr, GRAPHICSTHREAD_IMMEDIATE);
device->EventBegin("Temporal AA Resolve", threadID);
wiProfiler::BeginRange("Temporal AA Resolve", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Temporal AA Resolve", wiProfiler::DOMAIN_GPU, threadID);
fx.enableHDR();
fx.blendFlag = BLENDMODE_OPAQUE;
int current = device->GetFrameCount() % 2;
@@ -738,7 +738,7 @@ void RenderPath3D::TemporalAAResolve(const Texture2D& srcdstSceneRT, const Textu
fx.disableFullScreen();
}
fx.disableHDR();
wiProfiler::EndRange(threadID);
wiProfiler::EndRange(range);
device->EventEnd(threadID);
}
}
+2 -2
View File
@@ -86,7 +86,7 @@ void RenderPath3D_Deferred::Render() const
device->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_READ, RESOURCE_STATE_DEPTH_WRITE, threadID);
{
wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
const Texture2D* rts[] = {
&rtGBuffer[0],
@@ -108,7 +108,7 @@ void RenderPath3D_Deferred::Render() const
device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_SSAO, threadID);
wiRenderer::DrawScene(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, RENDERPASS_DEFERRED, getHairParticlesEnabled(), true);
wiProfiler::EndRange(threadID); // Opaque Scene
wiProfiler::EndRange(range); // Opaque Scene
}
device->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_WRITE, RESOURCE_STATE_COPY_SOURCE, threadID);
+2 -2
View File
@@ -71,7 +71,7 @@ void RenderPath3D_Forward::Render() const
// Opaque Scene:
{
wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
const Texture2D* rts[] = {
&rtMain[0],
@@ -96,7 +96,7 @@ void RenderPath3D_Forward::Render() const
device->BindRenderTargets(0, nullptr, nullptr, threadID);
wiProfiler::EndRange(threadID); // Opaque Scene
wiProfiler::EndRange(range); // Opaque Scene
}
if (getMSAASampleCount() > 1)
+2 -2
View File
@@ -104,7 +104,7 @@ void RenderPath3D_PathTracing::Render() const
}
else
{
wiProfiler::BeginRange("Traced Scene", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Traced Scene", wiProfiler::DOMAIN_GPU, threadID);
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID);
@@ -132,7 +132,7 @@ void RenderPath3D_PathTracing::Render() const
wiImage::Draw(&traceResult, fx, threadID);
wiProfiler::EndRange(threadID); // Traced Scene
wiProfiler::EndRange(range); // Traced Scene
}
}
+2 -2
View File
@@ -26,7 +26,7 @@ void RenderPath3D_TiledDeferred::Render() const
device->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_READ, RESOURCE_STATE_DEPTH_WRITE, threadID);
{
wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
const Texture2D* rts[] = {
&rtGBuffer[0],
@@ -48,7 +48,7 @@ void RenderPath3D_TiledDeferred::Render() const
device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_SSAO, threadID);
wiRenderer::DrawScene(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, RENDERPASS_DEFERRED, getHairParticlesEnabled(), true);
wiProfiler::EndRange(threadID); // Opaque Scene
wiProfiler::EndRange(range); // Opaque Scene
}
device->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_WRITE, RESOURCE_STATE_COPY_SOURCE, threadID);
+37 -25
View File
@@ -17,13 +17,15 @@ void RenderPath3D_TiledForward::Render() const
scene_read[1] = &rtMain_resolved[1];
}
RenderFrameSetUp(GRAPHICSTHREAD_IMMEDIATE);
RenderShadows(GRAPHICSTHREAD_IMMEDIATE);
RenderReflections(GRAPHICSTHREAD_IMMEDIATE);
wiJobSystem::context ctx;
wiJobSystem::Execute(ctx, [this, device] { RenderFrameSetUp(GRAPHICSTHREAD_SHADOWS); device->FinishCommandList(GRAPHICSTHREAD_SHADOWS); });
wiJobSystem::Execute(ctx, [this, device] { RenderShadows(GRAPHICSTHREAD_REFLECTIONS); device->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); });
wiJobSystem::Execute(ctx, [this, device] { RenderReflections(GRAPHICSTHREAD_SCENE); device->FinishCommandList(GRAPHICSTHREAD_SCENE); });
// Main scene:
{
GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE;
wiJobSystem::Execute(ctx, [&] {
GRAPHICSTHREAD threadID = GRAPHICSTHREAD_MISC1;
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID);
@@ -32,7 +34,7 @@ void RenderPath3D_TiledForward::Render() const
// depth prepass
{
wiProfiler::BeginRange("Z-Prepass", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Z-Prepass", wiProfiler::DOMAIN_GPU, threadID);
device->BindRenderTargets(0, nullptr, &depthBuffer, threadID);
device->ClearDepthStencil(&depthBuffer, CLEAR_DEPTH | CLEAR_STENCIL, 0, 0, threadID);
@@ -46,7 +48,7 @@ void RenderPath3D_TiledForward::Render() const
device->BindRenderTargets(0, nullptr, nullptr, threadID);
wiProfiler::EndRange(threadID);
wiProfiler::EndRange(range);
}
if (getMSAASampleCount() > 1)
@@ -72,7 +74,7 @@ void RenderPath3D_TiledForward::Render() const
// Opaque scene:
{
wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
const Texture2D* rts[] = {
&rtMain[0],
@@ -95,7 +97,7 @@ void RenderPath3D_TiledForward::Render() const
device->BindRenderTargets(0, nullptr, nullptr, threadID);
wiProfiler::EndRange(threadID); // Opaque Scene
wiProfiler::EndRange(range); // Opaque Scene
}
if (getMSAASampleCount() > 1)
@@ -108,34 +110,44 @@ void RenderPath3D_TiledForward::Render() const
RenderSSAO(threadID);
RenderSSR(*scene_read[0], threadID);
}
DownsampleDepthBuffer(GRAPHICSTHREAD_IMMEDIATE);
device->FinishCommandList(threadID);
});
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), GRAPHICSTHREAD_IMMEDIATE);
wiJobSystem::Execute(ctx, [&] {
DownsampleDepthBuffer(GRAPHICSTHREAD_MISC2);
RenderOutline(rtMain[0], GRAPHICSTHREAD_IMMEDIATE);
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), GRAPHICSTHREAD_MISC2);
RenderLightShafts(GRAPHICSTHREAD_IMMEDIATE);
RenderOutline(rtMain[0], GRAPHICSTHREAD_MISC2);
RenderVolumetrics(GRAPHICSTHREAD_IMMEDIATE);
RenderLightShafts(GRAPHICSTHREAD_MISC2);
RenderParticles(false, GRAPHICSTHREAD_IMMEDIATE);
RenderVolumetrics(GRAPHICSTHREAD_MISC2);
RenderRefractionSource(*scene_read[0], GRAPHICSTHREAD_IMMEDIATE);
RenderParticles(false, GRAPHICSTHREAD_MISC2);
RenderTransparents(rtMain[0], RENDERPASS_TILEDFORWARD, GRAPHICSTHREAD_IMMEDIATE);
RenderRefractionSource(*scene_read[0], GRAPHICSTHREAD_MISC2);
if (getMSAASampleCount() > 1)
{
device->MSAAResolve(scene_read[0], &rtMain[0], GRAPHICSTHREAD_IMMEDIATE);
}
RenderTransparents(rtMain[0], RENDERPASS_TILEDFORWARD, GRAPHICSTHREAD_MISC2);
TemporalAAResolve(*scene_read[0], *scene_read[1], GRAPHICSTHREAD_IMMEDIATE);
if (getMSAASampleCount() > 1)
{
device->MSAAResolve(scene_read[0], &rtMain[0], GRAPHICSTHREAD_MISC2);
}
RenderBloom(*scene_read[0], GRAPHICSTHREAD_IMMEDIATE);
TemporalAAResolve(*scene_read[0], *scene_read[1], GRAPHICSTHREAD_MISC2);
RenderPostprocessChain(*scene_read[0], *scene_read[1], GRAPHICSTHREAD_IMMEDIATE);
RenderBloom(*scene_read[0], GRAPHICSTHREAD_MISC2);
RenderPostprocessChain(*scene_read[0], *scene_read[1], GRAPHICSTHREAD_MISC2);
device->FinishCommandList(GRAPHICSTHREAD_MISC2);
});
wiJobSystem::Wait(ctx);
device->ExecuteCommandLists();
RenderPath2D::Render();
}
+2 -2
View File
@@ -357,7 +357,7 @@ void wiEmittedParticle::UpdateGPU(const TransformComponent& transform, const Mat
if (IsSPHEnabled())
{
wiProfiler::BeginRange("SPH - Simulation", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("SPH - Simulation", wiProfiler::DOMAIN_GPU, threadID);
// Smooth Particle Hydrodynamics:
device->EventBegin("SPH - Simulation", threadID);
@@ -456,7 +456,7 @@ void wiEmittedParticle::UpdateGPU(const TransformComponent& transform, const Mat
device->EventEnd(threadID);
wiProfiler::EndRange(threadID);
wiProfiler::EndRange(range);
}
device->EventBegin("Simulate", threadID);
+2 -2
View File
@@ -402,7 +402,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID)
}
wiProfiler::BeginRange("BVH Rebuild", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("BVH Rebuild", wiProfiler::DOMAIN_GPU, threadID);
UpdateGlobalMaterialResources(scene, threadID);
@@ -609,7 +609,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID)
#endif // BVH_VALIDATE
wiProfiler::EndRange(threadID); // BVH rebuild
wiProfiler::EndRange(range); // BVH rebuild
}
void wiGPUBVH::Bind(SHADERSTAGE stage, GRAPHICSTHREAD threadID) const
{
+4 -2
View File
@@ -314,7 +314,9 @@ namespace wiPhysicsEngine
return;
}
wiProfiler::BeginRange("Physics", wiProfiler::DOMAIN_CPU);
wiJobSystem::Wait(ctx);
auto range = wiProfiler::BeginRange("Physics", wiProfiler::DOMAIN_CPU);
btVector3 wind = btVector3(weather.windDirection.x, weather.windDirection.y, weather.windDirection.z);
@@ -499,6 +501,6 @@ namespace wiPhysicsEngine
}
}
wiProfiler::EndRange(); // Physics
wiProfiler::EndRange(range); // Physics
}
}
+30 -23
View File
@@ -8,6 +8,7 @@
#include <sstream>
#include <unordered_map>
#include <stack>
#include <mutex>
using namespace std;
using namespace wiGraphics;
@@ -16,23 +17,23 @@ namespace wiProfiler
{
bool ENABLED = false;
bool initialized = false;
std::mutex lock;
struct Range
{
PROFILER_DOMAIN domain;
PROFILER_DOMAIN domain = DOMAIN_CPU;
std::string name;
float time;
float time = 0;
GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE;
wiTimer cpuBegin, cpuEnd;
wiRenderer::GPUQueryRing<4> gpuBegin;
wiRenderer::GPUQueryRing<4> gpuEnd;
Range() :time(0), domain(DOMAIN_CPU) {}
~Range() {}
bool active = false;
};
std::unordered_map<std::string, Range*> ranges;
std::stack<std::string> rangeStack;
std::unordered_map<size_t, Range*> ranges;
wiRenderer::GPUQueryRing<4> disjoint;
void BeginFrame()
@@ -67,14 +68,14 @@ namespace wiProfiler
while (!wiRenderer::GetDevice()->QueryRead(disjoint_query, &disjoint_result));
}
assert(rangeStack.empty() && "There was a range which was not ended!");
if (disjoint_result.result_disjoint == FALSE)
{
for (auto& x : ranges)
{
auto& range = x.second;
assert(range->active == false && "There was a range that was not ended!");
range->time = 0;
switch (range->domain)
{
@@ -102,15 +103,18 @@ namespace wiProfiler
}
}
void BeginRange(const std::string& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID)
range_id BeginRange(const wiHashString& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID)
{
if (!ENABLED || !initialized)
return;
return 0;
if (ranges.find(name) == ranges.end())
range_id id = name.GetHash();
lock.lock();
if (ranges.find(id) == ranges.end())
{
Range* range = new Range;
range->name = name;
range->name = name.GetString();
range->domain = domain;
range->time = 0;
@@ -134,32 +138,35 @@ namespace wiProfiler
}
ranges.insert(make_pair(name, range));
ranges.insert(make_pair(id, range));
}
switch (domain)
{
case wiProfiler::DOMAIN_CPU:
ranges[name]->cpuBegin.record();
ranges[id]->cpuBegin.record();
break;
case wiProfiler::DOMAIN_GPU:
wiRenderer::GetDevice()->QueryEnd(ranges[name]->gpuBegin.Get_GPU(), threadID);
ranges[id]->threadID = threadID;
wiRenderer::GetDevice()->QueryEnd(ranges[id]->gpuBegin.Get_GPU(), threadID);
break;
default:
assert(0);
break;
}
rangeStack.push(name);
lock.unlock();
return id;
}
void EndRange(GRAPHICSTHREAD threadID)
void EndRange(range_id id)
{
if (!ENABLED || !initialized || rangeStack.empty())
if (!ENABLED || !initialized)
return;
const std::string& top = rangeStack.top();
lock.lock();
auto& it = ranges.find(top);
auto& it = ranges.find(id);
if (it != ranges.end())
{
switch (it->second->domain)
@@ -168,7 +175,7 @@ namespace wiProfiler
it->second->cpuEnd.record();
break;
case wiProfiler::DOMAIN_GPU:
wiRenderer::GetDevice()->QueryEnd(it->second->gpuEnd.Get_GPU(), threadID);
wiRenderer::GetDevice()->QueryEnd(it->second->gpuEnd.Get_GPU(), it->second->threadID);
break;
default:
assert(0);
@@ -180,7 +187,7 @@ namespace wiProfiler
assert(0);
}
rangeStack.pop();
lock.unlock();
}
void DrawData(int x, int y, GRAPHICSTHREAD threadID)
@@ -198,7 +205,7 @@ namespace wiProfiler
{
if (x.second->domain == domain)
{
ss << x.first << ": " << fixed << x.second->time << " ms" << endl;
ss << x.second->name << ": " << fixed << x.second->time << " ms" << endl;
}
}
ss << endl;
+12 -2
View File
@@ -1,5 +1,6 @@
#pragma once
#include "wiEnums.h"
#include "wiHashString.h"
#include <string>
@@ -11,15 +12,24 @@ namespace wiProfiler
DOMAIN_GPU,
DOMAIN_COUNT
};
typedef size_t range_id;
// Begin collecting profiling data for the current frame
void BeginFrame();
// Finalize collecting profiling data for the current frame
void EndFrame();
void BeginRange(const std::string& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE);
void EndRange(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE);
// Start a profiling range
range_id BeginRange(const wiHashString& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE);
// End a profiling range
void EndRange(range_id id);
// Renders a basic text of the Profiling results to the (x,y) screen coordinate
void DrawData(int x, int y, GRAPHICSTHREAD threadID);
// Enable/disable profiling
void SetEnabled(bool value);
};
+41 -34
View File
@@ -3610,7 +3610,7 @@ void UpdatePerFrameData(float dt, uint32_t layerMask)
// Perform culling and obtain closest reflector:
requestReflectionRendering = false;
wiProfiler::BeginRange("Frustum Culling", wiProfiler::DOMAIN_CPU);
auto range = wiProfiler::BeginRange("Frustum Culling", wiProfiler::DOMAIN_CPU);
{
for (auto& x : frameCullings)
{
@@ -3811,7 +3811,7 @@ void UpdatePerFrameData(float dt, uint32_t layerMask)
}
}
wiProfiler::EndRange(); // Frustum Culling
wiProfiler::EndRange(range); // Frustum Culling
// Ocean will override any current reflectors
waterPlane = scene.waterPlane;
@@ -4116,15 +4116,6 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
// Temporary array for GPU entities can be freed now:
frameAllocators[threadID].free(sizeof(ShaderEntityType)*SHADER_ENTITY_COUNT);
frameAllocators[threadID].free(sizeof(XMMATRIX)*MATRIXARRAY_COUNT);
// Bind the GPU entity array for all shaders that need it here:
GPUResource* resources[] = {
&resourceBuffers[RBTYPE_ENTITYARRAY],
&resourceBuffers[RBTYPE_MATRIXARRAY],
};
device->BindResources(VS, resources, SBSLOT_ENTITYARRAY, ARRAYSIZE(resources), threadID);
device->BindResources(PS, resources, SBSLOT_ENTITYARRAY, ARRAYSIZE(resources), threadID);
device->BindResources(CS, resources, SBSLOT_ENTITYARRAY, ARRAYSIZE(resources), threadID);
}
UpdateFrameCB(threadID);
@@ -4132,7 +4123,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
GetPrevCamera() = GetCamera();
wiProfiler::BeginRange("Skinning", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Skinning", wiProfiler::DOMAIN_GPU, threadID);
device->EventBegin("Skinning", threadID);
{
bool streamOutSetUp = false;
@@ -4204,7 +4195,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
}
device->EventEnd(threadID);
wiProfiler::EndRange(threadID); // skinning
wiProfiler::EndRange(range); // skinning
// Update soft body vertex buffers:
for (size_t i = 0; i < scene.softbodies.GetCount(); ++i)
@@ -4318,7 +4309,7 @@ void OcclusionCulling_Render(GRAPHICSTHREAD threadID)
GraphicsDevice* device = GetDevice();
const FrameCulling& culling = frameCullings.at(&GetCamera());
wiProfiler::BeginRange("Occlusion Culling Render", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Occlusion Culling Render", wiProfiler::DOMAIN_GPU, threadID);
int queryID = 0;
@@ -4384,7 +4375,7 @@ void OcclusionCulling_Render(GRAPHICSTHREAD threadID)
device->EventEnd(threadID);
}
wiProfiler::EndRange(threadID); // Occlusion Culling Render
wiProfiler::EndRange(range); // Occlusion Culling Render
}
void OcclusionCulling_Read()
{
@@ -4393,7 +4384,7 @@ void OcclusionCulling_Read()
return;
}
wiProfiler::BeginRange("Occlusion Culling Read", wiProfiler::DOMAIN_CPU);
auto range = wiProfiler::BeginRange("Occlusion Culling Read", wiProfiler::DOMAIN_CPU);
GraphicsDevice* device = GetDevice();
const FrameCulling& culling = frameCullings.at(&GetCamera());
@@ -4444,7 +4435,7 @@ void OcclusionCulling_Read()
device->EventEnd(GRAPHICSTHREAD_IMMEDIATE);
}
wiProfiler::EndRange(); // Occlusion Culling Read
wiProfiler::EndRange(range); // Occlusion Culling Read
}
void EndFrame()
{
@@ -4538,7 +4529,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID)
const Scene& scene = GetScene();
device->EventBegin("Light Render", threadID);
wiProfiler::BeginRange("Light Render", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Light Render", wiProfiler::DOMAIN_GPU, threadID);
// Environmental light (envmap + voxelGI) is always drawn
{
@@ -4611,7 +4602,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID)
}
wiProfiler::EndRange(threadID);
wiProfiler::EndRange(range);
device->EventEnd(threadID);
}
void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID)
@@ -4950,7 +4941,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui
if (!culling.culledLights.empty())
{
device->EventBegin("ShadowMap Render", threadID);
wiProfiler::BeginRange("Shadow Rendering", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Shadow Rendering", wiProfiler::DOMAIN_GPU, threadID);
BindConstantBuffers(VS, threadID);
BindConstantBuffers(PS, threadID);
@@ -5234,7 +5225,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui
device->BindRenderTargets(0, nullptr, nullptr, threadID);
wiProfiler::EndRange(); // Shadow Rendering
wiProfiler::EndRange(range); // Shadow Rendering
device->EventEnd(threadID);
}
}
@@ -5247,6 +5238,7 @@ void DrawScene(const CameraComponent& camera, bool tessellation, GRAPHICSTHREAD
device->EventBegin("DrawScene", threadID);
BindCommonResources(threadID);
BindShadowmaps(PS, threadID);
BindConstantBuffers(VS, threadID);
BindConstantBuffers(PS, threadID);
@@ -5329,6 +5321,7 @@ void DrawScene_Transparent(const CameraComponent& camera, RENDERPASS renderPass,
device->EventBegin("DrawScene_Transparent", threadID);
BindCommonResources(threadID);
BindShadowmaps(PS, threadID);
BindConstantBuffers(VS, threadID);
BindConstantBuffers(PS, threadID);
@@ -5403,6 +5396,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID)
device->EventBegin("DrawDebugWorld", threadID);
BindCommonResources(threadID);
BindConstantBuffers(VS, threadID);
BindConstantBuffers(PS, threadID);
@@ -6576,7 +6570,7 @@ void VoxelRadiance(GRAPHICSTHREAD threadID)
GraphicsDevice* device = GetDevice();
device->EventBegin("Voxel Radiance", threadID);
wiProfiler::BeginRange("Voxel Radiance", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Voxel Radiance", wiProfiler::DOMAIN_GPU, threadID);
const Scene& scene = GetScene();
@@ -6724,7 +6718,7 @@ void VoxelRadiance(GRAPHICSTHREAD threadID)
device->BindResource(PS, result, TEXSLOT_VOXELRADIANCE, threadID);
device->BindResource(CS, result, TEXSLOT_VOXELRADIANCE, threadID);
wiProfiler::EndRange(threadID);
wiProfiler::EndRange(range);
device->EventEnd(threadID);
}
@@ -6740,7 +6734,7 @@ inline XMUINT3 GetEntityCullingTileCount()
void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuffer_diffuse, const Texture2D* lightbuffer_specular)
{
const bool deferred = lightbuffer_diffuse != nullptr && lightbuffer_specular != nullptr;
wiProfiler::BeginRange("Entity Culling", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Entity Culling", wiProfiler::DOMAIN_GPU, threadID);
GraphicsDevice* device = GetDevice();
int _width = GetInternalResolution().x;
@@ -6910,7 +6904,7 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf
device->EventEnd(threadID);
}
wiProfiler::EndRange(threadID);
wiProfiler::EndRange(range);
}
@@ -7362,7 +7356,7 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA
// Begin raytrace
wiProfiler::BeginRange("RayTrace - ALL", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("RayTrace - ALL", wiProfiler::DOMAIN_GPU, threadID);
const XMFLOAT4& halton = wiMath::GetHaltonSequence((int)GetDevice()->GetFrameCount());
TracedRenderingCB cb;
@@ -7453,13 +7447,15 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA
// 1.) Compute Primary Trace (closest hit)
{
device->EventBegin("Primary Rays", threadID);
wiProfiler::range_id range;
if (bounce == 0)
{
wiProfiler::BeginRange("RayTrace - First Contact", wiProfiler::DOMAIN_GPU, threadID);
range = wiProfiler::BeginRange("RayTrace - First Contact", wiProfiler::DOMAIN_GPU, threadID);
}
else if (bounce == 1)
{
wiProfiler::BeginRange("RayTrace - First Bounce", wiProfiler::DOMAIN_GPU, threadID);
range = wiProfiler::BeginRange("RayTrace - First Bounce", wiProfiler::DOMAIN_GPU, threadID);
}
device->BindComputePSO(&CPSO[CSTYPE_RAYTRACE_PRIMARY], threadID);
@@ -7486,7 +7482,7 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA
if (bounce == 0 || bounce == 1)
{
wiProfiler::EndRange(threadID); // RayTrace - First Bounce
wiProfiler::EndRange(range); // RayTrace - First Bounce
}
device->EventEnd(threadID);
}
@@ -7503,9 +7499,11 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA
// 3.) Light sampling (any hit) <- only after first bounce has occured
{
device->EventBegin("Light Sampling Rays", threadID);
wiProfiler::range_id range;
if (bounce == 1)
{
wiProfiler::BeginRange("RayTrace - First Light Sampling", wiProfiler::DOMAIN_GPU, threadID);
range = wiProfiler::BeginRange("RayTrace - First Light Sampling", wiProfiler::DOMAIN_GPU, threadID);
}
device->BindComputePSO(&CPSO[CSTYPE_RAYTRACE_LIGHTSAMPLING], threadID);
@@ -7528,14 +7526,14 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA
if (bounce == 1)
{
wiProfiler::EndRange(threadID); // RayTrace - First Light Sampling
wiProfiler::EndRange(range); // RayTrace - First Light Sampling
}
device->EventEnd(threadID);
}
}
wiProfiler::EndRange(threadID); // RayTrace - ALL
wiProfiler::EndRange(range); // RayTrace - ALL
@@ -7959,7 +7957,7 @@ void RefreshLightmapAtlas(GRAPHICSTHREAD threadID)
if (!lightmapsToRefresh.empty())
{
wiProfiler::BeginRange("Lightmap Processing", wiProfiler::DOMAIN_GPU, threadID);
auto range = wiProfiler::BeginRange("Lightmap Processing", wiProfiler::DOMAIN_GPU, threadID);
// Update GPU scene and BVH data:
{
@@ -8012,7 +8010,7 @@ void RefreshLightmapAtlas(GRAPHICSTHREAD threadID)
}
wiProfiler::EndRange(threadID);
wiProfiler::EndRange(range);
}
device->BindResource(PS, GetGlobalLightmap(), TEXSLOT_GLOBALLIGHTMAP, threadID);
@@ -8043,6 +8041,15 @@ void BindCommonResources(GRAPHICSTHREAD threadID)
device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID);
device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID);
}
// Bind the GPU entity array for all shaders that need it here:
GPUResource* resources[] = {
&resourceBuffers[RBTYPE_ENTITYARRAY],
&resourceBuffers[RBTYPE_MATRIXARRAY],
};
device->BindResources(VS, resources, SBSLOT_ENTITYARRAY, ARRAYSIZE(resources), threadID);
device->BindResources(PS, resources, SBSLOT_ENTITYARRAY, ARRAYSIZE(resources), threadID);
device->BindResources(CS, resources, SBSLOT_ENTITYARRAY, ARRAYSIZE(resources), threadID);
}
void UpdateFrameCB(GRAPHICSTHREAD threadID)