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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 void GrVkBuffer::vkAbandon() { | 118 void GrVkBuffer::vkAbandon() { |
119 fResource->unrefAndAbandon(); | 119 fResource->unrefAndAbandon(); |
120 fMapPtr = nullptr; | 120 fMapPtr = nullptr; |
121 VALIDATE(); | 121 VALIDATE(); |
122 } | 122 } |
123 | 123 |
124 void* GrVkBuffer::vkMap(const GrVkGpu* gpu) { | 124 void* GrVkBuffer::vkMap(const GrVkGpu* gpu) { |
125 VALIDATE(); | 125 VALIDATE(); |
126 SkASSERT(!this->vkIsMapped()); | 126 SkASSERT(!this->vkIsMapped()); |
127 | 127 |
| 128 if (!fResource->unique()) { |
| 129 // in use by the command buffer, so we need to create a new one |
| 130 fResource->unref(gpu); |
| 131 fResource = Create(gpu, fDesc); |
| 132 } |
| 133 |
128 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc(), 0, VK_WHOLE_SI
ZE, 0, &fMapPtr)); | 134 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc(), 0, VK_WHOLE_SI
ZE, 0, &fMapPtr)); |
129 if (err) { | 135 if (err) { |
130 fMapPtr = nullptr; | 136 fMapPtr = nullptr; |
131 } | 137 } |
132 | 138 |
133 VALIDATE(); | 139 VALIDATE(); |
134 return fMapPtr; | 140 return fMapPtr; |
135 } | 141 } |
136 | 142 |
137 void GrVkBuffer::vkUnmap(const GrVkGpu* gpu) { | 143 void GrVkBuffer::vkUnmap(const GrVkGpu* gpu) { |
(...skipping 10 matching lines...) Expand all Loading... |
148 return SkToBool(fMapPtr); | 154 return SkToBool(fMapPtr); |
149 } | 155 } |
150 | 156 |
151 bool GrVkBuffer::vkUpdateData(const GrVkGpu* gpu, const void* src, size_t srcSiz
eInBytes) { | 157 bool GrVkBuffer::vkUpdateData(const GrVkGpu* gpu, const void* src, size_t srcSiz
eInBytes) { |
152 SkASSERT(!this->vkIsMapped()); | 158 SkASSERT(!this->vkIsMapped()); |
153 VALIDATE(); | 159 VALIDATE(); |
154 if (srcSizeInBytes > fDesc.fSizeInBytes) { | 160 if (srcSizeInBytes > fDesc.fSizeInBytes) { |
155 return false; | 161 return false; |
156 } | 162 } |
157 | 163 |
| 164 if (!fResource->unique()) { |
| 165 // in use by the command buffer, so we need to create a new one |
| 166 fResource->unref(gpu); |
| 167 fResource = Create(gpu, fDesc); |
| 168 } |
| 169 |
158 void* mapPtr; | 170 void* mapPtr; |
159 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc(), 0, srcSizeInBy
tes, 0, &mapPtr)); | 171 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc(), 0, srcSizeInBy
tes, 0, &mapPtr)); |
160 | 172 |
161 if (VK_SUCCESS != err) { | 173 if (VK_SUCCESS != err) { |
162 return false; | 174 return false; |
163 } | 175 } |
164 | 176 |
165 memcpy(mapPtr, src, srcSizeInBytes); | 177 memcpy(mapPtr, src, srcSizeInBytes); |
166 | 178 |
167 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc())); | 179 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc())); |
168 | 180 |
169 return true; | 181 return true; |
170 } | 182 } |
171 | 183 |
172 void GrVkBuffer::validate() const { | 184 void GrVkBuffer::validate() const { |
173 SkASSERT(!fResource || kVertex_Type == fDesc.fType || kIndex_Type == fDesc.f
Type | 185 SkASSERT(!fResource || kVertex_Type == fDesc.fType || kIndex_Type == fDesc.f
Type |
174 || kCopyRead_Type == fDesc.fType || kCopyWrite_Type == fDesc.fType | 186 || kCopyRead_Type == fDesc.fType || kCopyWrite_Type == fDesc.fType |
175 || kUniform_Type == fDesc.fType); | 187 || kUniform_Type == fDesc.fType); |
176 } | 188 } |
177 | 189 |
OLD | NEW |