MCPcopy Create free account
hub / github.com/alibaba/MNN / VulkanImage

Method VulkanImage

source/backend/vulkan/component/VulkanImage.cpp:27–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27VulkanImage::VulkanImage(const VulkanMemoryPool& pool, bool separate, const std::vector<int>& dims, VkFormat format, VkImageUsageFlags usage)
28 : mDevice(pool.device()), mPool(pool) {
29 if (format == VK_FORMAT_R32G32B32A32_SFLOAT && pool.permitFp16()) {
30 // FIXME: find better method
31 format = VK_FORMAT_R16G16B16A16_SFLOAT;
32 }
33 MNN_ASSERT(dims.size() >= 1 && dims.size() <= 3);
34 auto imageType = VK_IMAGE_TYPE_1D;
35 auto viewType = VK_IMAGE_VIEW_TYPE_1D;
36 mDims = dims;
37 auto mWidth = dims[0];
38 auto mHeight = 1;
39 auto mDepth = 1;
40 if (dims.size() > 1) {
41 mHeight = dims[1];
42 imageType = VK_IMAGE_TYPE_2D;
43 viewType = VK_IMAGE_VIEW_TYPE_2D;
44 }
45 if (dims.size() > 2) {
46 mDepth = dims[2];
47 imageType = VK_IMAGE_TYPE_3D;
48 viewType = VK_IMAGE_VIEW_TYPE_3D;
49 }
50
51 auto mFormat = format;
52 mInfo = std::make_tuple(imageType, mWidth, mHeight, mDepth, mFormat);
53 // FUNC_PRINT(format);
54 CALL_VK(mDevice.createImage(mImage.first, imageType, mWidth, mHeight, mDepth, mFormat, usage));
55 VkMemoryRequirements memRequirements;
56 mDevice.getImageMemoryRequirements(mImage.first, memRequirements);
57
58 mMemory = const_cast<VulkanMemoryPool&>(mPool).allocMemory(memRequirements, 0, separate);
59 // FUNC_PRINT(mMemory->type());
60 auto realMem = (VulkanMemory*)mMemory.first;
61 mDevice.bindImageMemory(mImage.first, realMem->get(), mMemory.second);
62 CALL_VK(mDevice.createImageView(mImage.second, mImage.first, viewType, format));
63}
64VulkanImage::~VulkanImage() {
65 mDevice.destroyImageView(mImage.second, nullptr);
66 mDevice.destroyImage(mImage.first);

Callers

nothing calls this directly

Calls 8

permitFp16Method · 0.80
createImageMethod · 0.80
bindImageMemoryMethod · 0.80
createImageViewMethod · 0.80
sizeMethod · 0.45
allocMemoryMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected