OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrVkGpu.h" | 8 #include "GrVkGpu.h" |
9 #include "GrVkImage.h" | 9 #include "GrVkImage.h" |
10 #include "GrVkMemory.h" | 10 #include "GrVkMemory.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 }; | 56 }; |
57 | 57 |
58 gpu->addImageMemoryBarrier(srcStageMask, dstStageMask, byRegion, &imageMemor
yBarrier); | 58 gpu->addImageMemoryBarrier(srcStageMask, dstStageMask, byRegion, &imageMemor
yBarrier); |
59 | 59 |
60 fInfo.fImageLayout = newLayout; | 60 fInfo.fImageLayout = newLayout; |
61 } | 61 } |
62 | 62 |
63 bool GrVkImage::InitImageInfo(const GrVkGpu* gpu, const ImageDesc& imageDesc, Gr
VkImageInfo* info) { | 63 bool GrVkImage::InitImageInfo(const GrVkGpu* gpu, const ImageDesc& imageDesc, Gr
VkImageInfo* info) { |
64 VkImage image = 0; | 64 VkImage image = 0; |
65 VkDeviceMemory alloc; | 65 VkDeviceMemory alloc; |
| 66 VkDeviceSize offset; |
66 | 67 |
67 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageDesc.fImageTil
ing) | 68 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageDesc.fImageTil
ing) |
68 ? VK_IMAGE_LAYOUT_PREINITIALIZED | 69 ? VK_IMAGE_LAYOUT_PREINITIALIZED |
69 : VK_IMAGE_LAYOUT_UNDEFINED; | 70 : VK_IMAGE_LAYOUT_UNDEFINED; |
70 | 71 |
71 // Create Image | 72 // Create Image |
72 VkSampleCountFlagBits vkSamples; | 73 VkSampleCountFlagBits vkSamples; |
73 if (!GrSampleCountToVkSampleCount(imageDesc.fSamples, &vkSamples)) { | 74 if (!GrSampleCountToVkSampleCount(imageDesc.fSamples, &vkSamples)) { |
74 return false; | 75 return false; |
75 } | 76 } |
(...skipping 19 matching lines...) Expand all Loading... |
95 imageDesc.fUsageFlags, // VkImageUsageFlags | 96 imageDesc.fUsageFlags, // VkImageUsageFlags |
96 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode | 97 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode |
97 0, // queueFamilyCount | 98 0, // queueFamilyCount |
98 0, // pQueueFamilyIndices | 99 0, // pQueueFamilyIndices |
99 initialLayout // initialLayout | 100 initialLayout // initialLayout |
100 }; | 101 }; |
101 | 102 |
102 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateImage(gpu->device(), &imageCre
ateInfo, nullptr, | 103 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateImage(gpu->device(), &imageCre
ateInfo, nullptr, |
103 &image)); | 104 &image)); |
104 | 105 |
105 if (!GrVkMemory::AllocAndBindImageMemory(gpu, image, imageDesc.fMemProps, &a
lloc)) { | 106 if (!GrVkMemory::AllocAndBindImageMemory(gpu, image, imageDesc.fMemProps, &a
lloc, &offset)) { |
106 VK_CALL(gpu, DestroyImage(gpu->device(), image, nullptr)); | 107 VK_CALL(gpu, DestroyImage(gpu->device(), image, nullptr)); |
107 return false; | 108 return false; |
108 } | 109 } |
109 | 110 |
110 info->fImage = image; | 111 info->fImage = image; |
111 info->fAlloc = alloc; | 112 info->fAlloc = alloc; |
| 113 info->fOffset = offset; |
112 info->fImageTiling = imageDesc.fImageTiling; | 114 info->fImageTiling = imageDesc.fImageTiling; |
113 info->fImageLayout = initialLayout; | 115 info->fImageLayout = initialLayout; |
114 info->fFormat = imageDesc.fFormat; | 116 info->fFormat = imageDesc.fFormat; |
115 info->fLevelCount = imageDesc.fLevels; | 117 info->fLevelCount = imageDesc.fLevels; |
116 return true; | 118 return true; |
117 } | 119 } |
118 | 120 |
119 void GrVkImage::DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo* info) { | 121 void GrVkImage::DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo* info) { |
120 VK_CALL(gpu, DestroyImage(gpu->device(), info->fImage, nullptr)); | 122 VK_CALL(gpu, DestroyImage(gpu->device(), info->fImage, nullptr)); |
121 VK_CALL(gpu, FreeMemory(gpu->device(), info->fAlloc, nullptr)); | 123 GrVkMemory::FreeImageMemory(gpu, info->fAlloc, info->fOffset); |
122 } | 124 } |
123 | 125 |
124 void GrVkImage::setNewResource(VkImage image, VkDeviceMemory alloc) { | 126 void GrVkImage::setNewResource(VkImage image, VkDeviceMemory alloc, VkDeviceSize
offset) { |
125 fResource = new Resource(image, alloc); | 127 fResource = new Resource(image, alloc, offset); |
126 } | 128 } |
127 | 129 |
128 GrVkImage::~GrVkImage() { | 130 GrVkImage::~GrVkImage() { |
129 // should have been released or abandoned first | 131 // should have been released or abandoned first |
130 SkASSERT(!fResource); | 132 SkASSERT(!fResource); |
131 } | 133 } |
132 | 134 |
133 void GrVkImage::releaseImage(const GrVkGpu* gpu) { | 135 void GrVkImage::releaseImage(const GrVkGpu* gpu) { |
134 if (fResource) { | 136 if (fResource) { |
135 fResource->unref(gpu); | 137 fResource->unref(gpu); |
136 fResource = nullptr; | 138 fResource = nullptr; |
137 } | 139 } |
138 } | 140 } |
139 | 141 |
140 void GrVkImage::abandonImage() { | 142 void GrVkImage::abandonImage() { |
141 if (fResource) { | 143 if (fResource) { |
142 fResource->unrefAndAbandon(); | 144 fResource->unrefAndAbandon(); |
143 fResource = nullptr; | 145 fResource = nullptr; |
144 } | 146 } |
145 } | 147 } |
146 | 148 |
147 void GrVkImage::Resource::freeGPUData(const GrVkGpu* gpu) const { | 149 void GrVkImage::Resource::freeGPUData(const GrVkGpu* gpu) const { |
148 VK_CALL(gpu, DestroyImage(gpu->device(), fImage, nullptr)); | 150 VK_CALL(gpu, DestroyImage(gpu->device(), fImage, nullptr)); |
149 VK_CALL(gpu, FreeMemory(gpu->device(), fAlloc, nullptr)); | 151 GrVkMemory::FreeImageMemory(gpu, fAlloc, fOffset); |
150 } | 152 } |
151 | 153 |
152 void GrVkImage::BorrowedResource::freeGPUData(const GrVkGpu* gpu) const { | 154 void GrVkImage::BorrowedResource::freeGPUData(const GrVkGpu* gpu) const { |
153 } | 155 } |
OLD | NEW |