Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions D3D11Engine/BaseLineRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
#include "pch.h"
#include "BaseLineRenderer.h"
#include "Logger.h"

BaseLineRenderer::BaseLineRenderer() {}

BaseLineRenderer::~BaseLineRenderer() {}

/** Adds a line to the list */
XRESULT BaseLineRenderer::AddLine( const LineVertex& v1, const LineVertex& v2 ) {
if ( LineCache.size() + 2 > kMaxCachedVertices ) {
if ( !CacheOverflowLogged ) {
LogWarn() << "Debug-line cache full (" << kMaxCachedVertices
<< " vertices). Further lines are dropped until it is flushed.";
CacheOverflowLogged = true;
}
return XR_FAILED;
}

LineCache.push_back( v1 );
LineCache.push_back( v2 );
return XR_SUCCESS;
}

/** Adds a screen-space line to the list */
XRESULT BaseLineRenderer::AddLineScreenSpace( const LineVertex& v1, const LineVertex& v2 ) {
if ( ScreenSpaceLineCache.size() + 2 > kMaxCachedVertices ) {
if ( !CacheOverflowLogged ) {
LogWarn() << "Screen-space debug-line cache full (" << kMaxCachedVertices
<< " vertices). Further lines are dropped until it is flushed.";
CacheOverflowLogged = true;
}
return XR_FAILED;
}

ScreenSpaceLineCache.push_back( v1 );
ScreenSpaceLineCache.push_back( v2 );
return XR_SUCCESS;
}

/** Clears the line cache */
XRESULT BaseLineRenderer::ClearCache() {
LineCache.clear();
ScreenSpaceLineCache.clear();
CacheOverflowLogged = false;
return XR_SUCCESS;
}

/** Plots a vector of floats */
void BaseLineRenderer::PlotNumbers( const std::vector<float>& values, const XMFLOAT3& location, const XMFLOAT3& direction, float distance, float heightScale, const XMFLOAT4& color ) {
for ( unsigned int i = 1; i < values.size(); i++ ) {
Expand Down
17 changes: 14 additions & 3 deletions D3D11Engine/BaseLineRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class BaseLineRenderer {
virtual ~BaseLineRenderer();

/** Adds a line to the list */
virtual XRESULT AddLine( const LineVertex& v1, const LineVertex& v2 ) = 0;
virtual XRESULT AddLineScreenSpace( const LineVertex& v1, const LineVertex& v2 ) = 0;
virtual XRESULT AddLine( const LineVertex& v1, const LineVertex& v2 );
virtual XRESULT AddLineScreenSpace( const LineVertex& v1, const LineVertex& v2 );

/** Flushes the cached lines */
virtual XRESULT Flush() = 0;
virtual XRESULT FlushScreenSpace() = 0;

/** Clears the line cache */
virtual XRESULT ClearCache() = 0;
virtual XRESULT ClearCache();

/** Adds a point locator to the renderlist */
void AddPointLocator( const XMFLOAT3& location, float size = 1, const XMFLOAT4& color = XMFLOAT4( 1, 1, 1, 1 ) );
Expand All @@ -64,5 +64,16 @@ class BaseLineRenderer {

/** Draws a wireframe mesh */
void AddWireframeMesh( const std::vector<ExVertexStruct>& vertices, const std::vector<VERTEX_INDEX>& indices, const XMFLOAT4& color = XMFLOAT4( 1, 1, 1, 1 ), const XMFLOAT4X4* world = nullptr );

protected:
// Hard cap per list, in VERTICES (two per line). Nothing drains these lists unless a frame actually
// renders the world, so an unbounded push (a stuck editor overlay, a world that never renders) would
// otherwise grow forever. 1M vertices = 32 MB of cache — far past anything the debug overlays emit.
static constexpr size_t kMaxCachedVertices = 1u << 20;

/** Line cache, shared storage for backends to Flush()/FlushScreenSpace() from */
std::vector<LineVertex> LineCache;
std::vector<LineVertex> ScreenSpaceLineCache;
bool CacheOverflowLogged = false;
};

13 changes: 7 additions & 6 deletions D3D11Engine/D3D11Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "D3D11VShader.h"
#include "D3D11GShader.h"
#include "D3D11PShader.h"
#include "D3D11PipelineStateCache.h"
#include "GSky.h"
#include <DDSTextureLoader.h>
#include "RenderToTextureBuffer.h"
Expand Down Expand Up @@ -201,12 +202,12 @@ XRESULT D3D11Effect::DrawRain() {
e->GetContext()->SOSetTargets( 1, D3D11VertexBuffer::From( RainBufferStreamTo.get() )->GetVertexBuffer().GetAddressOf(), &offset );

// Apply shaders
e->GetContext()->PSSetShader( nullptr, nullptr, 0 );
D3D11PipelineStateCache::SetPixelShader( e->GetContext().Get(), nullptr );
particleAdvanceVS->Apply();
streamOutGS->Apply();

// Rendering points only
e->GetContext()->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST );
D3D11PipelineStateCache::SetPrimitiveTopology( e->GetContext().Get(), D3D11_PRIMITIVE_TOPOLOGY_POINTLIST );
e->SetDefaultStates();
e->UpdateRenderStates();

Expand Down Expand Up @@ -236,7 +237,7 @@ XRESULT D3D11Effect::DrawRain() {
state.RasterizerState.SetDirty();

// Rendering instances only
e->GetContext()->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
D3D11PipelineStateCache::SetPrimitiveTopology( e->GetContext().Get(), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
e->UpdateRenderStates();

// Apply particle shaders
Expand Down Expand Up @@ -283,7 +284,7 @@ XRESULT D3D11Effect::DrawRain() {
}

// Reset this
e->GetContext()->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
D3D11PipelineStateCache::SetPrimitiveTopology( e->GetContext().Get(), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
e->GetContext()->GSSetShader( nullptr, 0, 0 );
return XR_SUCCESS;
}
Expand Down Expand Up @@ -395,7 +396,7 @@ XRESULT D3D11Effect::DrawRain_CS() {
state.RasterizerState.SetDirty();

// Rendering instances only
e->GetContext()->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
D3D11PipelineStateCache::SetPrimitiveTopology( e->GetContext().Get(), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
e->UpdateRenderStates();

// Apply particle shaders
Expand Down Expand Up @@ -441,7 +442,7 @@ XRESULT D3D11Effect::DrawRain_CS() {
}

// Reset primitive topology
e->GetContext()->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
D3D11PipelineStateCache::SetPrimitiveTopology( e->GetContext().Get(), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
return XR_SUCCESS;
}

Expand Down
3 changes: 2 additions & 1 deletion D3D11Engine/D3D11ForwardPlusRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "GothicAPI.h"
#include "GothicGraphicsState.h"
#include "ConstantBufferStructs.h"
#include "D3D11PipelineStateCache.h"
#include "GSky.h"
#include "zCTexture.h"
#include "zCMaterial.h"
Expand Down Expand Up @@ -64,7 +65,7 @@ void D3D11ForwardPlusRenderer::AddGeometryPasses(
context->OMSetRenderTargets( 1, &nullRTV, dsv );

// Disable pixel shader for depth-only rendering
context->PSSetShader( nullptr, nullptr, 0 );
D3D11PipelineStateCache::SetPixelShader( context.Get(), nullptr );

engine.SetRenderingStage( D3D11ENGINE_RENDER_STAGE::DES_Z_PRE_PASS );

Expand Down
Loading