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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 void GrVkBuffer::vkAbandon() { | 117 void GrVkBuffer::vkAbandon() { |
118 fResource->unrefAndAbandon(); | 118 fResource->unrefAndAbandon(); |
119 fResource = nullptr; | 119 fResource = nullptr; |
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 if (!fDesc.fDynamic) { | |
128 return nullptr; | |
129 } | |
130 | |
131 if (!fResource->unique()) { | 127 if (!fResource->unique()) { |
132 // in use by the command buffer, so we need to create a new one | 128 // in use by the command buffer, so we need to create a new one |
133 fResource->unref(gpu); | 129 fResource->unref(gpu); |
134 fResource = Create(gpu, fDesc); | 130 fResource = Create(gpu, fDesc); |
135 } | 131 } |
136 | 132 |
137 const GrVkAlloc& alloc = this->alloc(); | 133 if (fDesc.fDynamic) { |
138 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc.fMemory, alloc.fO
ffset, | 134 const GrVkAlloc& alloc = this->alloc(); |
139 VK_WHOLE_SIZE, 0, &fMapPtr)); | 135 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc.fMemory, allo
c.fOffset, |
140 if (err) { | 136 VK_WHOLE_SIZE, 0, &fMapPtr)); |
141 fMapPtr = nullptr; | 137 if (err) { |
| 138 fMapPtr = nullptr; |
| 139 } |
| 140 } else { |
| 141 fMapPtr = new unsigned char[this->size()]; |
142 } | 142 } |
143 | 143 |
144 VALIDATE(); | 144 VALIDATE(); |
145 return fMapPtr; | 145 return fMapPtr; |
146 } | 146 } |
147 | 147 |
148 void GrVkBuffer::vkUnmap(const GrVkGpu* gpu) { | 148 void GrVkBuffer::vkUnmap(GrVkGpu* gpu) { |
149 VALIDATE(); | 149 VALIDATE(); |
150 SkASSERT(this->vkIsMapped()); | 150 SkASSERT(this->vkIsMapped()); |
151 SkASSERT(fDesc.fDynamic); | |
152 | 151 |
153 VK_CALL(gpu, UnmapMemory(gpu->device(), this->alloc().fMemory)); | 152 if (fDesc.fDynamic) { |
| 153 VK_CALL(gpu, UnmapMemory(gpu->device(), this->alloc().fMemory)); |
| 154 } else { |
| 155 gpu->updateBuffer(this, fMapPtr, this->size()); |
| 156 delete (unsigned char*) fMapPtr; |
| 157 } |
154 | 158 |
155 fMapPtr = nullptr; | 159 fMapPtr = nullptr; |
156 } | 160 } |
157 | 161 |
158 bool GrVkBuffer::vkIsMapped() const { | 162 bool GrVkBuffer::vkIsMapped() const { |
159 VALIDATE(); | 163 VALIDATE(); |
160 return SkToBool(fMapPtr); | 164 return SkToBool(fMapPtr); |
161 } | 165 } |
162 | 166 |
163 bool GrVkBuffer::vkUpdateData(GrVkGpu* gpu, const void* src, size_t srcSizeInByt
es, | 167 bool GrVkBuffer::vkUpdateData(GrVkGpu* gpu, const void* src, size_t srcSizeInByt
es, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc.fMemory)); | 199 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc.fMemory)); |
196 | 200 |
197 return true; | 201 return true; |
198 } | 202 } |
199 | 203 |
200 void GrVkBuffer::validate() const { | 204 void GrVkBuffer::validate() const { |
201 SkASSERT(!fResource || kVertex_Type == fDesc.fType || kIndex_Type == fDesc.f
Type | 205 SkASSERT(!fResource || kVertex_Type == fDesc.fType || kIndex_Type == fDesc.f
Type |
202 || kCopyRead_Type == fDesc.fType || kCopyWrite_Type == fDesc.fType | 206 || kCopyRead_Type == fDesc.fType || kCopyWrite_Type == fDesc.fType |
203 || kUniform_Type == fDesc.fType); | 207 || kUniform_Type == fDesc.fType); |
204 } | 208 } |
OLD | NEW |