[Graphite] Add prepareResource step to Tasks when making Recordings.
Eventually we'll move the addCommands call on Task to happen from the Context. However, things like instantiation of proxies still needs to happen on the Recorder. Bug: skia:13357 Change-Id: I905a83e735164b7b82e7ffa916c535b0cd234594 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546857 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
parent
e636f6ab8c
commit
4d7d29c99f
@ -28,6 +28,8 @@ public:
|
||||
|
||||
~CopyTextureToBufferTask() override;
|
||||
|
||||
bool prepareResources(ResourceProvider*) override { return true; }
|
||||
|
||||
bool addCommands(ResourceProvider*, CommandBuffer*) override;
|
||||
|
||||
private:
|
||||
|
@ -54,6 +54,19 @@ std::unique_ptr<Recording> Recorder::snap() {
|
||||
// TODO: fulfill all promise images in the TextureDataCache here
|
||||
// TODO: create all the samplers needed in the TextureDataCache here
|
||||
|
||||
if (!fGraph->prepareResources(fResourceProvider.get())) {
|
||||
// Leaving 'fTrackedDevices' alone since they were flushed earlier and could still be
|
||||
// attached to extant SkSurfaces.
|
||||
size_t requiredAlignment = fGpu->caps()->requiredUniformBufferAlignment();
|
||||
fDrawBufferManager.reset(new DrawBufferManager(fResourceProvider.get(), requiredAlignment));
|
||||
fTextureDataCache = std::make_unique<TextureDataCache>();
|
||||
// We leave the UniformDataCache alone
|
||||
fGraph->reset();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: Adding commands to a CommandBuffer should all take place in the Context when we insert
|
||||
// a Recording.
|
||||
auto commandBuffer = fResourceProvider->createCommandBuffer();
|
||||
|
||||
if (!fGraph->addCommands(fResourceProvider.get(), commandBuffer.get())) {
|
||||
@ -67,6 +80,8 @@ std::unique_ptr<Recording> Recorder::snap() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: These buffer refs will need to be stored on Recording before they eventually get passed
|
||||
// onto the CommandBuffer.
|
||||
fDrawBufferManager->transferToCommandBuffer(commandBuffer.get());
|
||||
fUploadBufferManager->transferToCommandBuffer(commandBuffer.get());
|
||||
|
||||
|
@ -22,6 +22,9 @@ sk_sp<RenderPassTask> RenderPassTask::Make(std::vector<std::unique_ptr<DrawPass>
|
||||
sk_sp<TextureProxy> target) {
|
||||
// For now we have one DrawPass per RenderPassTask
|
||||
SkASSERT(passes.size() == 1);
|
||||
if (!target) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sk_sp<RenderPassTask>(new RenderPassTask(std::move(passes), desc, target));
|
||||
}
|
||||
@ -35,6 +38,17 @@ RenderPassTask::RenderPassTask(std::vector<std::unique_ptr<DrawPass>> passes,
|
||||
|
||||
RenderPassTask::~RenderPassTask() = default;
|
||||
|
||||
bool RenderPassTask::prepareResources(ResourceProvider* resourceProvider) {
|
||||
SkASSERT(fTarget);
|
||||
if (!fTarget->instantiate(resourceProvider)) {
|
||||
SKGPU_LOG_W("Given invalid texture proxy. Will not create renderpass!");
|
||||
SKGPU_LOG_W("Dimensions are (%d, %d).",
|
||||
fTarget->dimensions().width(), fTarget->dimensions().height());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderPassTask::addCommands(ResourceProvider* resourceProvider, CommandBuffer* commandBuffer) {
|
||||
// TBD: Expose the surfaces that will need to be attached within the renderpass?
|
||||
|
||||
@ -43,15 +57,10 @@ bool RenderPassTask::addCommands(ResourceProvider* resourceProvider, CommandBuff
|
||||
// provided to the task. Then close the render pass and we should have pixels..
|
||||
|
||||
// Instantiate the target
|
||||
if (fTarget) {
|
||||
if (!fTarget->instantiate(resourceProvider)) {
|
||||
SKGPU_LOG_W("Given invalid texture proxy. Will not create renderpass!");
|
||||
SKGPU_LOG_W("Dimensions are (%d, %d).",
|
||||
fTarget->dimensions().width(), fTarget->dimensions().height());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
SkASSERT(fTarget && fTarget->isInstantiated());
|
||||
|
||||
// We don't instantiate the MSAA or DS attachments in prepareResources because we want to use
|
||||
// the discardable attachments from the Context.
|
||||
sk_sp<Texture> colorAttachment;
|
||||
sk_sp<Texture> resolveAttachment;
|
||||
if (fRenderPassDesc.fColorResolveAttachment.fTextureInfo.isValid()) {
|
||||
|
@ -35,6 +35,8 @@ public:
|
||||
|
||||
~RenderPassTask() override;
|
||||
|
||||
bool prepareResources(ResourceProvider*) override;
|
||||
|
||||
bool addCommands(ResourceProvider*, CommandBuffer*) override;
|
||||
|
||||
private:
|
||||
|
@ -19,6 +19,10 @@ class Task : public SkRefCnt {
|
||||
public:
|
||||
~Task() override;
|
||||
|
||||
// Instantiate and prepare any Resources that must happen while the Task is still on the
|
||||
// Recorder.
|
||||
virtual bool prepareResources(ResourceProvider*) = 0;
|
||||
|
||||
// Returns true on success; false on failure.
|
||||
virtual bool addCommands(ResourceProvider*, CommandBuffer*) = 0;
|
||||
|
||||
|
@ -16,6 +16,16 @@ void TaskGraph::add(sk_sp<Task> task) {
|
||||
fTasks.emplace_back(std::move(task));
|
||||
}
|
||||
|
||||
bool TaskGraph::prepareResources(ResourceProvider* resourceProvider) {
|
||||
for (const auto& task: fTasks) {
|
||||
if (!task->prepareResources(resourceProvider)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskGraph::addCommands(ResourceProvider* resourceProvider, CommandBuffer* commandBuffer) {
|
||||
for (const auto& task: fTasks) {
|
||||
if (!task->addCommands(resourceProvider, commandBuffer)) {
|
||||
|
@ -23,7 +23,9 @@ public:
|
||||
void add(sk_sp<Task>);
|
||||
|
||||
// Returns true on success; false on failure
|
||||
bool prepareResources(ResourceProvider*);
|
||||
bool addCommands(ResourceProvider*, CommandBuffer*);
|
||||
|
||||
void reset();
|
||||
|
||||
protected:
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
const TextureInfo& textureInfo() const { return fInfo; }
|
||||
|
||||
bool instantiate(ResourceProvider*);
|
||||
bool isInstantiated() const { return SkToBool(fTexture); }
|
||||
sk_sp<Texture> refTexture() const;
|
||||
const Texture* texture() const;
|
||||
|
||||
|
@ -136,16 +136,20 @@ UploadInstance UploadInstance::Make(Recorder* recorder,
|
||||
return {bufferInfo.fBuffer, std::move(textureProxy), std::move(copyData)};
|
||||
}
|
||||
|
||||
void UploadInstance::addCommand(ResourceProvider* resourceProvider,
|
||||
CommandBuffer* commandBuffer) const {
|
||||
bool UploadInstance::prepareResources(ResourceProvider* resourceProvider) {
|
||||
if (!fTextureProxy) {
|
||||
SKGPU_LOG_E("No texture proxy specified for UploadTask");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (!fTextureProxy->instantiate(resourceProvider)) {
|
||||
SKGPU_LOG_E("Could not instantiate texture proxy for UploadTask!");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void UploadInstance::addCommand(CommandBuffer* commandBuffer) const {
|
||||
SkASSERT(fTextureProxy && fTextureProxy->isInstantiated());
|
||||
|
||||
// The CommandBuffer doesn't take ownership of the upload buffer here; it's owned by
|
||||
// UploadBufferManager, which will transfer ownership in transferToCommandBuffer.
|
||||
@ -192,10 +196,20 @@ UploadTask::UploadTask(const UploadInstance& instance) {
|
||||
|
||||
UploadTask::~UploadTask() {}
|
||||
|
||||
bool UploadTask::addCommands(ResourceProvider* resourceProvider,
|
||||
bool UploadTask::prepareResources(ResourceProvider* resourceProvider) {
|
||||
for (unsigned int i = 0; i < fInstances.size(); ++i) {
|
||||
if (!fInstances[i].prepareResources(resourceProvider)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UploadTask::addCommands(ResourceProvider*,
|
||||
CommandBuffer* commandBuffer) {
|
||||
for (unsigned int i = 0; i < fInstances.size(); ++i) {
|
||||
fInstances[i].addCommand(resourceProvider, commandBuffer);
|
||||
fInstances[i].addCommand(commandBuffer);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -44,8 +44,10 @@ public:
|
||||
|
||||
bool isValid() const { return fBuffer != nullptr; }
|
||||
|
||||
bool prepareResources(ResourceProvider*);
|
||||
|
||||
// Adds upload command to the given CommandBuffer
|
||||
void addCommand(ResourceProvider*, CommandBuffer*) const;
|
||||
void addCommand( CommandBuffer*) const;
|
||||
|
||||
private:
|
||||
UploadInstance() {}
|
||||
@ -95,6 +97,8 @@ public:
|
||||
|
||||
~UploadTask() override;
|
||||
|
||||
bool prepareResources(ResourceProvider*) override;
|
||||
|
||||
bool addCommands(ResourceProvider*, CommandBuffer*) override;
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user