Skip to content

Commit 41368de

Browse files
committed
Refactor: DirectX and OpenGL render backends now use command buffers internally, so the command execution can be tracked
1 parent 7e515fe commit 41368de

File tree

12 files changed

+224
-374
lines changed

12 files changed

+224
-374
lines changed

Source/Foundation/bsfCore/RenderAPI/BsRenderAPI.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ namespace bs
447447
*/
448448
virtual void submitCommandBuffer(const SPtr<CommandBuffer>& commandBuffer, UINT32 syncMask = 0xFFFFFFFF) = 0;
449449

450+
/**
451+
* Returns the currently active main command buffer instance. All commands queues without a user-provided command
452+
* buffer will be queued on this command buffer. The command buffer instance will change after it has been submitted.
453+
*/
454+
virtual SPtr<CommandBuffer> getMainCommandBuffer() const = 0;
455+
450456
/**
451457
* Gets the capabilities of a specific GPU.
452458
*

Source/Plugins/bsfD3D11RenderAPI/BsD3D11CommandBuffer.cpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,13 @@ namespace bs { namespace ct
2222
return;
2323
}
2424
#endif
25-
26-
mCommands.push_back(command);
27-
}
28-
29-
void D3D11CommandBuffer::appendSecondary(const SPtr<D3D11CommandBuffer>& secondaryBuffer)
30-
{
31-
#if BS_DEBUG_MODE
32-
if (!secondaryBuffer->mIsSecondary)
33-
{
34-
BS_LOG(Error, RenderBackend, "Cannot append a command buffer that is not secondary.");
35-
return;
36-
}
3725

38-
if (mIsSecondary)
39-
{
40-
BS_LOG(Error, RenderBackend, "Cannot append a buffer to a secondary command buffer.");
41-
return;
42-
}
43-
#endif
44-
45-
for (auto& entry : secondaryBuffer->mCommands)
46-
mCommands.push_back(entry);
26+
// We don't support command buffer queuing on DX11, so we just execute the command right away. This means
27+
// if caller uses a non-main command buffer the behaviour will likely be incorrect. To properly support
28+
// command queuing we'd need to remember state of GpuParams when first bound and handles updates to
29+
// buffers after they are bound (and potentially other things).
30+
command();
31+
mCommandQueued = true;
4732
}
4833

4934
void D3D11CommandBuffer::executeCommands()
@@ -62,9 +47,6 @@ namespace bs { namespace ct
6247
}
6348
#endif
6449

65-
for (auto& entry : mCommands)
66-
entry();
67-
6850
mFence = bs_shared_ptr_new<D3D11EventQuery>(mDeviceIdx);
6951
mFence->begin();
7052
mIsSubmitted = true;
@@ -75,12 +57,12 @@ namespace bs { namespace ct
7557
if (mIsSubmitted)
7658
return isComplete() ? CommandBufferState::Done : CommandBufferState::Executing;
7759

78-
return mCommands.empty() ? CommandBufferState::Empty : CommandBufferState::Recording;
60+
return mCommandQueued ? CommandBufferState::Recording : CommandBufferState::Empty;
7961
}
8062

8163
void D3D11CommandBuffer::reset()
8264
{
83-
mCommands.clear();
65+
mCommandQueued = false;
8466
mIsSubmitted = false;
8567
}
8668

Source/Plugins/bsfD3D11RenderAPI/BsD3D11CommandBuffer.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ namespace bs { namespace ct
2424
/** Registers a new command in the command buffer. */
2525
void queueCommand(const std::function<void()> command);
2626

27-
/** Appends all commands from the secondary buffer into this command buffer. */
28-
void appendSecondary(const SPtr<D3D11CommandBuffer>& secondaryBuffer);
29-
3027
/** Executes all commands in the command buffer. Not supported on secondary buffer. */
3128
void executeCommands();
3229

@@ -35,7 +32,7 @@ namespace bs { namespace ct
3532

3633
/** @copydoc CommandBuffer::reset() */
3734
void reset() override;
38-
35+
3936
private:
4037
friend class D3D11CommandBufferManager;
4138
friend class D3D11RenderAPI;
@@ -45,11 +42,9 @@ namespace bs { namespace ct
4542
/** Returns true if the command buffer has finished executing on the GPU. */
4643
bool isComplete() const;
4744

48-
Vector<std::function<void()>> mCommands;
4945
SPtr<D3D11EventQuery> mFence;
46+
bool mCommandQueued = false;
5047
bool mIsSubmitted = false;
51-
52-
DrawOperationType mActiveDrawOp = DOT_TRIANGLE_LIST;
5348
};
5449

5550
/** @} */

0 commit comments

Comments
 (0)