Remove DSL from GrGaussianConvolutionFragmentProcessor.

Since this is super performance-sensitive, I manually checked to ensure
that the generated code didn't change. Other than differences in
variable name mangling, our final output looks to be identical.

Change-Id: I1bdf012f9b15bafcd85a9e73abfb3fa444459c60
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/540300
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-05-16 10:42:32 -04:00 committed by SkCQ
parent cb61d1ff99
commit bde670a39b
2 changed files with 38 additions and 40 deletions

View File

@ -282,7 +282,6 @@ generated_cc_atom(
deps = [ deps = [
":GrGaussianConvolutionFragmentProcessor_hdr", ":GrGaussianConvolutionFragmentProcessor_hdr",
":GrTextureEffect_hdr", ":GrTextureEffect_hdr",
"//include/sksl:DSL_hdr",
"//src/core:SkGpuBlurUtils_hdr", "//src/core:SkGpuBlurUtils_hdr",
"//src/gpu:KeyBuilder_hdr", "//src/gpu:KeyBuilder_hdr",
"//src/gpu/ganesh:GrTextureProxy_hdr", "//src/gpu/ganesh:GrTextureProxy_hdr",
@ -290,7 +289,6 @@ generated_cc_atom(
"//src/gpu/ganesh/glsl:GrGLSLFragmentShaderBuilder_hdr", "//src/gpu/ganesh/glsl:GrGLSLFragmentShaderBuilder_hdr",
"//src/gpu/ganesh/glsl:GrGLSLProgramDataManager_hdr", "//src/gpu/ganesh/glsl:GrGLSLProgramDataManager_hdr",
"//src/gpu/ganesh/glsl:GrGLSLUniformHandler_hdr", "//src/gpu/ganesh/glsl:GrGLSLUniformHandler_hdr",
"//src/sksl/dsl/priv:DSLFPs_hdr",
], ],
) )

View File

@ -7,7 +7,6 @@
#include "src/gpu/ganesh/effects/GrGaussianConvolutionFragmentProcessor.h" #include "src/gpu/ganesh/effects/GrGaussianConvolutionFragmentProcessor.h"
#include "include/sksl/DSL.h"
#include "src/core/SkGpuBlurUtils.h" #include "src/core/SkGpuBlurUtils.h"
#include "src/gpu/KeyBuilder.h" #include "src/gpu/KeyBuilder.h"
#include "src/gpu/ganesh/GrTexture.h" #include "src/gpu/ganesh/GrTexture.h"
@ -16,7 +15,6 @@
#include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h" #include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/ganesh/glsl/GrGLSLProgramDataManager.h" #include "src/gpu/ganesh/glsl/GrGLSLProgramDataManager.h"
#include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h" #include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h"
#include "src/sksl/dsl/priv/DSLFPs.h"
// For brevity // For brevity
using UniformHandle = GrGLSLProgramDataManager::UniformHandle; using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
@ -55,14 +53,13 @@ void GrGaussianConvolutionFragmentProcessor::Impl::emitCode(EmitArgs& args) {
const GrGaussianConvolutionFragmentProcessor& ce = const GrGaussianConvolutionFragmentProcessor& ce =
args.fFp.cast<GrGaussianConvolutionFragmentProcessor>(); args.fFp.cast<GrGaussianConvolutionFragmentProcessor>();
using namespace SkSL::dsl; GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
StartFragmentProcessor(this, &args);
GlobalVar increment(kUniform_Modifier, kHalf2_Type, "Increment"); const char* increment;
Declare(increment); fIncrementUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, SkSLType::kHalf2,
fIncrementUni = VarUniformHandle(increment); "Increment", &increment);
int width = SkGpuBlurUtils::LinearKernelWidth(ce.fRadius); int width = SkGpuBlurUtils::LinearKernelWidth(ce.fRadius);
LoopType loopType = loop_type(*args.fShaderCaps); LoopType loopType = loop_type(*args.fShaderCaps);
int arrayCount; int arrayCount;
@ -74,49 +71,52 @@ void GrGaussianConvolutionFragmentProcessor::Impl::emitCode(EmitArgs& args) {
SkASSERT(4 * arrayCount >= width); SkASSERT(4 * arrayCount >= width);
} }
GlobalVar kernel(kUniform_Modifier, Array(kHalf4_Type, arrayCount), "Kernel"); const char* kernel;
Declare(kernel); fKernelUni = uniformHandler->addUniformArray(&ce, kFragment_GrShaderFlag, SkSLType::kHalf4,
fKernelUni = VarUniformHandle(kernel); "Kernel", arrayCount, &kernel);
const char* offsets;
fOffsetsUni = uniformHandler->addUniformArray(&ce, kFragment_GrShaderFlag, SkSLType::kHalf4,
GlobalVar offsets(kUniform_Modifier, Array(kHalf4_Type, arrayCount), "Offsets"); "Offsets", arrayCount, &offsets);
Declare(offsets);
fOffsetsUni = VarUniformHandle(offsets);
Var color(kHalf4_Type, "color", Half4(0));
Declare(color);
Var coord(kFloat2_Type, "coord", sk_SampleCoord());
Declare(coord);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("half4 color = half4(0);"
"float2 coord = %s;", args.fSampleCoord);
switch (loopType) { switch (loopType) {
case LoopType::kUnrolled: case LoopType::kUnrolled:
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
color += SampleChild(/*index=*/0, coord + offsets[i / 4][i & 3] * increment) * std::string childCoord = SkSL::String::printf("(coord + %s[%d][%d] * %s)",
kernel[i / 4][i & 0x3]; offsets, i / 4, i & 3, increment);
SkString sample = this->invokeChild(/*childIndex=*/0, args, childCoord);
fragBuilder->codeAppendf("color += %s * %s[%d][%d];\n",
sample.c_str(), kernel, i / 4, i & 3);
} }
break; break;
case LoopType::kFixedLength: { case LoopType::kFixedLength: {
Var i(kInt_Type, "i", 0); std::string childCoord = SkSL::String::printf("(coord + %s[i / 4][i & 3] * %s)",
For(Declare(i), i < width, i++, offsets, increment);
color += SampleChild(/*index=*/0, coord + offsets[i / 4][i & 3] * increment) * SkString sample = this->invokeChild(/*childIndex=*/0, args, childCoord);
kernel[i / 4][i & 0x3]); fragBuilder->codeAppendf("for (int i=0; i<%d; ++i) {\n"
" color += %s * %s[i / 4][i & 3];\n"
"}",
width, sample.c_str(), kernel);
break; break;
} }
case LoopType::kVariableLength: { case LoopType::kVariableLength: {
GlobalVar kernelWidth(kUniform_Modifier, kInt_Type, "kernelWidth"); const char* kernelWidth;
Declare(kernelWidth); fKernelWidthUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag,
fKernelWidthUni = VarUniformHandle(kernelWidth); SkSLType::kInt, "KernelWidth",
Var i(kInt_Type, "i", 0); &kernelWidth);
For(Declare(i), i < kernelWidth, i++, std::string childCoord = SkSL::String::printf("(coord + %s[i / 4][i & 3] * %s)",
color += SampleChild(/*index=*/0, coord + offsets[i / 4][i & 3] * increment) * offsets, increment);
kernel[i / 4][i & 0x3]); SkString sample = this->invokeChild(/*childIndex=*/0, args, childCoord);
fragBuilder->codeAppendf("for (int i=0; i<%s; ++i) {\n"
" color += %s * %s[i / 4][i & 3];\n"
"}",
kernelWidth, sample.c_str(), kernel);
break; break;
} }
} }
fragBuilder->codeAppendf("return color;\n");
Return(color);
EndFragmentProcessor();
} }
void GrGaussianConvolutionFragmentProcessor::Impl::onSetData(const GrGLSLProgramDataManager& pdman, void GrGaussianConvolutionFragmentProcessor::Impl::onSetData(const GrGLSLProgramDataManager& pdman,