diff options
-rw-r--r-- | include/gpu/GrShaderCaps.h | 9 | ||||
-rw-r--r-- | src/gpu/GrShaderCaps.cpp | 1 | ||||
-rw-r--r-- | src/gpu/gl/GrGLCaps.cpp | 10 | ||||
-rw-r--r-- | src/sksl/SkSLGLSLCodeGenerator.cpp | 6 | ||||
-rw-r--r-- | src/sksl/SkSLUtil.h | 22 | ||||
-rw-r--r-- | tests/SkSLGLSLTest.cpp | 27 |
6 files changed, 68 insertions, 7 deletions
diff --git a/include/gpu/GrShaderCaps.h b/include/gpu/GrShaderCaps.h index 82fd077592..b56694c7dc 100644 --- a/include/gpu/GrShaderCaps.h +++ b/include/gpu/GrShaderCaps.h @@ -139,6 +139,14 @@ public: return fShaderDerivativeExtensionString; } + // Returns the string of an extension that must be enabled in the shader to support geometry + // shaders. If nullptr is returned then no extension needs to be enabled. Before calling this + // function, the caller must verify that geometryShaderSupport exists. + const char* geometryShaderExtensionString() const { + SkASSERT(this->geometryShaderSupport()); + return fGeometryShaderExtensionString; + } + // Returns the string of an extension that must be enabled in the shader to support // geometry shader invocations. If nullptr is returned then no extension needs to be enabled. // Before calling this function, the caller must verify that gsInvocationsSupport exists. @@ -271,6 +279,7 @@ private: const char* fVersionDeclString; const char* fShaderDerivativeExtensionString; + const char* fGeometryShaderExtensionString; const char* fGSInvocationsExtensionString; const char* fFragCoordConventionsExtensionString; const char* fSecondaryOutputExtensionString; diff --git a/src/gpu/GrShaderCaps.cpp b/src/gpu/GrShaderCaps.cpp index e232f3d826..2041ada635 100644 --- a/src/gpu/GrShaderCaps.cpp +++ b/src/gpu/GrShaderCaps.cpp @@ -52,6 +52,7 @@ GrShaderCaps::GrShaderCaps(const GrContextOptions& options) { fVersionDeclString = nullptr; fShaderDerivativeExtensionString = nullptr; + fGeometryShaderExtensionString = nullptr; fGSInvocationsExtensionString = nullptr; fFragCoordConventionsExtensionString = nullptr; fSecondaryOutputExtensionString = nullptr; diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 038a1b1a73..4996859c51 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -331,14 +331,18 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) && ctxInfo.glslGeneration() >= k130_GrGLSLGeneration; - } - else { + } else { shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended"); shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_standard_derivatives"); - shaderCaps->fGeometryShaderSupport = ctxInfo.hasExtension("GL_EXT_geometry_shader"); + if (ctxInfo.version() >= GR_GL_VER(3,2)) { + shaderCaps->fGeometryShaderSupport = true; + } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) { + shaderCaps->fGeometryShaderSupport = true; + shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader"; + } if (shaderCaps->fGeometryShaderSupport && kQualcomm_GrGLDriver == ctxInfo.driver()) { // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry shaders. // @127.0 is the earliest verified driver to not crash. diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp index ad3fde52f9..9e2336e22e 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.cpp +++ b/src/sksl/SkSLGLSLCodeGenerator.cpp @@ -1246,6 +1246,12 @@ bool GLSLCodeGenerator::generateCode() { fOut = &fHeader; fProgramKind = fProgram.fKind; this->writeHeader(); + if (Program::kGeometry_Kind == fProgramKind && + fProgram.fSettings.fCaps->geometryShaderExtensionString()) { + fHeader.writeText("#extension "); + fHeader.writeText(fProgram.fSettings.fCaps->geometryShaderExtensionString()); + fHeader.writeText(" : require\n"); + } StringStream body; fOut = &body; for (const auto& e : fProgram.fElements) { diff --git a/src/sksl/SkSLUtil.h b/src/sksl/SkSLUtil.h index 1d9d53f6e8..7a39386269 100644 --- a/src/sksl/SkSLUtil.h +++ b/src/sksl/SkSLUtil.h @@ -155,6 +155,10 @@ public: return nullptr; } + const char* geometryShaderExtensionString() const { + return nullptr; + } + const char* gsInvocationsExtensionString() const { return nullptr; } @@ -184,7 +188,6 @@ public: sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions()); result->fVersionDeclString = "#version 400"; result->fShaderDerivativeSupport = true; - result->fGSInvocationsSupport = true; return result; } @@ -253,6 +256,14 @@ public: return result; } + static sk_sp<GrShaderCaps> GeometryShaderSupport() { + sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions()); + result->fVersionDeclString = "#version 400"; + result->fGeometryShaderSupport = true; + result->fGSInvocationsSupport = true; + return result; + } + static sk_sp<GrShaderCaps> NoGSInvocationsSupport() { sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions()); result->fVersionDeclString = "#version 400"; @@ -261,6 +272,15 @@ public: return result; } + static sk_sp<GrShaderCaps> GeometryShaderExtensionString() { + sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions()); + result->fVersionDeclString = "#version 310es"; + result->fGeometryShaderSupport = true; + result->fGeometryShaderExtensionString = "GL_EXT_geometry_shader"; + result->fGSInvocationsSupport = true; + return result; + } + static sk_sp<GrShaderCaps> GSInvocationsExtensionString() { sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions()); result->fVersionDeclString = "#version 400"; diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 7c69de62be..1ae421f8af 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -1146,7 +1146,7 @@ DEF_TEST(SkSLGeometry, r) { "EmitVertex();" "EndPrimitive();" "}", - *SkSL::ShaderCapsFactory::Default(), + *SkSL::ShaderCapsFactory::GeometryShaderSupport(), "#version 400\n" "layout (points) in ;\n" "layout (invocations = 2) in ;\n" @@ -1485,7 +1485,7 @@ DEF_TEST(SkSLDeadLoopVar, r) { ); } -DEF_TEST(SkSLInvocations, r) { +DEF_TEST(SkSLGeometryShaders, r) { test(r, "layout(points) in;" "layout(invocations = 2) in;" @@ -1539,6 +1539,27 @@ DEF_TEST(SkSLInvocations, r) { " EndPrimitive();\n" "}\n", SkSL::Program::kGeometry_Kind); + test(r, + "layout(points, invocations = 2) in;" + "layout(invocations = 3) in;" + "layout(line_strip, max_vertices = 2) out;" + "void main() {" + "sk_Position = sk_in[0].sk_Position + float4(-0.5, 0, 0, sk_InvocationID);" + "EmitVertex();" + "EndPrimitive();" + "}", + *SkSL::ShaderCapsFactory::GeometryShaderExtensionString(), + "#version 310es\n" + "#extension GL_EXT_geometry_shader : require\n" + "layout (points, invocations = 2) in ;\n" + "layout (invocations = 3) in ;\n" + "layout (line_strip, max_vertices = 2) out ;\n" + "void main() {\n" + " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(gl_InvocationID));\n" + " EmitVertex();\n" + " EndPrimitive();\n" + "}\n", + SkSL::Program::kGeometry_Kind); } DEF_TEST(SkSLTypePrecision, r) { @@ -1719,7 +1740,7 @@ DEF_TEST(SkSLNormalization, r) { "EmitVertex();" "EndPrimitive();" "}", - *SkSL::ShaderCapsFactory::Default(), + *SkSL::ShaderCapsFactory::GeometryShaderSupport(), "#version 400\n" "uniform vec4 sk_RTAdjust;\n" "layout (points) in ;\n" |