[graphite] Add a result param to graphite callbacks.
Bug: skia:12974 Change-Id: Ie10ef5c8ab4e04647233a6039d22a2eb6437d6bf Reviewed-on: https://skia-review.googlesource.com/c/skia/+/526022 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
027b9c0d38
commit
6b52f372c3
@ -30,7 +30,10 @@ generated_cc_atom(
|
||||
name = "GraphiteTypes_hdr",
|
||||
hdrs = ["GraphiteTypes.h"],
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = ["//include/core:SkTypes_hdr"],
|
||||
deps = [
|
||||
"//include/core:SkTypes_hdr",
|
||||
"//include/gpu:GpuTypes_hdr",
|
||||
],
|
||||
)
|
||||
|
||||
generated_cc_atom(
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define skgpu_GraphiteTypes_DEFINED
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/gpu/GpuTypes.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -17,8 +18,16 @@ namespace skgpu {
|
||||
class Recording;
|
||||
|
||||
using GpuFinishedContext = void*;
|
||||
using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext);
|
||||
using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackResult);
|
||||
|
||||
/**
|
||||
* The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or
|
||||
* when there is a failure that caused it not to be submitted. The callback will always be called
|
||||
* and the caller can use the callback to know it is safe to free any resources associated with
|
||||
* the Recording that they may be holding onto. If the Recording is successfully submitted to the
|
||||
* GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All
|
||||
* other cases where some failure occured it will be called with CallbackResult::kFailed.
|
||||
*/
|
||||
struct InsertRecordingInfo {
|
||||
Recording* fRecording = nullptr;
|
||||
GpuFinishedContext fFinishedContext = nullptr;
|
||||
|
@ -37,7 +37,12 @@ void CommandBuffer::addFinishedProc(sk_sp<RefCntedCallback> finishedProc) {
|
||||
fFinishedProcs.push_back(std::move(finishedProc));
|
||||
}
|
||||
|
||||
void CommandBuffer::callFinishedProcs() {
|
||||
void CommandBuffer::callFinishedProcs(bool success) {
|
||||
if (!success) {
|
||||
for (int i = 0; i < fFinishedProcs.count(); ++i) {
|
||||
fFinishedProcs[i]->setFailureResult();
|
||||
}
|
||||
}
|
||||
fFinishedProcs.reset();
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
void trackResource(sk_sp<Resource> resource);
|
||||
|
||||
void addFinishedProc(sk_sp<RefCntedCallback> finishedProc);
|
||||
void callFinishedProcs();
|
||||
void callFinishedProcs(bool success);
|
||||
|
||||
bool beginRenderPass(const RenderPassDesc&,
|
||||
sk_sp<Texture> colorTexture,
|
||||
|
@ -60,6 +60,9 @@ void Context::insertRecording(const InsertRecordingInfo& info) {
|
||||
|
||||
SkASSERT(info.fRecording);
|
||||
if (!info.fRecording) {
|
||||
if (callback) {
|
||||
callback->setFailureResult();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ GpuWorkSubmission::GpuWorkSubmission(sk_sp<CommandBuffer> cmdBuffer)
|
||||
: fCommandBuffer(std::move(cmdBuffer)) {}
|
||||
|
||||
GpuWorkSubmission::~GpuWorkSubmission() {
|
||||
fCommandBuffer->callFinishedProcs();
|
||||
fCommandBuffer->callFinishedProcs(/*success=*/true);
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -59,7 +59,7 @@ std::unique_ptr<skgpu::ResourceProvider> Gpu::makeResourceProvider(
|
||||
|
||||
class WorkSubmission final : public skgpu::GpuWorkSubmission {
|
||||
public:
|
||||
WorkSubmission(sk_sp<CommandBuffer> cmdBuffer)
|
||||
WorkSubmission(sk_sp<skgpu::CommandBuffer> cmdBuffer)
|
||||
: GpuWorkSubmission(std::move(cmdBuffer)) {}
|
||||
~WorkSubmission() override {}
|
||||
|
||||
@ -76,12 +76,13 @@ private:
|
||||
|
||||
skgpu::Gpu::OutstandingSubmission Gpu::onSubmit(sk_sp<skgpu::CommandBuffer> commandBuffer) {
|
||||
SkASSERT(commandBuffer);
|
||||
sk_sp<CommandBuffer>& mtlCmdBuffer = (sk_sp<CommandBuffer>&)(commandBuffer);
|
||||
CommandBuffer* mtlCmdBuffer = static_cast<CommandBuffer*>(commandBuffer.get());
|
||||
if (!mtlCmdBuffer->commit()) {
|
||||
commandBuffer->callFinishedProcs(/*success=*/false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GpuWorkSubmission> submission(new WorkSubmission(mtlCmdBuffer));
|
||||
std::unique_ptr<GpuWorkSubmission> submission(new WorkSubmission(std::move(commandBuffer)));
|
||||
return submission;
|
||||
}
|
||||
|
||||
|
@ -801,6 +801,7 @@ skia_native_gpu_sources = [
|
||||
]
|
||||
|
||||
skia_shared_gpu_sources = [
|
||||
"$_include/gpu/GpuTypes.h",
|
||||
"$_include/gpu/ShaderErrorHandler.h",
|
||||
"$_include/private/SingleOwner.h",
|
||||
"$_src/gpu/Blend.h",
|
||||
|
@ -167,3 +167,10 @@ generated_cc_atom(
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = ["//include/core:SkTypes_hdr"],
|
||||
)
|
||||
|
||||
generated_cc_atom(
|
||||
name = "GpuTypes_hdr",
|
||||
hdrs = ["GpuTypes.h"],
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = ["//include/core:SkTypes_hdr"],
|
||||
)
|
||||
|
32
include/gpu/GpuTypes.h
Normal file
32
include/gpu/GpuTypes.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2022 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef skgpu_GpuTypes_DEFINED
|
||||
#define skgpu_GpuTypes_DEFINED
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
/**
|
||||
* This file includes numerous public types that are used by all of our gpu backends.
|
||||
*/
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
/**
|
||||
* Value passed into various callbacks to tell the client the result of operations connected to a
|
||||
* specific callback. The actual interpretation of kFailed and kSuccess are dependent on the
|
||||
* specific callbacks and are documented with the callback itself.
|
||||
*/
|
||||
enum class CallbackResult : bool {
|
||||
kFailed = true,
|
||||
kSuccess = true,
|
||||
};
|
||||
|
||||
|
||||
} // namespace skgpu
|
||||
|
||||
#endif // skgpu_GpuTypes_DEFINED
|
@ -3564,5 +3564,8 @@ generated_cc_atom(
|
||||
name = "RefCntedCallback_hdr",
|
||||
hdrs = ["RefCntedCallback.h"],
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = ["//include/core:SkRefCnt_hdr"],
|
||||
deps = [
|
||||
"//include/core:SkRefCnt_hdr",
|
||||
"//include/gpu:GpuTypes_hdr",
|
||||
],
|
||||
)
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define skgpu_RefCntedCallback_DEFINED
|
||||
|
||||
#include "include/core/SkRefCnt.h"
|
||||
#include "include/gpu/GpuTypes.h"
|
||||
|
||||
namespace skgpu {
|
||||
/**
|
||||
@ -18,6 +19,7 @@ class RefCntedCallback : public SkNVRefCnt<RefCntedCallback> {
|
||||
public:
|
||||
using Context = void*;
|
||||
using Callback = void (*)(Context);
|
||||
using ResultCallback = void (*)(Context, CallbackResult);
|
||||
|
||||
static sk_sp<RefCntedCallback> Make(Callback proc, Context ctx) {
|
||||
if (!proc) {
|
||||
@ -26,19 +28,45 @@ public:
|
||||
return sk_sp<RefCntedCallback>(new RefCntedCallback(proc, ctx));
|
||||
}
|
||||
|
||||
~RefCntedCallback() { fReleaseProc(fReleaseCtx); }
|
||||
static sk_sp<RefCntedCallback> Make(ResultCallback proc, Context ctx) {
|
||||
if (!proc) {
|
||||
return nullptr;
|
||||
}
|
||||
return sk_sp<RefCntedCallback>(new RefCntedCallback(proc, ctx));
|
||||
}
|
||||
|
||||
~RefCntedCallback() {
|
||||
if (fReleaseProc) {
|
||||
SkASSERT(!fResultReleaseProc);
|
||||
fReleaseProc(fReleaseCtx);
|
||||
} else {
|
||||
SkASSERT(fResultReleaseProc);
|
||||
fResultReleaseProc(fReleaseCtx, fResult);
|
||||
}
|
||||
}
|
||||
|
||||
Context context() const { return fReleaseCtx; }
|
||||
|
||||
void setFailureResult() {
|
||||
SkASSERT(fResultReleaseProc);
|
||||
// Shouldn't really be calling this multiple times.
|
||||
SkASSERT(fResult == CallbackResult::kSuccess);
|
||||
fResult = CallbackResult::kFailed;
|
||||
}
|
||||
|
||||
private:
|
||||
RefCntedCallback(Callback proc, Context ctx) : fReleaseProc(proc), fReleaseCtx(ctx) {}
|
||||
RefCntedCallback(ResultCallback proc, Context ctx)
|
||||
: fResultReleaseProc(proc), fReleaseCtx(ctx) {}
|
||||
RefCntedCallback(const RefCntedCallback&) = delete;
|
||||
RefCntedCallback(RefCntedCallback&&) = delete;
|
||||
RefCntedCallback& operator=(const RefCntedCallback&) = delete;
|
||||
RefCntedCallback& operator=(RefCntedCallback&&) = delete;
|
||||
|
||||
Callback fReleaseProc;
|
||||
Callback fReleaseProc = nullptr;
|
||||
ResultCallback fResultReleaseProc = nullptr;
|
||||
Context fReleaseCtx;
|
||||
CallbackResult fResult = CallbackResult::kSuccess;
|
||||
};
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -98,7 +98,10 @@ generated_cc_atom(
|
||||
name = "FlushFinishTracker_hdr",
|
||||
hdrs = ["FlushFinishTracker.h"],
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = ["//include/core:SkRefCnt_hdr"],
|
||||
deps = [
|
||||
"//include/core:SkRefCnt_hdr",
|
||||
"//include/gpu:GpuTypes_hdr",
|
||||
],
|
||||
)
|
||||
|
||||
generated_cc_atom(
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define FlushFinishTracker_DEFINED
|
||||
|
||||
#include "include/core/SkRefCnt.h"
|
||||
#include "include/gpu/GpuTypes.h"
|
||||
|
||||
class GrDirectContext;
|
||||
|
||||
@ -26,6 +27,10 @@ public:
|
||||
tracker->unref();
|
||||
}
|
||||
|
||||
static void FlushFinishedResult(void* finishedContext, skgpu::CallbackResult) {
|
||||
FlushFinished(finishedContext);
|
||||
}
|
||||
|
||||
FlushFinishTracker(GrDirectContext* context) : fContext(context) {}
|
||||
#ifdef SK_GRAPHITE_ENABLED
|
||||
FlushFinishTracker(skgpu::Context* context) : fGraphiteContext(context) {}
|
||||
|
@ -38,7 +38,7 @@ void GraphiteTestContext::submitRecordingAndWaitOnSync(skgpu::Context* context,
|
||||
skgpu::InsertRecordingInfo info;
|
||||
info.fRecording = recording;
|
||||
info.fFinishedContext = fFinishTrackers[fCurrentFlushIdx].get();
|
||||
info.fFinishedProc = sk_gpu_test::FlushFinishTracker::FlushFinished;
|
||||
info.fFinishedProc = sk_gpu_test::FlushFinishTracker::FlushFinishedResult;
|
||||
context->insertRecording(info);
|
||||
|
||||
context->submit(skgpu::SyncToCpu::kNo);
|
||||
|
Loading…
Reference in New Issue
Block a user