[graphite] Hook up viewer

Bug: skia:12633
Change-Id: Id0bd892375e3a3e2886714f19b7fd8da2232e4e2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/479736
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2022-01-14 13:41:29 -05:00 committed by SkCQ
parent 17d90a09a8
commit 7022d74567
6 changed files with 50 additions and 34 deletions

View File

@ -339,17 +339,19 @@ UniqueKey Caps::makeGraphicsPipelineKey(const GraphicsPipelineDesc& pipelineDesc
}
bool Caps::onIsTexturable(const skgpu::TextureInfo& info) const {
return info.mtlTextureSpec().fUsage & MTLTextureUsageShaderRead &&
this->isTexturable((MTLPixelFormat)info.mtlTextureSpec().fFormat);
if (!(info.mtlTextureSpec().fUsage & MTLTextureUsageShaderRead)) {
return false;
}
if (info.mtlTextureSpec().fFramebufferOnly) {
return false;
}
return this->isTexturable((MTLPixelFormat)info.mtlTextureSpec().fFormat);
}
bool Caps::isTexturable(MTLPixelFormat format) const {
// TODO: Fill out format table so that we can query all formats. For now we only support RGBA8
// which is supported everywhere.
if (format != MTLPixelFormatRGBA8Unorm) {
return false;
}
return true;
// and BGRA8 which is supported everywhere.
return format == MTLPixelFormatRGBA8Unorm || format == MTLPixelFormatBGRA8Unorm;
}
bool Caps::isRenderable(const skgpu::TextureInfo& info) const {
@ -359,8 +361,9 @@ bool Caps::isRenderable(const skgpu::TextureInfo& info) const {
bool Caps::isRenderable(MTLPixelFormat format, uint32_t numSamples) const {
// TODO: Fill out format table so that we can query all formats. For now we only support RGBA8
// with a sampleCount of 1 which is supported everywhere.
if (format != MTLPixelFormatRGBA8Unorm || numSamples != 1) {
// and BGRA8 with a sampleCount of 1 which is supported everywhere.
if ((format != MTLPixelFormatRGBA8Unorm && format != MTLPixelFormatBGRA8Unorm) ||
numSamples != 1) {
return false;
}
return true;
@ -370,9 +373,11 @@ bool Caps::isRenderable(MTLPixelFormat format, uint32_t numSamples) const {
bool Caps::onAreColorTypeAndTextureInfoCompatible(SkColorType type,
const skgpu::TextureInfo& info) const {
// TODO: Fill out format table so that we can query all formats. For now we only support RGBA8
// for both the color type and format.
return type == kRGBA_8888_SkColorType &&
info.mtlTextureSpec().fFormat == MTLPixelFormatRGBA8Unorm;
// or BGRA8 for both the color type and format.
return (type == kRGBA_8888_SkColorType &&
info.mtlTextureSpec().fFormat == MTLPixelFormatRGBA8Unorm) ||
(type == kBGRA_8888_SkColorType &&
info.mtlTextureSpec().fFormat == MTLPixelFormatBGRA8Unorm);
}
} // namespace skgpu::mtl

View File

@ -399,6 +399,7 @@ sk_sp<GraphicsPipeline> GraphicsPipeline::Make(const Context* context,
renderPassDesc.fColorAttachment.fTextureInfo.getMtlTextureInfo(&mtlTexInfo);
mtlColorAttachment.pixelFormat = (MTLPixelFormat)mtlTexInfo.fFormat;
mtlColorAttachment.blendingEnabled = FALSE;
mtlColorAttachment.writeMask = writesColor ? MTLColorWriteMaskAll : MTLColorWriteMaskNone;

View File

@ -53,6 +53,8 @@ MTLPixelFormat SkColorTypeToFormat(SkColorType colorType) {
switch (colorType) {
case kRGBA_8888_SkColorType:
return MTLPixelFormatRGBA8Unorm;
case kBGRA_8888_SkColorType:
return MTLPixelFormatBGRA8Unorm;
case kAlpha_8_SkColorType:
return MTLPixelFormatR8Unorm;
case kRGBA_F16_SkColorType:

View File

@ -9,8 +9,13 @@
#include "src/core/SkMathPriv.h"
#include "tools/sk_app/GraphiteMetalWindowContext.h"
#include "experimental/graphite/include/BackendTexture.h"
#include "experimental/graphite/include/Context.h"
#include "experimental/graphite/include/Recorder.h"
#include "experimental/graphite/include/Recording.h"
#include "experimental/graphite/include/SkStuff.h"
#include "experimental/graphite/include/mtl/MtlBackendContext.h"
#include "experimental/graphite/include/mtl/MtlTypes.h"
using sk_app::DisplayParams;
using sk_app::GraphiteMetalWindowContext;
@ -46,9 +51,10 @@ void GraphiteMetalWindowContext::initializeContext() {
fValid = this->onInitializeContext();
skgpu::mtl::BackendContext backendContext = {};
backendContext.fDevice.retain((GrMTLHandle)fDevice.get());
backendContext.fQueue.retain((GrMTLHandle)fQueue.get());
backendContext.fDevice.retain((skgpu::mtl::Handle)fDevice.get());
backendContext.fQueue.retain((skgpu::mtl::Handle)fQueue.get());
fGraphiteContext = skgpu::Context::MakeMetal(backendContext);
fGraphiteRecorder = fGraphiteContext->makeRecorder();
// TODO
// if (!fGraphiteContext && fDisplayParams.fMSAASampleCount > 1) {
// fDisplayParams.fMSAASampleCount /= 2;
@ -70,11 +76,6 @@ void GraphiteMetalWindowContext::destroyContext() {
fMetalLayer = nil;
fValid = false;
#if GR_METAL_SDK_VERSION >= 230
if (@available(macOS 11.0, iOS 14.0, *)) {
[fPipelineArchive release];
}
#endif
fQueue.reset();
fDevice.reset();
}
@ -83,27 +84,29 @@ sk_sp<SkSurface> GraphiteMetalWindowContext::getBackbufferSurface() {
sk_sp<SkSurface> surface;
id<CAMetalDrawable> currentDrawable = [fMetalLayer nextDrawable];
// TODO
// GrMtlTextureInfo fbInfo;
// fbInfo.fTexture.retain(currentDrawable.texture);
//
// GrBackendRenderTarget backendRT(fWidth,
// fHeight,
// fSampleCount,
// fbInfo);
//
// surface = SkSurface::MakeFromBackendRenderTarget(fContext.get(), backendRT,
// kTopLeft_GrSurfaceOrigin,
// kBGRA_8888_SkColorType,
// fDisplayParams.fColorSpace,
// &fDisplayParams.fSurfaceProps);
skgpu::mtl::TextureInfo mtlInfo((skgpu::mtl::Handle)currentDrawable.texture);
fDrawableHandle = CFRetain((GrMTLHandle) currentDrawable);
skgpu::BackendTexture backendTex(this->dimensions(),
(skgpu::mtl::Handle)currentDrawable.texture);
surface = MakeGraphiteFromBackendTexture(this->graphiteRecorder(),
backendTex,
kBGRA_8888_SkColorType,
fDisplayParams.fColorSpace,
&fDisplayParams.fSurfaceProps);
fDrawableHandle = CFRetain((skgpu::mtl::Handle) currentDrawable);
return surface;
}
void GraphiteMetalWindowContext::swapBuffers() {
// This chunk of code should not be in this class but higher up either in Window or
// WindowContext
std::unique_ptr<skgpu::Recording> recording = fGraphiteRecorder->snap();
fGraphiteContext->insertRecording(std::move(recording));
fGraphiteContext->submit(skgpu::SyncToCpu::kNo);
id<CAMetalDrawable> currentDrawable = (id<CAMetalDrawable>)fDrawableHandle;
id<MTLCommandBuffer> commandBuffer([*fQueue commandBuffer]);

View File

@ -10,6 +10,7 @@
#include "include/gpu/GrDirectContext.h"
#ifdef SK_GRAPHITE_ENABLED
#include "experimental/graphite/include/Context.h"
#include "experimental/graphite/include/Recorder.h"
#endif
namespace sk_app {

View File

@ -17,6 +17,7 @@ class SkSurface;
#ifdef SK_GRAPHITE_ENABLED
namespace skgpu {
class Context;
class Recorder;
}
#endif
@ -44,10 +45,12 @@ public:
GrDirectContext* directContext() const { return fContext.get(); }
#ifdef SK_GRAPHITE_ENABLED
skgpu::Context* graphiteContext() const { return fGraphiteContext.get(); }
skgpu::Recorder* graphiteRecorder() const { return fGraphiteRecorder.get(); }
#endif
int width() const { return fWidth; }
int height() const { return fHeight; }
SkISize dimensions() const { return {fWidth, fHeight}; }
int sampleCount() const { return fSampleCount; }
int stencilBits() const { return fStencilBits; }
@ -57,6 +60,7 @@ protected:
sk_sp<GrDirectContext> fContext;
#if SK_GRAPHITE_ENABLED
sk_sp<skgpu::Context> fGraphiteContext;
std::unique_ptr<skgpu::Recorder> fGraphiteRecorder;
#endif
int fWidth;