Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
18
19namespace skgpu::graphite {
20
22 const RenderPassDesc& desc,
24 // For now we have one DrawPass per RenderPassTask
25 SkASSERT(passes.size() == 1);
26 if (!target) {
27 return nullptr;
28 }
29
30 if (desc.fColorAttachment.fTextureInfo.isValid()) {
31 // The color attachment's samples count must ether match the render pass's samples count
32 // or be 1 (when multisampled render to single sampled is used).
33 SkASSERT(desc.fSampleCount == desc.fColorAttachment.fTextureInfo.numSamples() ||
34 1 == desc.fColorAttachment.fTextureInfo.numSamples());
35 }
36
37 if (desc.fDepthStencilAttachment.fTextureInfo.isValid()) {
38 SkASSERT(desc.fSampleCount == desc.fDepthStencilAttachment.fTextureInfo.numSamples());
39 }
40
41 return sk_sp<RenderPassTask>(new RenderPassTask(std::move(passes), desc, target));
42}
43
44RenderPassTask::RenderPassTask(DrawPassList passes,
45 const RenderPassDesc& desc,
47 : fDrawPasses(std::move(passes)), fRenderPassDesc(desc), fTarget(std::move(target)) {}
48
50
52 const RuntimeEffectDictionary* runtimeDict) {
53 SkASSERT(fTarget);
54 if (!TextureProxy::InstantiateIfNotLazy(resourceProvider, fTarget.get())) {
55 SKGPU_LOG_W("Failed to instantiate RenderPassTask target. Will not create renderpass!");
56 SKGPU_LOG_W("Dimensions are (%d, %d).",
57 fTarget->dimensions().width(), fTarget->dimensions().height());
58 return Status::kFail;
59 }
60
61 // Assuming one draw pass per renderpasstask for now
62 SkASSERT(fDrawPasses.size() == 1);
63 for (const auto& drawPass: fDrawPasses) {
64 if (!drawPass->prepareResources(resourceProvider, runtimeDict, fRenderPassDesc)) {
65 return Status::kFail;
66 }
67 }
68 return Status::kSuccess;
69}
70
72 CommandBuffer* commandBuffer,
73 ReplayTargetData replayData) {
74 // TBD: Expose the surfaces that will need to be attached within the renderpass?
75
76 // TODO: for task execution, start the render pass, then iterate passes and
77 // possibly(?) start each subpass, and call DrawPass::addCommands() on the command buffer
78 // provided to the task. Then close the render pass and we should have pixels..
79
80 // Instantiate the target
81 SkASSERT(fTarget && fTarget->isInstantiated());
82
83 if (fTarget->texture() == replayData.fTarget) {
84 commandBuffer->setReplayTranslation(replayData.fTranslation);
85 } else {
86 commandBuffer->clearReplayTranslation();
87 }
88
89 // We don't instantiate the MSAA or DS attachments in prepareResources because we want to use
90 // the discardable attachments from the Context.
91 ResourceProvider* resourceProvider = context->priv().resourceProvider();
92 sk_sp<Texture> colorAttachment;
93 sk_sp<Texture> resolveAttachment;
94 if (fRenderPassDesc.fColorResolveAttachment.fTextureInfo.isValid()) {
95 SkASSERT(fTarget->numSamples() == 1 &&
96 fRenderPassDesc.fColorAttachment.fTextureInfo.numSamples() > 1);
97 colorAttachment = resourceProvider->findOrCreateDiscardableMSAAAttachment(
98 fTarget->dimensions(), fRenderPassDesc.fColorAttachment.fTextureInfo);
99 if (!colorAttachment) {
100 SKGPU_LOG_W("Could not get Color attachment for RenderPassTask");
101 return Status::kFail;
102 }
103 resolveAttachment = fTarget->refTexture();
104 } else {
105 colorAttachment = fTarget->refTexture();
106 }
107
108 sk_sp<Texture> depthStencilAttachment;
109 if (fRenderPassDesc.fDepthStencilAttachment.fTextureInfo.isValid()) {
110 // TODO: ensure this is a scratch/recycled texture
111 SkASSERT(fTarget->isInstantiated());
112 SkISize dimensions = context->priv().caps()->getDepthAttachmentDimensions(
113 fTarget->texture()->textureInfo(), fTarget->dimensions());
114 depthStencilAttachment = resourceProvider->findOrCreateDepthStencilAttachment(
115 dimensions, fRenderPassDesc.fDepthStencilAttachment.fTextureInfo);
116 if (!depthStencilAttachment) {
117 SKGPU_LOG_W("Could not get DepthStencil attachment for RenderPassTask");
118 return Status::kFail;
119 }
120 }
121
122 // TODO(b/313629288) we always pass in the render target's dimensions as the viewport here.
123 // Using the dimensions of the logical device that we're drawing to could reduce flakiness in
124 // rendering.
125 if (commandBuffer->addRenderPass(fRenderPassDesc,
126 std::move(colorAttachment),
127 std::move(resolveAttachment),
128 std::move(depthStencilAttachment),
129 SkRect::Make(fTarget->dimensions()),
130 fDrawPasses)) {
131 return Status::kSuccess;
132 } else {
133 return Status::kFail;
134 }
135}
136
137} // 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:60
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 *, 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:416
uint32_t * target
Definition ref_ptr.h:256
static SkRect Make(const SkISize &size)
Definition SkRect.h:669