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 GLES_NODE_CONTEXT_POOL_MANAGER_GLES_H 17 #define GLES_NODE_CONTEXT_POOL_MANAGER_GLES_H 18 19 #include <base/containers/unordered_map.h> 20 #include <base/containers/vector.h> 21 #include <render/namespace.h> 22 23 #include "device/gpu_resource_handle_util.h" 24 #include "nodecontext/node_context_pool_manager.h" 25 26 RENDER_BEGIN_NAMESPACE() 27 class Device; 28 class DeviceGLES; 29 struct RenderCommandBeginRenderPass; 30 class GpuResourceManager; 31 32 struct LowlevelFramebufferGL { 33 uint32_t width { 0 }; 34 uint32_t height { 0 }; 35 struct SubPassPair { 36 // one fbo per subpass, one resolve fbo per subpass (if needed) 37 uint32_t fbo { 0 }; 38 uint32_t resolve { 0 }; 39 }; 40 BASE_NS::vector<SubPassPair> fbos; 41 }; 42 struct ContextFramebufferCacheGLES { 43 // render pass hash (created in render command list) to frame buffer index 44 BASE_NS::unordered_map<uint64_t, uint32_t> renderPassHashToIndex; 45 // stores a frame index everytime the frame buffer is used (can be destroyed later on) 46 BASE_NS::vector<uint64_t> frameBufferFrameUseIndex; 47 48 BASE_NS::vector<LowlevelFramebufferGL> framebuffers; 49 }; 50 51 class NodeContextPoolManagerGLES final : public NodeContextPoolManager { 52 public: 53 NodeContextPoolManagerGLES(Device& device, GpuResourceManager& gpuResourceManager); 54 ~NodeContextPoolManagerGLES(); 55 56 void BeginFrame() override; 57 void BeginBackendFrame() override; 58 59 EngineResourceHandle GetFramebufferHandle(const RenderCommandBeginRenderPass& beginRenderPass); 60 const LowlevelFramebufferGL* GetFramebuffer(const EngineResourceHandle handle) const; 61 62 void FilterRenderPass(RenderCommandBeginRenderPass& beginRenderPass); 63 #if ((RENDER_VALIDATION_ENABLED == 1) || (RENDER_VULKAN_VALIDATION_ENABLED == 1)) 64 // not used ATM SetValidationDebugName(const BASE_NS::string_view debugName)65 void SetValidationDebugName(const BASE_NS::string_view debugName) override {}; 66 #endif 67 private: 68 DeviceGLES& device_; 69 GpuResourceManager& gpuResourceMgr_; 70 uint32_t bufferingIndex_ { 0 }; 71 uint32_t bufferingCount_ { 0 }; 72 ContextFramebufferCacheGLES framebufferCache_; 73 BASE_NS::vector<uint32_t> imageMap_; 74 bool multisampledRenderToTexture_ = false; 75 bool multiViewMultisampledRenderToTexture_ = false; 76 bool multiView_ = false; 77 78 #if (RENDER_VALIDATION_ENABLED == 1) 79 uint64_t frameIndexFront_ { 0 }; 80 uint64_t frameIndexBack_ { 0 }; 81 #endif 82 }; 83 RENDER_END_NAMESPACE() 84 85 #endif // CORE__RENDER__GLES__NODE_CONTEXT_POOL_MANAGER_GLES_H 86