Declare and initialize ViewID_OVR and InstanceID
The patch modifies the vertex shader's AST to declare and initialize
the global variables ViewID_OVR and InstanceID. Every occurrence of
gl_ViewID_OVR gets replaced by ViewID_OVR and initialized in main
with a value dependent on gl_InstanceID and the number of views.
To guarantee correct results for instanced rendering, each occurrence
of gl_InstanceID is replaced with InstanceID and initialized similarly.
BUG=angleproject:2062
TEST=angle_unittests
Change-Id: I48be688605b5af869bc370758e70ccc209ea4419
Reviewed-on: https://chromium-review.googlesource.com/548596
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index c70fafc..c975038 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -13,6 +13,7 @@
#include "compiler/translator/AddAndTrueToLoopCondition.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/CallDAG.h"
+#include "compiler/translator/DeclareAndInitBuiltinsForInstancedMultiview.h"
#include "compiler/translator/DeferGlobalInitializers.h"
#include "compiler/translator/EmulateGLFragColorBroadcast.h"
#include "compiler/translator/EmulatePrecision.h"
@@ -406,6 +407,12 @@
if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS))
arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root);
+ if (success && (compileOptions & SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW) &&
+ parseContext.isMultiviewExtensionEnabled() && getShaderType() == GL_VERTEX_SHADER)
+ {
+ DeclareAndInitBuiltinsForInstancedMultiview(root, getNumViews());
+ }
+
// gl_Position is always written in compatibility output mode
if (success && shaderType == GL_VERTEX_SHADER &&
((compileOptions & SH_INIT_GL_POSITION) ||