1 /* 2 * Copyright (c) 2022 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_NODE_RENDER_STAGING_H 17 #define 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(uint32_t clearByteSize); 43 44 struct StagingMappedBuffer { 45 RenderHandle handle; 46 uint8_t* mappedData { nullptr }; 47 uint32_t byteSize { 0U }; 48 }; 49 50 static void CopyHostToStaging( 51 const IRenderNodeGpuResourceManager& gpuResourceMgr, const StagingConsumeStruct& stagingData); 52 static void CopyHostToStaging(const StagingConsumeStruct& stagingData, const StagingMappedBuffer& smb); 53 static void CopyStagingToImages(IRenderCommandList& cmdList, const IRenderNodeGpuResourceManager& gpuResourceMgr, 54 const StagingConsumeStruct& stagingData, const StagingConsumeStruct& renderDataStoreStagingData); 55 static void CopyBuffersToBuffers(IRenderCommandList& cmdList, const StagingConsumeStruct& stagingData, 56 const StagingConsumeStruct& renderDataStoreStagingData); 57 static void CopyImagesToBuffers(IRenderCommandList& cmdList, const StagingConsumeStruct& stagingData, 58 const StagingConsumeStruct& renderDataStoreStagingData); 59 static void CopyImagesToImages(IRenderCommandList& cmdList, const StagingConsumeStruct& stagingData, 60 const StagingConsumeStruct& renderDataStoreStagingData); 61 62 void ClearImages(IRenderCommandList& cmdList, const IRenderNodeGpuResourceManager& gpuResourceMgr, 63 const StagingImageClearConsumeStruct& imageClearData); 64 65 private: 66 IRenderNodeContextManager* renderNodeContextMgr_ { nullptr }; 67 68 // GLES cannot directly use graphics API clear commands 69 // we still want to do CPU-GPU copy in multi-threaded way, so render front-end is used 70 struct AddionalCopyBuffer { 71 RenderHandleReference handle; 72 uint32_t byteSize { 0u }; 73 uint32_t byteOffset { 0u }; 74 }; 75 AddionalCopyBuffer additionalCopyBuffer_; 76 }; 77 RENDER_END_NAMESPACE() 78 79 #endif // RENDER_NODE_RENDER_STAGING_H 80