[graphite] Revise RenderPassTask construction
RenderPassTask should only represent a single RenderPass with possible
subpasses (represented by DrawPasses). This reconstructs the RenderPass
setup to match this thinking. RenderPassDesc now stores TextureProxys for
the attachments, since we may not have instantiated the Textures by the
time we create the RenderPassTask.
Bug: skia:12466
Change-Id: I4f8cab77a297aaf76bea7dd1cc3afd00143b8103
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/470460
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/experimental/graphite/src/CommandBuffer.cpp b/experimental/graphite/src/CommandBuffer.cpp
index 3bd6f9a..28af760 100644
--- a/experimental/graphite/src/CommandBuffer.cpp
+++ b/experimental/graphite/src/CommandBuffer.cpp
@@ -13,6 +13,7 @@
#include "experimental/graphite/src/Buffer.h"
#include "experimental/graphite/src/Texture.h"
+#include "experimental/graphite/src/TextureProxy.h"
namespace skgpu {
@@ -28,8 +29,8 @@
this->onBeginRenderPass(renderPassDesc);
auto& colorInfo = renderPassDesc.fColorAttachment;
- if (colorInfo.fTexture) {
- this->trackResource(std::move(colorInfo.fTexture));
+ if (colorInfo.fTextureProxy) {
+ this->trackResource(colorInfo.fTextureProxy->refTexture());
}
if (colorInfo.fStoreOp == StoreOp::kStore) {
fHasWork = true;
diff --git a/experimental/graphite/src/CommandBuffer.h b/experimental/graphite/src/CommandBuffer.h
index f1f083c..988687a 100644
--- a/experimental/graphite/src/CommandBuffer.h
+++ b/experimental/graphite/src/CommandBuffer.h
@@ -20,9 +20,10 @@
class Gpu;
class GraphicsPipeline;
class Texture;
+class TextureProxy;
struct AttachmentDesc {
- sk_sp<Texture> fTexture; // the ref on this will be taken by the command buffer
+ sk_sp<TextureProxy> fTextureProxy;
LoadOp fLoadOp;
StoreOp fStoreOp;
};
diff --git a/experimental/graphite/src/DrawContext.cpp b/experimental/graphite/src/DrawContext.cpp
index 7461dbd..489dd19 100644
--- a/experimental/graphite/src/DrawContext.cpp
+++ b/experimental/graphite/src/DrawContext.cpp
@@ -7,6 +7,7 @@
#include "experimental/graphite/src/DrawContext.h"
+#include "experimental/graphite/src/CommandBuffer.h"
#include "experimental/graphite/src/DrawList.h"
#include "experimental/graphite/src/DrawPass.h"
#include "experimental/graphite/src/RenderPassTask.h"
@@ -93,7 +94,16 @@
return nullptr;
}
- return RenderPassTask::Make(std::move(fDrawPasses));
+ // TODO: At this point we would determine all the targets used by the drawPasses,
+ // build up the union of them and store them in the RenderPassDesc. However, for
+ // the moment we should have only one drawPass.
+ SkASSERT(fDrawPasses.size() == 1);
+ RenderPassDesc desc;
+ desc.fColorAttachment.fTextureProxy = sk_ref_sp(fDrawPasses[0]->target());
+ desc.fColorAttachment.fLoadOp = LoadOp::kLoad;
+ desc.fColorAttachment.fStoreOp = StoreOp::kStore;
+
+ return RenderPassTask::Make(std::move(fDrawPasses), desc);
}
} // namespace skgpu
diff --git a/experimental/graphite/src/RenderPassTask.cpp b/experimental/graphite/src/RenderPassTask.cpp
index 8e0d8f9..4260e36 100644
--- a/experimental/graphite/src/RenderPassTask.cpp
+++ b/experimental/graphite/src/RenderPassTask.cpp
@@ -14,46 +14,49 @@
namespace skgpu {
-sk_sp<RenderPassTask> RenderPassTask::Make(std::vector<std::unique_ptr<DrawPass>> passes) {
- return sk_sp<RenderPassTask>(new RenderPassTask(std::move(passes)));
+sk_sp<RenderPassTask> RenderPassTask::Make(std::vector<std::unique_ptr<DrawPass>> passes,
+ const RenderPassDesc& desc) {
+ // For now we have one DrawPass per RenderPassTask
+ SkASSERT(passes.size() == 1);
+
+ return sk_sp<RenderPassTask>(new RenderPassTask(std::move(passes), desc));
}
-RenderPassTask::RenderPassTask(std::vector<std::unique_ptr<DrawPass>> passes)
- : fDrawPasses(std::move(passes)) {}
+RenderPassTask::RenderPassTask(std::vector<std::unique_ptr<DrawPass>> passes,
+ const RenderPassDesc& desc)
+ : fDrawPasses(std::move(passes))
+ , fRenderPassDesc(desc) {}
RenderPassTask::~RenderPassTask() = default;
void RenderPassTask::addCommands(ResourceProvider* resourceProvider, CommandBuffer* commandBuffer) {
// TBD: Expose the surfaces that will need to be attached within the renderpass?
- // TODO: for task execution, iterate the draw passes (can assume just 1 for sprint?) and
- // determine RenderPassDesc. Then start the render pass, then iterate passes again and
+ // TODO: for task execution, start the render pass, then iterate passes and
// possibly(?) start each subpass, and call DrawPass::addCommands() on the command buffer
// provided to the task. Then close the render pass and we should have pixels..
- // TODO: For now just generate a renderpass for each draw pass until we start using subpasses
- for (const auto& drawPass: fDrawPasses) {
- RenderPassDesc desc;
-
- auto target = drawPass->target();
- target->instantiate(resourceProvider);
- desc.fColorAttachment.fTexture = target->refTexture();
- if (!desc.fColorAttachment.fTexture) {
- SkDebugf("WARNING: given invalid texture proxy, will not draw!\n");
+ // Instantiate the attachments
+ if (fRenderPassDesc.fColorAttachment.fTextureProxy) {
+ auto target = fRenderPassDesc.fColorAttachment.fTextureProxy;
+ if (!target->instantiate(resourceProvider)) {
+ SkDebugf("WARNING: given invalid texture proxy. Will not create renderpass!\n");
SkDebugf("Dimensions are (%d, %d).\n", target->dimensions().width(),
target->dimensions().height());
- continue;
+ return;
}
- // TODO: need to get these from the drawPass somehow
- desc.fColorAttachment.fLoadOp = LoadOp::kLoad;
- desc.fColorAttachment.fStoreOp = StoreOp::kStore;
-
- commandBuffer->beginRenderPass(desc);
-
- drawPass->addCommands(commandBuffer);
-
- commandBuffer->endRenderPass();
}
+ // TODO: instantiate depth and stencil
+
+ commandBuffer->beginRenderPass(fRenderPassDesc);
+
+ // Assuming one draw pass per renderpasstask for now
+ SkASSERT(fDrawPasses.size() == 1);
+ for (const auto& drawPass: fDrawPasses) {
+ drawPass->addCommands(commandBuffer);
+ }
+
+ commandBuffer->endRenderPass();
}
} // namespace skgpu
diff --git a/experimental/graphite/src/RenderPassTask.h b/experimental/graphite/src/RenderPassTask.h
index a86830f..c674fef 100644
--- a/experimental/graphite/src/RenderPassTask.h
+++ b/experimental/graphite/src/RenderPassTask.h
@@ -8,6 +8,7 @@
#ifndef skgpu_RenderPassTask_DEFINED
#define skgpu_RenderPassTask_DEFINED
+#include "experimental/graphite/src/CommandBuffer.h"
#include "experimental/graphite/src/Task.h"
#include <vector>
@@ -27,16 +28,18 @@
*/
class RenderPassTask final : public Task {
public:
- static sk_sp<RenderPassTask> Make(std::vector<std::unique_ptr<DrawPass>> passes);
+ static sk_sp<RenderPassTask> Make(std::vector<std::unique_ptr<DrawPass>> passes,
+ const RenderPassDesc&);
~RenderPassTask() override;
void addCommands(ResourceProvider*, CommandBuffer*) override;
private:
- RenderPassTask(std::vector<std::unique_ptr<DrawPass>> passes);
+ RenderPassTask(std::vector<std::unique_ptr<DrawPass>> passes, const RenderPassDesc&);
std::vector<std::unique_ptr<DrawPass>> fDrawPasses;
+ RenderPassDesc fRenderPassDesc;
};
} // namespace skgpu
diff --git a/experimental/graphite/src/TextureProxy.cpp b/experimental/graphite/src/TextureProxy.cpp
index f8a5280..9e77456 100644
--- a/experimental/graphite/src/TextureProxy.cpp
+++ b/experimental/graphite/src/TextureProxy.cpp
@@ -33,6 +33,10 @@
return fTexture;
}
+const Texture* TextureProxy::texture() const {
+ return fTexture.get();
+}
+
#ifdef SK_DEBUG
void TextureProxy::validateTexture(const Texture* texture) {
SkASSERT(fDimensions == texture->dimensions());
diff --git a/experimental/graphite/src/TextureProxy.h b/experimental/graphite/src/TextureProxy.h
index 6d84f50..2a740d6 100644
--- a/experimental/graphite/src/TextureProxy.h
+++ b/experimental/graphite/src/TextureProxy.h
@@ -31,6 +31,7 @@
bool instantiate(ResourceProvider*);
sk_sp<Texture> refTexture() const;
+ const Texture* texture() const;
private:
#ifdef SK_DEBUG
diff --git a/experimental/graphite/src/mtl/MtlCommandBuffer.mm b/experimental/graphite/src/mtl/MtlCommandBuffer.mm
index 5676fb6..425c6bd 100644
--- a/experimental/graphite/src/mtl/MtlCommandBuffer.mm
+++ b/experimental/graphite/src/mtl/MtlCommandBuffer.mm
@@ -7,6 +7,7 @@
#include "experimental/graphite/src/mtl/MtlCommandBuffer.h"
+#include "experimental/graphite/src/TextureProxy.h"
#include "experimental/graphite/src/mtl/MtlBlitCommandEncoder.h"
#include "experimental/graphite/src/mtl/MtlBuffer.h"
#include "experimental/graphite/src/mtl/MtlCaps.h"
@@ -67,8 +68,6 @@
SkASSERT(!fActiveRenderCommandEncoder);
this->endBlitCommandEncoder();
- auto& colorInfo = renderPassDesc.fColorAttachment;
-
const static MTLLoadAction mtlLoadAction[] {
MTLLoadActionLoad,
MTLLoadActionClear,
@@ -89,14 +88,17 @@
sk_cfp<MTLRenderPassDescriptor*> descriptor([[MTLRenderPassDescriptor alloc] init]);
// Set up color attachment.
- auto colorAttachment = (*descriptor).colorAttachments[0];
- Texture* colorTexture = (Texture*)colorInfo.fTexture.get();
- colorAttachment.texture = colorTexture->mtlTexture();
- const std::array<float, 4>& clearColor = renderPassDesc.fClearColor;
- colorAttachment.clearColor =
- MTLClearColorMake(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
- colorAttachment.loadAction = mtlLoadAction[static_cast<int>(colorInfo.fLoadOp)];
- colorAttachment.storeAction = mtlStoreAction[static_cast<int>(colorInfo.fStoreOp)];
+ auto& colorInfo = renderPassDesc.fColorAttachment;
+ if (colorInfo.fTextureProxy) {
+ auto colorAttachment = (*descriptor).colorAttachments[0];
+ const Texture* colorTexture = (const Texture*)colorInfo.fTextureProxy->texture();
+ colorAttachment.texture = colorTexture->mtlTexture();
+ const std::array<float, 4>& clearColor = renderPassDesc.fClearColor;
+ colorAttachment.clearColor =
+ MTLClearColorMake(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
+ colorAttachment.loadAction = mtlLoadAction[static_cast<int>(colorInfo.fLoadOp)];
+ colorAttachment.storeAction = mtlStoreAction[static_cast<int>(colorInfo.fStoreOp)];
+ }
// TODO:
// * setup resolve
diff --git a/tests/graphite/CommandBufferTest.cpp b/tests/graphite/CommandBufferTest.cpp
index cbef85e..e6b681d 100644
--- a/tests/graphite/CommandBufferTest.cpp
+++ b/tests/graphite/CommandBufferTest.cpp
@@ -17,6 +17,7 @@
#include "experimental/graphite/src/GraphicsPipeline.h"
#include "experimental/graphite/src/ResourceProvider.h"
#include "experimental/graphite/src/Texture.h"
+#include "experimental/graphite/src/TextureProxy.h"
#if GRAPHITE_TEST_UTILS
// set to 1 if you want to do GPU capture of the commandBuffer
@@ -54,16 +55,16 @@
TextureInfo textureInfo;
#endif
- sk_sp<Texture> texture = gpu->resourceProvider()->findOrCreateTexture(textureSize,
- textureInfo);
- REPORTER_ASSERT(reporter, texture);
+ auto target = sk_sp<TextureProxy>(new TextureProxy(textureSize, textureInfo));
+ REPORTER_ASSERT(reporter, target);
RenderPassDesc renderPassDesc = {};
- renderPassDesc.fColorAttachment.fTexture = texture;
+ renderPassDesc.fColorAttachment.fTextureProxy = target;
renderPassDesc.fColorAttachment.fLoadOp = LoadOp::kClear;
renderPassDesc.fColorAttachment.fStoreOp = StoreOp::kStore;
renderPassDesc.fClearColor = { 1, 0, 0, 1 }; // red
+ target->instantiate(gpu->resourceProvider());
commandBuffer->beginRenderPass(renderPassDesc);
// Shared uniform buffer
@@ -179,7 +180,7 @@
bufferSize, BufferType::kXferGpuToCpu, PrioritizeGpuReads::kNo);
REPORTER_ASSERT(reporter, copyBuffer);
SkIRect srcRect = { 0, 0, kTextureWidth, kTextureHeight };
- commandBuffer->copyTextureToBuffer(texture, srcRect, copyBuffer, 0, rowBytes);
+ commandBuffer->copyTextureToBuffer(target->refTexture(), srcRect, copyBuffer, 0, rowBytes);
bool result = gpu->submit(commandBuffer);
REPORTER_ASSERT(reporter, result);