Chromium Code Reviews| 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 "GrVkResource.h" | 11 #include "GrVkResource.h" |
| 12 #include "vk/GrVkDefines.h" | 12 #include "vk/GrVkDefines.h" |
| 13 | 13 |
| 14 class GrVkGpu; | 14 class GrVkGpu; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * This class serves as the base of GrVk*Buffer classes. It was written to avoid code | 17 * This class serves as the base of GrVk*Buffer classes. It was written to avoid code |
| 18 * duplication in those classes. | 18 * duplication in those classes. |
| 19 */ | 19 */ |
| 20 class GrVkBuffer : public SkNoncopyable { | 20 class GrVkBuffer : public SkNoncopyable { |
| 21 public: | 21 public: |
| 22 ~GrVkBuffer() { | 22 ~GrVkBuffer() { |
| 23 // either release or abandon should have been called by the owner of thi s object. | 23 // either release or abandon should have been called by the owner of thi s object. |
| 24 SkASSERT(!fResource); | 24 SkASSERT(!fResource); |
| 25 } | 25 } |
| 26 | 26 |
| 27 VkBuffer buffer() const { return fResource->fBuffer; } | 27 VkBuffer buffer() const { return fResource->fBuffer; } |
| 28 VkDeviceMemory alloc() const { return fResource->fAlloc; } | 28 VkDeviceMemory alloc() const { return fResource->fAlloc; } |
| 29 VkDeviceSize offset() const { return fResource->fOffset; } | |
| 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 enum Type { |
| 40 kVertex_Type, | 41 kVertex_Type, |
| 41 kIndex_Type, | 42 kIndex_Type, |
| 42 kUniform_Type, | 43 kUniform_Type, |
| 43 kCopyRead_Type, | 44 kCopyRead_Type, |
| 44 kCopyWrite_Type, | 45 kCopyWrite_Type, |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 protected: | 48 protected: |
| 48 struct Desc { | 49 struct Desc { |
| 49 size_t fSizeInBytes; | 50 size_t fSizeInBytes; |
| 50 Type fType; // vertex buffer, index buffer, etc. | 51 Type fType; // vertex buffer, index buffer, etc. |
| 51 bool fDynamic; | 52 bool fDynamic; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 class Resource : public GrVkResource { | 55 class Resource : public GrVkResource { |
| 55 public: | 56 public: |
| 56 Resource(VkBuffer buf, VkDeviceMemory alloc) : INHERITED(), fBuffer(buf) , fAlloc(alloc) {} | 57 Resource(VkBuffer buf, VkDeviceMemory alloc, VkDeviceSize offset) |
| 58 : INHERITED(), fBuffer(buf), fAlloc(alloc), fOffset(offset) {} | |
| 57 | 59 |
| 58 VkBuffer fBuffer; | 60 VkBuffer fBuffer; |
| 59 VkDeviceMemory fAlloc; | 61 VkDeviceMemory fAlloc; |
|
egdaniel
2016/05/31 13:22:14
I haven't though deeply into this, but do you thin
jvanverth1
2016/05/31 22:05:57
I added a GrVkAlloc struct to GrVkTypes that wraps
| |
| 62 VkDeviceSize fOffset; | |
| 63 | |
| 60 private: | 64 private: |
| 61 void freeGPUData(const GrVkGpu* gpu) const; | 65 void freeGPUData(const GrVkGpu* gpu) const; |
| 62 | 66 |
| 63 typedef GrVkResource INHERITED; | 67 typedef GrVkResource INHERITED; |
| 64 }; | 68 }; |
| 65 | 69 |
| 66 // convenience routine for raw buffer creation | 70 // convenience routine for raw buffer creation |
| 67 static const Resource* Create(const GrVkGpu* gpu, | 71 static const Resource* Create(const GrVkGpu* gpu, |
| 68 const Desc& descriptor); | 72 const Desc& descriptor); |
| 69 | 73 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 86 bool vkIsMapped() const; | 90 bool vkIsMapped() const; |
| 87 | 91 |
| 88 Desc fDesc; | 92 Desc fDesc; |
| 89 const Resource* fResource; | 93 const Resource* fResource; |
| 90 void* fMapPtr; | 94 void* fMapPtr; |
| 91 | 95 |
| 92 typedef SkNoncopyable INHERITED; | 96 typedef SkNoncopyable INHERITED; |
| 93 }; | 97 }; |
| 94 | 98 |
| 95 #endif | 99 #endif |
| OLD | NEW |