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

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

Issue 2344323002: Refactor vulkan buffer mapping and unmapping (Closed)
Patch Set: Dont delete static cpu buffer Created 4 years, 3 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 | « no previous file | src/gpu/vk/GrVkBuffer.cpp » ('j') | src/gpu/vk/GrVkBuffer.cpp » ('J')
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 #ifndef GrVkBuffer_DEFINED 8 #ifndef GrVkBuffer_DEFINED
9 #define GrVkBuffer_DEFINED 9 #define GrVkBuffer_DEFINED
10 10
11 #include "GrVkResource.h" 11 #include "GrVkResource.h"
12 #include "vk/GrVkDefines.h" 12 #include "vk/GrVkDefines.h"
13 #include "vk/GrVkTypes.h" 13 #include "vk/GrVkTypes.h"
14 14
15 class GrVkGpu; 15 class GrVkGpu;
16 16
17 /** 17 /**
18 * This class serves as the base of GrVk*Buffer classes. It was written to avoid code 18 * This class serves as the base of GrVk*Buffer classes. It was written to avoid code
19 * duplication in those classes. 19 * duplication in those classes.
20 */ 20 */
21 class GrVkBuffer : public SkNoncopyable { 21 class GrVkBuffer : public SkNoncopyable {
22 public: 22 public:
23 virtual ~GrVkBuffer() { 23 virtual ~GrVkBuffer() {
24 // either release or abandon should have been called by the owner of thi s object. 24 // either release or abandon should have been called by the owner of thi s object.
25 SkASSERT(!fResource); 25 SkASSERT(!fResource);
26 delete [] (unsigned char*)fMapPtr;
26 } 27 }
27 28
28 VkBuffer buffer() const { return fResource->fBuffer; } 29 VkBuffer buffer() const { return fResource->fBuffer; }
29 const GrVkAlloc& alloc() const { return fResource->fAlloc; } 30 const GrVkAlloc& alloc() const { return fResource->fAlloc; }
30 const GrVkRecycledResource* resource() const { return fResource; } 31 const GrVkRecycledResource* resource() const { return fResource; }
31 size_t size() const { return fDesc.fSizeInBytes; } 32 size_t size() const { return fDesc.fSizeInBytes; }
32 VkDeviceSize offset() const { return fOffset; } 33 VkDeviceSize offset() const { return fOffset; }
33 34
34 void addMemoryBarrier(const GrVkGpu* gpu, 35 void addMemoryBarrier(const GrVkGpu* gpu,
35 VkAccessFlags srcAccessMask, 36 VkAccessFlags srcAccessMask,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 }; 77 };
77 78
78 // convenience routine for raw buffer creation 79 // convenience routine for raw buffer creation
79 static const Resource* Create(const GrVkGpu* gpu, 80 static const Resource* Create(const GrVkGpu* gpu,
80 const Desc& descriptor); 81 const Desc& descriptor);
81 82
82 GrVkBuffer(const Desc& desc, const GrVkBuffer::Resource* resource) 83 GrVkBuffer(const Desc& desc, const GrVkBuffer::Resource* resource)
83 : fDesc(desc), fResource(resource), fOffset(0), fMapPtr(nullptr) { 84 : fDesc(desc), fResource(resource), fOffset(0), fMapPtr(nullptr) {
84 } 85 }
85 86
86 void* vkMap(const GrVkGpu* gpu); 87 void* vkMap(GrVkGpu* gpu);
87 void vkUnmap(GrVkGpu* gpu); 88 void vkUnmap(GrVkGpu* gpu);
88 // If the caller passes in a non null createdNewBuffer, this function will s et the bool to true 89 // If the caller passes in a non null createdNewBuffer, this function will s et the bool to true
89 // if it creates a new VkBuffer to upload the data to. 90 // if it creates a new VkBuffer to upload the data to.
90 bool vkUpdateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes, 91 bool vkUpdateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes,
91 bool* createdNewBuffer = nullptr); 92 bool* createdNewBuffer = nullptr);
92 93
93 void vkAbandon(); 94 void vkAbandon();
94 void vkRelease(const GrVkGpu* gpu); 95 void vkRelease(const GrVkGpu* gpu);
95 96
96 private: 97 private:
97 virtual const Resource* createResource(GrVkGpu* gpu, 98 virtual const Resource* createResource(GrVkGpu* gpu,
98 const Desc& descriptor) { 99 const Desc& descriptor) {
99 return Create(gpu, descriptor); 100 return Create(gpu, descriptor);
100 } 101 }
101 102
103 void innerMap(GrVkGpu* gpu, size_t size, bool* createdNewBuffer = nullptr);
104 void innerUnmap(GrVkGpu* gpu, size_t size);
105
102 void validate() const; 106 void validate() const;
103 bool vkIsMapped() const; 107 bool vkIsMapped() const;
104 108
105 Desc fDesc; 109 Desc fDesc;
106 const Resource* fResource; 110 const Resource* fResource;
107 VkDeviceSize fOffset; 111 VkDeviceSize fOffset;
108 void* fMapPtr; 112 void* fMapPtr;
109 113
110 typedef SkNoncopyable INHERITED; 114 typedef SkNoncopyable INHERITED;
111 }; 115 };
112 116
113 #endif 117 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/vk/GrVkBuffer.cpp » ('j') | src/gpu/vk/GrVkBuffer.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698