• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 VULKAN_GPU_BUFFER_VK_H
17 #define VULKAN_GPU_BUFFER_VK_H
18 
19 #include <vulkan/vulkan_core.h>
20 
21 #include <render/device/gpu_resource_desc.h>
22 #include <render/namespace.h>
23 #include <render/vulkan/intf_device_vk.h>
24 
25 #include "device/gpu_buffer.h"
26 #include "vulkan/gpu_memory_allocator_vk.h"
27 
28 RENDER_BEGIN_NAMESPACE()
29 class Device;
30 
31 class GpuBufferVk final : public GpuBuffer {
32 public:
33     GpuBufferVk(Device& device, const GpuBufferDesc& desc);
34     ~GpuBufferVk();
35 
36     const GpuBufferDesc& GetDesc() const override;
37     const GpuBufferPlatformDataVk& GetPlatformData() const;
38 
39     void* Map() override;
40     void* MapMemory() override;
41     void Unmap() const override;
42 
43 private:
44     void AllocateMemory(const VkMemoryPropertyFlags requiredFlags, const VkMemoryPropertyFlags preferredFlags);
45 
46     Device& device_;
47 
48     GpuBufferPlatformDataVk plat_;
49     GpuBufferDesc desc_;
50 
51     bool isPersistantlyMapped_ { false };
52     bool isMappable_ { false };
53     bool isRingBuffer_ { false };
54     uint32_t bufferingCount_ { 1u };
55 
56     // debug assert usage only
57     mutable bool isMapped_ { false };
58 
59     struct MemoryAllocation {
60         VmaAllocation allocation;
61         VmaAllocationInfo allocationInfo;
62     };
63     MemoryAllocation mem_ {};
64 };
65 RENDER_END_NAMESPACE()
66 
67 #endif // VULKAN_GPU_BUFFER_VK_H
68