48 return lock._buffer == nullptr || lock._range._length == 0u;
56 return lock._sourceLayout == lock._targetLayout || lock._targetView._srcTexture == nullptr;
110 cmd->DeleteCmd( cmd );
123 if ( _commands.max_size() < reservedCmdCount )
125 _commands.reserve( reservedCmdCount );
133 _commands.reserve( _commands.size() + other._commands.size() );
144 if(other != INVALID_HANDLE<GFX::CommandBuffer> )
170 bool tryMerge =
true;
174 prevCommand =
nullptr;
178 if ( cmd ==
nullptr || ShouldSkipBatch( cmd->type() ) )
185 if ( prevCommand !=
nullptr &&
186 prevType == cmd->type() &&
189 cmd->DeleteCmd( cmd );
194 prevType = cmd->type();
200 while ( EraseEmptyCommands( _commands ) );
203 bool hasWork =
false;
211 switch ( cmd->type() )
242 hasWork = crtCmd->
_source != INVALID_HANDLE<Texture> && crtCmd->
_destination != INVALID_HANDLE<Texture>;
247 hasWork = crtCmd->
_texture != INVALID_HANDLE<Texture>;
260 const auto [error, lastCmdIndex] =
validate();
277 if ( _commands.empty() ) [[unlikely]]
291 const Pipeline* prevPipeline =
nullptr;
292 const Rect<I32>* prevScissorRect =
nullptr;
293 const Rect<I32>* prevViewportRect =
nullptr;
302 switch ( cmd->type() )
309 if ( cmds.size() == 1 )
311 erase = cmds.begin()->_drawCount == 0u;
315 erase = RemoveEmptyDrawCommands( cmds ) && cmds.empty();
324 if ( prevPipeline ==
nullptr || prevPipeline->stateHash() != pipeline->stateHash() )
326 prevPipeline = pipeline;
349 if ( bindCmd->_usage !=
DescriptorSetUsage::COUNT && (prevDescriptorSet ==
nullptr || *prevDescriptorSet != bindCmd->_set) )
351 prevDescriptorSet = &bindCmd->_set;
361 if (RemoveEmptyLocks( memCmd ))
363 erase =
IsEmpty( memCmd->_bufferLocks ) &&
364 IsEmpty( memCmd->_textureLayoutChanges);
372 if ( prevScissorRect ==
nullptr || *prevScissorRect != scissorRect )
374 prevScissorRect = &scissorRect;
384 erase = readCmd->
_buffer ==
nullptr ||
385 readCmd->_target.first ==
nullptr ||
386 readCmd->_elementCount == 0u ||
387 readCmd->_target.second == 0u;
395 if ( prevViewportRect ==
nullptr || *prevViewportRect != viewportRect )
397 prevViewportRect = &viewportRect;
434 if (EraseEmptyCommands( _commands ))
453 size_t cmdIndex = 0u;
454 bool pushedPass =
false, pushedQuery =
false, hasPipeline =
false;
456 I32 pushedDebugScope = 0, pushedCamera = 0, pushedViewport = 0;
461 switch ( cmd->type() )
472 for (
const auto& it : beginRenderPassCmd->_descriptor._writeLayers )
510 if ( pushedDebugScope == 0 )
550 if ( !(workGroupCount.
x > 0 &&
593 if ( pushedDebugScope != 0 )
597 if ( pushedCamera != 0 )
601 if ( pushedViewport != 0 )
611 const auto append = [](
string& target,
const string& text,
const I32 indent )
613 for (
I32 i = 0; i < indent; ++i )
615 target.append(
" " );
617 target.append( text );
644 string out =
"\n\n\n\n";
648 out.append(
"[ " + std::to_string( idx++ ) +
" ]: " );
649 ToString( *cmd, cmd->type(), crtIndent, out );
652 out.append(
"\n\n\n\n" );
660 if ( previousGDC._cmd.instanceCount != currentGDC._cmd.instanceCount && (previousGDC._cmd.instanceCount > 1 || currentGDC._cmd.instanceCount > 1) )
670 const U32 offsetCrt =
to_U32( currentGDC._commandOffset );
671 const U32 offsetPrev =
to_U32( previousGDC._commandOffset );
672 if ( offsetCrt - offsetPrev == previousGDC._drawCount )
675 previousGDC._drawCount += currentGDC._drawCount;
677 currentGDC._drawCount = 0;
689 commands.insert( cend( commands ),
690 eastl::make_move_iterator( begin( crtCommand->
_drawCommands ) ),
691 eastl::make_move_iterator( end( crtCommand->
_drawCommands ) ) );
696 eastl::sort( begin( commands ),
705 const size_t commandCount = commands.size();
706 for (
size_t previousCommandIndex = 0, currentCommandIndex = 1;
707 currentCommandIndex < commandCount;
708 ++currentCommandIndex )
710 if ( !
BatchDrawCommands( commands[previousCommandIndex], commands[currentCommandIndex] ) )
712 previousCommandIndex = currentCommandIndex;
716 while ( RemoveEmptyDrawCommands( commands ) );
790 bool partial =
false;
794 if ( lhsUniforms ==
nullptr )
796 lhsUniforms = rhsUniforms;
799 else if ( rhsUniforms ==
nullptr )
804 return Merge(*lhsUniforms, *rhsUniforms, partial);
#define PROFILE_SCOPE_AUTO(CATEGORY)
#define PROFILE_SCOPE(NAME, CATEGORY)
eastl::fixed_vector< CommandBase *, COMMAND_BUFFER_INIT_SIZE, true > CommandList
string toString() const
Multi-line. indented list of all commands (and params for some of them)
std::pair< ErrorType, size_t > validate() const
Verify that the commands in the buffer are valid and in the right order.
static const DeviceInformation & GetDeviceInformation() noexcept
FORCE_INLINE I64 getGUID() const noexcept
constexpr bool ENABLE_GPU_VALIDATION
Error callbacks, validations, buffer checks, etc. are controlled by this flag. Heavy performance impa...
static const char * errorType[]
bool EraseEmptyCommands(CommandBuffer::CommandList &commands)
bool RemoveEmptyDrawCommands(GenericDrawCommandContainer &commands)
FORCE_INLINE bool ShouldSkipBatch(const CommandType type) noexcept
bool RemoveEmptyLocks(GFX::MemoryBarrierCommand *memCmd)
void ToString(const CommandBase &cmd, const CommandType type, I32 &crtIndent, string &out)
CommandBuffer * Get(Handle< CommandBuffer > handle)
void AddCommandBufferToQueue(CommandBufferQueue &queue, const Handle< GFX::CommandBuffer > &commandBuffer)
void ResetCommandBufferQueue(CommandBufferQueue &queue)
bool BatchDrawCommands(GenericDrawCommand &previousGDC, GenericDrawCommand ¤tGDC) noexcept
@ MISSING_PUSH_DEBUG_SCOPE
@ INVALID_RENDER_PASS_FOR_PIPELINE
@ MISSING_POP_DEBUG_SCOPE
@ MISSING_BEGIN_RENDER_PASS
@ INVALID_BEGIN_RENDER_PASS
@ MISSING_END_RENDER_PASS
@ MISSING_BEGIN_GPU_QUERY
bool Merge(DrawCommand *prevCommand, DrawCommand *crtCommand)
void DeallocateCommandBuffer(Handle< CommandBuffer > &buffer)
bool TryMergeCommands(CommandType type, T *prevCommand, T *crtCommand)
constexpr Optick::Category::Type Graphics
Str StringFormat(const char *fmt, Args &&...args)
constexpr U8 INVALID_INDEX
constexpr U32 to_U32(const T value)
constexpr U16 to_U16(const T value)
void efficient_clear(eastl::fixed_vector< T, nodeCount, bEnableOverflow, OverflowAllocator > &fixed_vector)
bool IsEmpty(const BufferLocks &locks) noexcept
eastl::fixed_vector< GenericDrawCommand, 1, true > GenericDrawCommandContainer
bool Compatible(const GenericDrawCommand &lhs, const GenericDrawCommand &rhs) noexcept
bool dvd_erase_if(eastl::vector< T, A > &vec, Predicate &&pred)
Project const SceneEntry & entry
constexpr auto to_base(const Type value) -> Type
static NO_INLINE void errorfn(const char *format, T &&... args)
U16 _shaderStageVisibility
std::array< DescriptorSetBinding, MAX_BINDINGS_PER_DESCRIPTOR_SET > _bindings
const Pipeline * _pipeline
DescriptorSetUsage _usage
Handle< Texture > _texture
virtual void addToBuffer(CommandBuffer *buffer) const =0
virtual void DeleteCmd(CommandBase *&cmd) const =0
Handle< GFX::CommandBuffer > _buffer
eastl::fixed_vector< Entry, COMMAND_BUFFER_INIT_SIZE, true > _commandBuffers
Handle< Texture > _destination
Handle< Texture > _source
GenericDrawCommandContainer _drawCommands
TextureLayoutChanges _textureLayoutChanges
Handle< Texture > _texture
DELEGATE_STD< void, const ImageReadbackData & > _callback
PushConstantsStruct _fastData
UniformData * _uniformData
bool set() const noexcept