1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CORE_RENDER_RENDER_BARRIER_LIST_H 17 #define CORE_RENDER_RENDER_BARRIER_LIST_H 18 19 #include <cstddef> 20 #include <cstdint> 21 22 #include <base/containers/unique_ptr.h> 23 #include <base/containers/unordered_map.h> 24 #include <base/containers/vector.h> 25 #include <render/namespace.h> 26 #include <render/resource_handle.h> 27 28 #include "nodecontext/render_command_list.h" 29 #include "util/linear_allocator.h" 30 RENDER_BEGIN_NAMESPACE()31RENDER_BEGIN_NAMESPACE() 32 /** RenderBarrierList. 33 * Stores barriers per single RenderCommandList. 34 * Barriers are created with RenderGraph. 35 */ 36 class RenderBarrierList final { 37 public: 38 struct BarrierPointBarrierList { 39 uint32_t count { 0u }; 40 CommandBarrier* commandBarriers { nullptr }; 41 42 // linked when going through all barriers 43 BarrierPointBarrierList* nextBarrierPointBarrierList { nullptr }; 44 }; 45 struct BarrierPointBarriers { 46 // indirection, usually has only one BarrierPointBarrierList 47 uint32_t barrierListCount { 0u }; 48 uint32_t fullCommandBarrierCount { 0u }; 49 50 // pointer to first BarrierPointBarrierList 51 BarrierPointBarrierList* firstBarrierList { nullptr }; 52 // pointer to last BarrierPointBarrierList 53 BarrierPointBarrierList* lastBarrierList { nullptr }; 54 }; 55 56 struct LinearAllocatorStruct { 57 uint32_t currentIndex { 0 }; 58 BASE_NS::vector<BASE_NS::unique_ptr<LinearAllocator>> allocators; 59 }; 60 61 explicit RenderBarrierList(const uint32_t reserveBarrierCountHint); 62 ~RenderBarrierList() = default; 63 64 RenderBarrierList(const RenderBarrierList&) = delete; 65 RenderBarrierList operator=(const RenderBarrierList&) = delete; 66 67 // reset buffers and data 68 void BeginFrame(); 69 70 void AddBarriersToBarrierPoint(const uint32_t barrierPointIndex, const BASE_NS::vector<CommandBarrier>& barriers); 71 bool HasBarriers(const uint32_t barrierPointIndex) const; 72 const BarrierPointBarriers* GetBarrierPointBarriers(const uint32_t barrierPointIndex) const; 73 74 private: 75 BASE_NS::unordered_map<uint32_t, size_t> barrierPointIndextoIndex_; 76 77 BASE_NS::vector<BarrierPointBarriers> barrierPointBarriers_; 78 LinearAllocatorStruct linearAllocator_; 79 }; 80 RENDER_END_NAMESPACE() 81 82 #endif // CORE_RENDER_RENDER_BARRIER_LIST_H 83