Flutter Engine
The Flutter Engine
GrAttachment.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
11#include "src/gpu/DataUtils.h"
16
17size_t GrAttachment::onGpuMemorySize() const {
18 // The GrTexture[RenderTarget] is built up by a bunch of attachments each of which are their
19 // own GrGpuResource. Ideally the GrRenderTarget would not be a GrGpuResource and the GrTexture
20 // would just merge with the new GrSurface/Attachment world. Then we could just depend on each
21 // attachment to give its own size since we don't have GrGpuResources owning other
22 // GrGpuResources. Until we get to that point we need to live in some hybrid world. We will let
23 // the msaa and stencil attachments track their own size because they do get cached separately.
24 // For all GrTexture* based things we will continue to to use the GrTexture* to report size and
25 // the owned attachments will have no size and be uncached.
26 if (!(fSupportedUsages & UsageFlags::kTexture) && fMemoryless == GrMemoryless::kNo) {
29
30 uint64_t size = skgpu::NumCompressedBlocks(compression, this->dimensions());
32 size *= this->numSamples();
33 return size;
34 }
35 return 0;
36}
37
39 const GrCaps& caps,
41 SkISize dimensions,
42 GrAttachment::UsageFlags requiredUsage,
43 int sampleCnt,
44 skgpu::Mipmapped mipmapped,
45 GrProtected isProtected,
46 GrMemoryless memoryless) {
47 SkASSERT(!dimensions.isEmpty());
48
49 SkASSERT(static_cast<uint32_t>(isProtected) <= 1);
50 SkASSERT(static_cast<uint32_t>(memoryless) <= 1);
51 SkASSERT(static_cast<uint32_t>(requiredUsage) < (1u << 8));
52 SkASSERT(static_cast<uint32_t>(sampleCnt) < (1u << (32 - 10)));
53
54 uint64_t formatKey = caps.computeFormatKey(format);
55 (*builder)[0] = dimensions.width();
56 (*builder)[1] = dimensions.height();
57 (*builder)[2] = formatKey & 0xFFFFFFFF;
58 (*builder)[3] = (formatKey >> 32) & 0xFFFFFFFF;
59 (*builder)[4] = (static_cast<uint32_t>(isProtected) << 0) |
60 (static_cast<uint32_t>(memoryless) << 1) |
61 (static_cast<uint32_t>(requiredUsage) << 2) |
62 (static_cast<uint32_t>(sampleCnt) << 10);
63}
64
67 SkISize dimensions,
68 UsageFlags requiredUsage,
69 int sampleCnt,
70 skgpu::Mipmapped mipmapped,
71 GrProtected isProtected,
72 GrMemoryless memoryless,
75
77 build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected,
78 memoryless);
79}
80
83 SkISize dimensions,
84 UsageFlags requiredUsage,
85 int sampleCnt,
86 skgpu::Mipmapped mipmapped,
87 GrProtected isProtected,
88 GrMemoryless memoryless,
91
93 build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected,
94 memoryless);
95}
96
97void GrAttachment::computeScratchKey(skgpu::ScratchKey* key) const {
98 // We do don't cache GrAttachments as scratch resources when used for stencils or textures. For
99 // stencils we share/cache them with unique keys so that they can be shared. Textures are in a
100 // weird place on the Vulkan backend. Currently, GrVkTexture contains a GrAttachment (GrVkImage)
101 // that actually holds the VkImage. The GrVkTexture is cached as a scratch resource and is
102 // responsible for tracking the gpuMemorySize. Thus we set the size of the texture GrVkImage,
103 // above in onGpuMemorySize, to be zero. Therefore, we can't have the GrVkImage getting cached
104 // separately on its own in the GrResourceCache or we may grow forever adding them thinking they
105 // contatin a memory that's size 0 and never freeing the actual VkImages.
106 if (!SkToBool(fSupportedUsages & UsageFlags::kStencilAttachment) &&
107 !SkToBool(fSupportedUsages & UsageFlags::kTexture)) {
109 ComputeScratchKey(*this->getGpu()->caps(),
110 this->backendFormat(),
111 this->dimensions(),
112 fSupportedUsages,
113 this->numSamples(),
114 this->mipmapped(),
116 fMemoryless,
117 key);
118 }
119}
static void build_key(skgpu::ResourceKey::Builder *builder, const GrCaps &caps, const GrBackendFormat &format, SkISize dimensions, GrAttachment::UsageFlags requiredUsage, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected isProtected, GrMemoryless memoryless)
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)
size_t GrBackendFormatBytesPerBlock(const GrBackendFormat &format)
GrMemoryless
Definition: GrTypesPriv.h:123
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkTextureCompressionType
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
skgpu::Mipmapped mipmapped() const
Definition: GrAttachment.h:40
int numSamples() const
Definition: GrAttachment.h:38
static void ComputeScratchKey(const GrCaps &caps, const GrBackendFormat &format, SkISize dimensions, UsageFlags requiredUsage, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected, GrMemoryless, skgpu::ScratchKey *key)
static void ComputeSharedAttachmentUniqueKey(const GrCaps &caps, const GrBackendFormat &format, SkISize dimensions, UsageFlags requiredUsage, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected isProtected, GrMemoryless memoryless, skgpu::UniqueKey *key)
Definition: GrCaps.h:57
virtual uint64_t computeFormatKey(const GrBackendFormat &) const =0
GrGpu * getGpu() const
virtual GrBackendFormat backendFormat() const =0
SkISize dimensions() const
Definition: GrSurface.h:27
bool isProtected() const
Definition: GrSurface.h:87
static ResourceType GenerateResourceType()
Definition: ResourceKey.cpp:16
uint32_t ResourceType
Definition: ResourceKey.h:200
static Domain GenerateDomain()
Definition: ResourceKey.cpp:27
uint32_t uint32_t * format
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Mipmapped
Definition: GpuTypes.h:53
size_t NumCompressedBlocks(SkTextureCompressionType type, SkISize baseDimensions)
Definition: DataUtils.cpp:163
Protected
Definition: GpuTypes.h:61
Definition: SkSize.h:16
bool isEmpty() const
Definition: SkSize.h:31
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37