1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrVkImage_DEFINED
#define GrVkImage_DEFINED
#include "GrVkResource.h"
#include "GrTypesPriv.h"
#include "SkTypes.h"
#include "vk/GrVkDefines.h"
class GrVkGpu;
class GrVkImage : SkNoncopyable {
public:
// unlike GrVkBuffer, this needs to be public so GrVkStencilAttachment can use it
class Resource : public GrVkResource {
public:
enum Flags {
kNo_Flags = 0,
kLinearTiling_Flag = 0x01,
kBorrowed_Flag = 0x02
};
VkImage fImage;
VkDeviceMemory fAlloc;
VkFormat fFormat;
uint32_t fFlags;
Resource()
: INHERITED()
, fImage(VK_NULL_HANDLE)
, fAlloc(VK_NULL_HANDLE)
, fFormat(VK_FORMAT_UNDEFINED)
, fFlags(kNo_Flags) {}
Resource(VkImage image, VkDeviceMemory alloc, uint32_t flags, VkFormat format)
: fImage(image), fAlloc(alloc), fFormat(format), fFlags(flags) {}
~Resource() override {}
private:
void freeGPUData(const GrVkGpu* gpu) const override;
typedef GrVkResource INHERITED;
};
// for wrapped textures
class BorrowedResource : public Resource {
public:
BorrowedResource(VkImage image, VkDeviceMemory alloc, uint32_t flags, VkFormat format)
: Resource(image, alloc, (flags | kBorrowed_Flag), format) {
}
private:
void freeGPUData(const GrVkGpu* gpu) const override;
};
GrVkImage(const Resource* imageResource) : fResource(imageResource) {
if (imageResource->fFlags & Resource::kLinearTiling_Flag) {
fCurrentLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
} else {
fCurrentLayout = VK_IMAGE_LAYOUT_UNDEFINED;
}
imageResource->ref();
}
virtual ~GrVkImage();
VkImage textureImage() const { return fResource->fImage; }
VkDeviceMemory textureMemory() const { return fResource->fAlloc; }
const Resource* resource() const { return fResource; }
bool isLinearTiled() const {
return SkToBool(fResource->fFlags & Resource::kLinearTiling_Flag);
}
VkImageLayout currentLayout() const { return fCurrentLayout; }
void setImageLayout(const GrVkGpu* gpu,
VkImageLayout newLayout,
VkAccessFlags srcAccessMask,
VkAccessFlags dstAccessMask,
VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
bool byRegion);
struct ImageDesc {
VkImageType fImageType;
VkFormat fFormat;
uint32_t fWidth;
uint32_t fHeight;
uint32_t fLevels;
uint32_t fSamples;
VkImageTiling fImageTiling;
VkImageUsageFlags fUsageFlags;
VkFlags fMemProps;
ImageDesc()
: fImageType(VK_IMAGE_TYPE_2D)
, fFormat(VK_FORMAT_UNDEFINED)
, fWidth(0)
, fHeight(0)
, fLevels(1)
, fSamples(1)
, fImageTiling(VK_IMAGE_TILING_OPTIMAL)
, fUsageFlags(0)
, fMemProps(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {}
};
static const Resource* CreateResource(const GrVkGpu* gpu, const ImageDesc& imageDesc);
protected:
void releaseImage(const GrVkGpu* gpu);
void abandonImage();
const Resource* fResource;
VkImageLayout fCurrentLayout;
};
#endif
|