• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "experimental/graphite/src/RenderPassTask.h"
9 
10 #include "experimental/graphite/src/CommandBuffer.h"
11 #include "experimental/graphite/src/DrawPass.h"
12 #include "experimental/graphite/src/Texture.h"
13 #include "experimental/graphite/src/TextureProxy.h"
14 
15 namespace skgpu {
16 
Make(std::vector<std::unique_ptr<DrawPass>> passes,const RenderPassDesc & desc)17 sk_sp<RenderPassTask> RenderPassTask::Make(std::vector<std::unique_ptr<DrawPass>> passes,
18                                            const RenderPassDesc& desc) {
19     // For now we have one DrawPass per RenderPassTask
20     SkASSERT(passes.size() == 1);
21 
22     return sk_sp<RenderPassTask>(new RenderPassTask(std::move(passes), desc));
23 }
24 
RenderPassTask(std::vector<std::unique_ptr<DrawPass>> passes,const RenderPassDesc & desc)25 RenderPassTask::RenderPassTask(std::vector<std::unique_ptr<DrawPass>> passes,
26                                const RenderPassDesc& desc)
27         : fDrawPasses(std::move(passes))
28         , fRenderPassDesc(desc) {}
29 
30 RenderPassTask::~RenderPassTask() = default;
31 
addCommands(ResourceProvider * resourceProvider,CommandBuffer * commandBuffer)32 void RenderPassTask::addCommands(ResourceProvider* resourceProvider, CommandBuffer* commandBuffer) {
33     // TBD: Expose the surfaces that will need to be attached within the renderpass?
34 
35     // TODO: for task execution, start the render pass, then iterate passes and
36     // possibly(?) start each subpass, and call DrawPass::addCommands() on the command buffer
37     // provided to the task. Then close the render pass and we should have pixels..
38 
39     // Instantiate the attachments
40     if (fRenderPassDesc.fColorAttachment.fTextureProxy) {
41         auto target = fRenderPassDesc.fColorAttachment.fTextureProxy;
42         if (!target->instantiate(resourceProvider)) {
43             SkDebugf("WARNING: given invalid texture proxy. Will not create renderpass!\n");
44             SkDebugf("Dimensions are (%d, %d).\n", target->dimensions().width(),
45                      target->dimensions().height());
46             return;
47         }
48     }
49     // TODO: instantiate depth and stencil
50 
51     commandBuffer->beginRenderPass(fRenderPassDesc);
52 
53     // Assuming one draw pass per renderpasstask for now
54     SkASSERT(fDrawPasses.size() == 1);
55     for (const auto& drawPass: fDrawPasses) {
56         drawPass->addCommands(commandBuffer);
57     }
58 
59     commandBuffer->endRenderPass();
60 }
61 
62 } // namespace skgpu
63