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 #ifndef GrVkBuffer_DEFINED | 8 #ifndef GrVkBuffer_DEFINED |
9 #define GrVkBuffer_DEFINED | 9 #define GrVkBuffer_DEFINED |
10 | 10 |
11 #include "GrBuffer.h" | |
11 #include "vk/GrVkInterface.h" | 12 #include "vk/GrVkInterface.h" |
12 #include "GrVkResource.h" | 13 #include "GrVkResource.h" |
13 | 14 |
14 class GrVkGpu; | 15 class GrVkGpu; |
15 | 16 |
16 /** | 17 /** |
17 * 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 |
18 * duplication in those classes. | 19 * duplication in those classes. |
19 */ | 20 */ |
20 class GrVkBuffer : public SkNoncopyable { | 21 class GrVkBuffer : public GrBuffer { |
21 public: | 22 public: |
22 ~GrVkBuffer() { | 23 ~GrVkBuffer() { |
23 // 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. |
24 SkASSERT(!fResource); | 25 SkASSERT(!fResource); |
25 } | 26 } |
26 | 27 |
27 VkBuffer buffer() const { return fResource->fBuffer; } | 28 VkBuffer buffer() const { return fResource->fBuffer; } |
28 VkDeviceMemory alloc() const { return fResource->fAlloc; } | 29 VkDeviceMemory alloc() const { return fResource->fAlloc; } |
29 const GrVkResource* resource() const { return fResource; } | 30 const GrVkResource* resource() const { return fResource; } |
30 size_t size() const { return fDesc.fSizeInBytes; } | 31 size_t size() const { return fDesc.fSizeInBytes; } |
31 | 32 |
32 void addMemoryBarrier(const GrVkGpu* gpu, | 33 void addMemoryBarrier(const GrVkGpu* gpu, |
33 VkAccessFlags srcAccessMask, | 34 VkAccessFlags srcAccessMask, |
34 VkAccessFlags dstAccessMask, | 35 VkAccessFlags dstAccessMask, |
35 VkPipelineStageFlags srcStageMask, | 36 VkPipelineStageFlags srcStageMask, |
36 VkPipelineStageFlags dstStageMask, | 37 VkPipelineStageFlags dstStageMask, |
37 bool byRegion) const; | 38 bool byRegion) const; |
38 | 39 |
39 enum Type { | |
40 kVertex_Type, | |
41 kIndex_Type, | |
42 kUniform_Type, | |
43 kCopyRead_Type, | |
44 kCopyWrite_Type, | |
45 }; | |
46 | |
47 protected: | 40 protected: |
48 struct Desc { | 41 struct Desc { |
49 size_t fSizeInBytes; | 42 size_t fSizeInBytes; |
50 Type fType; // vertex buffer, index buffer, etc. | 43 GrBufferType fType; // vertex buffer, index buffer, etc. |
51 bool fDynamic; | 44 GrAccessPattern fAccessPattern; |
52 }; | 45 }; |
53 | 46 |
54 class Resource : public GrVkResource { | 47 class Resource : public GrVkResource { |
55 public: | 48 public: |
56 Resource(VkBuffer buf, VkDeviceMemory alloc) : INHERITED(), fBuffer(buf) , fAlloc(alloc) {} | 49 Resource(VkBuffer buf, VkDeviceMemory alloc) : INHERITED(), fBuffer(buf) , fAlloc(alloc) {} |
57 | 50 |
58 VkBuffer fBuffer; | 51 VkBuffer fBuffer; |
59 VkDeviceMemory fAlloc; | 52 VkDeviceMemory fAlloc; |
60 private: | 53 private: |
61 void freeGPUData(const GrVkGpu* gpu) const; | 54 void freeGPUData(const GrVkGpu* gpu) const; |
62 | 55 |
63 typedef GrVkResource INHERITED; | 56 typedef GrVkResource INHERITED; |
64 }; | 57 }; |
65 | 58 |
66 // convenience routine for raw buffer creation | 59 // convenience routine for raw buffer creation |
67 static const Resource* Create(const GrVkGpu* gpu, | 60 static const Resource* Create(const GrVkGpu* gpu, |
68 const Desc& descriptor); | 61 const Desc& descriptor); |
69 | 62 |
70 GrVkBuffer(const Desc& desc, const GrVkBuffer::Resource* resource) | 63 GrVkBuffer(GrVkGpu* gpu, const Desc& desc, const GrVkBuffer::Resource* resou rce); |
71 : fDesc(desc), fResource(resource), fMapPtr(nullptr) { | |
72 } | |
73 | 64 |
74 void* vkMap(const GrVkGpu* gpu); | 65 GrVkGpu* vkGpu() const; |
75 void vkUnmap(const GrVkGpu* gpu); | |
76 bool vkUpdateData(const GrVkGpu* gpu, const void* src, size_t srcSizeInBytes ); | |
77 | 66 |
78 void vkAbandon(); | 67 void onMap() override; |
79 void vkRelease(const GrVkGpu* gpu); | 68 void onUnmap() override; |
69 bool onUpdateData(const void* src, size_t srcSizeInBytes) override; | |
70 | |
71 void onAbandon() override; | |
72 void onRelease() override; | |
80 | 73 |
81 private: | 74 private: |
82 void validate() const; | 75 void validate() const; |
83 bool vkIsMapped() const; | 76 bool vkIsMapped() const; |
84 | 77 |
85 Desc fDesc; | 78 Desc fDesc; |
86 const Resource* fResource; | 79 const Resource* fResource; |
87 void* fMapPtr; | 80 void* fMapPtr; |
jvanverth1
2016/03/24 17:05:43
This needs to be deleted -- it duplicates fMapPtr
| |
88 | 81 |
89 typedef SkRefCnt INHERITED; | 82 typedef GrBuffer INHERITED; |
90 }; | 83 }; |
91 | 84 |
92 #endif | 85 #endif |
OLD | NEW |