mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 22:50:45 +00:00
SP: Update debug drawing so that it's only allocating vertex/index buffer once.
This commit is contained in:
parent
1e30b08363
commit
f451b41981
4 changed files with 38 additions and 42 deletions
|
@ -40,12 +40,12 @@ extern DeviceManager* deviceManager;
|
|||
|
||||
namespace
|
||||
{
|
||||
const int c_drawVertsCapacity = ( 20000 * 4 );
|
||||
//const int c_drawIndexesCapacity = ( 20000 * 6 );
|
||||
const int c_drawVertsCapacity = ( 40000 * 4 );
|
||||
const int c_drawIndexesCapacity = ( c_drawVertsCapacity * 2 );
|
||||
|
||||
idDrawVert drawVerts[c_drawVertsCapacity];
|
||||
triIndex_t lineIndices[c_drawVertsCapacity * 2];
|
||||
triIndex_t sphereIndices[c_drawVertsCapacity * 2];
|
||||
triIndex_t lineIndices[c_drawIndexesCapacity];
|
||||
triIndex_t sphereIndices[c_drawIndexesCapacity];
|
||||
|
||||
bool active = false;
|
||||
}
|
||||
|
@ -53,7 +53,10 @@ bool active = false;
|
|||
int fhImmediateMode::drawCallCount = 0;
|
||||
int fhImmediateMode::drawCallVertexSize = 0;
|
||||
|
||||
void fhImmediateMode::Init()
|
||||
idVertexBuffer fhImmediateMode::vertexBuffer;
|
||||
idIndexBuffer fhImmediateMode::indexBuffer;
|
||||
|
||||
void fhImmediateMode::Init( nvrhi::ICommandList* commandList )
|
||||
{
|
||||
for( int i = 0; i < c_drawVertsCapacity * 2; ++i )
|
||||
{
|
||||
|
@ -61,6 +64,7 @@ void fhImmediateMode::Init()
|
|||
}
|
||||
|
||||
ResetStats();
|
||||
InitBuffers( commandList );
|
||||
}
|
||||
|
||||
void fhImmediateMode::ResetStats()
|
||||
|
@ -68,6 +72,7 @@ void fhImmediateMode::ResetStats()
|
|||
drawCallCount = 0;
|
||||
drawCallVertexSize = 0;
|
||||
}
|
||||
|
||||
int fhImmediateMode::DrawCallCount()
|
||||
{
|
||||
return drawCallCount;
|
||||
|
@ -78,6 +83,14 @@ int fhImmediateMode::DrawCallVertexSize()
|
|||
return drawCallVertexSize;
|
||||
}
|
||||
|
||||
void fhImmediateMode::InitBuffers( nvrhi::ICommandList* commandList )
|
||||
{
|
||||
commandList->open();
|
||||
vertexBuffer.AllocBufferObject( nullptr, c_drawVertsCapacity * sizeof( idDrawVert ), bufferUsageType_t::BU_STATIC, commandList );
|
||||
indexBuffer.AllocBufferObject( nullptr, c_drawIndexesCapacity * sizeof( triIndex_t ), bufferUsageType_t::BU_STATIC, commandList );
|
||||
commandList->close();
|
||||
deviceManager->GetDevice()->executeCommandList( commandList );
|
||||
}
|
||||
|
||||
fhImmediateMode::fhImmediateMode( nvrhi::ICommandList* _commandList, bool geometryOnly ) :
|
||||
commandList( _commandList ),
|
||||
|
@ -116,27 +129,8 @@ void fhImmediateMode::End()
|
|||
return;
|
||||
}
|
||||
|
||||
nvrhi::BufferDesc vertexBufferDesc;
|
||||
vertexBufferDesc.byteSize = drawVertsUsed * sizeof( idDrawVert );
|
||||
vertexBufferDesc.isVertexBuffer = true;
|
||||
vertexBufferDesc.debugName = "VertexBuffer";
|
||||
vertexBufferDesc.initialState = nvrhi::ResourceStates::CopyDest;
|
||||
vertexBuffer = deviceManager->GetDevice()->createBuffer( vertexBufferDesc );
|
||||
|
||||
commandList->beginTrackingBufferState( vertexBuffer, nvrhi::ResourceStates::CopyDest );
|
||||
commandList->writeBuffer( vertexBuffer, drawVerts, drawVertsUsed * sizeof( idDrawVert ) );
|
||||
commandList->setPermanentBufferState( vertexBuffer, nvrhi::ResourceStates::VertexBuffer );
|
||||
|
||||
nvrhi::BufferDesc indexBufferDesc;
|
||||
indexBufferDesc.byteSize = drawVertsUsed * sizeof( triIndex_t );
|
||||
indexBufferDesc.isIndexBuffer = true;
|
||||
indexBufferDesc.debugName = "IndexBuffer";
|
||||
indexBufferDesc.initialState = nvrhi::ResourceStates::CopyDest;
|
||||
indexBuffer = deviceManager->GetDevice()->createBuffer( indexBufferDesc );
|
||||
|
||||
commandList->beginTrackingBufferState( indexBuffer, nvrhi::ResourceStates::CopyDest );
|
||||
commandList->writeBuffer( indexBuffer, lineIndices, drawVertsUsed * sizeof( triIndex_t ) );
|
||||
commandList->setPermanentBufferState( indexBuffer, nvrhi::ResourceStates::IndexBuffer );
|
||||
vertexBuffer.Update( drawVerts, drawVertsUsed * sizeof( idDrawVert ), 0, false, commandList );
|
||||
indexBuffer.Update( lineIndices, drawVertsUsed * sizeof( triIndex_t ), 0, false, commandList );
|
||||
|
||||
renderProgManager.CommitConstantBuffer( commandList );
|
||||
|
||||
|
@ -167,8 +161,8 @@ void fhImmediateMode::End()
|
|||
state.bindings.push_back( tr.backend.currentBindingSets[i] );
|
||||
}
|
||||
|
||||
state.indexBuffer = { indexBuffer, nvrhi::Format::R16_UINT, 0 };
|
||||
state.vertexBuffers = { { vertexBuffer, 0, 0 } };
|
||||
state.indexBuffer = { indexBuffer.GetAPIObject(), nvrhi::Format::R16_UINT, 0};
|
||||
state.vertexBuffers = { { vertexBuffer.GetAPIObject(), 0, 0 } };
|
||||
state.pipeline = pipeline;
|
||||
state.framebuffer = tr.backend.currentFrameBuffer->GetApiObject();
|
||||
|
||||
|
|
|
@ -72,14 +72,17 @@ public:
|
|||
|
||||
static void AddTrianglesFromPolygon( fhImmediateMode& im, const idVec3* xyz, int num );
|
||||
|
||||
static void Init();
|
||||
static void Init( nvrhi::ICommandList* commandList );
|
||||
static void ResetStats();
|
||||
static int DrawCallCount();
|
||||
static int DrawCallVertexSize();
|
||||
private:
|
||||
|
||||
static void InitBuffers( nvrhi::ICommandList* commandList );
|
||||
|
||||
nvrhi::CommandListHandle commandList;
|
||||
nvrhi::BufferHandle vertexBuffer;
|
||||
nvrhi::BufferHandle indexBuffer;
|
||||
static idVertexBuffer vertexBuffer;
|
||||
static idIndexBuffer indexBuffer;
|
||||
|
||||
bool geometryOnly;
|
||||
float currentTexCoord[2];
|
||||
|
|
|
@ -115,7 +115,7 @@ bool idVertexBuffer::AllocBufferObject( const void* data, int allocSize, bufferU
|
|||
}
|
||||
else
|
||||
{
|
||||
vertexBufferDesc.initialState = nvrhi::ResourceStates::Common;
|
||||
vertexBufferDesc.initialState = nvrhi::ResourceStates::CopyDest;
|
||||
vertexBufferDesc.keepInitialState = true;
|
||||
vertexBufferDesc.debugName = "Static idDrawVert vertex buffer";
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ bool idVertexBuffer::AllocBufferObject( const void* data, int allocSize, bufferU
|
|||
}
|
||||
|
||||
// copy the data
|
||||
if( data != NULL )
|
||||
if( data )
|
||||
{
|
||||
Update( data, allocSize, 0, true, commandList );
|
||||
}
|
||||
|
@ -196,9 +196,9 @@ void idVertexBuffer::Update( const void* data, int updateSize, int offset, bool
|
|||
{
|
||||
if( initialUpdate )
|
||||
{
|
||||
commandList->beginTrackingBufferState( bufferHandle, nvrhi::ResourceStates::Common );
|
||||
commandList->beginTrackingBufferState( bufferHandle, nvrhi::ResourceStates::CopyDest );
|
||||
commandList->writeBuffer( bufferHandle, data, numBytes, GetOffset() + offset );
|
||||
commandList->setPermanentBufferState( bufferHandle, nvrhi::ResourceStates::ShaderResource | nvrhi::ResourceStates::VertexBuffer );
|
||||
commandList->setPermanentBufferState( bufferHandle, nvrhi::ResourceStates::VertexBuffer );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -309,21 +309,20 @@ bool idIndexBuffer::AllocBufferObject( const void* data, int allocSize, bufferUs
|
|||
nvrhi::BufferDesc indexBufferDesc;
|
||||
indexBufferDesc.byteSize = numBytes;
|
||||
indexBufferDesc.isIndexBuffer = true;
|
||||
indexBufferDesc.initialState = nvrhi::ResourceStates::Common;
|
||||
indexBufferDesc.initialState = nvrhi::ResourceStates::CopyDest;
|
||||
indexBufferDesc.canHaveRawViews = true;
|
||||
indexBufferDesc.canHaveTypedViews = true;
|
||||
indexBufferDesc.format = nvrhi::Format::R16_UINT;
|
||||
|
||||
if( _usage == BU_STATIC )
|
||||
{
|
||||
indexBufferDesc.debugName = "VertexCache Static Index Buffer";
|
||||
indexBufferDesc.keepInitialState = true;
|
||||
indexBufferDesc.debugName = "VertexCache Static Index Buffer";
|
||||
}
|
||||
else if( _usage == BU_DYNAMIC )
|
||||
{
|
||||
indexBufferDesc.debugName = "VertexCache Mapped Index Buffer";
|
||||
indexBufferDesc.initialState = nvrhi::ResourceStates::CopyDest;
|
||||
indexBufferDesc.cpuAccess = nvrhi::CpuAccessMode::Write;
|
||||
indexBufferDesc.debugName = "VertexCache Mapped Index Buffer";
|
||||
}
|
||||
|
||||
bufferHandle = deviceManager->GetDevice()->createBuffer( indexBufferDesc );
|
||||
|
@ -396,9 +395,9 @@ void idIndexBuffer::Update( const void* data, int updateSize, int offset, bool i
|
|||
{
|
||||
if( initialUpdate )
|
||||
{
|
||||
commandList->beginTrackingBufferState( bufferHandle, nvrhi::ResourceStates::Common );
|
||||
commandList->beginTrackingBufferState( bufferHandle, nvrhi::ResourceStates::CopyDest );
|
||||
commandList->writeBuffer( bufferHandle, data, numBytes, GetOffset() + offset );
|
||||
commandList->setPermanentBufferState( bufferHandle, nvrhi::ResourceStates::IndexBuffer | nvrhi::ResourceStates::ShaderResource );
|
||||
commandList->setPermanentBufferState( bufferHandle, nvrhi::ResourceStates::IndexBuffer );
|
||||
commandList->commitBarriers();
|
||||
}
|
||||
else
|
||||
|
|
|
@ -160,7 +160,7 @@ void idRenderBackend::Init()
|
|||
commandList->close();
|
||||
deviceManager->GetDevice()->executeCommandList( commandList );
|
||||
|
||||
fhImmediateMode::Init();
|
||||
fhImmediateMode::Init( commandList );
|
||||
|
||||
// allocate the frame data, which may be more if smp is enabled
|
||||
R_InitFrameData();
|
||||
|
|
Loading…
Reference in a new issue