20 uint32_t startVertexLocation) {
22 std::move(vertexBuffer), std::move(constantBuffers),
23 vertexCount, startVertexLocation);
29 uint32_t startIndexLocation, int32_t baseVertexLocation,
32 std::move(vertexBuffer), std::move(indexBuffer),
33 std::move(constantBuffers), indexCount, startIndexLocation,
45 std::move(buffer), Data, Size);
69 const auto& commands = CurrentArena().Commands();
73 cachedShadowDraws.clear();
78 auto type = cmd->GetType();
82 if (bindCmd->GetSlot() == 0) {
83 lastSlot0Buffer = &bindCmd->GetBuffer();
84 }
else if (bindCmd->GetSlot() == 3) {
85 lastSlot3Buffer = &bindCmd->GetBuffer();
90 lastSlot0Buffer && *lastSlot0Buffer &&
99 cachedShadowDraws.push_back(entry);
115 auto& pendingState = m_pendingState;
116 auto& forwardCmds = m_forwardCmds;
117 pendingState.clear();
121 bool lastMaterialForward =
false;
131 auto type = cmd->GetType();
135 lastMaterial = bmc->GetMaterial();
138 pendingState.push_back(cmd);
145 forwardCmds.insert(forwardCmds.end(),
146 pendingState.begin(),
148 pendingState.clear();
149 forwardCmds.push_back(cmd);
150 lastMaterial =
nullptr;
151 lastMaterialForward =
false;
155 if (isStateCmd(type)) {
156 pendingState.push_back(cmd);
164 const bool isSkinned = cmd->IsSkinned();
165 if (lastMaterialForward || isSkinned) {
167 forwardCmds.insert(forwardCmds.end(),
168 pendingState.begin(),
170 forwardCmds.push_back(cmd);
173 for (
auto& s : pendingState) s->Execute(context);
174 cmd->Execute(context);
176 pendingState.clear();
181 cmd->Execute(context);
189 cmd->Execute(context);
205 if (entry.transformBuffer && *entry.transformBuffer) {
210 if (entry.boneBuffer && *entry.boneBuffer) {
213 entry.command->ExecuteShadow(context);
233 cachedShadowDraws.clear();
234 m_pendingState.clear();
235 m_forwardCmds.clear();
236 for (CommandArena& arena : m_arenas) arena.Reset();
240 void RenderCommandQueue::AdvanceArena() {
241 m_pendingState.clear();
242 m_forwardCmds.clear();
243 m_currentArena = (m_currentArena + 1) % ARENA_COUNT;
244 CurrentArena().Reset();
247 void* RenderCommandQueue::CommandArena::Allocate(
size_t size,
250 if (m_blockIndex < m_blocks.size()) {
251 Block& block = m_blocks[m_blockIndex];
253 (m_offset + alignment - 1) & ~(alignment - 1);
254 if (start + size <= block.size) {
255 m_offset = start + size;
256 return block.data.get() + start;
262 const size_t blockSize = std::max(BLOCK_SIZE, size + alignment);
264 {std::make_unique<std::byte[]>(blockSize), blockSize});
268 void RenderCommandQueue::CommandArena::Reset() {
269 for (RenderCommandBase* command : m_commands)
270 command->~RenderCommandBase();
278 Instance->ClearAll();
Implements a dynamic array-like list for storing and managing a collection of elements.
bool IsForwardRendered() const
True when this material must skip the GBuffer and render in the forward transparent pass.
Binds a constant buffer to a pipeline slot.
Binds a material's shader and textures for subsequent draws.
Wraps an arbitrary callback as a queueable render command.
std::function< void(RenderContext *)> ExecuteFunction
Non-indexed draw command with its vertex and constant buffers.
Indexed draw command with its vertex, index, and constant buffers.
One recorded draw plus the state it needs to replay into a command list.
void SetCastsShadow(bool v)
Frame-scoped queue of recorded draw/state commands, replayed into a RenderContext at flush time.
void Clear()
Drops queued commands for the current frame, keeping the cached shadow draw list.
void SubmitUpdateConstantBuffer(RefPtr< BufferBase > buffer, void *Data, uint16_t Size)
Queues a constant buffer write with data captured at submit time.
void SubmitSetRenderMode(RenderMode mode)
void SubmitCustomCommand(CustomCommand::ExecuteFunction function)
Queues an arbitrary callback to run inline with other render commands.
void ExecuteCommands(RenderContext *context)
void SubmitBindMaterial(::Sleak::Material *material)
Queues a material bind, switching shader/texture state for subsequent draws.
void ExecuteShadowPass(RenderContext *context)
void SubmitDrawIndexed(RefPtr< BufferBase > vertexBuffer, RefPtr< BufferBase > indexBuffer, List< RefPtr< BufferBase > > constantBuffers, uint32_t indexCount, uint32_t startIndexLocation=0, int32_t baseVertexLocation=0, bool castsShadow=true)
Queues an indexed draw with its vertex/index buffers and constant buffers.
void ClearAll()
Drops queued commands and the cached shadow draw list.
void SubmitDraw(RefPtr< BufferBase > vertexBuffer, List< RefPtr< BufferBase > > constantBuffers, uint32_t vertexCount, uint32_t startVertexLocation=0)
Queues a non-indexed draw with its vertex buffer and constant buffers.
void SubmitSetRenderFace(RenderFace face)
void SubmitBindConstantBuffer(RefPtr< BufferBase > buffer, uint8_t slot)
Queues a constant buffer bind at the given slot.
Abstract interface for high-level graphics command execution and resource management.
virtual void BeginForwardTransparentPass()
virtual void BindBoneBuffer(RefPtr< BufferBase > buffer)
virtual void EndForwardTransparentPass()
virtual bool IsDeferredEnabled() const
virtual void ExecuteDeferredLightingPass()
virtual void BindConstantBuffer(RefPtr< BufferBase > buffer, uint32_t slot=0)=0
Switches the cull-face mode.
Switches the rasterizer fill mode.
Constant buffer write, captured by value into inline storage or a heap fallback for larger payloads.
Backend-facing rendering layer shared by the four graphics backends.
CommandType
Discriminator for RenderCommandBase subclasses, used for sorting and batching.
RenderMode
Rasterizer fill style for a draw.
RenderFace
Which triangle winding gets culled.
Root namespace for everything the engine exposes.
A draw command paired with the transform/bone buffers it needs to replay in the shadow pass.
const RefPtr< BufferBase > * boneBuffer
RenderCommandBase * command
const RefPtr< BufferBase > * transformBuffer