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 RENDER_RENDER__NODE__RENDER_STAGING_H 17 #define RENDER_RENDER__NODE__RENDER_STAGING_H 18 19 #include <render/device/intf_gpu_resource_manager.h> 20 #include <render/namespace.h> 21 #include <render/nodecontext/intf_render_node.h> 22 #include <render/render_data_structures.h> 23 24 #include "device/gpu_resource_manager.h" 25 26 RENDER_BEGIN_NAMESPACE() 27 class IRenderCommandList; 28 class IRenderNodeContextManager; 29 struct RenderNodeGraphInputs; 30 struct StagingDirectDataCopyConsumeStruct; 31 struct StagingImageClearConsumeStruct; 32 33 class RenderStaging final { 34 public: 35 RenderStaging() = default; 36 ~RenderStaging() = default; 37 38 void Init(IRenderNodeContextManager& renderNodeContextMgr); 39 40 // additional clear byte size for GLES backend 41 // we need to allocate a CPU/GPU buffer to copy data from CPU to texture 42 void PreExecuteFrame(const uint32_t clearByteSize); 43 44 void CopyHostToStaging( 45 const IRenderNodeGpuResourceManager& gpuResourceMgr, const StagingConsumeStruct& stagingData); 46 void CopyStagingToImages(IRenderCommandList& cmdList, const IRenderNodeGpuResourceManager& gpuResourceMgr, 47 const StagingConsumeStruct& stagingData, const StagingConsumeStruct& renderDataStoreStagingData); 48 void CopyBuffersToBuffers(IRenderCommandList& cmdList, const StagingConsumeStruct& stagingData, 49 const StagingConsumeStruct& renderDataStoreStagingData); 50 void CopyImagesToBuffers(IRenderCommandList& cmdList, const IRenderNodeGpuResourceManager& gpuResourceMgr, 51 const StagingConsumeStruct& stagingData, const StagingConsumeStruct& renderDataStoreStagingData); 52 void CopyImagesToImages(IRenderCommandList& cmdList, const IRenderNodeGpuResourceManager& gpuResourceMgr, 53 const StagingConsumeStruct& stagingData, const StagingConsumeStruct& renderDataStoreStagingData); 54 55 void ClearImages(IRenderCommandList& cmdList, const IRenderNodeGpuResourceManager& gpuResourceMgr, 56 const StagingImageClearConsumeStruct& imageClearData); 57 58 private: 59 IRenderNodeContextManager* renderNodeContextMgr_ { nullptr }; 60 61 // GLES cannot directly use graphics API clear commands 62 // we still want to do CPU-GPU copy in multi-threaded way, so render front-end is used 63 struct AddionalCopyBuffer { 64 RenderHandleReference handle; 65 uint32_t byteSize { 0u }; 66 uint32_t byteOffset { 0u }; 67 }; 68 AddionalCopyBuffer additionalCopyBuffer_; 69 }; 70 RENDER_END_NAMESPACE() 71 72 #endif // CORE__RENDER__NODE__RENDER_NODE_STAGING_H 73