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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 GrVkAlloc alloc; | 65 GrVkAlloc alloc; |
66 | 66 |
67 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageDesc.fImageTil
ing) | 67 bool isLinear = VK_IMAGE_TILING_LINEAR == imageDesc.fImageTiling; |
68 ? VK_IMAGE_LAYOUT_PREINITIALIZED | 68 VkImageLayout initialLayout = isLinear ? VK_IMAGE_LAYOUT_PREINITIALIZED |
69 : VK_IMAGE_LAYOUT_UNDEFINED; | 69 : VK_IMAGE_LAYOUT_UNDEFINED; |
70 | 70 |
71 // Create Image | 71 // Create Image |
72 VkSampleCountFlagBits vkSamples; | 72 VkSampleCountFlagBits vkSamples; |
73 if (!GrSampleCountToVkSampleCount(imageDesc.fSamples, &vkSamples)) { | 73 if (!GrSampleCountToVkSampleCount(imageDesc.fSamples, &vkSamples)) { |
74 return false; | 74 return false; |
75 } | 75 } |
76 | 76 |
77 SkASSERT(VK_IMAGE_TILING_OPTIMAL == imageDesc.fImageTiling || | 77 SkASSERT(VK_IMAGE_TILING_OPTIMAL == imageDesc.fImageTiling || |
78 VK_SAMPLE_COUNT_1_BIT == vkSamples); | 78 VK_SAMPLE_COUNT_1_BIT == vkSamples); |
79 | 79 |
(...skipping 15 matching lines...) Expand all Loading... |
95 imageDesc.fUsageFlags, // VkImageUsageFlags | 95 imageDesc.fUsageFlags, // VkImageUsageFlags |
96 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode | 96 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode |
97 0, // queueFamilyCount | 97 0, // queueFamilyCount |
98 0, // pQueueFamilyIndices | 98 0, // pQueueFamilyIndices |
99 initialLayout // initialLayout | 99 initialLayout // initialLayout |
100 }; | 100 }; |
101 | 101 |
102 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateImage(gpu->device(), &imageCre
ateInfo, nullptr, | 102 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateImage(gpu->device(), &imageCre
ateInfo, nullptr, |
103 &image)); | 103 &image)); |
104 | 104 |
105 if (!GrVkMemory::AllocAndBindImageMemory(gpu, image, imageDesc.fMemProps, &a
lloc)) { | 105 if (!GrVkMemory::AllocAndBindImageMemory(gpu, image, isLinear, &alloc)) { |
106 VK_CALL(gpu, DestroyImage(gpu->device(), image, nullptr)); | 106 VK_CALL(gpu, DestroyImage(gpu->device(), image, nullptr)); |
107 return false; | 107 return false; |
108 } | 108 } |
109 | 109 |
110 info->fImage = image; | 110 info->fImage = image; |
111 info->fAlloc = alloc; | 111 info->fAlloc = alloc; |
112 info->fImageTiling = imageDesc.fImageTiling; | 112 info->fImageTiling = imageDesc.fImageTiling; |
113 info->fImageLayout = initialLayout; | 113 info->fImageLayout = initialLayout; |
114 info->fFormat = imageDesc.fFormat; | 114 info->fFormat = imageDesc.fFormat; |
115 info->fLevelCount = imageDesc.fLevels; | 115 info->fLevelCount = imageDesc.fLevels; |
116 return true; | 116 return true; |
117 } | 117 } |
118 | 118 |
119 void GrVkImage::DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo* info) { | 119 void GrVkImage::DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo* info) { |
120 VK_CALL(gpu, DestroyImage(gpu->device(), info->fImage, nullptr)); | 120 VK_CALL(gpu, DestroyImage(gpu->device(), info->fImage, nullptr)); |
121 GrVkMemory::FreeImageMemory(gpu, info->fAlloc); | 121 bool isLinear = VK_IMAGE_TILING_LINEAR == info->fImageTiling; |
| 122 GrVkMemory::FreeImageMemory(gpu, isLinear, info->fAlloc); |
122 } | 123 } |
123 | 124 |
124 void GrVkImage::setNewResource(VkImage image, const GrVkAlloc& alloc) { | 125 void GrVkImage::setNewResource(VkImage image, const GrVkAlloc& alloc, VkImageTil
ing tiling) { |
125 fResource = new Resource(image, alloc); | 126 fResource = new Resource(image, alloc, tiling); |
126 } | 127 } |
127 | 128 |
128 GrVkImage::~GrVkImage() { | 129 GrVkImage::~GrVkImage() { |
129 // should have been released or abandoned first | 130 // should have been released or abandoned first |
130 SkASSERT(!fResource); | 131 SkASSERT(!fResource); |
131 } | 132 } |
132 | 133 |
133 void GrVkImage::releaseImage(const GrVkGpu* gpu) { | 134 void GrVkImage::releaseImage(const GrVkGpu* gpu) { |
134 if (fResource) { | 135 if (fResource) { |
135 fResource->unref(gpu); | 136 fResource->unref(gpu); |
136 fResource = nullptr; | 137 fResource = nullptr; |
137 } | 138 } |
138 } | 139 } |
139 | 140 |
140 void GrVkImage::abandonImage() { | 141 void GrVkImage::abandonImage() { |
141 if (fResource) { | 142 if (fResource) { |
142 fResource->unrefAndAbandon(); | 143 fResource->unrefAndAbandon(); |
143 fResource = nullptr; | 144 fResource = nullptr; |
144 } | 145 } |
145 } | 146 } |
146 | 147 |
147 void GrVkImage::Resource::freeGPUData(const GrVkGpu* gpu) const { | 148 void GrVkImage::Resource::freeGPUData(const GrVkGpu* gpu) const { |
148 VK_CALL(gpu, DestroyImage(gpu->device(), fImage, nullptr)); | 149 VK_CALL(gpu, DestroyImage(gpu->device(), fImage, nullptr)); |
149 GrVkMemory::FreeImageMemory(gpu, fAlloc); | 150 bool isLinear = (VK_IMAGE_TILING_LINEAR == fImageTiling); |
| 151 GrVkMemory::FreeImageMemory(gpu, isLinear, fAlloc); |
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 |