• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
2 //
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 #ifndef VK_DEVICE_MEMORY_HPP_
16 #define VK_DEVICE_MEMORY_HPP_
17 
18 #include "VkConfig.h"
19 #include "VkObject.hpp"
20 
21 namespace vk {
22 
23 class DeviceMemory : public Object<DeviceMemory, VkDeviceMemory>
24 {
25 public:
26 	DeviceMemory(const VkMemoryAllocateInfo *pCreateInfo, void *mem);
27 
28 	static size_t ComputeRequiredAllocationSize(const VkMemoryAllocateInfo *pCreateInfo);
29 
30 #if SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD
31 	VkResult exportFd(int *pFd) const;
32 #endif
33 
34 #if SWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER
35 	VkResult exportAhb(struct AHardwareBuffer **pAhb) const;
36 	static VkResult getAhbProperties(const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties);
37 #endif
38 
39 	void destroy(const VkAllocationCallbacks *pAllocator);
40 	VkResult allocate();
41 	VkResult map(VkDeviceSize offset, VkDeviceSize size, void **ppData);
42 	VkDeviceSize getCommittedMemoryInBytes() const;
43 	void *getOffsetPointer(VkDeviceSize pOffset) const;
getMemoryTypeIndex() const44 	uint32_t getMemoryTypeIndex() const { return memoryTypeIndex; }
45 
46 	// If this is external memory, return true iff its handle type matches the bitmask
47 	// provided by |supportedExternalHandleTypes|. Otherwise, always return true.
48 	bool checkExternalMemoryHandleType(
49 	    VkExternalMemoryHandleTypeFlags supportedExternalMemoryHandleType) const;
50 
51 	// Internal implementation class for external memory. Platform-specific.
52 	class ExternalBase;
53 
54 private:
55 	void *buffer = nullptr;
56 	VkDeviceSize size = 0;
57 	uint32_t memoryTypeIndex = 0;
58 	ExternalBase *external = nullptr;
59 };
60 
Cast(VkDeviceMemory object)61 static inline DeviceMemory *Cast(VkDeviceMemory object)
62 {
63 	return DeviceMemory::Cast(object);
64 }
65 
66 }  // namespace vk
67 
68 #endif  // VK_DEVICE_MEMORY_HPP_
69