Flutter Engine
The Flutter Engine
RenderPassTask.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
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
19
20namespace skgpu::graphite {
21
23 const RenderPassDesc& desc,
25 // For now we have one DrawPass per RenderPassTask
26 SkASSERT(passes.size() == 1);
27 if (!target) {
28 return nullptr;
29 }
30
31 if (desc.fColorAttachment.fTextureInfo.isValid()) {
32 // The color attachment's samples count must ether match the render pass's samples count
33 // or be 1 (when multisampled render to single sampled is used).
34 SkASSERT(desc.fSampleCount == desc.fColorAttachment.fTextureInfo.numSamples() ||
35 1 == desc.fColorAttachment.fTextureInfo.numSamples());
36 }
37
38 if (desc.fDepthStencilAttachment.fTextureInfo.isValid()) {
39 SkASSERT(desc.fSampleCount == desc.fDepthStencilAttachment.fTextureInfo.numSamples());
40 }
41
42 return sk_sp<RenderPassTask>(new RenderPassTask(std::move(passes), desc, target));
43}
44
45RenderPassTask::RenderPassTask(DrawPassList passes,
46 const RenderPassDesc& desc,
48 : fDrawPasses(std::move(passes)), fRenderPassDesc(desc), fTarget(std::move(target)) {}
49
51
53 ScratchResourceManager* scratchManager,
54 const RuntimeEffectDictionary* runtimeDict) {
55 SkASSERT(fTarget);
56 if (!TextureProxy::InstantiateIfNotLazy(scratchManager, fTarget.get())) {
57 SKGPU_LOG_W("Failed to instantiate RenderPassTask target. Will not create renderpass!");
58 SKGPU_LOG_W("Dimensions are (%d, %d).",
59 fTarget->dimensions().width(), fTarget->dimensions().height());
60 return Status::kFail;
61 }
62
63 // Assuming one draw pass per renderpasstask for now
64 SkASSERT(fDrawPasses.size() == 1);
65 for (const auto& drawPass: fDrawPasses) {
66 if (!drawPass->prepareResources(resourceProvider, runtimeDict, fRenderPassDesc)) {
67 return Status::kFail;
68 }
69 }
70
71 // Once all internal resources have been prepared and instantiated, reclaim any pending returns
72 // from the scratch manager, since at the equivalent point in the task graph's addCommands()
73 // phase, the renderpass will have sampled from any scratch textures and their contents no
74 // longer have to be preserved.
75 scratchManager->notifyResourcesConsumed();
76 return Status::kSuccess;
77}
78
80 CommandBuffer* commandBuffer,
81 ReplayTargetData replayData) {
82 // TBD: Expose the surfaces that will need to be attached within the renderpass?
83
84 // TODO: for task execution, start the render pass, then iterate passes and
85 // possibly(?) start each subpass, and call DrawPass::addCommands() on the command buffer
86 // provided to the task. Then close the render pass and we should have pixels..
87
88 // Instantiate the target
89 SkASSERT(fTarget && fTarget->isInstantiated());
90
91 if (fTarget->texture() == replayData.fTarget) {
92 commandBuffer->setReplayTranslation(replayData.fTranslation);
93 } else {
94 commandBuffer->clearReplayTranslation();
95 }
96
97 // We don't instantiate the MSAA or DS attachments in prepareResources because we want to use
98 // the discardable attachments from the Context.
99 ResourceProvider* resourceProvider = context->priv().resourceProvider();
100 sk_sp<Texture> colorAttachment;
101 sk_sp<Texture> resolveAttachment;
102 if (fRenderPassDesc.fColorResolveAttachment.fTextureInfo.isValid()) {
103 SkASSERT(fTarget->numSamples() == 1 &&
104 fRenderPassDesc.fColorAttachment.fTextureInfo.numSamples() > 1);
105 colorAttachment = resourceProvider->findOrCreateDiscardableMSAAAttachment(
106 fTarget->dimensions(), fRenderPassDesc.fColorAttachment.fTextureInfo);
107 if (!colorAttachment) {
108 SKGPU_LOG_W("Could not get Color attachment for RenderPassTask");
109 return Status::kFail;
110 }
111 resolveAttachment = fTarget->refTexture();
112 } else {
113 colorAttachment = fTarget->refTexture();
114 }
115
116 sk_sp<Texture> depthStencilAttachment;
117 if (fRenderPassDesc.fDepthStencilAttachment.fTextureInfo.isValid()) {
118 // TODO: ensure this is a scratch/recycled texture
119 SkASSERT(fTarget->isInstantiated());
120 SkISize dimensions = context->priv().caps()->getDepthAttachmentDimensions(
121 fTarget->texture()->textureInfo(), fTarget->dimensions());
122 depthStencilAttachment = resourceProvider->findOrCreateDepthStencilAttachment(
123 dimensions, fRenderPassDesc.fDepthStencilAttachment.fTextureInfo);
124 if (!depthStencilAttachment) {
125 SKGPU_LOG_W("Could not get DepthStencil attachment for RenderPassTask");
126 return Status::kFail;
127 }
128 }
129
130 // TODO(b/313629288) we always pass in the render target's dimensions as the viewport here.
131 // Using the dimensions of the logical device that we're drawing to could reduce flakiness in
132 // rendering.
133 if (commandBuffer->addRenderPass(fRenderPassDesc,
134 std::move(colorAttachment),
135 std::move(resolveAttachment),
136 std::move(depthStencilAttachment),
137 SkRect::Make(fTarget->dimensions()),
138 fDrawPasses)) {
139 return Status::kSuccess;
140 } else {
141 return Status::kFail;
142 }
143}
144
145} // namespace skgpu::graphite
#define SKGPU_LOG_W(fmt,...)
Definition: Log.h:40
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual SkISize getDepthAttachmentDimensions(const TextureInfo &, const SkISize colorAttachmentDimensions) const
Definition: Caps.cpp:61
bool addRenderPass(const RenderPassDesc &, sk_sp< Texture > colorTexture, sk_sp< Texture > resolveTexture, sk_sp< Texture > depthStencilTexture, SkRect viewport, const DrawPassList &drawPasses)
void setReplayTranslation(SkIVector translation)
const Caps * caps() const
Definition: ContextPriv.h:32
ResourceProvider * resourceProvider() const
Definition: ContextPriv.h:49
static sk_sp< RenderPassTask > Make(DrawPassList, const RenderPassDesc &, sk_sp< TextureProxy > target)
Status addCommands(Context *, CommandBuffer *, ReplayTargetData) override
Status prepareResources(ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *) override
sk_sp< Texture > findOrCreateDiscardableMSAAAttachment(SkISize dimensions, const TextureInfo &)
sk_sp< Texture > findOrCreateDepthStencilAttachment(SkISize dimensions, const TextureInfo &)
uint32_t numSamples() const
Definition: TextureInfo.h:78
static bool InstantiateIfNotLazy(ResourceProvider *, TextureProxy *)
int size() const
Definition: SkTArray.h:421
uint32_t * target
Definition: ref_ptr.h:256
Definition: SkSize.h:16
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
AttachmentDesc fDepthStencilAttachment
AttachmentDesc fColorResolveAttachment