• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "gpu_resource_util.h"
17 
18 #include <base/containers/byte_array.h>
19 #include <render/device/intf_device.h>
20 #include <render/namespace.h>
21 #include <render/resource_handle.h>
22 
23 #include "device/gpu_buffer.h"
24 #include "device/gpu_resource_manager.h"
25 #include "util/log.h"
26 #if RENDER_HAS_VULKAN_BACKEND
27 #include "vulkan/gpu_resource_util_vk.h"
28 #endif
29 #if RENDER_HAS_GLES_BACKEND || RENDER_HAS_GL_BACKEND
30 #include "gles/gpu_resource_util_gles.h"
31 #endif
32 
33 RENDER_BEGIN_NAMESPACE()
34 namespace GpuResourceUtil {
CopyGpuResource(const IDevice & device,const GpuResourceManager & gpuResourceMgr,const RenderHandle handle,BASE_NS::ByteArray & byteArray)35 void CopyGpuResource(const IDevice& device, const GpuResourceManager& gpuResourceMgr, const RenderHandle handle,
36     BASE_NS::ByteArray& byteArray)
37 {
38     const RenderHandleType handleType = RenderHandleUtil::GetHandleType(handle);
39     PLUGIN_ASSERT_MSG(handleType == RenderHandleType::GPU_BUFFER, "only gpu buffers supported");
40     if (handleType == RenderHandleType::GPU_BUFFER) {
41         GpuBuffer* resource = gpuResourceMgr.GetBuffer(handle);
42         PLUGIN_ASSERT(resource);
43         if (resource == nullptr) {
44             return;
45         }
46 
47         const DeviceBackendType backendType = device.GetBackendType();
48 #if RENDER_HAS_VULKAN_BACKEND
49         if (backendType == DeviceBackendType::VULKAN) {
50             CopyGpuBufferVk(*resource, byteArray);
51         }
52 #endif
53 #if RENDER_HAS_GLES_BACKEND || RENDER_HAS_GL_BACKEND
54         if ((backendType == DeviceBackendType::OPENGL) || (backendType == DeviceBackendType::OPENGLES)) {
55             CopyGpuBufferGLES(*resource, byteArray);
56         }
57 #endif
58     }
59 }
60 
DebugBufferName(const IDevice & device,const GpuBuffer & buffer,const BASE_NS::string_view name)61 void DebugBufferName(const IDevice& device, const GpuBuffer& buffer, const BASE_NS::string_view name)
62 {
63     const DeviceBackendType backendType = device.GetBackendType();
64 #if RENDER_HAS_VULKAN_BACKEND
65     if (backendType == DeviceBackendType::VULKAN) {
66         DebugBufferNameVk(device, buffer, name);
67     }
68 #endif
69 #if RENDER_HAS_GLES_BACKEND || RENDER_HAS_GL_BACKEND
70     if (backendType == DeviceBackendType::OPENGL) {
71         DebugBufferNameGLES(device, buffer, name);
72     }
73 #endif
74 }
75 
DebugImageName(const IDevice & device,const GpuImage & image,const BASE_NS::string_view name)76 void DebugImageName(const IDevice& device, const GpuImage& image, const BASE_NS::string_view name)
77 {
78     const DeviceBackendType backendType = device.GetBackendType();
79 #if RENDER_HAS_VULKAN_BACKEND
80     if (backendType == DeviceBackendType::VULKAN) {
81         DebugImageNameVk(device, image, name);
82     }
83 #endif
84 #if RENDER_HAS_GLES_BACKEND || RENDER_HAS_GL_BACKEND
85     if (backendType == DeviceBackendType::OPENGL) {
86         DebugImageNameGLES(device, image, name);
87     }
88 #endif
89 }
90 
DebugSamplerName(const IDevice & device,const GpuSampler & sampler,const BASE_NS::string_view name)91 void DebugSamplerName(const IDevice& device, const GpuSampler& sampler, const BASE_NS::string_view name)
92 {
93     const DeviceBackendType backendType = device.GetBackendType();
94 #if RENDER_HAS_VULKAN_BACKEND
95     if (backendType == DeviceBackendType::VULKAN) {
96         DebugSamplerNameVk(device, sampler, name);
97     }
98 #endif
99 #if RENDER_HAS_GLES_BACKEND || RENDER_HAS_GL_BACKEND
100     if (backendType == DeviceBackendType::OPENGL) {
101         DebugSamplerNameGLES(device, sampler, name);
102     }
103 #endif
104 }
105 
106 } // namespace GpuResourceUtil
107 RENDER_END_NAMESPACE()
108