added support for sk_ClipDistance

Change-Id: I9ea202679211b98cf98165c8609f24f9b4e14b66
Reviewed-on: https://skia-review.googlesource.com/8247
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2017-02-09 10:15:25 -05:00 committed by Skia Commit-Bot
parent 5d4cd9ea88
commit 67d64605d3
5 changed files with 35 additions and 5 deletions

View File

@ -17,9 +17,10 @@
#include "SkSLErrorReporter.h"
#include "SkSLIRGenerator.h"
#define SK_FRAGCOLOR_BUILTIN 10001
#define SK_FRAGCOORD_BUILTIN 15
#define SK_VERTEXID_BUILTIN 5
#define SK_FRAGCOLOR_BUILTIN 10001
#define SK_FRAGCOORD_BUILTIN 15
#define SK_VERTEXID_BUILTIN 5
#define SK_CLIPDISTANCE_BUILTIN 3
namespace SkSL {

View File

@ -329,6 +329,9 @@ void GLSLCodeGenerator::writeVariableReference(const VariableReference& ref) {
case SK_VERTEXID_BUILTIN:
this->write("gl_VertexID");
break;
case SK_CLIPDISTANCE_BUILTIN:
this->write("gl_ClipDistance");
break;
default:
this->write(ref.fVariable.fName);
}
@ -346,7 +349,13 @@ void GLSLCodeGenerator::writeFieldAccess(const FieldAccess& f) {
this->writeExpression(*f.fBase, kPostfix_Precedence);
this->write(".");
}
this->write(f.fBase->fType.fields()[f.fFieldIndex].fName);
switch (f.fBase->fType.fields()[f.fFieldIndex].fModifiers.fLayout.fBuiltin) {
case SK_CLIPDISTANCE_BUILTIN:
this->write("gl_ClipDistance");
break;
default:
this->write(f.fBase->fType.fields()[f.fFieldIndex].fName);
}
}
void GLSLCodeGenerator::writeSwizzle(const Swizzle& swizzle) {

View File

@ -3,6 +3,7 @@ STRINGIFY(
// defines built-in interfaces supported by SkiaSL fragment shaders
layout(builtin=15) in vec4 sk_FragCoord;
layout(builtin=3) float sk_ClipDistance[1];
// 9999 is a temporary value that causes us to ignore these declarations beyond
// adding them to the symbol table. This works fine in GLSL (where they do not

View File

@ -4,7 +4,8 @@ STRINGIFY(
out gl_PerVertex {
layout(builtin=0) vec4 gl_Position;
layout(builtin=1) float gl_PointSize;
layout(builtin=1) float gl_PointSize;
layout(builtin=3) float sk_ClipDistance[1];
};
layout(builtin=5) int sk_VertexID;

View File

@ -688,4 +688,22 @@ DEF_TEST(SkSLVertexID, r) {
SkSL::Program::kVertex_Kind);
}
DEF_TEST(SkSLClipDistance, r) {
test(r,
"void main() { sk_ClipDistance[0] = 0; }",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"void main() {\n"
" gl_ClipDistance[0] = 0.0;\n"
"}\n",
SkSL::Program::kVertex_Kind);
test(r,
"void main() { sk_FragColor = vec4(sk_ClipDistance[0]); }",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" sk_FragColor = vec4(gl_ClipDistance[0]);\n"
"}\n");
}
#endif