Revert "Hook up ShaderErrorHandler in the Metal backend."

This reverts commit 69df532a55.

Reason for revert: See if this is causing the iOS redness on our tree

Original change's description:
> Hook up ShaderErrorHandler in the Metal backend.
>
> Also cleans up dumping of shader code to use GrShaderUtils.
>
> Change-Id: I4d2a13e1a54284d7da0242b74cebb3900921fc35
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/337077
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>

TBR=jvanverth@google.com,brianosman@google.com

Change-Id: I34125bd560cfbd12e50c732137cf921067457be2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/337184
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2020-11-20 21:59:56 +00:00 committed by Skia Commit-Bot
parent 10089c6a42
commit 0758da2c60
7 changed files with 95 additions and 92 deletions

View File

@ -214,15 +214,4 @@ GrContextOptions::ShaderErrorHandler* DefaultShaderErrorHandler() {
return &gHandler;
}
void PrintShaderBanner(SkSL::Program::Kind programKind) {
const char* typeName = "Unknown";
switch (programKind) {
case SkSL::Program::kVertex_Kind: typeName = "Vertex"; break;
case SkSL::Program::kGeometry_Kind: typeName = "Geometry"; break;
case SkSL::Program::kFragment_Kind: typeName = "Fragment"; break;
default: break;
}
SkDebugf("---- %s shader ----------------------------------------------------\n", typeName);
}
} // namespace GrShaderUtils

View File

@ -11,7 +11,6 @@
#include "include/core/SkTypes.h"
#include "include/gpu/GrContextOptions.h"
#include "src/sksl/SkSLString.h"
#include "src/sksl/ir/SkSLProgram.h"
namespace GrShaderUtils {
@ -29,8 +28,6 @@ inline void PrintLineByLine(const SkSL::String& text) {
GrContextOptions::ShaderErrorHandler* DefaultShaderErrorHandler();
void PrintShaderBanner(SkSL::Program::Kind programKind);
} // namespace GrShaderUtils
#endif

View File

@ -17,6 +17,17 @@
static const bool gPrintSKSL = false;
static const bool gPrintGLSL = false;
void print_shader_banner(SkSL::Program::Kind programKind) {
const char* typeName = "Unknown";
switch (programKind) {
case SkSL::Program::kVertex_Kind: typeName = "Vertex"; break;
case SkSL::Program::kGeometry_Kind: typeName = "Geometry"; break;
case SkSL::Program::kFragment_Kind: typeName = "Fragment"; break;
default: break;
}
SkDebugf("---- %s shader ----------------------------------------------------\n", typeName);
}
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context,
SkSL::Program::Kind programKind,
const SkSL::String& sksl,
@ -37,7 +48,7 @@ std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context,
}
if (gPrintSKSL || gPrintGLSL) {
GrShaderUtils::PrintShaderBanner(programKind);
print_shader_banner(programKind);
if (gPrintSKSL) {
SkDebugf("SKSL:\n");
GrShaderUtils::PrintLineByLine(GrShaderUtils::PrettyPrint(sksl));

View File

@ -53,13 +53,12 @@ private:
SkSL::Program::Kind kind,
const SkSL::Program::Settings& settings,
SkSL::String* msl,
SkSL::Program::Inputs* inputs,
GrContextOptions::ShaderErrorHandler* errorHandler);
SkSL::Program::Inputs* inputs);
id<MTLLibrary> compileMtlShaderLibrary(const SkSL::String& shader,
SkSL::Program::Inputs inputs,
GrContextOptions::ShaderErrorHandler* errorHandler);
SkSL::Program::Inputs inputs);
void storeShadersInCache(const SkSL::String shaders[], const SkSL::Program::Inputs inputs[],
bool isSkSL);
bool loadShadersFromCache(SkReadBuffer* cached, __strong id<MTLLibrary> outLibraries[]);
GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }

View File

@ -66,6 +66,27 @@ static constexpr SkFourByteTag kMSL_Tag = SkSetFourByteTag('M', 'S', 'L', ' ');
static constexpr SkFourByteTag kSKSL_Tag = SkSetFourByteTag('S', 'K', 'S', 'L');
bool GrMtlPipelineStateBuilder::loadShadersFromCache(SkReadBuffer* cached,
__strong id<MTLLibrary> outLibraries[]) {
SkSL::String shaders[kGrShaderTypeCount];
SkSL::Program::Inputs inputs[kGrShaderTypeCount];
if (!GrPersistentCacheUtils::UnpackCachedShaders(cached, shaders, inputs, kGrShaderTypeCount)) {
return false;
}
outLibraries[kVertex_GrShaderType] = this->compileMtlShaderLibrary(
shaders[kVertex_GrShaderType],
inputs[kVertex_GrShaderType]);
outLibraries[kFragment_GrShaderType] = this->compileMtlShaderLibrary(
shaders[kFragment_GrShaderType],
inputs[kFragment_GrShaderType]);
return outLibraries[kVertex_GrShaderType] &&
outLibraries[kFragment_GrShaderType] &&
shaders[kGeometry_GrShaderType].empty(); // Geometry shaders are not supported
}
void GrMtlPipelineStateBuilder::storeShadersInCache(const SkSL::String shaders[],
const SkSL::Program::Inputs inputs[],
bool isSkSL) {
@ -85,21 +106,18 @@ id<MTLLibrary> GrMtlPipelineStateBuilder::generateMtlShaderLibrary(
SkSL::Program::Kind kind,
const SkSL::Program::Settings& settings,
SkSL::String* msl,
SkSL::Program::Inputs* inputs,
GrContextOptions::ShaderErrorHandler* errorHandler) {
SkSL::Program::Inputs* inputs) {
id<MTLLibrary> shaderLibrary = GrGenerateMtlShaderLibrary(fGpu, shader,
kind, settings, msl, inputs,
errorHandler);
kind, settings, msl, inputs);
if (shaderLibrary != nil && inputs->fRTHeight) {
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
}
return shaderLibrary;
}
id<MTLLibrary> GrMtlPipelineStateBuilder::compileMtlShaderLibrary(
const SkSL::String& shader, SkSL::Program::Inputs inputs,
GrContextOptions::ShaderErrorHandler* errorHandler) {
id<MTLLibrary> shaderLibrary = GrCompileMtlShaderLibrary(fGpu, shader, errorHandler);
id<MTLLibrary> GrMtlPipelineStateBuilder::compileMtlShaderLibrary(const SkSL::String& shader,
SkSL::Program::Inputs inputs) {
id<MTLLibrary> shaderLibrary = GrCompileMtlShaderLibrary(fGpu, shader);
if (shaderLibrary != nil && inputs.fRTHeight) {
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
}
@ -395,23 +413,12 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(GrRenderTarget* renderTa
}
}
auto errorHandler = fGpu->getContext()->priv().getShaderErrorHandler();
SkSL::String shaders[kGrShaderTypeCount];
SkSL::Program::Inputs inputs[kGrShaderTypeCount];
if (kMSL_Tag == shaderType &&
GrPersistentCacheUtils::UnpackCachedShaders(&reader, shaders, inputs, kGrShaderTypeCount)) {
shaderLibraries[kVertex_GrShaderType] = this->compileMtlShaderLibrary(
shaders[kVertex_GrShaderType],
inputs[kVertex_GrShaderType],
errorHandler);
shaderLibraries[kFragment_GrShaderType] = this->compileMtlShaderLibrary(
shaders[kFragment_GrShaderType],
inputs[kFragment_GrShaderType],
errorHandler);
if (!shaderLibraries[kVertex_GrShaderType] || !shaderLibraries[kFragment_GrShaderType]) {
return nullptr;
}
if (kMSL_Tag == shaderType && this->loadShadersFromCache(&reader, shaderLibraries)) {
// We successfully loaded and compiled MSL
} else {
SkSL::String shaders[kGrShaderTypeCount];
SkSL::Program::Inputs inputs[kGrShaderTypeCount];
SkSL::String* sksl[kGrShaderTypeCount] = {
&fVS.fCompilerString,
nullptr, // geometry shaders not supported
@ -432,15 +439,17 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(GrRenderTarget* renderTa
SkSL::Program::kVertex_Kind,
settings,
&shaders[kVertex_GrShaderType],
&inputs[kVertex_GrShaderType],
errorHandler);
&inputs[kVertex_GrShaderType]);
shaderLibraries[kFragment_GrShaderType] = this->generateMtlShaderLibrary(
*sksl[kFragment_GrShaderType],
SkSL::Program::kFragment_Kind,
settings,
&shaders[kFragment_GrShaderType],
&inputs[kFragment_GrShaderType],
errorHandler);
&inputs[kFragment_GrShaderType]);
// Geometry shaders are not supported
SkASSERT(!this->primitiveProcessor().willUseGeoShader());
if (!shaderLibraries[kVertex_GrShaderType] || !shaderLibraries[kFragment_GrShaderType]) {
return nullptr;
}
@ -460,9 +469,6 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(GrRenderTarget* renderTa
}
}
// Geometry shaders are not supported
SkASSERT(!this->primitiveProcessor().willUseGeoShader());
id<MTLFunction> vertexFunction =
[shaderLibraries[kVertex_GrShaderType] newFunctionWithName: @"vertexMain"];
id<MTLFunction> fragmentFunction =

View File

@ -69,19 +69,17 @@ MTLTextureDescriptor* GrGetMTLTextureDescriptor(id<MTLTexture> mtlTexture);
* Returns a compiled MTLLibrary created from MSL code generated by SkSLC
*/
id<MTLLibrary> GrGenerateMtlShaderLibrary(const GrMtlGpu* gpu,
const SkSL::String& sksl,
const SkSL::String& shaderString,
SkSL::Program::Kind kind,
const SkSL::Program::Settings& settings,
SkSL::String* msl,
SkSL::Program::Inputs* outInputs,
GrContextOptions::ShaderErrorHandler* errorHandler);
SkSL::String* mslShader,
SkSL::Program::Inputs* outInputs);
/**
* Returns a compiled MTLLibrary created from MSL code
*/
id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu,
const SkSL::String& msl,
GrContextOptions::ShaderErrorHandler* errorHandler);
const SkSL::String& shaderString);
/**
* Replacement for newLibraryWithSource:options:error that has a timeout.

View File

@ -10,7 +10,6 @@
#include "include/gpu/GrBackendSurface.h"
#include "include/private/GrTypesPriv.h"
#include "include/private/SkMutex.h"
#include "src/gpu/GrShaderUtils.h"
#include "src/gpu/GrSurface.h"
#include "src/gpu/mtl/GrMtlGpu.h"
#include "src/gpu/mtl/GrMtlRenderTarget.h"
@ -23,6 +22,8 @@
#error This file must be compiled with Arc. Use -fobjc-arc flag
#endif
#define PRINT_MSL 0 // print out the MSL code generated
NSError* GrCreateMtlError(NSString* description, GrMtlErrorCode errorCode) {
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:description
forKey:NSLocalizedDescriptionKey];
@ -47,55 +48,55 @@ MTLTextureDescriptor* GrGetMTLTextureDescriptor(id<MTLTexture> mtlTexture) {
return texDesc;
}
// Print the source code for all shaders generated.
static const bool gPrintSKSL = false;
static const bool gPrintMSL = false;
#if PRINT_MSL
void print_msl(const char* source) {
SkTArray<SkString> lines;
SkStrSplit(source, "\n", kStrict_SkStrSplitMode, &lines);
for (int i = 0; i < lines.count(); i++) {
SkString& line = lines[i];
line.prependf("%4i\t", i + 1);
SkDebugf("%s\n", line.c_str());
}
}
#endif
id<MTLLibrary> GrGenerateMtlShaderLibrary(const GrMtlGpu* gpu,
const SkSL::String& sksl,
SkSL::Program::Kind programKind,
const SkSL::String& shaderString,
SkSL::Program::Kind kind,
const SkSL::Program::Settings& settings,
SkSL::String* msl,
SkSL::Program::Inputs* outInputs,
GrContextOptions::ShaderErrorHandler* errorHandler) {
#ifdef SK_DEBUG
SkSL::String src = GrShaderUtils::PrettyPrint(sksl);
#else
const SkSL::String& src = sksl;
#endif
SkSL::Compiler* compiler = gpu->shaderCompiler();
SkSL::String* mslShader,
SkSL::Program::Inputs* outInputs) {
std::unique_ptr<SkSL::Program> program =
gpu->shaderCompiler()->convertProgram(programKind,
src,
gpu->shaderCompiler()->convertProgram(kind,
shaderString,
settings);
if (!program || !compiler->toMetal(*program, msl)) {
errorHandler->compileError(src.c_str(), compiler->errorText().c_str());
if (!program) {
SkDebugf("SkSL error:\n%s\n", gpu->shaderCompiler()->errorText().c_str());
SkASSERT(false);
return nil;
}
if (gPrintSKSL || gPrintMSL) {
GrShaderUtils::PrintShaderBanner(programKind);
if (gPrintSKSL) {
SkDebugf("SKSL:\n");
GrShaderUtils::PrintLineByLine(GrShaderUtils::PrettyPrint(sksl));
}
if (gPrintMSL) {
SkDebugf("MSL:\n");
GrShaderUtils::PrintLineByLine(GrShaderUtils::PrettyPrint(*msl));
}
*outInputs = program->fInputs;
if (!gpu->shaderCompiler()->toMetal(*program, mslShader)) {
SkDebugf("%s\n", gpu->shaderCompiler()->errorText().c_str());
SkASSERT(false);
return nil;
}
*outInputs = program->fInputs;
return GrCompileMtlShaderLibrary(gpu, *msl, errorHandler);
return GrCompileMtlShaderLibrary(gpu, *mslShader);
}
id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu,
const SkSL::String& msl,
GrContextOptions::ShaderErrorHandler* errorHandler) {
auto nsSource = [[NSString alloc] initWithBytesNoCopy:const_cast<char*>(msl.c_str())
length:msl.size()
const SkSL::String& shaderString) {
auto nsSource = [[NSString alloc] initWithBytesNoCopy:const_cast<char*>(shaderString.c_str())
length:shaderString.size()
encoding:NSUTF8StringEncoding
freeWhenDone:NO];
#if PRINT_MSL
print_msl(nsSource.UTF8String);
#endif
NSError* error = nil;
#if defined(SK_BUILD_FOR_MAC)
id<MTLLibrary> compiledLibrary = GrMtlNewLibraryWithSource(gpu->device(), nsSource,
@ -106,7 +107,9 @@ id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu,
error:&error];
#endif
if (!compiledLibrary) {
errorHandler->compileError(msl.c_str(), error.debugDescription.UTF8String);
SkDebugf("Error compiling MSL shader: %s\n%s\n",
shaderString.c_str(),
error.debugDescription.UTF8String);
return nil;
}