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_DEVICE_IGPU_RESOURCE_CACHE_H 17 #define API_RENDER_DEVICE_IGPU_RESOURCE_CACHE_H 18 19 #include <cstdint> 20 21 #include <base/containers/array_view.h> 22 #include <base/containers/string_view.h> 23 #include <base/util/formats.h> 24 #include <render/device/gpu_resource_desc.h> 25 #include <render/device/pipeline_state_desc.h> 26 #include <render/namespace.h> 27 #include <render/resource_handle.h> 28 29 RENDER_BEGIN_NAMESPACE() 30 /** \addtogroup group_igpuresourcecache 31 * @{ 32 */ 33 /** Cache GPU image desc 34 */ 35 struct CacheGpuImageDesc { 36 /** format */ 37 BASE_NS::Format format { BASE_NS::BASE_FORMAT_R8G8B8A8_SRGB }; 38 39 /** width */ 40 uint32_t width { 0u }; 41 /** height */ 42 uint32_t height { 0u }; 43 44 /** mip count */ 45 uint32_t mipCount { 1u }; 46 /** layer count */ 47 uint32_t layerCount { 1u }; 48 49 /** MSAA sample count */ 50 SampleCountFlags sampleCountFlags { SampleCountFlagBits::CORE_SAMPLE_COUNT_1_BIT }; 51 52 /** component mapping */ 53 ComponentMapping componentMapping {}; 54 }; 55 56 /** Cache GPU image pair 57 */ 58 struct CacheGpuImagePair { 59 /** First image */ 60 RenderHandleReference firstImage {}; 61 /** Second image */ 62 RenderHandleReference secondImage {}; 63 }; 64 65 /** Gpu resource cache. 66 * Internally synchronized. 67 * 68 * Caches gpu resource for use and can be obtained for re-use. 69 */ 70 class IGpuResourceCache { 71 public: 72 IGpuResourceCache(const IGpuResourceCache&) = delete; 73 IGpuResourceCache& operator=(const IGpuResourceCache&) = delete; 74 75 /** Reserve GPU image. 76 * @param desc image description. 77 * @return handle. 78 */ 79 virtual RenderHandleReference ReserveGpuImage(const CacheGpuImageDesc& desc) = 0; 80 81 /** Reserve GPU images. 82 * @param descs image descriptions. 83 * @return handles. 84 */ 85 virtual BASE_NS::vector<RenderHandleReference> ReserveGpuImages( 86 const BASE_NS::array_view<const CacheGpuImageDesc> descs) = 0; 87 88 /** Get image description. 89 * @param handle Handle of the image. 90 * @return Image description. 91 */ 92 virtual CacheGpuImageDesc GetCacheGpuImageDesc(const RenderHandleReference& handle) const = 0; 93 94 /** Reserve GPU image pair usually for msaa -> resolve. 95 * @param desc image description. 96 * @param sampleCountFlags Sample count flags for the second image. 97 * @return Image pair. 98 */ 99 virtual CacheGpuImagePair ReserveGpuImagePair( 100 const CacheGpuImageDesc& desc, const SampleCountFlags sampleCountFlags) = 0; 101 102 protected: 103 IGpuResourceCache() = default; 104 virtual ~IGpuResourceCache() = default; 105 }; 106 /** @} */ 107 RENDER_END_NAMESPACE() 108 109 #endif // API_RENDER_DEVICE_IGPU_RESOURCE_MANAGER_H 110