Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: src/gpu/vk/GrVkBuffer.cpp

Issue 2018933004: Add offset to memory allocations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkBuffer.h ('k') | src/gpu/vk/GrVkGpu.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "GrVkUtil.h" 11 #include "GrVkUtil.h"
12 12
13 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) 13 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
14 14
15 #ifdef SK_DEBUG 15 #ifdef SK_DEBUG
16 #define VALIDATE() this->validate() 16 #define VALIDATE() this->validate()
17 #else 17 #else
18 #define VALIDATE() do {} while(false) 18 #define VALIDATE() do {} while(false)
19 #endif 19 #endif
20 20
21 const GrVkBuffer::Resource* GrVkBuffer::Create(const GrVkGpu* gpu, const Desc& d esc) { 21 const GrVkBuffer::Resource* GrVkBuffer::Create(const GrVkGpu* gpu, const Desc& d esc) {
22 VkBuffer buffer; 22 VkBuffer buffer;
23 VkDeviceMemory alloc; 23 GrVkAlloc alloc;
24 24
25 // create the buffer object 25 // create the buffer object
26 VkBufferCreateInfo bufInfo; 26 VkBufferCreateInfo bufInfo;
27 memset(&bufInfo, 0, sizeof(VkBufferCreateInfo)); 27 memset(&bufInfo, 0, sizeof(VkBufferCreateInfo));
28 bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; 28 bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
29 bufInfo.flags = 0; 29 bufInfo.flags = 0;
30 bufInfo.size = desc.fSizeInBytes; 30 bufInfo.size = desc.fSizeInBytes;
31 switch (desc.fType) { 31 switch (desc.fType) {
32 case kVertex_Type: 32 case kVertex_Type:
33 bufInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; 33 bufInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 requiredMemProps, 72 requiredMemProps,
73 &alloc)) { 73 &alloc)) {
74 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr)); 74 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr));
75 return nullptr; 75 return nullptr;
76 } 76 }
77 } 77 }
78 78
79 const GrVkBuffer::Resource* resource = new GrVkBuffer::Resource(buffer, allo c); 79 const GrVkBuffer::Resource* resource = new GrVkBuffer::Resource(buffer, allo c);
80 if (!resource) { 80 if (!resource) {
81 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr)); 81 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr));
82 VK_CALL(gpu, FreeMemory(gpu->device(), alloc, nullptr)); 82 GrVkMemory::FreeBufferMemory(gpu, alloc);
83 return nullptr; 83 return nullptr;
84 } 84 }
85 85
86 return resource; 86 return resource;
87 } 87 }
88 88
89 89
90 void GrVkBuffer::addMemoryBarrier(const GrVkGpu* gpu, 90 void GrVkBuffer::addMemoryBarrier(const GrVkGpu* gpu,
91 VkAccessFlags srcAccessMask, 91 VkAccessFlags srcAccessMask,
92 VkAccessFlags dstAccesMask, 92 VkAccessFlags dstAccesMask,
(...skipping 11 matching lines...) Expand all
104 0, // offset 104 0, // offset
105 fDesc.fSizeInBytes, // size 105 fDesc.fSizeInBytes, // size
106 }; 106 };
107 107
108 // TODO: restrict to area of buffer we're interested in 108 // TODO: restrict to area of buffer we're interested in
109 gpu->addBufferMemoryBarrier(srcStageMask, dstStageMask, byRegion, &bufferMem oryBarrier); 109 gpu->addBufferMemoryBarrier(srcStageMask, dstStageMask, byRegion, &bufferMem oryBarrier);
110 } 110 }
111 111
112 void GrVkBuffer::Resource::freeGPUData(const GrVkGpu* gpu) const { 112 void GrVkBuffer::Resource::freeGPUData(const GrVkGpu* gpu) const {
113 SkASSERT(fBuffer); 113 SkASSERT(fBuffer);
114 SkASSERT(fAlloc); 114 SkASSERT(fAlloc.fMemory);
115 VK_CALL(gpu, DestroyBuffer(gpu->device(), fBuffer, nullptr)); 115 VK_CALL(gpu, DestroyBuffer(gpu->device(), fBuffer, nullptr));
116 VK_CALL(gpu, FreeMemory(gpu->device(), fAlloc, nullptr)); 116 GrVkMemory::FreeBufferMemory(gpu, fAlloc);
117 } 117 }
118 118
119 void GrVkBuffer::vkRelease(const GrVkGpu* gpu) { 119 void GrVkBuffer::vkRelease(const GrVkGpu* gpu) {
120 VALIDATE(); 120 VALIDATE();
121 fResource->unref(gpu); 121 fResource->unref(gpu);
122 fResource = nullptr; 122 fResource = nullptr;
123 fMapPtr = nullptr; 123 fMapPtr = nullptr;
124 VALIDATE(); 124 VALIDATE();
125 } 125 }
126 126
127 void GrVkBuffer::vkAbandon() { 127 void GrVkBuffer::vkAbandon() {
128 fResource->unrefAndAbandon(); 128 fResource->unrefAndAbandon();
129 fResource = nullptr; 129 fResource = nullptr;
130 fMapPtr = nullptr; 130 fMapPtr = nullptr;
131 VALIDATE(); 131 VALIDATE();
132 } 132 }
133 133
134 void* GrVkBuffer::vkMap(const GrVkGpu* gpu) { 134 void* GrVkBuffer::vkMap(const GrVkGpu* gpu) {
135 VALIDATE(); 135 VALIDATE();
136 SkASSERT(!this->vkIsMapped()); 136 SkASSERT(!this->vkIsMapped());
137 137
138 if (!fResource->unique()) { 138 if (!fResource->unique()) {
139 // in use by the command buffer, so we need to create a new one 139 // in use by the command buffer, so we need to create a new one
140 fResource->unref(gpu); 140 fResource->unref(gpu);
141 fResource = Create(gpu, fDesc); 141 fResource = Create(gpu, fDesc);
142 } 142 }
143 143
144 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc(), 0, VK_WHOLE_SI ZE, 0, &fMapPtr)); 144 const GrVkAlloc& alloc = this->alloc();
145 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc.fMemory, alloc.fO ffset,
146 VK_WHOLE_SIZE, 0, &fMapPtr));
egdaniel 2016/06/01 16:02:46 Does whole size here just mean from offset to end?
145 if (err) { 147 if (err) {
146 fMapPtr = nullptr; 148 fMapPtr = nullptr;
147 } 149 }
148 150
149 VALIDATE(); 151 VALIDATE();
150 return fMapPtr; 152 return fMapPtr;
151 } 153 }
152 154
153 void GrVkBuffer::vkUnmap(const GrVkGpu* gpu) { 155 void GrVkBuffer::vkUnmap(const GrVkGpu* gpu) {
154 VALIDATE(); 156 VALIDATE();
155 SkASSERT(this->vkIsMapped()); 157 SkASSERT(this->vkIsMapped());
156 158
157 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc())); 159 VK_CALL(gpu, UnmapMemory(gpu->device(), this->alloc().fMemory));
158 160
159 fMapPtr = nullptr; 161 fMapPtr = nullptr;
160 } 162 }
161 163
162 bool GrVkBuffer::vkIsMapped() const { 164 bool GrVkBuffer::vkIsMapped() const {
163 VALIDATE(); 165 VALIDATE();
164 return SkToBool(fMapPtr); 166 return SkToBool(fMapPtr);
165 } 167 }
166 168
167 bool GrVkBuffer::vkUpdateData(const GrVkGpu* gpu, const void* src, size_t srcSiz eInBytes, 169 bool GrVkBuffer::vkUpdateData(const GrVkGpu* gpu, const void* src, size_t srcSiz eInBytes,
168 bool* createdNewBuffer) { 170 bool* createdNewBuffer) {
169 SkASSERT(!this->vkIsMapped()); 171 SkASSERT(!this->vkIsMapped());
170 VALIDATE(); 172 VALIDATE();
171 if (srcSizeInBytes > fDesc.fSizeInBytes) { 173 if (srcSizeInBytes > fDesc.fSizeInBytes) {
172 return false; 174 return false;
173 } 175 }
174 176
175 if (!fResource->unique()) { 177 if (!fResource->unique()) {
176 // in use by the command buffer, so we need to create a new one 178 // in use by the command buffer, so we need to create a new one
177 fResource->unref(gpu); 179 fResource->unref(gpu);
178 fResource = Create(gpu, fDesc); 180 fResource = Create(gpu, fDesc);
179 if (createdNewBuffer) { 181 if (createdNewBuffer) {
180 *createdNewBuffer = true; 182 *createdNewBuffer = true;
181 } 183 }
182 } 184 }
183 185
184 void* mapPtr; 186 void* mapPtr;
185 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc(), 0, srcSizeInBy tes, 0, &mapPtr)); 187 const GrVkAlloc& alloc = this->alloc();
188 VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc.fMemory, alloc.fO ffset,
189 srcSizeInBytes, 0, &mapPtr));
186 190
187 if (VK_SUCCESS != err) { 191 if (VK_SUCCESS != err) {
188 return false; 192 return false;
189 } 193 }
190 194
191 memcpy(mapPtr, src, srcSizeInBytes); 195 memcpy(mapPtr, src, srcSizeInBytes);
192 196
193 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc())); 197 VK_CALL(gpu, UnmapMemory(gpu->device(), alloc.fMemory));
194 198
195 return true; 199 return true;
196 } 200 }
197 201
198 void GrVkBuffer::validate() const { 202 void GrVkBuffer::validate() const {
199 SkASSERT(!fResource || kVertex_Type == fDesc.fType || kIndex_Type == fDesc.f Type 203 SkASSERT(!fResource || kVertex_Type == fDesc.fType || kIndex_Type == fDesc.f Type
200 || kCopyRead_Type == fDesc.fType || kCopyWrite_Type == fDesc.fType 204 || kCopyRead_Type == fDesc.fType || kCopyWrite_Type == fDesc.fType
201 || kUniform_Type == fDesc.fType); 205 || kUniform_Type == fDesc.fType);
202 } 206 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkBuffer.h ('k') | src/gpu/vk/GrVkGpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698