added support for sk_VertexID

Change-Id: If3a2b7527ae6805ba54860c6ca6219431e2f3f76
Reviewed-on: https://skia-review.googlesource.com/8145
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2017-02-07 14:53:32 -05:00 committed by Skia Commit-Bot
parent 8c3f4ae56a
commit a51740c4f8
5 changed files with 25 additions and 7 deletions

View File

@ -33,6 +33,7 @@ following differences between SkSL and GLSL:
'do_something_else();', depending on whether that cap is enabled or not.
* no #version statement is required, and will be ignored if present
* the output color is sk_FragColor (do not declare it)
* use sk_VertexID instead of gl_VertexID
* lowp, mediump, and highp are always permitted (but will only be respected if
you run on a GLES device)
* you do not need to include ".0" to make a number a float (meaning that

View File

@ -18,7 +18,8 @@
#include "SkSLIRGenerator.h"
#define SK_FRAGCOLOR_BUILTIN 10001
#define SK_FRAGCOORD_BUILTIN 15
#define SK_FRAGCOORD_BUILTIN 15
#define SK_VERTEXID_BUILTIN 5
namespace SkSL {

View File

@ -326,6 +326,9 @@ void GLSLCodeGenerator::writeVariableReference(const VariableReference& ref) {
case SK_FRAGCOORD_BUILTIN:
this->writeFragCoord();
break;
case SK_VERTEXID_BUILTIN:
this->write("gl_VertexID");
break;
default:
this->write(ref.fVariable.fName);
}

View File

@ -7,5 +7,7 @@ out gl_PerVertex {
layout(builtin=1) float gl_PointSize;
};
layout(builtin=5) int sk_VertexID;
)

View File

@ -12,12 +12,11 @@
#if SK_SUPPORT_GPU
static void test(skiatest::Reporter* r, const char* src, const SkSL::Program::Settings& settings,
const char* expected, SkSL::Program::Inputs* inputs) {
const char* expected, SkSL::Program::Inputs* inputs,
SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) {
SkSL::Compiler compiler;
SkString output;
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind,
SkString(src),
settings);
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(kind, SkString(src), settings);
if (!program) {
SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
}
@ -35,11 +34,11 @@ static void test(skiatest::Reporter* r, const char* src, const SkSL::Program::Se
}
static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& caps,
const char* expected) {
const char* expected, SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) {
SkSL::Program::Settings settings;
settings.fCaps = &caps;
SkSL::Program::Inputs inputs;
test(r, src, settings, expected, &inputs);
test(r, src, settings, expected, &inputs, kind);
}
DEF_TEST(SkSLHelloWorld, r) {
@ -677,4 +676,16 @@ DEF_TEST(SkSLFragCoord, r) {
REPORTER_ASSERT(r, !inputs.fRTHeight);
}
DEF_TEST(SkSLVertexID, r) {
test(r,
"out int id; void main() { id = sk_VertexID; }",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out int id;\n"
"void main() {\n"
" id = gl_VertexID;\n"
"}\n",
SkSL::Program::kVertex_Kind);
}
#endif