Skip to content

Commit

Permalink
skip a bit of unnecessary work in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Dec 3, 2024
1 parent fa9aab6 commit 9e2d4e4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
52 changes: 30 additions & 22 deletions WickedEngine/wiRenderPath3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2031,10 +2031,6 @@ namespace wi
{
GraphicsDevice* device = wi::graphics::GetDevice();

device->EventBegin("Copy scene tex only mip0 for ocean", cmd);
wi::renderer::Postprocess_Downsample4x(rtMain, rtSceneCopy, cmd);
device->EventEnd(cmd);

// Water ripple rendering:
if (!scene->waterRipples.empty())
{
Expand Down Expand Up @@ -2074,6 +2070,16 @@ namespace wi
device->Barrier(barriers, arraysize(barriers), cmd);
}

Rect scissor = GetScissorInternalResolution();
device->BindScissorRects(1, &scissor, cmd);

Viewport vp;
vp.width = (float)depthBuffer_Main.GetDesc().width;
vp.height = (float)depthBuffer_Main.GetDesc().height;
vp.min_depth = 0;
vp.max_depth = 1;
device->BindViewports(1, &vp, cmd);

RenderPassImage rp[] = {
RenderPassImage::RenderTarget(&rtMain_render, RenderPassImage::LoadOp::LOAD),
RenderPassImage::DepthStencil(
Expand All @@ -2086,29 +2092,30 @@ namespace wi
),
RenderPassImage::Resolve(&rtMain),
};
device->RenderPassBegin(rp, getMSAASampleCount() > 1 ? 3 : 2, cmd);

Rect scissor = GetScissorInternalResolution();
device->BindScissorRects(1, &scissor, cmd);
// Draw only the ocean first, fog and lightshafts will be blended on top:
if (scene->ocean.IsValid())
{
device->EventBegin("Copy scene tex only mip0 for ocean", cmd);
wi::renderer::Postprocess_Downsample4x(rtMain, rtSceneCopy, cmd);
device->EventEnd(cmd);

Viewport vp;
vp.width = (float)depthBuffer_Main.GetDesc().width;
vp.height = (float)depthBuffer_Main.GetDesc().height;
vp.min_depth = 0;
vp.max_depth = 1;
device->BindViewports(1, &vp, cmd);
device->RenderPassBegin(rp, getMSAASampleCount() > 1 ? 3 : 2, cmd);

// Draw only the ocean first, fog and lightshafts will be blended on top:
wi::renderer::DrawScene(
visibility_main,
RENDERPASS_MAIN,
cmd,
wi::renderer::DRAWSCENE_OCEAN
);
wi::renderer::DrawScene(
visibility_main,
RENDERPASS_MAIN,
cmd,
wi::renderer::DRAWSCENE_OCEAN
);

device->RenderPassEnd(cmd);
device->RenderPassEnd(cmd);
}

RenderSceneMIPChain(cmd);
if (visibility_main.IsTransparentsVisible())
{
RenderSceneMIPChain(cmd);
}

device->RenderPassBegin(rp, getMSAASampleCount() > 1 ? 3 : 2, cmd);

Expand Down Expand Up @@ -2141,6 +2148,7 @@ namespace wi
}

// Transparent scene
if (visibility_main.IsTransparentsVisible())
{
auto range = wi::profiler::BeginRangeGPU("Transparent Scene", cmd);
device->EventBegin("Transparent Scene", cmd);
Expand Down
5 changes: 5 additions & 0 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,11 @@ void UpdateVisibility(Visibility& vis)
vis.locker.unlock();
}

if (object.GetFilterMask() & FILTER_TRANSPARENT)
{
vis.transparents_visible.store(true);
}

if (vis.flags & Visibility::ALLOW_OCCLUSION_CULLING)
{
if (object.IsRenderable() && occlusion_result.occlusionQueries[vis.scene->queryheap_idx] < 0)
Expand Down
8 changes: 7 additions & 1 deletion WickedEngine/wiRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ namespace wi::renderer
float closestRefPlane = std::numeric_limits<float>::max();
XMFLOAT4 reflectionPlane = XMFLOAT4(0, 1, 0, 0);
std::atomic_bool volumetriclight_request{ false };
std::atomic_bool transparents_visible{ false };

void Clear()
{
Expand All @@ -161,6 +162,7 @@ namespace wi::renderer
closestRefPlane = std::numeric_limits<float>::max();
planar_reflection_visible = false;
volumetriclight_request.store(false);
transparents_visible.store(false);
}

bool IsRequestedPlanarReflections() const
Expand All @@ -171,6 +173,10 @@ namespace wi::renderer
{
return volumetriclight_request.load();
}
bool IsTransparentsVisible() const
{
return transparents_visible.load();
}
};

// Performs frustum culling.
Expand Down Expand Up @@ -242,7 +248,7 @@ namespace wi::renderer
DRAWSCENE_MAINCAMERA = 1 << 9, // If this is active, then ObjectComponent with SetNotVisibleInMainCamera(true) won't be drawn
};

// Draw the world from a camera. You must call BindCameraCB() at least once in this frame prior to this
// Draw the world from a camera. You must call BindCameraCB() at least once in this command list prior to this
void DrawScene(
const Visibility& vis,
wi::enums::RENDERPASS renderPass,
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 623;
const int revision = 624;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit 9e2d4e4

Please sign in to comment.