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 API_RENDER_IRENDER_DATA_STORE_DEFAULT_STAGING_H
17 #define API_RENDER_IRENDER_DATA_STORE_DEFAULT_STAGING_H
18
19 #include <base/util/uid.h>
20 #include <render/datastore/intf_render_data_store.h>
21 #include <render/device/pipeline_state_desc.h>
22 #include <render/namespace.h>
23 #include <render/resource_handle.h>
24
RENDER_BEGIN_NAMESPACE()25 RENDER_BEGIN_NAMESPACE()
26 /**
27 * IRenderDataStoreDefaultStaging interface.
28 * Interface to add custom staging data.
29 *
30 * Internally synchronized.
31 */
32 class IRenderDataStoreDefaultStaging : public IRenderDataStore {
33 public:
34 static constexpr BASE_NS::Uid UID { "6f3af7c1-5e6e-49c9-8364-c454a872d228" };
35
36 /** Copy info to copy begin of frame or end of frame
37 */
38 enum class ResourceCopyInfo : uint32_t {
39 /** Copy data in the beginning of the next frame (default) */
40 BEGIN_FRAME = 0,
41 /** Copy data in the end of the next frame */
42 END_FRAME = 1,
43 };
44
45 /** Copy data to buffer on GPU through staging GPU buffer.
46 * @param data Byte data.
47 * @param dstHandle Dst resource.
48 * @param bufferCopy Buffer copy info struct.
49 */
50 virtual void CopyDataToBuffer(const BASE_NS::array_view<const uint8_t>& data,
51 const RenderHandleReference& dstHandle, const BufferCopy& bufferCopy) = 0;
52
53 /** Copy data to coherent GPU buffer on CPU through staging render node.
54 * GPU buffer must be created with CORE_MEMORY_PROPERTY_HOST_VISIBLE_BIT and CORE_MEMORY_PROPERTY_HOST_COHERENT_BIT.
55 * (Optionally: CORE_ENGINE_BUFFER_CREATION_DYNAMIC_RING_BUFFER)
56 * @param data Byte data.
57 * @param dstHandle Dst resource.
58 * @param bufferCopy Buffer copy info struct.
59 */
60 virtual void CopyDataToBufferOnCpu(const BASE_NS::array_view<const uint8_t>& data,
61 const RenderHandleReference& dstHandle, const BufferCopy& bufferCopy) = 0;
62
63 /** Copy data to image on GPU through staging GPU buffer.
64 * @param data Byte data.
65 * @param dstHandle Dst resource.
66 * @param BufferImageCopy Info for copying.
67 */
68 virtual void CopyDataToImage(const BASE_NS::array_view<const uint8_t>& data, const RenderHandleReference& dstHandle,
69 const BufferImageCopy& bufferImageCopy) = 0;
70
71 /** Copy buffer to buffer on GPU through staging.
72 * @param srcHandle Src resource.
73 * @param dstHandle Dst resource.
74 * @param bufferCopy Buffer copy info struct.
75 */
76 virtual void CopyBufferToBuffer(const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle,
77 const BufferCopy& bufferCopy) = 0;
78
79 /** Copy buffer to image on GPU through staging.
80 * @param srcHandle Src resource.
81 * @param dstHandle Dst resource.
82 * @param bufferCopy Buffer image copy info struct.
83 */
84 virtual void CopyBufferToImage(const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle,
85 const BufferImageCopy& bufferImageCopy) = 0;
86
87 /** Copy buffer to image on GPU through staging.
88 * @param srcHandle Src resource.
89 * @param dstHandle Dst resource.
90 * @param bufferImageCopies Buffer image copy info struct for each image layer/level.
91 */
92 virtual void CopyBufferToImage(const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle,
93 BASE_NS::array_view<const BufferImageCopy> bufferImageCopies) = 0;
94
95 /** Copy image to buffer on GPU through staging.
96 * @param srcHandle Src resource.
97 * @param dstHandle Dst resource.
98 * @param bufferImageCopy Buffer image copy info struct.
99 */
100 virtual void CopyImageToBuffer(const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle,
101 const BufferImageCopy& bufferImageCopy) = 0;
102
103 /** Copy image to image on GPU through staging.
104 * @param srcHandle Src resource.
105 * @param dstHandle Dst resource.
106 * @param imageCopy Image to image copy info struct.
107 */
108 virtual void CopyImageToImage(
109 const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle, const ImageCopy& imageCopy) = 0;
110
111 /** Copy image to buffer on GPU through staging.
112 * @param srcHandle Src resource.
113 * @param dstHandle Dst resource.
114 * @param bufferImageCopy Buffer image copy info struct.
115 * @param copyInfo Copy info.
116 */
117 virtual void CopyImageToBuffer(const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle,
118 const BufferImageCopy& bufferImageCopy, const ResourceCopyInfo copyInfo) = 0;
119
120 /** Copy image to image on GPU through staging.
121 * @param srcHandle Src resource.
122 * @param dstHandle Dst resource.
123 * @param imageCopy Image to image copy info struct.
124 * @param copyInfo Copy info.
125 */
126 virtual void CopyImageToImage(const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle,
127 const ImageCopy& imageCopy, const ResourceCopyInfo copyInfo) = 0;
128
129 /** Copy buffer to buffer on GPU through staging.
130 * @param srcHandle Src resource.
131 * @param dstHandle Dst resource.
132 * @param bufferCopy Buffer copy info struct.
133 * @param copyInfo Copy info.
134 */
135 virtual void CopyBufferToBuffer(const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle,
136 const BufferCopy& bufferCopy, const ResourceCopyInfo copyInfo) = 0;
137
138 /** Copy buffer to image on GPU through staging.
139 * @param srcHandle Src resource.
140 * @param dstHandle Dst resource.
141 * @param bufferCopy Buffer image copy info struct.
142 * @param copyInfo Copy info.
143 */
144 virtual void CopyBufferToImage(const RenderHandleReference& srcHandle, const RenderHandleReference& dstHandle,
145 const BufferImageCopy& bufferImageCopy, const ResourceCopyInfo copyInfo) = 0;
146
147 /** Clear image. Might be usable in the first frame if image is partially updated after that
148 * Often should not be used every frame.
149 * NOTE: some backends like OpenGLES might not support fully converted texture format clears.
150 * Prefer using shader clears if typical zero clears etc. are not desired
151 * @param handle Color image handle
152 * @param color Clear color value
153 */
154 virtual void ClearColorImage(const RenderHandleReference& handle, const ClearColorValue color) = 0;
155
156 protected:
157 IRenderDataStoreDefaultStaging() = default;
158 ~IRenderDataStoreDefaultStaging() override = default;
159 };
160 RENDER_END_NAMESPACE()
161
162 #endif // API_RENDER_IRENDER_DATA_STORE_DEFAULT_STAGING_H
163