diff options
author | Brian Osman <brianosman@google.com> | 2018-02-12 14:32:17 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-02-13 16:30:20 +0000 |
commit | 8a83ca4e9afc9e3c08b4e8c33a74392f9b3154d7 (patch) | |
tree | a0f4596f598a8330ef2a95a3964c4fe43bda46a2 /src/sksl | |
parent | c126191fd1f540f7318516a965c85a5bff07dad1 (diff) |
Add "sharpen" option to SkSL, to LOD bias all textures
This adds a fixed bias (-0.5) to the computed LOD of all
mip-mapped texture fetches. (Technically, to all texture
fetches, but that only matters for mip-mapped ones).
Clients can opt-in with a new GrContextOption.
Bug: skia:7541
Bug: chromium:562162
Change-Id: Ie3cd0679c4ab66f62d2dc32e7e68e5c99355115e
Reviewed-on: https://skia-review.googlesource.com/106322
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r-- | src/sksl/SkSLGLSLCodeGenerator.cpp | 8 | ||||
-rw-r--r-- | src/sksl/SkSLSPIRVCodeGenerator.cpp | 12 | ||||
-rw-r--r-- | src/sksl/ir/SkSLProgram.h | 2 |
3 files changed, 20 insertions, 2 deletions
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp index d02948f388..f94cc4ca0b 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.cpp +++ b/src/sksl/SkSLGLSLCodeGenerator.cpp @@ -505,12 +505,14 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) { fHeader.writeText(" : require\n"); fFoundDerivatives = true; } + bool isTextureFunctionWithBias = false; if (c.fFunction.fName == "texture" && c.fFunction.fBuiltin) { const char* dim = ""; bool proj = false; switch (c.fArguments[0]->fType.dimensions()) { case SpvDim1D: dim = "1D"; + isTextureFunctionWithBias = true; if (c.fArguments[1]->fType == *fContext.fFloat_Type) { proj = false; } else { @@ -520,6 +522,7 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) { break; case SpvDim2D: dim = "2D"; + isTextureFunctionWithBias = true; if (c.fArguments[1]->fType == *fContext.fFloat2_Type) { proj = false; } else { @@ -529,6 +532,7 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) { break; case SpvDim3D: dim = "3D"; + isTextureFunctionWithBias = true; if (c.fArguments[1]->fType == *fContext.fFloat3_Type) { proj = false; } else { @@ -538,6 +542,7 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) { break; case SpvDimCube: dim = "Cube"; + isTextureFunctionWithBias = true; proj = false; break; case SpvDimRect: @@ -573,6 +578,9 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) { separator = ", "; this->writeExpression(*arg, kSequence_Precedence); } + if (fProgram.fSettings.fSharpenTextures && isTextureFunctionWithBias) { + this->write(", -0.5"); + } this->write(")"); } diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index cb8b388521..d01a82dae2 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -824,8 +824,16 @@ SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIn out); } else { ASSERT(c.fArguments.size() == 2); - this->writeInstruction(op, type, result, sampler, uv, - out); + if (fProgram.fSettings.fSharpenTextures) { + FloatLiteral lodBias(fContext, -1, -0.5); + this->writeInstruction(op, type, result, sampler, uv, + SpvImageOperandsBiasMask, + this->writeFloatLiteral(lodBias), + out); + } else { + this->writeInstruction(op, type, result, sampler, uv, + out); + } } break; } diff --git a/src/sksl/ir/SkSLProgram.h b/src/sksl/ir/SkSLProgram.h index 3184547476..a63cd237ac 100644 --- a/src/sksl/ir/SkSLProgram.h +++ b/src/sksl/ir/SkSLProgram.h @@ -76,6 +76,8 @@ struct Program { bool fReplaceSettings = true; // if true, all halfs are forced to be floats bool fForceHighPrecision = false; + // if true, add -0.5 bias to LOD of all texture lookups + bool fSharpenTextures = false; std::unordered_map<String, Value> fArgs; }; |