Commit d9fa0744 by Jeff Gilbert Committed by Jamie Madill

Emit OVR_multiview2 on ESSL/GLSL outputs.

Add ARB_shader_viewport_layer_array support to SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER. Bug: angleproject:3404 Change-Id: Ia89517d0cc92400ce47c9118e8c1abf8285aec41 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1585452Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 344ecaa6
...@@ -230,7 +230,7 @@ const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C ...@@ -230,7 +230,7 @@ const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C
// With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport // With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport
// selection in the following way: // selection in the following way:
// - Code to enable the extension NV_viewport_array2 is included. // - Code to enable the extension ARB_shader_viewport_layer_array/NV_viewport_array2 is included.
// - Code to select the viewport index or layer is inserted at the beginning of main after // - Code to select the viewport index or layer is inserted at the beginning of main after
// ViewID_OVR's initialization. // ViewID_OVR's initialization.
// - A declaration of the uniform multiviewBaseViewLayerIndex. // - A declaration of the uniform multiviewBaseViewLayerIndex.
......
...@@ -1379,4 +1379,40 @@ bool TCompiler::isVaryingDefined(const char *varyingName) ...@@ -1379,4 +1379,40 @@ bool TCompiler::isVaryingDefined(const char *varyingName)
return false; return false;
} }
void EmitMultiviewGLSL(const TCompiler &compiler,
const ShCompileOptions &compileOptions,
const TBehavior behavior,
TInfoSinkBase &sink)
{
ASSERT(behavior != EBhUndefined);
if (behavior == EBhDisable)
return;
const bool isVertexShader = (compiler.getShaderType() == GL_VERTEX_SHADER);
if (compileOptions & SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW)
{
// Emit ARB_shader_viewport_layer_array/NV_viewport_array2 in a vertex shader if the
// SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER option is set and the
// OVR_multiview(2) extension is requested.
if (isVertexShader && (compileOptions & SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER))
{
sink << "#if defined(GL_ARB_shader_viewport_layer_array)\n"
<< "#extension GL_ARB_shader_viewport_layer_array : require\n"
<< "#elif defined(GL_NV_viewport_array2)\n"
<< "#extension GL_NV_viewport_array2 : require\n"
<< "#endif\n";
}
}
else
{
sink << "#extension GL_OVR_multiview2 : " << GetBehaviorString(behavior) << "\n";
const auto &numViews = compiler.getNumViews();
if (isVertexShader && numViews != -1)
{
sink << "layout(num_views=" << numViews << ") in;\n";
}
}
}
} // namespace sh } // namespace sh
...@@ -296,6 +296,8 @@ class TCompiler : public TShHandleBase ...@@ -296,6 +296,8 @@ class TCompiler : public TShHandleBase
TCompiler *ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output); TCompiler *ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
void DeleteCompiler(TCompiler *); void DeleteCompiler(TCompiler *);
void EmitMultiviewGLSL(const TCompiler &, const ShCompileOptions &, TBehavior, TInfoSinkBase &sink);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_COMPILER_H_ #endif // COMPILER_TRANSLATOR_COMPILER_H_
...@@ -124,9 +124,6 @@ void TranslatorESSL::writeExtensionBehavior(ShCompileOptions compileOptions) ...@@ -124,9 +124,6 @@ void TranslatorESSL::writeExtensionBehavior(ShCompileOptions compileOptions)
{ {
TInfoSinkBase &sink = getInfoSink().obj; TInfoSinkBase &sink = getInfoSink().obj;
const TExtensionBehavior &extBehavior = getExtensionBehavior(); const TExtensionBehavior &extBehavior = getExtensionBehavior();
const bool isMultiviewExtEmulated =
(compileOptions & (SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW |
SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER)) != 0u;
for (TExtensionBehavior::const_iterator iter = extBehavior.begin(); iter != extBehavior.end(); for (TExtensionBehavior::const_iterator iter = extBehavior.begin(); iter != extBehavior.end();
++iter) ++iter)
{ {
...@@ -145,16 +142,9 @@ void TranslatorESSL::writeExtensionBehavior(ShCompileOptions compileOptions) ...@@ -145,16 +142,9 @@ void TranslatorESSL::writeExtensionBehavior(ShCompileOptions compileOptions)
sink << "#extension GL_NV_draw_buffers : " << GetBehaviorString(iter->second) sink << "#extension GL_NV_draw_buffers : " << GetBehaviorString(iter->second)
<< "\n"; << "\n";
} }
else if (isMultiview && isMultiviewExtEmulated) else if (isMultiview)
{ {
if (getShaderType() == GL_VERTEX_SHADER && EmitMultiviewGLSL(*this, compileOptions, iter->second, sink);
(compileOptions & SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER) != 0u)
{
// Emit the NV_viewport_array2 extension in a vertex shader if the
// SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER option is set and the
// OVR_multiview2 extension is requested.
sink << "#extension GL_NV_viewport_array2 : require\n";
}
} }
else if (iter->first == TExtension::EXT_geometry_shader) else if (iter->first == TExtension::EXT_geometry_shader)
{ {
......
...@@ -279,13 +279,9 @@ void TranslatorGLSL::writeExtensionBehavior(TIntermNode *root, ShCompileOptions ...@@ -279,13 +279,9 @@ void TranslatorGLSL::writeExtensionBehavior(TIntermNode *root, ShCompileOptions
const bool isMultiview = const bool isMultiview =
(iter.first == TExtension::OVR_multiview) || (iter.first == TExtension::OVR_multiview2); (iter.first == TExtension::OVR_multiview) || (iter.first == TExtension::OVR_multiview2);
if (isMultiview && getShaderType() == GL_VERTEX_SHADER && if (isMultiview)
(compileOptions & SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER) != 0u)
{ {
// Emit the NV_viewport_array2 extension in a vertex shader if the EmitMultiviewGLSL(*this, compileOptions, iter.second, sink);
// SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER option is set and the OVR_multiview2(2)
// extension is requested.
sink << "#extension GL_NV_viewport_array2 : require\n";
} }
// Support ANGLE_texture_multisample extension on GLSL300 // Support ANGLE_texture_multisample extension on GLSL300
......
...@@ -1106,7 +1106,8 @@ void GenerateCaps(const FunctionsGL *functions, ...@@ -1106,7 +1106,8 @@ void GenerateCaps(const FunctionsGL *functions,
extensions->fragDepth = functions->standard == STANDARD_GL_DESKTOP || extensions->fragDepth = functions->standard == STANDARD_GL_DESKTOP ||
functions->hasGLESExtension("GL_EXT_frag_depth"); functions->hasGLESExtension("GL_EXT_frag_depth");
if (functions->hasGLExtension("GL_NV_viewport_array2")) if (functions->hasGLExtension("GL_ARB_shader_viewport_layer_array") ||
functions->hasGLExtension("GL_NV_viewport_array2"))
{ {
extensions->multiview = true; extensions->multiview = true;
extensions->multiview2 = true; extensions->multiview2 = true;
......
...@@ -716,4 +716,28 @@ TEST_F(OVRMultiview2VertexShaderOutputCodeTest, GlLayerIsSet) ...@@ -716,4 +716,28 @@ TEST_F(OVRMultiview2VertexShaderOutputCodeTest, GlLayerIsSet)
EXPECT_TRUE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, expectedStrings)); EXPECT_TRUE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, expectedStrings));
} }
} // namespace // Test that the OVR_multiview2 without emulation is emits OVR_multiview2 output.
\ No newline at end of file TEST_F(OVRMultiview2VertexShaderOutputCodeTest, NativeOvrMultiview2Output)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 3) in;\n"
"void main()\n"
"{\n"
"}\n";
compile(shaderString);
std::vector<const char *> expectedStrings = {"#extension GL_OVR_multiview2",
"layout(num_views"};
EXPECT_TRUE(foundInCodeInOrder(SH_ESSL_OUTPUT, expectedStrings));
EXPECT_TRUE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, expectedStrings));
EXPECT_FALSE(foundInGLSLCode("#extension GL_NV_viewport_array2"));
EXPECT_FALSE(foundInESSLCode("#extension GL_NV_viewport_array2"));
EXPECT_FALSE(foundInGLSLCode("gl_ViewportIndex"));
EXPECT_FALSE(foundInESSLCode("gl_ViewportIndex"));
}
} // namespace
...@@ -1720,6 +1720,9 @@ TEST_P(MultiviewRenderPrimitiveTest, LineLoop) ...@@ -1720,6 +1720,9 @@ TEST_P(MultiviewRenderPrimitiveTest, LineLoop)
{ {
return; return;
} }
// Only this subtest fails on intel-hd-630-ubuntu-stable. Driver bug?
// https://bugs.chromium.org/p/angleproject/issues/detail?id=3472
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux() && IsOpenGL());
GLuint program = CreateSimplePassthroughProgram(2, GetParam().mMultiviewExtension); GLuint program = CreateSimplePassthroughProgram(2, GetParam().mMultiviewExtension);
ASSERT_NE(program, 0u); ASSERT_NE(program, 0u);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment