1 /* 2 * Copyright (C) 2023 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 size_t width { 0 }; 34 size_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 58 EngineResourceHandle GetFramebufferHandle(const RenderCommandBeginRenderPass& beginRenderPass); 59 const LowlevelFramebufferGL& GetFramebuffer(const EngineResourceHandle handle) const; 60 61 void FilterRenderPass(RenderCommandBeginRenderPass& beginRenderPass); 62 #if ((RENDER_VALIDATION_ENABLED == 1) || (RENDER_VULKAN_VALIDATION_ENABLED == 1)) 63 // not used ATM SetValidationDebugName(const BASE_NS::string_view debugName)64 void SetValidationDebugName(const BASE_NS::string_view debugName) override {}; 65 #endif 66 private: 67 DeviceGLES& device_; 68 GpuResourceManager& gpuResourceMgr_; 69 uint32_t bufferingIndex_ { 0 }; 70 uint32_t bufferingCount_ { 0 }; 71 ContextFramebufferCacheGLES framebufferCache_; 72 BASE_NS::vector<uint32_t> imageMap_; 73 bool multisampledRenderToTexture_ = false; 74 }; 75 RENDER_END_NAMESPACE() 76 77 #endif // CORE__RENDER__GLES__NODE_CONTEXT_POOL_MANAGER_GLES_H 78