| 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 "GrVkBuffer.h" | 8 #include "GrVkBuffer.h" |
| 9 #include "GrVkGpu.h" | 9 #include "GrVkGpu.h" |
| 10 #include "GrVkMemory.h" | 10 #include "GrVkMemory.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; | 49 bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 50 bufInfo.queueFamilyIndexCount = 0; | 50 bufInfo.queueFamilyIndexCount = 0; |
| 51 bufInfo.pQueueFamilyIndices = nullptr; | 51 bufInfo.pQueueFamilyIndices = nullptr; |
| 52 | 52 |
| 53 VkResult err; | 53 VkResult err; |
| 54 err = VK_CALL(gpu, CreateBuffer(gpu->device(), &bufInfo, nullptr, &buffer)); | 54 err = VK_CALL(gpu, CreateBuffer(gpu->device(), &bufInfo, nullptr, &buffer)); |
| 55 if (err) { | 55 if (err) { |
| 56 return nullptr; | 56 return nullptr; |
| 57 } | 57 } |
| 58 | 58 |
| 59 VkMemoryPropertyFlags requiredMemProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
| | |
| 60 VK_MEMORY_PROPERTY_HOST_COHERENT_BI
T | | |
| 61 VK_MEMORY_PROPERTY_HOST_CACHED_BIT; | |
| 62 | |
| 63 if (!GrVkMemory::AllocAndBindBufferMemory(gpu, | 59 if (!GrVkMemory::AllocAndBindBufferMemory(gpu, |
| 64 buffer, | 60 buffer, |
| 65 requiredMemProps, | 61 desc.fType, |
| 66 &alloc)) { | 62 &alloc)) { |
| 67 // Try again without requiring host cached memory | 63 return nullptr; |
| 68 requiredMemProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | | |
| 69 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; | |
| 70 if (!GrVkMemory::AllocAndBindBufferMemory(gpu, | |
| 71 buffer, | |
| 72 requiredMemProps, | |
| 73 &alloc)) { | |
| 74 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr)); | |
| 75 return nullptr; | |
| 76 } | |
| 77 } | 64 } |
| 78 | 65 |
| 79 const GrVkBuffer::Resource* resource = new GrVkBuffer::Resource(buffer, allo
c); | 66 const GrVkBuffer::Resource* resource = new GrVkBuffer::Resource(buffer, allo
c, desc.fType); |
| 80 if (!resource) { | 67 if (!resource) { |
| 81 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr)); | 68 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr)); |
| 82 GrVkMemory::FreeBufferMemory(gpu, alloc); | 69 GrVkMemory::FreeBufferMemory(gpu, desc.fType, alloc); |
| 83 return nullptr; | 70 return nullptr; |
| 84 } | 71 } |
| 85 | 72 |
| 86 return resource; | 73 return resource; |
| 87 } | 74 } |
| 88 | 75 |
| 89 | |
| 90 void GrVkBuffer::addMemoryBarrier(const GrVkGpu* gpu, | 76 void GrVkBuffer::addMemoryBarrier(const GrVkGpu* gpu, |
| 91 VkAccessFlags srcAccessMask, | 77 VkAccessFlags srcAccessMask, |
| 92 VkAccessFlags dstAccesMask, | 78 VkAccessFlags dstAccesMask, |
| 93 VkPipelineStageFlags srcStageMask, | 79 VkPipelineStageFlags srcStageMask, |
| 94 VkPipelineStageFlags dstStageMask, | 80 VkPipelineStageFlags dstStageMask, |
| 95 bool byRegion) const { | 81 bool byRegion) const { |
| 96 VkBufferMemoryBarrier bufferMemoryBarrier = { | 82 VkBufferMemoryBarrier bufferMemoryBarrier = { |
| 97 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // sType | 83 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // sType |
| 98 NULL, // pNext | 84 NULL, // pNext |
| 99 srcAccessMask, // srcAccessMask | 85 srcAccessMask, // srcAccessMask |
| 100 dstAccesMask, // dstAccessMask | 86 dstAccesMask, // dstAccessMask |
| 101 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex | 87 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex |
| 102 VK_QUEUE_FAMILY_IGNORED, // dstQueueFamilyIndex | 88 VK_QUEUE_FAMILY_IGNORED, // dstQueueFamilyIndex |
| 103 this->buffer(), // buffer | 89 this->buffer(), // buffer |
| 104 0, // offset | 90 0, // offset |
| 105 fDesc.fSizeInBytes, // size | 91 fDesc.fSizeInBytes, // size |
| 106 }; | 92 }; |
| 107 | 93 |
| 108 // TODO: restrict to area of buffer we're interested in | 94 // TODO: restrict to area of buffer we're interested in |
| 109 gpu->addBufferMemoryBarrier(srcStageMask, dstStageMask, byRegion, &bufferMem
oryBarrier); | 95 gpu->addBufferMemoryBarrier(srcStageMask, dstStageMask, byRegion, &bufferMem
oryBarrier); |
| 110 } | 96 } |
| 111 | 97 |
| 112 void GrVkBuffer::Resource::freeGPUData(const GrVkGpu* gpu) const { | 98 void GrVkBuffer::Resource::freeGPUData(const GrVkGpu* gpu) const { |
| 113 SkASSERT(fBuffer); | 99 SkASSERT(fBuffer); |
| 114 SkASSERT(fAlloc.fMemory); | 100 SkASSERT(fAlloc.fMemory); |
| 115 VK_CALL(gpu, DestroyBuffer(gpu->device(), fBuffer, nullptr)); | 101 VK_CALL(gpu, DestroyBuffer(gpu->device(), fBuffer, nullptr)); |
| 116 GrVkMemory::FreeBufferMemory(gpu, fAlloc); | 102 GrVkMemory::FreeBufferMemory(gpu, fType, fAlloc); |
| 117 } | 103 } |
| 118 | 104 |
| 119 void GrVkBuffer::vkRelease(const GrVkGpu* gpu) { | 105 void GrVkBuffer::vkRelease(const GrVkGpu* gpu) { |
| 120 VALIDATE(); | 106 VALIDATE(); |
| 121 fResource->unref(gpu); | 107 fResource->unref(gpu); |
| 122 fResource = nullptr; | 108 fResource = nullptr; |
| 123 fMapPtr = nullptr; | 109 fMapPtr = nullptr; |
| 124 VALIDATE(); | 110 VALIDATE(); |
| 125 } | 111 } |
| 126 | 112 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc.fMemory)); | 183 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc.fMemory)); |
| 198 | 184 |
| 199 return true; | 185 return true; |
| 200 } | 186 } |
| 201 | 187 |
| 202 void GrVkBuffer::validate() const { | 188 void GrVkBuffer::validate() const { |
| 203 SkASSERT(!fResource || kVertex_Type == fDesc.fType || kIndex_Type == fDesc.f
Type | 189 SkASSERT(!fResource || kVertex_Type == fDesc.fType || kIndex_Type == fDesc.f
Type |
| 204 || kCopyRead_Type == fDesc.fType || kCopyWrite_Type == fDesc.fType | 190 || kCopyRead_Type == fDesc.fType || kCopyWrite_Type == fDesc.fType |
| 205 || kUniform_Type == fDesc.fType); | 191 || kUniform_Type == fDesc.fType); |
| 206 } | 192 } |
| OLD | NEW |