[graphite] Add ContextOptions

Bug: skia:13118
Change-Id: I0d6e0a9f542680456d3de82a32376722c5b9cd1d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/549097
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2022-06-14 08:51:56 -04:00 committed by SkCQ
parent 3f7af60e79
commit 56e6286317
15 changed files with 81 additions and 21 deletions

View File

@ -11,6 +11,7 @@ _include_private = get_path_info("../include/private/gpu/graphite", "abspath")
skia_graphite_public = [
"$_include/BackendTexture.h",
"$_include/Context.h",
"$_include/ContextOptions.h",
"$_include/GraphiteTypes.h",
"$_include/Recorder.h",
"$_include/Recording.h",

View File

@ -10,6 +10,7 @@
#include "include/core/SkRefCnt.h"
#include "include/core/SkShader.h"
#include "include/gpu/graphite/ContextOptions.h"
#include "include/gpu/graphite/GraphiteTypes.h"
class SkBlenderID;
@ -39,7 +40,7 @@ public:
~Context();
#ifdef SK_METAL
static std::unique_ptr<Context> MakeMetal(const skgpu::graphite::MtlBackendContext&);
static std::unique_ptr<Context> MakeMetal(const MtlBackendContext&, const ContextOptions&);
#endif
BackendApi backend() const { return fBackend; }

View File

@ -0,0 +1,27 @@
/*
* 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_graphite_ContextOptions_DEFINED
#define skgpu_graphite_ContextOptions_DEFINED
namespace skgpu { class ShaderErrorHandler; }
namespace skgpu::graphite {
struct SK_API ContextOptions {
ContextOptions() {}
/**
* If present, use this object to report shader compilation failures. If not, report failures
* via SkDebugf and assert.
*/
skgpu::ShaderErrorHandler* fShaderErrorHandler = nullptr;
};
} // namespace skgpu::graphite
#endif // skgpu_graphite_ContextOptions

View File

@ -7,6 +7,8 @@
#include "src/gpu/graphite/Caps.h"
#include "include/gpu/ShaderErrorHandler.h"
#include "include/gpu/graphite/ContextOptions.h"
#include "include/gpu/graphite/TextureInfo.h"
#include "src/sksl/SkSLUtil.h"
@ -15,8 +17,14 @@ namespace skgpu::graphite {
Caps::Caps() : fShaderCaps(std::make_unique<SkSL::ShaderCaps>()) {}
Caps::~Caps() {}
void Caps::finishInitialization() {
void Caps::finishInitialization(const ContextOptions& options) {
this->initSkCaps(fShaderCaps.get());
if (options.fShaderErrorHandler) {
fShaderErrorHandler = options.fShaderErrorHandler;
} else {
fShaderErrorHandler = DefaultShaderErrorHandler();
}
}
bool Caps::isTexturable(const TextureInfo& info) const {

View File

@ -16,12 +16,13 @@
#include "src/gpu/Swizzle.h"
#include "src/gpu/graphite/ResourceTypes.h"
namespace SkSL {
struct ShaderCaps;
}
namespace SkSL { struct ShaderCaps; }
namespace skgpu { class ShaderErrorHandler; }
namespace skgpu::graphite {
struct ContextOptions;
class GraphicsPipelineDesc;
class GraphiteResourceKey;
struct RenderPassDesc;
@ -78,12 +79,14 @@ public:
// SkColorType and TextureInfo.
skgpu::Swizzle getWriteSwizzle(SkColorType, const TextureInfo&) const;
skgpu::ShaderErrorHandler* shaderErrorHandler() const { return fShaderErrorHandler; }
protected:
Caps();
// Subclasses must call this at the end of their init method in order to do final processing on
// the caps.
void finishInitialization();
void finishInitialization(const ContextOptions&);
// TODO: This value should be set by some context option. For now just making it 4.
uint32_t defaultMSAASamples() const { return 4; }
@ -111,6 +114,15 @@ protected:
bool fClampToBorderSupport = true;
//////////////////////////////////////////////////////////////////////////////////////////
// Client-provided Caps
/**
* If present, use this object to report shader compilation failures. If not, report failures
* via SkDebugf and assert.
*/
ShaderErrorHandler* fShaderErrorHandler = nullptr;
private:
virtual bool onIsTexturable(const TextureInfo&) const = 0;
virtual const ColorTypeInfo* getColorTypeInfo(SkColorType, const TextureInfo&) const = 0;

View File

@ -40,8 +40,9 @@ Context::Context(sk_sp<Gpu> gpu, BackendApi backend)
Context::~Context() {}
#ifdef SK_METAL
std::unique_ptr<Context> Context::MakeMetal(const MtlBackendContext& backendContext) {
sk_sp<Gpu> gpu = MtlTrampoline::MakeGpu(backendContext);
std::unique_ptr<Context> Context::MakeMetal(const MtlBackendContext& backendContext,
const ContextOptions& options) {
sk_sp<Gpu> gpu = MtlTrampoline::MakeGpu(backendContext, options);
if (!gpu) {
return nullptr;
}

View File

@ -15,10 +15,11 @@
#include "src/gpu/graphite/Caps.h"
namespace skgpu::graphite {
struct ContextOptions;
class MtlCaps final : public skgpu::graphite::Caps {
public:
MtlCaps(const id<MTLDevice>);
MtlCaps(const id<MTLDevice>, const ContextOptions&);
~MtlCaps() override {}
TextureInfo getDefaultSampledTextureInfo(SkColorType,

View File

@ -17,7 +17,7 @@
namespace skgpu::graphite {
MtlCaps::MtlCaps(const id<MTLDevice> device)
MtlCaps::MtlCaps(const id<MTLDevice> device, const ContextOptions& options)
: Caps() {
this->initGPUFamily(device);
this->initCaps(device);
@ -27,7 +27,7 @@ MtlCaps::MtlCaps(const id<MTLDevice> device)
// Metal-specific MtlCaps
this->finishInitialization();
this->finishInitialization(options);
}
// translates from older MTLFeatureSet interface to MTLGPUFamily interface

View File

@ -18,10 +18,11 @@
#import <Metal/Metal.h>
namespace skgpu::graphite {
struct ContextOptions;
class MtlGpu final : public Gpu {
public:
static sk_sp<Gpu> Make(const MtlBackendContext&);
static sk_sp<Gpu> Make(const MtlBackendContext&, const ContextOptions&);
~MtlGpu() override;
id<MTLDevice> device() const { return fDevice.get(); }

View File

@ -18,7 +18,8 @@
namespace skgpu::graphite {
sk_sp<skgpu::graphite::Gpu> MtlGpu::Make(const MtlBackendContext& context) {
sk_sp<skgpu::graphite::Gpu> MtlGpu::Make(const MtlBackendContext& context,
const ContextOptions& options) {
// TODO: This was taken from GrMtlGpu.mm's Make, does graphite deserve a higher version?
if (@available(macOS 10.14, iOS 11.0, *)) {
// no warning needed
@ -35,9 +36,11 @@ sk_sp<skgpu::graphite::Gpu> MtlGpu::Make(const MtlBackendContext& context) {
sk_cfp<id<MTLDevice>> device = sk_ret_cfp((id<MTLDevice>)(context.fDevice.get()));
sk_cfp<id<MTLCommandQueue>> queue = sk_ret_cfp((id<MTLCommandQueue>)(context.fQueue.get()));
sk_sp<const MtlCaps> caps(new MtlCaps(device.get()));
sk_sp<const MtlCaps> caps(new MtlCaps(device.get(), options));
return sk_sp<skgpu::graphite::Gpu>(new MtlGpu(std::move(device), std::move(queue), std::move(caps)));
return sk_sp<skgpu::graphite::Gpu>(new MtlGpu(std::move(device),
std::move(queue),
std::move(caps)));
}
MtlGpu::MtlGpu(sk_cfp<id<MTLDevice>> device,

View File

@ -509,7 +509,7 @@ sk_sp<MtlGraphicsPipeline> MtlGraphicsPipeline::Make(
settings.fForceNoRTFlip = true;
ShaderErrorHandler* errorHandler = DefaultShaderErrorHandler();
ShaderErrorHandler* errorHandler = gpu->caps()->shaderErrorHandler();
if (!SkSLToMSL(gpu,
get_sksl_vs(pipelineDesc),
SkSL::ProgramKind::kGraphiteVertex,

View File

@ -11,6 +11,7 @@
#include "include/core/SkRefCnt.h"
namespace skgpu::graphite {
struct ContextOptions;
class Gpu;
struct MtlBackendContext;
@ -20,7 +21,7 @@ struct MtlBackendContext;
*/
class MtlTrampoline {
public:
static sk_sp<skgpu::graphite::Gpu> MakeGpu(const MtlBackendContext&);
static sk_sp<skgpu::graphite::Gpu> MakeGpu(const MtlBackendContext&, const ContextOptions&);
};
} // namespace skgpu::graphite

View File

@ -10,8 +10,9 @@
#include "src/gpu/graphite/mtl/MtlGpu.h"
namespace skgpu::graphite {
sk_sp<skgpu::graphite::Gpu> MtlTrampoline::MakeGpu(const MtlBackendContext& backendContext) {
return MtlGpu::Make(backendContext);
sk_sp<skgpu::graphite::Gpu> MtlTrampoline::MakeGpu(const MtlBackendContext& backendContext,
const ContextOptions& options) {
return MtlGpu::Make(backendContext, options);
}
} // namespace skgpu::graphite

View File

@ -8,6 +8,7 @@
#include "tools/graphite/mtl/GraphiteMtlTestContext.h"
#include "include/gpu/graphite/Context.h"
#include "include/gpu/graphite/ContextOptions.h"
#include "include/gpu/graphite/mtl/MtlTypes.h"
#ifdef SK_METAL
@ -48,7 +49,7 @@ std::unique_ptr<GraphiteTestContext> MtlTestContext::Make() {
}
std::unique_ptr<skgpu::graphite::Context> MtlTestContext::makeContext() {
return skgpu::graphite::Context::MakeMetal(fMtl);
return skgpu::graphite::Context::MakeMetal(fMtl, skgpu::graphite::ContextOptions{});
}
} // namespace skiatest::graphite::mtl

View File

@ -11,6 +11,7 @@
#include "include/gpu/graphite/BackendTexture.h"
#include "include/gpu/graphite/Context.h"
#include "include/gpu/graphite/ContextOptions.h"
#include "include/gpu/graphite/Recorder.h"
#include "include/gpu/graphite/Recording.h"
#include "include/gpu/graphite/SkStuff.h"
@ -53,7 +54,8 @@ void GraphiteMetalWindowContext::initializeContext() {
skgpu::graphite::MtlBackendContext backendContext = {};
backendContext.fDevice.retain((skgpu::graphite::MtlHandle)fDevice.get());
backendContext.fQueue.retain((skgpu::graphite::MtlHandle)fQueue.get());
fGraphiteContext = skgpu::graphite::Context::MakeMetal(backendContext);
fGraphiteContext = skgpu::graphite::Context::MakeMetal(backendContext,
skgpu::graphite::ContextOptions());
fGraphiteRecorder = fGraphiteContext->makeRecorder();
// TODO
// if (!fGraphiteContext && fDisplayParams.fMSAASampleCount > 1) {