| 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 |
#include "src/gpu/graphite/DrawPass.h" |
| 8 |
|
| 9 |
#include "src/core/SkTraceEvent.h" |
| 10 |
#include "src/gpu/graphite/Log.h" |
| 11 |
#include "src/gpu/graphite/PaintParams.h" |
| 12 |
#include "src/gpu/graphite/PaintParamsKey.h" |
| 13 |
#include "src/gpu/graphite/PipelineCreationTask.h" |
| 14 |
#include "src/gpu/graphite/PipelineData.h" |
| 15 |
#include "src/gpu/graphite/RenderPassDesc.h" |
| 16 |
#include "src/gpu/graphite/Resource.h" // IWYU pragma: keep |
| 17 |
#include "src/gpu/graphite/ResourceProvider.h" |
| 18 |
#include "src/gpu/graphite/ResourceTypes.h" |
| 19 |
#include "src/gpu/graphite/RuntimeEffectDictionary.h" |
| 20 |
#include "src/gpu/graphite/Texture.h" // IWYU pragma: keep |
| 21 |
#include "src/gpu/graphite/TextureProxy.h" |
| 22 |
|
| 23 |
|
| 24 |
using namespace skia_private; |
| 25 |
|
| 26 |
namespace skgpu::graphite { |
| 27 |
|
| 28 |
DrawPass::DrawPass(sk_sp<TextureProxy> target, |
| 29 |
std::pair<LoadOp, StoreOp> ops, |
| 30 |
std::array<float, 4> clearColor, |
| 31 |
sk_sp<FloatStorageManager> floatStorageManager) |
| 32 |
: fTarget(std::move(target)) |
| 33 |
, fBounds(SkIRect::MakeEmpty()) |
| 34 |
, fOps(ops) |
| 35 |
, fClearColor(clearColor) |
| 36 |
, fFloatStorageManager(floatStorageManager) {} |
| 37 |
|
| 38 |
DrawPass::~DrawPass() = default; |
| 39 |
|
| 40 |
bool DrawPass::prepareResources(ResourceProvider* resourceProvider, |
| 41 |
sk_sp<const RuntimeEffectDictionary> runtimeDict, |
| 42 |
const RenderPassDesc& renderPassDesc) { |
| 43 |
TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 44 |
|
| 45 |
fPipelineHandles.reserve(fPipelineDescs.size()); |
| 46 |
for (const GraphicsPipelineDesc& pipelineDesc : fPipelineDescs) { |
| 47 |
fPipelineHandles.push_back( |
| 48 |
resourceProvider->createGraphicsPipelineHandle(pipelineDesc, |
| 49 |
renderPassDesc, |
| 50 |
PipelineCreationFlags::kNone)); |
| 51 |
resourceProvider->startPipelineCreationTask(runtimeDict, fPipelineHandles.back()); |
| 52 |
} |
| 53 |
|
| 54 |
// The DrawPass may be long lived on a Recording and we no longer need the GraphicPipelineDescs |
| 55 |
// once we've created pipeline handles, so we drop the storage for them here. |
| 56 |
fPipelineDescs.clear(); |
| 57 |
|
| 58 |
// TODO(robertphillips): move this resolvePipeline loop to addResourceRefs |
| 59 |
fFullPipelines.reserve(fPipelineHandles.size()); |
| 60 |
for (const GraphicsPipelineHandle& handle : fPipelineHandles) { |
| 61 |
sk_sp<GraphicsPipeline> pipeline = resourceProvider->resolveHandle(handle); |
| 62 |
if (!pipeline) { |
| 63 |
SKGPU_LOG_W("Failed to create GraphicsPipeline for draw in RenderPass. Dropping pass!"); |
| 64 |
return false; |
| 65 |
} |
| 66 |
fFullPipelines.push_back(std::move(pipeline)); |
| 67 |
} |
| 68 |
fPipelineHandles.clear(); |
| 69 |
|
| 70 |
for (int i = 0; i < fSampledTextures.size(); ++i) { |
| 71 |
// It should not have been possible to draw an Image that has an invalid texture info |
| 72 |
SkASSERT(fSampledTextures[i]->textureInfo().isValid()); |
| 73 |
// Tasks should have been ordered to instantiate any scratch textures already, or any |
| 74 |
// client-owned image will have been instantiated at creation. However, if a TextureProxy |
| 75 |
// was cached for reuse across Recordings, it's possible that the initializing Recording |
| 76 |
// failed, leaving the TextureProxy in a bad state (and currently with no way to reconstruct |
| 77 |
// the tasks required to initialize it). |
| 78 |
// TODO(b/409888039): Once TextureProxies track their dependendent tasks to include in all |
| 79 |
// Recordings, this "should" be able to changed to asserts. |
| 80 |
if (!fSampledTextures[i]->isInstantiated() && !fSampledTextures[i]->isLazy()) { |
| 81 |
SKGPU_LOG_W("Cannot sample from an uninstantiated TextureProxy, label %s", |
| 82 |
fSampledTextures[i]->label()); |
| 83 |
return false; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
// TODO(robertphillips): when fFullHandles resolution is moved to addResourceRefs, this will |
| 88 |
// either need to move there as well, or the label will have to be available on the |
| 89 |
// GraphicsPipelineHandle (plausible since we either have the pipeline with its label, or we |
| 90 |
// likely calculated the label as part of triggering a cache miss). |
| 91 |
{ |
| 92 |
TRACE_EVENT0_ALWAYS("skia.shaders", "GraphitePipelineUse"); |
| 93 |
TRACE_EVENT0_ALWAYS("skia.shaders", TRACE_STR_COPY(renderPassDesc.toString().c_str())); |
| 94 |
for (int i = 0 ; i < fFullPipelines.size(); ++i) { |
| 95 |
TRACE_EVENT_INSTANT1_ALWAYS( |
| 96 |
"skia.shaders", |
| 97 |
TRACE_STR_COPY(fFullPipelines[i]->getLabel()), |
| 98 |
TRACE_EVENT_SCOPE_THREAD, |
| 99 |
"area", sk_float_saturate2int(fPipelineDrawAreas[i])); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
return true; |
| 104 |
} |
| 105 |
|
| 106 |
bool DrawPass::addResourceRefs(ResourceProvider* resourceProvider, |
| 107 |
CommandBuffer* commandBuffer) { |
| 108 |
for (int i = 0; i < fFullPipelines.size(); ++i) { |
| 109 |
commandBuffer->trackResource(fFullPipelines[i]); |
| 110 |
} |
| 111 |
for (int i = 0; i < fSampledTextures.size(); ++i) { |
| 112 |
commandBuffer->trackCommandBufferResource(fSampledTextures[i]->refTexture()); |
| 113 |
} |
| 114 |
|
| 115 |
return true; |
| 116 |
} |
| 117 |
|
| 118 |
} // namespace skgpu::graphite |