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 GrVkImage_DEFINED | 8 #ifndef GrVkImage_DEFINED |
9 #define GrVkImage_DEFINED | 9 #define GrVkImage_DEFINED |
10 | 10 |
11 #include "GrVkResource.h" | 11 #include "GrVkResource.h" |
12 | 12 |
13 #include "GrTypesPriv.h" | 13 #include "GrTypesPriv.h" |
14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
15 | 15 |
16 #include "vk/GrVkDefines.h" | 16 #include "vk/GrVkDefines.h" |
| 17 #include "vk/GrVkTypes.h" |
17 | 18 |
18 class GrVkGpu; | 19 class GrVkGpu; |
19 | 20 |
20 class GrVkImage : SkNoncopyable { | 21 class GrVkImage : SkNoncopyable { |
| 22 private: |
| 23 class Resource; |
| 24 |
21 public: | 25 public: |
22 // unlike GrVkBuffer, this needs to be public so GrVkStencilAttachment can u
se it | 26 enum Wrapped { |
23 class Resource : public GrVkResource { | 27 kNot_Wrapped, |
24 public: | 28 kAdopted_Wrapped, |
25 enum Flags { | 29 kBorrowed_Wrapped, |
26 kNo_Flags = 0, | |
27 kLinearTiling_Flag = 0x01, | |
28 kBorrowed_Flag = 0x02 | |
29 }; | |
30 | |
31 VkImage fImage; | |
32 VkDeviceMemory fAlloc; | |
33 VkFormat fFormat; | |
34 uint32_t fLevelCount; | |
35 uint32_t fFlags; | |
36 | |
37 Resource() | |
38 : INHERITED() | |
39 , fImage(VK_NULL_HANDLE) | |
40 , fAlloc(VK_NULL_HANDLE) | |
41 , fFormat(VK_FORMAT_UNDEFINED) | |
42 , fLevelCount(0) | |
43 , fFlags(kNo_Flags) {} | |
44 | |
45 Resource(VkImage image, VkDeviceMemory alloc, VkFormat format, uint32_t
levelCount, | |
46 uint32_t flags) | |
47 : fImage(image), fAlloc(alloc), fFormat(format), fLevelCount(levelCo
unt) | |
48 , fFlags(flags) {} | |
49 | |
50 ~Resource() override {} | |
51 | |
52 private: | |
53 void freeGPUData(const GrVkGpu* gpu) const override; | |
54 | |
55 typedef GrVkResource INHERITED; | |
56 }; | 30 }; |
57 | 31 |
58 // for wrapped textures | 32 GrVkImage(const GrVkImageInfo& info, Wrapped wrapped) |
59 class BorrowedResource : public Resource { | 33 : fInfo(info) |
60 public: | 34 , fIsBorrowed(kBorrowed_Wrapped == wrapped) { |
61 BorrowedResource(VkImage image, VkDeviceMemory alloc, VkFormat format, u
int32_t levelCount, | 35 if (kBorrowed_Wrapped == wrapped) { |
62 uint32_t flags) | 36 fResource = new BorrowedResource(info.fImage, info.fAlloc); |
63 : Resource(image, alloc, format, levelCount, (flags | kBorrowed_Flag
)) { | 37 } else { |
| 38 fResource = new Resource(info.fImage, info.fAlloc); |
64 } | 39 } |
65 private: | 40 } |
66 void freeGPUData(const GrVkGpu* gpu) const override; | 41 virtual ~GrVkImage(); |
67 }; | |
68 | 42 |
69 GrVkImage(const Resource* imageResource) : fResource(imageResource) { | 43 VkImage image() const { return fInfo.fImage; } |
70 if (imageResource->fFlags & Resource::kLinearTiling_Flag) { | 44 VkDeviceMemory memory() const { return fInfo.fAlloc; } |
71 fCurrentLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; | 45 VkFormat imageFormat() const { return fInfo.fFormat; } |
72 } else { | 46 const Resource* resource() const { return fResource; } |
73 fCurrentLayout = VK_IMAGE_LAYOUT_UNDEFINED; | 47 bool isLinearTiled() const { |
74 } | 48 return SkToBool(VK_IMAGE_TILING_LINEAR == fInfo.fImageTiling); |
75 imageResource->ref(); | |
76 } | 49 } |
77 | 50 |
78 virtual ~GrVkImage(); | 51 VkImageLayout currentLayout() const { return fInfo.fImageLayout; } |
79 | |
80 VkImage textureImage() const { return fResource->fImage; } | |
81 VkDeviceMemory textureMemory() const { return fResource->fAlloc; } | |
82 const Resource* resource() const { return fResource; } | |
83 bool isLinearTiled() const { | |
84 return SkToBool(fResource->fFlags & Resource::kLinearTiling_Flag); | |
85 } | |
86 | |
87 VkImageLayout currentLayout() const { return fCurrentLayout; } | |
88 | 52 |
89 void setImageLayout(const GrVkGpu* gpu, | 53 void setImageLayout(const GrVkGpu* gpu, |
90 VkImageLayout newLayout, | 54 VkImageLayout newLayout, |
91 VkAccessFlags dstAccessMask, | 55 VkAccessFlags dstAccessMask, |
92 VkPipelineStageFlags dstStageMask, | 56 VkPipelineStageFlags dstStageMask, |
93 bool byRegion); | 57 bool byRegion); |
94 | 58 |
95 struct ImageDesc { | 59 struct ImageDesc { |
96 VkImageType fImageType; | 60 VkImageType fImageType; |
97 VkFormat fFormat; | 61 VkFormat fFormat; |
(...skipping 10 matching lines...) Expand all Loading... |
108 , fFormat(VK_FORMAT_UNDEFINED) | 72 , fFormat(VK_FORMAT_UNDEFINED) |
109 , fWidth(0) | 73 , fWidth(0) |
110 , fHeight(0) | 74 , fHeight(0) |
111 , fLevels(1) | 75 , fLevels(1) |
112 , fSamples(1) | 76 , fSamples(1) |
113 , fImageTiling(VK_IMAGE_TILING_OPTIMAL) | 77 , fImageTiling(VK_IMAGE_TILING_OPTIMAL) |
114 , fUsageFlags(0) | 78 , fUsageFlags(0) |
115 , fMemProps(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {} | 79 , fMemProps(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {} |
116 }; | 80 }; |
117 | 81 |
118 static const Resource* CreateResource(const GrVkGpu* gpu, const ImageDesc& i
mageDesc); | 82 static bool InitImageInfo(const GrVkGpu* gpu, const ImageDesc& imageDesc, Gr
VkImageInfo*); |
| 83 // Destroys the internal VkImage and VkDeviceMemory in the GrVkImageInfo |
| 84 static void DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo*); |
119 | 85 |
120 protected: | 86 protected: |
121 | |
122 void releaseImage(const GrVkGpu* gpu); | 87 void releaseImage(const GrVkGpu* gpu); |
123 void abandonImage(); | 88 void abandonImage(); |
124 | 89 |
| 90 void setNewResource(VkImage image, VkDeviceMemory alloc); |
| 91 |
| 92 GrVkImageInfo fInfo; |
| 93 bool fIsBorrowed; |
| 94 |
| 95 private: |
| 96 // unlike GrVkBuffer, this needs to be public so GrVkStencilAttachment can u
se it |
| 97 class Resource : public GrVkResource { |
| 98 public: |
| 99 Resource() |
| 100 : INHERITED() |
| 101 , fImage(VK_NULL_HANDLE) |
| 102 , fAlloc(VK_NULL_HANDLE) { |
| 103 } |
| 104 |
| 105 Resource(VkImage image, VkDeviceMemory alloc) : fImage(image), fAlloc(al
loc) {} |
| 106 |
| 107 ~Resource() override {} |
| 108 |
| 109 private: |
| 110 void freeGPUData(const GrVkGpu* gpu) const override; |
| 111 |
| 112 VkImage fImage; |
| 113 VkDeviceMemory fAlloc; |
| 114 |
| 115 typedef GrVkResource INHERITED; |
| 116 }; |
| 117 |
| 118 // for wrapped textures |
| 119 class BorrowedResource : public Resource { |
| 120 public: |
| 121 BorrowedResource(VkImage image, VkDeviceMemory alloc) : Resource(image,
alloc) { |
| 122 } |
| 123 private: |
| 124 void freeGPUData(const GrVkGpu* gpu) const override; |
| 125 }; |
| 126 |
125 const Resource* fResource; | 127 const Resource* fResource; |
126 | 128 |
127 VkImageLayout fCurrentLayout; | 129 friend class GrVkRenderTarget; |
128 }; | 130 }; |
129 | 131 |
130 #endif | 132 #endif |
OLD | NEW |