@@ -584,142 +584,4 @@ namespace stratus {
584584 }
585585 return indices;
586586 }
587-
588- GpuCommandBuffer::GpuCommandBuffer () {
589-
590- }
591-
592- void GpuCommandBuffer::RemoveCommandsAt (const std::unordered_set<size_t >& indices) {
593- VerifyArraySizes_ ();
594- if (indices.size () == 0 ) return ;
595-
596- // std::vector<uint64_t> newHandles;
597- std::vector<uint32_t > newMaterialIndices;
598- std::vector<glm::mat4> newPrevFrameModelTransforms;
599- std::vector<glm::mat4> newModelTransforms;
600- std::vector<GpuDrawElementsIndirectCommand> newIndirectDrawCommands;
601- for (size_t i = 0 ; i < NumDrawCommands (); ++i) {
602- if (indices.find (i) == indices.end ()) {
603- // handlesToIndicesMap.insert(std::make_pair(handles[i], newHandles.size()));
604- // newHandles.push_back(handles[i]);
605- newMaterialIndices.push_back (materialIndices[i]);
606- newPrevFrameModelTransforms.push_back (prevFrameModelTransforms[i]);
607- newModelTransforms.push_back (modelTransforms[i]);
608- newIndirectDrawCommands.push_back (indirectDrawCommands[i]);
609- }
610- // else {
611- // handlesToIndicesMap.erase(handles[i]);
612- // }
613- }
614-
615- // handles = std::move(newHandles);
616- materialIndices = std::move (newMaterialIndices);
617- prevFrameModelTransforms = std::move (newPrevFrameModelTransforms);
618- modelTransforms = std::move (newModelTransforms);
619- indirectDrawCommands = std::move (newIndirectDrawCommands);
620- }
621-
622- size_t GpuCommandBuffer::NumDrawCommands () const {
623- return indirectDrawCommands.size ();
624- }
625-
626- void GpuCommandBuffer::UploadDataToGpu () {
627- VerifyArraySizes_ ();
628-
629- const size_t numElems = NumDrawCommands ();
630- if (numElems == 0 ) return ;
631-
632- if (indirectDrawCommands_ == GpuBuffer () || indirectDrawCommands_.SizeBytes () < (numElems * sizeof (GpuDrawElementsIndirectCommand))) {
633- const Bitfield flags = GPU_DYNAMIC_DATA;
634-
635- materialIndices_ = GpuBuffer ((const void *)materialIndices.data (), numElems * sizeof (uint32_t ), flags);
636- prevFrameModelTransforms_ = GpuBuffer ((const void *)prevFrameModelTransforms.data (), numElems * sizeof (glm::mat4), flags);
637- modelTransforms_ = GpuBuffer ((const void *)modelTransforms.data (), numElems * sizeof (glm::mat4), flags);
638- indirectDrawCommands_ = GpuBuffer ((const void *)indirectDrawCommands.data (), numElems * sizeof (GpuDrawElementsIndirectCommand), flags);
639- if (aabbs.size () > 0 ) {
640- aabbs_ = GpuBuffer ((const void *)aabbs.data (), numElems * sizeof (GpuAABB), flags);
641- }
642- }
643- else {
644- materialIndices_.CopyDataToBuffer (0 , numElems * sizeof (uint32_t ), (const void *)materialIndices.data ());
645- prevFrameModelTransforms_.CopyDataToBuffer (0 , numElems * sizeof (glm::mat4), (const void *)prevFrameModelTransforms.data ());
646- modelTransforms_.CopyDataToBuffer (0 , numElems * sizeof (glm::mat4), (const void *)modelTransforms.data ());
647- indirectDrawCommands_.CopyDataToBuffer (0 , numElems * sizeof (GpuDrawElementsIndirectCommand), (const void *)indirectDrawCommands.data ());
648- if (aabbs.size () > 0 ) {
649- aabbs_.CopyDataToBuffer (0 , numElems * sizeof (GpuAABB), (const void *)aabbs.data ());
650- }
651- }
652- }
653-
654- void GpuCommandBuffer::BindMaterialIndicesBuffer (uint32_t index) {
655- if (materialIndices_ == GpuBuffer ()) {
656- throw std::runtime_error (" Null material indices GpuBuffer" );
657- }
658- materialIndices_.BindBase (GpuBaseBindingPoint::SHADER_STORAGE_BUFFER, index);
659- }
660-
661- void GpuCommandBuffer::BindPrevFrameModelTransformBuffer (uint32_t index) {
662- if (prevFrameModelTransforms_ == GpuBuffer ()) {
663- throw std::runtime_error (" Null previous frame model transform GpuBuffer" );
664- }
665- prevFrameModelTransforms_.BindBase (GpuBaseBindingPoint::SHADER_STORAGE_BUFFER, index);
666- }
667-
668- void GpuCommandBuffer::BindModelTransformBuffer (uint32_t index) {
669- if (modelTransforms_ == GpuBuffer ()) {
670- throw std::runtime_error (" Null model transform GpuBuffer" );
671- }
672- modelTransforms_.BindBase (GpuBaseBindingPoint::SHADER_STORAGE_BUFFER, index);
673- }
674-
675- void GpuCommandBuffer::BindAabbBuffer (uint32_t index) {
676- if (aabbs_ == GpuBuffer ()) {
677- throw std::runtime_error (" Null aabb GpuBuffer" );
678- }
679- aabbs_.BindBase (GpuBaseBindingPoint::SHADER_STORAGE_BUFFER, index);
680- }
681-
682- void GpuCommandBuffer::BindIndirectDrawCommands () {
683- if (indirectDrawCommands_ == GpuBuffer ()) {
684- throw std::runtime_error (" Null indirect draw command buffer" );
685- }
686- indirectDrawCommands_.Bind (GpuBindingPoint::DRAW_INDIRECT_BUFFER);
687- }
688-
689- void GpuCommandBuffer::UnbindIndirectDrawCommands () {
690- if (indirectDrawCommands_ == GpuBuffer ()) {
691- throw std::runtime_error (" Null indirect draw command buffer" );
692- }
693- indirectDrawCommands_.Unbind (GpuBindingPoint::DRAW_INDIRECT_BUFFER);
694- }
695-
696- void GpuCommandBuffer::VerifyArraySizes_ () const {
697- if (// materialIndices.size() == handlesToIndicesMap.size() &&
698- // materialIndices.size() == handles.size() &&
699- materialIndices.size () != prevFrameModelTransforms.size () ||
700- materialIndices.size () != modelTransforms.size () ||
701- materialIndices.size () != indirectDrawCommands.size ()) {
702- throw std::runtime_error (" Sizes do not match up in GpuBuffer" );
703- }
704-
705- if (aabbs.size () > 0 ) {
706- assert (aabbs.size () == indirectDrawCommands.size ());
707- }
708- }
709-
710- const GpuBuffer& GpuCommandBuffer::GetIndirectDrawCommandsBuffer () const {
711- return indirectDrawCommands_;
712- }
713-
714- GpuCommandBufferPtr GpuCommandBuffer::Copy () const {
715- GpuCommandBufferPtr copy = GpuCommandBufferPtr (new GpuCommandBuffer ());
716- copy->materialIndices = materialIndices;
717- copy->prevFrameModelTransforms = prevFrameModelTransforms;
718- copy->modelTransforms = modelTransforms;
719- copy->indirectDrawCommands = indirectDrawCommands;
720- copy->aabbs = aabbs;
721-
722- copy->UploadDataToGpu ();
723- return copy;
724- }
725587}
0 commit comments