Merge branch 'master' into cloud-android-current-release

Key changes:
- Add libnativewindow dependency for Android O (cf. Project Treble).
- Restrict building Subzero to Marshmallow and up (only affects ARM).
- Restrict GLSL globals to be initialized with constant expressions.
- Log an error when unsupported Android pixel formats are used.

Change-Id: I48277f8954c191b50ab2d769375cf511d2458171
diff --git a/.travis.yml b/.travis.yml
index 92e428f..d949cfb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,11 @@
 language: cpp
 
-os: linux
+os:
+  - linux
+  - osx
+
 dist: trusty
+osx_image: xcode8
 sudo: false
 
 compiler:
diff --git a/Android.mk b/Android.mk
index b4d82e3..a89cdf0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -14,8 +14,22 @@
 # limitations under the License.
 #
 
-LOCAL_PATH:= $(call my-dir)
+LOCAL_PATH := $(call my-dir)
 
+# Use Subzero as the Reactor JIT back-end on ARM, else LLVM.
+ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm))
+use_subzero := true
+endif
+
+# Subzero requires full C++11 support, which is available from Marshmallow and up.
+ifdef use_subzero
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23 && echo PreMarshmallow),PreMarshmallow)
+unsupported_build := true
+endif
+endif
+
+ifndef unsupported_build
 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64 arm))
 include $(call all-makefiles-under,$(LOCAL_PATH))
 endif
+endif
\ No newline at end of file
diff --git a/BUILD.gn b/BUILD.gn
index 7530b91..39f72cb 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -31,27 +31,44 @@
       "NOMINMAX",
       "_WINDLL",
       "NO_SANITIZE_FUNCTION=",
-      "ANGLE_DISABLE_TRACE",
     ]
+
+    if (!is_debug) {
+      defines += [ "ANGLE_DISABLE_TRACE" ]
+    }
   } else {
     cflags = [
       "-std=c++11",
       "-fno-exceptions",
       "-fno-operator-names",
-      "-ffunction-sections",
-      "-fdata-sections",
-      "-fomit-frame-pointer",
-      "-Os",
     ]
 
     defines += [
       "__STDC_CONSTANT_MACROS",
       "__STDC_LIMIT_MACROS",
       "NO_SANITIZE_FUNCTION=__attribute__((no_sanitize(\"function\")))",
-      "ANGLE_DISABLE_TRACE",
-      "NDEBUG",
     ]
 
+    if (is_debug) {
+      cflags += [
+        "-g",
+        "-g3",
+      ]
+    } else {  # Release
+      # All Release builds use function/data sections to make the shared libraries smaller
+      cflags += [
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-fomit-frame-pointer",
+        "-Os",
+      ]
+
+      defines += [
+        "ANGLE_DISABLE_TRACE",
+        "NDEBUG",
+      ]
+    }
+
     if (target_cpu == "x64") {  # 64 bit version
       cflags += [
         "-m64",
diff --git a/include/EGL/egl.h b/include/EGL/egl.h
index 13ccde3..93a2187 100644
--- a/include/EGL/egl.h
+++ b/include/EGL/egl.h
@@ -6,7 +6,7 @@
 #endif
 
 /*
-** Copyright (c) 2013-2014 The Khronos Group Inc.
+** Copyright (c) 2013-2017 The Khronos Group Inc.
 **
 ** Permission is hereby granted, free of charge, to any person obtaining a
 ** copy of this software and/or associated documentation files (the
@@ -31,14 +31,14 @@
 ** This header is generated from the Khronos OpenGL / OpenGL ES XML
 ** API Registry. The current version of the Registry, generator scripts
 ** used to make the header, and the header can be found at
-**   http://www.opengl.org/registry/
+**   http://www.khronos.org/registry/egl
 **
-** Khronos $Revision: 28371 $ on $Date: 2014-10-01 09:16:09 -0700 (Wed, 01 Oct 2014) $
+** Khronos $Git commit SHA1: a732b061e7 $ on $Git commit date: 2017-06-17 23:27:53 +0100 $
 */
 
 #include <EGL/eglplatform.h>
 
-/* Generated on date 20141001 */
+/* Generated on date 20170627 */
 
 /* Generated C header for:
  * API: egl
@@ -78,7 +78,7 @@
 #define EGL_CONFIG_ID                     0x3028
 #define EGL_CORE_NATIVE_ENGINE            0x305B
 #define EGL_DEPTH_SIZE                    0x3025
-#define EGL_DONT_CARE                     ((EGLint)-1)
+#define EGL_DONT_CARE                     EGL_CAST(EGLint,-1)
 #define EGL_DRAW                          0x3059
 #define EGL_EXTENSIONS                    0x3055
 #define EGL_FALSE                         0
@@ -95,9 +95,9 @@
 #define EGL_NONE                          0x3038
 #define EGL_NON_CONFORMANT_CONFIG         0x3051
 #define EGL_NOT_INITIALIZED               0x3001
-#define EGL_NO_CONTEXT                    ((EGLContext)0)
-#define EGL_NO_DISPLAY                    ((EGLDisplay)0)
-#define EGL_NO_SURFACE                    ((EGLSurface)0)
+#define EGL_NO_CONTEXT                    EGL_CAST(EGLContext,0)
+#define EGL_NO_DISPLAY                    EGL_CAST(EGLDisplay,0)
+#define EGL_NO_SURFACE                    EGL_CAST(EGLSurface,0)
 #define EGL_PBUFFER_BIT                   0x0001
 #define EGL_PIXMAP_BIT                    0x0002
 #define EGL_READ                          0x305A
@@ -197,7 +197,7 @@
 #define EGL_RGB_BUFFER                    0x308E
 #define EGL_SINGLE_BUFFER                 0x3085
 #define EGL_SWAP_BEHAVIOR                 0x3093
-#define EGL_UNKNOWN                       ((EGLint)-1)
+#define EGL_UNKNOWN                       EGL_CAST(EGLint,-1)
 #define EGL_VERTICAL_RESOLUTION           0x3091
 EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI (EGLenum api);
 EGLAPI EGLenum EGLAPIENTRY eglQueryAPI (void);
@@ -224,7 +224,7 @@
 
 #ifndef EGL_VERSION_1_4
 #define EGL_VERSION_1_4 1
-#define EGL_DEFAULT_DISPLAY               ((EGLNativeDisplayType)0)
+#define EGL_DEFAULT_DISPLAY               EGL_CAST(EGLNativeDisplayType,0)
 #define EGL_MULTISAMPLE_RESOLVE_BOX_BIT   0x0200
 #define EGL_MULTISAMPLE_RESOLVE           0x3099
 #define EGL_MULTISAMPLE_RESOLVE_DEFAULT   0x309A
@@ -266,7 +266,7 @@
 #define EGL_FOREVER                       0xFFFFFFFFFFFFFFFFull
 #define EGL_TIMEOUT_EXPIRED               0x30F5
 #define EGL_CONDITION_SATISFIED           0x30F6
-#define EGL_NO_SYNC                       ((EGLSync)0)
+#define EGL_NO_SYNC                       EGL_CAST(EGLSync,0)
 #define EGL_SYNC_FENCE                    0x30F9
 #define EGL_GL_COLORSPACE                 0x309D
 #define EGL_GL_COLORSPACE_SRGB            0x3089
@@ -283,12 +283,12 @@
 #define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x30B7
 #define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x30B8
 #define EGL_IMAGE_PRESERVED               0x30D2
-#define EGL_NO_IMAGE                      ((EGLImage)0)
+#define EGL_NO_IMAGE                      EGL_CAST(EGLImage,0)
 EGLAPI EGLSync EGLAPIENTRY eglCreateSync (EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
 EGLAPI EGLBoolean EGLAPIENTRY eglDestroySync (EGLDisplay dpy, EGLSync sync);
 EGLAPI EGLint EGLAPIENTRY eglClientWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
 EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttrib (EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
-EGLAPI EGLImage EGLAPIENTRY eglCreateImage (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+EGLAPI EGLImage EGLAPIENTRY eglCreateImage (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
 EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImage (EGLDisplay dpy, EGLImage image);
 EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay (EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
 EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 4e81e44..d2def03 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -6,7 +6,7 @@
 #endif
 
 /*
-** Copyright (c) 2013-2015 The Khronos Group Inc.
+** Copyright (c) 2013-2017 The Khronos Group Inc.
 **
 ** Permission is hereby granted, free of charge, to any person obtaining a
 ** copy of this software and/or associated documentation files (the
@@ -31,14 +31,14 @@
 ** This header is generated from the Khronos OpenGL / OpenGL ES XML
 ** API Registry. The current version of the Registry, generator scripts
 ** used to make the header, and the header can be found at
-**   http://www.opengl.org/registry/
+**   http://www.khronos.org/registry/egl
 **
-** Khronos $Revision: 32040 $ on $Date: 2015-09-22 15:57:58 -0700 (Tue, 22 Sep 2015) $
+** Khronos $Git commit SHA1: a732b061e7 $ on $Git commit date: 2017-06-17 23:27:53 +0100 $
 */
 
 #include <EGL/eglplatform.h>
 
-#define EGL_EGLEXT_VERSION 20150922
+#define EGL_EGLEXT_VERSION 20170627
 
 /* Generated C header for:
  * API: egl
@@ -77,6 +77,13 @@
 #define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR   0x0040
 #endif /* EGL_KHR_config_attribs */
 
+#ifndef EGL_KHR_context_flush_control
+#define EGL_KHR_context_flush_control 1
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR 0
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_KHR  0x2097
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR 0x2098
+#endif /* EGL_KHR_context_flush_control */
+
 #ifndef EGL_KHR_create_context
 #define EGL_KHR_create_context 1
 #define EGL_CONTEXT_MAJOR_VERSION_KHR     0x3098
@@ -103,7 +110,7 @@
 #define EGL_KHR_debug 1
 typedef void *EGLLabelKHR;
 typedef void *EGLObjectKHR;
-typedef void (EGLAPIENTRY  *EGLDEBUGPROC)(EGLenum error,const char *command,EGLint messageType,EGLLabelKHR threadLabel,EGLLabelKHR objectLabel,const char* message);
+typedef void (EGLAPIENTRY  *EGLDEBUGPROCKHR)(EGLenum error,const char *command,EGLint messageType,EGLLabelKHR threadLabel,EGLLabelKHR objectLabel,const char* message);
 #define EGL_OBJECT_THREAD_KHR             0x33B0
 #define EGL_OBJECT_DISPLAY_KHR            0x33B1
 #define EGL_OBJECT_CONTEXT_KHR            0x33B2
@@ -116,16 +123,25 @@
 #define EGL_DEBUG_MSG_WARN_KHR            0x33BB
 #define EGL_DEBUG_MSG_INFO_KHR            0x33BC
 #define EGL_DEBUG_CALLBACK_KHR            0x33B8
-typedef EGLint (EGLAPIENTRYP PFNEGLDEBUGMESSAGECONTROLKHRPROC) (EGLDEBUGPROC callback, const EGLAttrib *attrib_list);
+typedef EGLint (EGLAPIENTRYP PFNEGLDEBUGMESSAGECONTROLKHRPROC) (EGLDEBUGPROCKHR callback, const EGLAttrib *attrib_list);
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEBUGKHRPROC) (EGLint attribute, EGLAttrib *value);
 typedef EGLint (EGLAPIENTRYP PFNEGLLABELOBJECTKHRPROC) (EGLDisplay display, EGLenum objectType, EGLObjectKHR object, EGLLabelKHR label);
 #ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLint EGLAPIENTRY eglDebugMessageControlKHR (EGLDEBUGPROC callback, const EGLAttrib *attrib_list);
+EGLAPI EGLint EGLAPIENTRY eglDebugMessageControlKHR (EGLDEBUGPROCKHR callback, const EGLAttrib *attrib_list);
 EGLAPI EGLBoolean EGLAPIENTRY eglQueryDebugKHR (EGLint attribute, EGLAttrib *value);
 EGLAPI EGLint EGLAPIENTRY eglLabelObjectKHR (EGLDisplay display, EGLenum objectType, EGLObjectKHR object, EGLLabelKHR label);
 #endif
 #endif /* EGL_KHR_debug */
 
+#ifndef EGL_KHR_display_reference
+#define EGL_KHR_display_reference 1
+#define EGL_TRACK_REFERENCES_KHR          0x3352
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBKHRPROC) (EGLDisplay dpy, EGLint name, EGLAttrib *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribKHR (EGLDisplay dpy, EGLint name, EGLAttrib *value);
+#endif
+#endif /* EGL_KHR_display_reference */
+
 #ifndef EGL_KHR_fence_sync
 #define EGL_KHR_fence_sync 1
 typedef khronos_utime_nanoseconds_t EGLTimeKHR;
@@ -188,7 +204,7 @@
 #define EGL_KHR_image 1
 typedef void *EGLImageKHR;
 #define EGL_NATIVE_PIXMAP_KHR             0x30B0
-#define EGL_NO_IMAGE_KHR                  ((EGLImageKHR)0)
+#define EGL_NO_IMAGE_KHR                  EGL_CAST(EGLImageKHR,0)
 typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
 #ifdef EGL_EGLEXT_PROTOTYPES
@@ -250,6 +266,16 @@
 #endif
 #endif /* EGL_KHR_lock_surface3 */
 
+#ifndef EGL_KHR_mutable_render_buffer
+#define EGL_KHR_mutable_render_buffer 1
+#define EGL_MUTABLE_RENDER_BUFFER_BIT_KHR 0x1000
+#endif /* EGL_KHR_mutable_render_buffer */
+
+#ifndef EGL_KHR_no_config_context
+#define EGL_KHR_no_config_context 1
+#define EGL_NO_CONFIG_KHR                 EGL_CAST(EGLConfig,0)
+#endif /* EGL_KHR_no_config_context */
+
 #ifndef EGL_KHR_partial_update
 #define EGL_KHR_partial_update 1
 #define EGL_BUFFER_AGE_KHR                0x313D
@@ -292,7 +318,7 @@
 #define EGL_SYNC_REUSABLE_KHR             0x30FA
 #define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR   0x0001
 #define EGL_FOREVER_KHR                   0xFFFFFFFFFFFFFFFFull
-#define EGL_NO_SYNC_KHR                   ((EGLSyncKHR)0)
+#define EGL_NO_SYNC_KHR                   EGL_CAST(EGLSyncKHR,0)
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
 #ifdef EGL_EGLEXT_PROTOTYPES
 EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
@@ -305,7 +331,7 @@
 typedef void *EGLStreamKHR;
 typedef khronos_uint64_t EGLuint64KHR;
 #ifdef KHRONOS_SUPPORT_INT64
-#define EGL_NO_STREAM_KHR                 ((EGLStreamKHR)0)
+#define EGL_NO_STREAM_KHR                 EGL_CAST(EGLStreamKHR,0)
 #define EGL_CONSUMER_LATENCY_USEC_KHR     0x3210
 #define EGL_PRODUCER_FRAME_KHR            0x3212
 #define EGL_CONSUMER_FRAME_KHR            0x3213
@@ -333,6 +359,24 @@
 #endif /* KHRONOS_SUPPORT_INT64 */
 #endif /* EGL_KHR_stream */
 
+#ifndef EGL_KHR_stream_attrib
+#define EGL_KHR_stream_attrib 1
+#ifdef KHRONOS_SUPPORT_INT64
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMATTRIBKHRPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETSTREAMATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamAttribKHR (EGLDisplay dpy, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglSetStreamAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_stream_attrib */
+
 #ifndef EGL_KHR_stream_consumer_gltexture
 #define EGL_KHR_stream_consumer_gltexture 1
 #ifdef EGL_KHR_stream
@@ -352,7 +396,7 @@
 #define EGL_KHR_stream_cross_process_fd 1
 typedef int EGLNativeFileDescriptorKHR;
 #ifdef EGL_KHR_stream
-#define EGL_NO_FILE_DESCRIPTOR_KHR        ((EGLNativeFileDescriptorKHR)(-1))
+#define EGL_NO_FILE_DESCRIPTOR_KHR        EGL_CAST(EGLNativeFileDescriptorKHR,-1)
 typedef EGLNativeFileDescriptorKHR (EGLAPIENTRYP PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
 typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
 #ifdef EGL_EGLEXT_PROTOTYPES
@@ -429,11 +473,28 @@
 #endif
 #endif /* EGL_ANDROID_blob_cache */
 
+#ifndef EGL_ANDROID_create_native_client_buffer
+#define EGL_ANDROID_create_native_client_buffer 1
+#define EGL_NATIVE_BUFFER_USAGE_ANDROID   0x3143
+#define EGL_NATIVE_BUFFER_USAGE_PROTECTED_BIT_ANDROID 0x00000001
+#define EGL_NATIVE_BUFFER_USAGE_RENDERBUFFER_BIT_ANDROID 0x00000002
+#define EGL_NATIVE_BUFFER_USAGE_TEXTURE_BIT_ANDROID 0x00000004
+typedef EGLClientBuffer (EGLAPIENTRYP PFNEGLCREATENATIVECLIENTBUFFERANDROIDPROC) (const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLClientBuffer EGLAPIENTRY eglCreateNativeClientBufferANDROID (const EGLint *attrib_list);
+#endif
+#endif /* EGL_ANDROID_create_native_client_buffer */
+
 #ifndef EGL_ANDROID_framebuffer_target
 #define EGL_ANDROID_framebuffer_target 1
 #define EGL_FRAMEBUFFER_TARGET_ANDROID    0x3147
 #endif /* EGL_ANDROID_framebuffer_target */
 
+#ifndef EGL_ANDROID_front_buffer_auto_refresh
+#define EGL_ANDROID_front_buffer_auto_refresh 1
+#define EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID 0x314C
+#endif /* EGL_ANDROID_front_buffer_auto_refresh */
+
 #ifndef EGL_ANDROID_image_native_buffer
 #define EGL_ANDROID_image_native_buffer 1
 #define EGL_NATIVE_BUFFER_ANDROID         0x3140
@@ -451,6 +512,15 @@
 #endif
 #endif /* EGL_ANDROID_native_fence_sync */
 
+#ifndef EGL_ANDROID_presentation_time
+#define EGL_ANDROID_presentation_time 1
+typedef khronos_stime_nanoseconds_t EGLnsecsANDROID;
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLPRESENTATIONTIMEANDROIDPROC) (EGLDisplay dpy, EGLSurface surface, EGLnsecsANDROID time);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglPresentationTimeANDROID (EGLDisplay dpy, EGLSurface surface, EGLnsecsANDROID time);
+#endif
+#endif /* EGL_ANDROID_presentation_time */
+
 #ifndef EGL_ANDROID_recordable
 #define EGL_ANDROID_recordable 1
 #define EGL_RECORDABLE_ANDROID            0x3142
@@ -484,11 +554,21 @@
 #define EGL_FIXED_SIZE_ANGLE              0x3201
 #endif /* EGL_ANGLE_window_fixed_size */
 
+#ifndef EGL_ARM_implicit_external_sync
+#define EGL_ARM_implicit_external_sync 1
+#define EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM 0x328A
+#endif /* EGL_ARM_implicit_external_sync */
+
 #ifndef EGL_ARM_pixmap_multisample_discard
 #define EGL_ARM_pixmap_multisample_discard 1
 #define EGL_DISCARD_SAMPLES_ARM           0x3286
 #endif /* EGL_ARM_pixmap_multisample_discard */
 
+#ifndef EGL_EXT_bind_to_front
+#define EGL_EXT_bind_to_front 1
+#define EGL_FRONT_BUFFER_EXT              0x3464
+#endif /* EGL_EXT_bind_to_front */
+
 #ifndef EGL_EXT_buffer_age
 #define EGL_EXT_buffer_age 1
 #define EGL_BUFFER_AGE_EXT                0x313D
@@ -498,6 +578,30 @@
 #define EGL_EXT_client_extensions 1
 #endif /* EGL_EXT_client_extensions */
 
+#ifndef EGL_EXT_compositor
+#define EGL_EXT_compositor 1
+#define EGL_PRIMARY_COMPOSITOR_CONTEXT_EXT 0x3460
+#define EGL_EXTERNAL_REF_ID_EXT           0x3461
+#define EGL_COMPOSITOR_DROP_NEWEST_FRAME_EXT 0x3462
+#define EGL_COMPOSITOR_KEEP_NEWEST_FRAME_EXT 0x3463
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETCONTEXTLISTEXTPROC) (const EGLint *external_ref_ids, EGLint num_entries);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETCONTEXTATTRIBUTESEXTPROC) (EGLint external_ref_id, const EGLint *context_attributes, EGLint num_entries);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETWINDOWLISTEXTPROC) (EGLint external_ref_id, const EGLint *external_win_ids, EGLint num_entries);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETWINDOWATTRIBUTESEXTPROC) (EGLint external_win_id, const EGLint *window_attributes, EGLint num_entries);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORBINDTEXWINDOWEXTPROC) (EGLint external_win_id);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETSIZEEXTPROC) (EGLint external_win_id, EGLint width, EGLint height);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSWAPPOLICYEXTPROC) (EGLint external_win_id, EGLint policy);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetContextListEXT (const EGLint *external_ref_ids, EGLint num_entries);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetContextAttributesEXT (EGLint external_ref_id, const EGLint *context_attributes, EGLint num_entries);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetWindowListEXT (EGLint external_ref_id, const EGLint *external_win_ids, EGLint num_entries);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetWindowAttributesEXT (EGLint external_win_id, const EGLint *window_attributes, EGLint num_entries);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorBindTexWindowEXT (EGLint external_win_id);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetSizeEXT (EGLint external_win_id, EGLint width, EGLint height);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSwapPolicyEXT (EGLint external_win_id, EGLint policy);
+#endif
+#endif /* EGL_EXT_compositor */
+
 #ifndef EGL_EXT_create_context_robustness
 #define EGL_EXT_create_context_robustness 1
 #define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF
@@ -509,7 +613,7 @@
 #ifndef EGL_EXT_device_base
 #define EGL_EXT_device_base 1
 typedef void *EGLDeviceEXT;
-#define EGL_NO_DEVICE_EXT                 ((EGLDeviceEXT)(0))
+#define EGL_NO_DEVICE_EXT                 EGL_CAST(EGLDeviceEXT,0)
 #define EGL_BAD_DEVICE_EXT                0x322B
 #define EGL_DEVICE_EXT                    0x322C
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICEATTRIBEXTPROC) (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
@@ -542,6 +646,36 @@
 #define EGL_EXT_device_query 1
 #endif /* EGL_EXT_device_query */
 
+#ifndef EGL_EXT_gl_colorspace_bt2020_linear
+#define EGL_EXT_gl_colorspace_bt2020_linear 1
+#define EGL_GL_COLORSPACE_BT2020_LINEAR_EXT 0x333F
+#endif /* EGL_EXT_gl_colorspace_bt2020_linear */
+
+#ifndef EGL_EXT_gl_colorspace_bt2020_pq
+#define EGL_EXT_gl_colorspace_bt2020_pq 1
+#define EGL_GL_COLORSPACE_BT2020_PQ_EXT   0x3340
+#endif /* EGL_EXT_gl_colorspace_bt2020_pq */
+
+#ifndef EGL_EXT_gl_colorspace_display_p3
+#define EGL_EXT_gl_colorspace_display_p3 1
+#define EGL_GL_COLORSPACE_DISPLAY_P3_EXT  0x3363
+#endif /* EGL_EXT_gl_colorspace_display_p3 */
+
+#ifndef EGL_EXT_gl_colorspace_display_p3_linear
+#define EGL_EXT_gl_colorspace_display_p3_linear 1
+#define EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT 0x3362
+#endif /* EGL_EXT_gl_colorspace_display_p3_linear */
+
+#ifndef EGL_EXT_gl_colorspace_scrgb
+#define EGL_EXT_gl_colorspace_scrgb 1
+#define EGL_GL_COLORSPACE_SCRGB_EXT       0x3351
+#endif /* EGL_EXT_gl_colorspace_scrgb */
+
+#ifndef EGL_EXT_gl_colorspace_scrgb_linear
+#define EGL_EXT_gl_colorspace_scrgb_linear 1
+#define EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT 0x3350
+#endif /* EGL_EXT_gl_colorspace_scrgb_linear */
+
 #ifndef EGL_EXT_image_dma_buf_import
 #define EGL_EXT_image_dma_buf_import 1
 #define EGL_LINUX_DMA_BUF_EXT             0x3270
@@ -568,6 +702,34 @@
 #define EGL_YUV_CHROMA_SITING_0_5_EXT     0x3285
 #endif /* EGL_EXT_image_dma_buf_import */
 
+#ifndef EGL_EXT_image_dma_buf_import_modifiers
+#define EGL_EXT_image_dma_buf_import_modifiers 1
+#define EGL_DMA_BUF_PLANE3_FD_EXT         0x3440
+#define EGL_DMA_BUF_PLANE3_OFFSET_EXT     0x3441
+#define EGL_DMA_BUF_PLANE3_PITCH_EXT      0x3442
+#define EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT 0x3443
+#define EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT 0x3444
+#define EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT 0x3445
+#define EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT 0x3446
+#define EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT 0x3447
+#define EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT 0x3448
+#define EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT 0x3449
+#define EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT 0x344A
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFFORMATSEXTPROC) (EGLDisplay dpy, EGLint max_formats, EGLint *formats, EGLint *num_formats);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFMODIFIERSEXTPROC) (EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDmaBufFormatsEXT (EGLDisplay dpy, EGLint max_formats, EGLint *formats, EGLint *num_formats);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDmaBufModifiersEXT (EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers);
+#endif
+#endif /* EGL_EXT_image_dma_buf_import_modifiers */
+
+#ifndef EGL_EXT_image_implicit_sync_control
+#define EGL_EXT_image_implicit_sync_control 1
+#define EGL_IMPORT_SYNC_TYPE_EXT          0x3470
+#define EGL_IMPORT_IMPLICIT_SYNC_EXT      0x3471
+#define EGL_IMPORT_EXPLICIT_SYNC_EXT      0x3472
+#endif /* EGL_EXT_image_implicit_sync_control */
+
 #ifndef EGL_EXT_multiview_window
 #define EGL_EXT_multiview_window 1
 #define EGL_MULTIVIEW_VIEW_COUNT_EXT      0x3134
@@ -577,8 +739,8 @@
 #define EGL_EXT_output_base 1
 typedef void *EGLOutputLayerEXT;
 typedef void *EGLOutputPortEXT;
-#define EGL_NO_OUTPUT_LAYER_EXT           ((EGLOutputLayerEXT)0)
-#define EGL_NO_OUTPUT_PORT_EXT            ((EGLOutputPortEXT)0)
+#define EGL_NO_OUTPUT_LAYER_EXT           EGL_CAST(EGLOutputLayerEXT,0)
+#define EGL_NO_OUTPUT_PORT_EXT            EGL_CAST(EGLOutputPortEXT,0)
 #define EGL_BAD_OUTPUT_LAYER_EXT          0x322D
 #define EGL_BAD_OUTPUT_PORT_EXT           0x322E
 #define EGL_SWAP_INTERVAL_EXT             0x322F
@@ -615,6 +777,13 @@
 #define EGL_OPENWF_PORT_ID_EXT            0x3239
 #endif /* EGL_EXT_output_openwf */
 
+#ifndef EGL_EXT_pixel_format_float
+#define EGL_EXT_pixel_format_float 1
+#define EGL_COLOR_COMPONENT_TYPE_EXT      0x3339
+#define EGL_COLOR_COMPONENT_TYPE_FIXED_EXT 0x333A
+#define EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT 0x333B
+#endif /* EGL_EXT_pixel_format_float */
+
 #ifndef EGL_EXT_platform_base
 #define EGL_EXT_platform_base 1
 typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, void *native_display, const EGLint *attrib_list);
@@ -643,9 +812,13 @@
 #define EGL_PLATFORM_X11_SCREEN_EXT       0x31D6
 #endif /* EGL_EXT_platform_x11 */
 
+#ifndef EGL_EXT_protected_content
+#define EGL_EXT_protected_content 1
+#define EGL_PROTECTED_CONTENT_EXT         0x32C0
+#endif /* EGL_EXT_protected_content */
+
 #ifndef EGL_EXT_protected_surface
 #define EGL_EXT_protected_surface 1
-#define EGL_PROTECTED_CONTENT_EXT         0x32C0
 #endif /* EGL_EXT_protected_surface */
 
 #ifndef EGL_EXT_stream_consumer_egloutput
@@ -656,6 +829,27 @@
 #endif
 #endif /* EGL_EXT_stream_consumer_egloutput */
 
+#ifndef EGL_EXT_surface_CTA861_3_metadata
+#define EGL_EXT_surface_CTA861_3_metadata 1
+#define EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT 0x3360
+#define EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT 0x3361
+#endif /* EGL_EXT_surface_CTA861_3_metadata */
+
+#ifndef EGL_EXT_surface_SMPTE2086_metadata
+#define EGL_EXT_surface_SMPTE2086_metadata 1
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT 0x3341
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT 0x3342
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT 0x3343
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT 0x3344
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT 0x3345
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT 0x3346
+#define EGL_SMPTE2086_WHITE_POINT_X_EXT   0x3347
+#define EGL_SMPTE2086_WHITE_POINT_Y_EXT   0x3348
+#define EGL_SMPTE2086_MAX_LUMINANCE_EXT   0x3349
+#define EGL_SMPTE2086_MIN_LUMINANCE_EXT   0x334A
+#define EGL_METADATA_SCALING_EXT          50000
+#endif /* EGL_EXT_surface_SMPTE2086_metadata */
+
 #ifndef EGL_EXT_swap_buffers_with_damage
 #define EGL_EXT_swap_buffers_with_damage 1
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
@@ -724,6 +918,12 @@
 #define EGL_CONTEXT_PRIORITY_LOW_IMG      0x3103
 #endif /* EGL_IMG_context_priority */
 
+#ifndef EGL_IMG_image_plane_attribs
+#define EGL_IMG_image_plane_attribs 1
+#define EGL_NATIVE_BUFFER_MULTIPLANE_SEPARATE_IMG 0x3105
+#define EGL_NATIVE_BUFFER_PLANE_OFFSET_IMG 0x3106
+#endif /* EGL_IMG_image_plane_attribs */
+
 #ifndef EGL_MESA_drm_image
 #define EGL_MESA_drm_image 1
 #define EGL_DRM_BUFFER_FORMAT_MESA        0x31D0
@@ -756,6 +956,11 @@
 #define EGL_PLATFORM_GBM_MESA             0x31D7
 #endif /* EGL_MESA_platform_gbm */
 
+#ifndef EGL_MESA_platform_surfaceless
+#define EGL_MESA_platform_surfaceless 1
+#define EGL_PLATFORM_SURFACELESS_MESA     0x31DD
+#endif /* EGL_MESA_platform_surfaceless */
+
 #ifndef EGL_NOK_swap_region
 #define EGL_NOK_swap_region 1
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOKPROC) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
@@ -839,6 +1044,129 @@
 #endif
 #endif /* EGL_NV_post_sub_buffer */
 
+#ifndef EGL_NV_robustness_video_memory_purge
+#define EGL_NV_robustness_video_memory_purge 1
+#define EGL_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV 0x334C
+#endif /* EGL_NV_robustness_video_memory_purge */
+
+#ifndef EGL_NV_stream_consumer_gltexture_yuv
+#define EGL_NV_stream_consumer_gltexture_yuv 1
+#define EGL_YUV_PLANE0_TEXTURE_UNIT_NV    0x332C
+#define EGL_YUV_PLANE1_TEXTURE_UNIT_NV    0x332D
+#define EGL_YUV_PLANE2_TEXTURE_UNIT_NV    0x332E
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALATTRIBSNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLAttrib *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalAttribsNV (EGLDisplay dpy, EGLStreamKHR stream, EGLAttrib *attrib_list);
+#endif
+#endif /* EGL_NV_stream_consumer_gltexture_yuv */
+
+#ifndef EGL_NV_stream_cross_display
+#define EGL_NV_stream_cross_display 1
+#define EGL_STREAM_CROSS_DISPLAY_NV       0x334E
+#endif /* EGL_NV_stream_cross_display */
+
+#ifndef EGL_NV_stream_cross_object
+#define EGL_NV_stream_cross_object 1
+#define EGL_STREAM_CROSS_OBJECT_NV        0x334D
+#endif /* EGL_NV_stream_cross_object */
+
+#ifndef EGL_NV_stream_cross_partition
+#define EGL_NV_stream_cross_partition 1
+#define EGL_STREAM_CROSS_PARTITION_NV     0x323F
+#endif /* EGL_NV_stream_cross_partition */
+
+#ifndef EGL_NV_stream_cross_process
+#define EGL_NV_stream_cross_process 1
+#define EGL_STREAM_CROSS_PROCESS_NV       0x3245
+#endif /* EGL_NV_stream_cross_process */
+
+#ifndef EGL_NV_stream_cross_system
+#define EGL_NV_stream_cross_system 1
+#define EGL_STREAM_CROSS_SYSTEM_NV        0x334F
+#endif /* EGL_NV_stream_cross_system */
+
+#ifndef EGL_NV_stream_fifo_next
+#define EGL_NV_stream_fifo_next 1
+#define EGL_PENDING_FRAME_NV              0x3329
+#define EGL_STREAM_TIME_PENDING_NV        0x332A
+#endif /* EGL_NV_stream_fifo_next */
+
+#ifndef EGL_NV_stream_fifo_synchronous
+#define EGL_NV_stream_fifo_synchronous 1
+#define EGL_STREAM_FIFO_SYNCHRONOUS_NV    0x3336
+#endif /* EGL_NV_stream_fifo_synchronous */
+
+#ifndef EGL_NV_stream_frame_limits
+#define EGL_NV_stream_frame_limits 1
+#define EGL_PRODUCER_MAX_FRAME_HINT_NV    0x3337
+#define EGL_CONSUMER_MAX_FRAME_HINT_NV    0x3338
+#endif /* EGL_NV_stream_frame_limits */
+
+#ifndef EGL_NV_stream_metadata
+#define EGL_NV_stream_metadata 1
+#define EGL_MAX_STREAM_METADATA_BLOCKS_NV 0x3250
+#define EGL_MAX_STREAM_METADATA_BLOCK_SIZE_NV 0x3251
+#define EGL_MAX_STREAM_METADATA_TOTAL_SIZE_NV 0x3252
+#define EGL_PRODUCER_METADATA_NV          0x3253
+#define EGL_CONSUMER_METADATA_NV          0x3254
+#define EGL_PENDING_METADATA_NV           0x3328
+#define EGL_METADATA0_SIZE_NV             0x3255
+#define EGL_METADATA1_SIZE_NV             0x3256
+#define EGL_METADATA2_SIZE_NV             0x3257
+#define EGL_METADATA3_SIZE_NV             0x3258
+#define EGL_METADATA0_TYPE_NV             0x3259
+#define EGL_METADATA1_TYPE_NV             0x325A
+#define EGL_METADATA2_TYPE_NV             0x325B
+#define EGL_METADATA3_TYPE_NV             0x325C
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBNVPROC) (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETSTREAMMETADATANVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLint n, EGLint offset, EGLint size, const void *data);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMMETADATANVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum name, EGLint n, EGLint offset, EGLint size, void *data);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribNV (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglSetStreamMetadataNV (EGLDisplay dpy, EGLStreamKHR stream, EGLint n, EGLint offset, EGLint size, const void *data);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamMetadataNV (EGLDisplay dpy, EGLStreamKHR stream, EGLenum name, EGLint n, EGLint offset, EGLint size, void *data);
+#endif
+#endif /* EGL_NV_stream_metadata */
+
+#ifndef EGL_NV_stream_remote
+#define EGL_NV_stream_remote 1
+#define EGL_STREAM_STATE_INITIALIZING_NV  0x3240
+#define EGL_STREAM_TYPE_NV                0x3241
+#define EGL_STREAM_PROTOCOL_NV            0x3242
+#define EGL_STREAM_ENDPOINT_NV            0x3243
+#define EGL_STREAM_LOCAL_NV               0x3244
+#define EGL_STREAM_PRODUCER_NV            0x3247
+#define EGL_STREAM_CONSUMER_NV            0x3248
+#define EGL_STREAM_PROTOCOL_FD_NV         0x3246
+#endif /* EGL_NV_stream_remote */
+
+#ifndef EGL_NV_stream_reset
+#define EGL_NV_stream_reset 1
+#define EGL_SUPPORT_RESET_NV              0x3334
+#define EGL_SUPPORT_REUSE_NV              0x3335
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLRESETSTREAMNVPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglResetStreamNV (EGLDisplay dpy, EGLStreamKHR stream);
+#endif
+#endif /* EGL_NV_stream_reset */
+
+#ifndef EGL_NV_stream_socket
+#define EGL_NV_stream_socket 1
+#define EGL_STREAM_PROTOCOL_SOCKET_NV     0x324B
+#define EGL_SOCKET_HANDLE_NV              0x324C
+#define EGL_SOCKET_TYPE_NV                0x324D
+#endif /* EGL_NV_stream_socket */
+
+#ifndef EGL_NV_stream_socket_inet
+#define EGL_NV_stream_socket_inet 1
+#define EGL_SOCKET_TYPE_INET_NV           0x324F
+#endif /* EGL_NV_stream_socket_inet */
+
+#ifndef EGL_NV_stream_socket_unix
+#define EGL_NV_stream_socket_unix 1
+#define EGL_SOCKET_TYPE_UNIX_NV           0x324E
+#endif /* EGL_NV_stream_socket_unix */
+
 #ifndef EGL_NV_stream_sync
 #define EGL_NV_stream_sync 1
 #define EGL_SYNC_NEW_FRAME_NV             0x321F
@@ -865,7 +1193,7 @@
 #define EGL_SYNC_TYPE_NV                  0x30ED
 #define EGL_SYNC_CONDITION_NV             0x30EE
 #define EGL_SYNC_FENCE_NV                 0x30EF
-#define EGL_NO_SYNC_NV                    ((EGLSyncNV)0)
+#define EGL_NO_SYNC_NV                    EGL_CAST(EGLSyncNV,0)
 typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync);
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync);
diff --git a/include/EGL/eglplatform.h b/include/EGL/eglplatform.h
index a3b7234..f5a22bc 100644
--- a/include/EGL/eglplatform.h
+++ b/include/EGL/eglplatform.h
@@ -2,7 +2,7 @@
 #define __eglplatform_h_
 
 /*
-** Copyright (c) 2007-2013 The Khronos Group Inc.
+** Copyright (c) 2007-2016 The Khronos Group Inc.
 **
 ** Permission is hereby granted, free of charge, to any person obtaining a
 ** copy of this software and/or associated documentation files (the
@@ -92,6 +92,12 @@
 typedef struct egl_native_pixmap_t*     EGLNativePixmapType;
 typedef void*                           EGLNativeDisplayType;
 
+#elif defined(USE_OZONE)
+
+typedef intptr_t EGLNativeDisplayType;
+typedef intptr_t EGLNativeWindowType;
+typedef intptr_t EGLNativePixmapType;
+
 #elif defined(__unix__)
 
 /* X11 (tentative)  */
@@ -121,4 +127,12 @@
  */
 typedef khronos_int32_t EGLint;
 
+
+/* C++ / C typecast macros for special EGL handle values */
+#if defined(__cplusplus)
+#define EGL_CAST(type, value) (static_cast<type>(value))
+#else
+#define EGL_CAST(type, value) ((type) (value))
+#endif
+
 #endif /* __eglplatform_h */
diff --git a/include/KHR/khrplatform.h b/include/KHR/khrplatform.h
index c9e6f17..1ad3554 100644
--- a/include/KHR/khrplatform.h
+++ b/include/KHR/khrplatform.h
@@ -26,7 +26,7 @@
 
 /* Khronos platform-specific types and definitions.
  *
- * $Revision: 23298 $ on $Date: 2013-09-30 17:07:13 -0700 (Mon, 30 Sep 2013) $
+ * $Revision: 32517 $ on $Date: 2016-03-11 02:41:19 -0800 (Fri, 11 Mar 2016) $
  *
  * Adopters may modify this file to suit their platform. Adopters are
  * encouraged to submit platform specific modifications to the Khronos
@@ -101,6 +101,8 @@
 #   define KHRONOS_APICALL __declspec(dllimport)
 #elif defined (__SYMBIAN32__)
 #   define KHRONOS_APICALL IMPORT_C
+#elif defined(__ANDROID__)
+#   define KHRONOS_APICALL __attribute__((visibility("default")))
 #else
 #   define KHRONOS_APICALL
 #endif
@@ -223,7 +225,7 @@
 typedef unsigned short int     khronos_uint16_t;
 
 /*
- * Types that differ between LLP64 and LP64 architectures - in LLP64, 
+ * Types that differ between LLP64 and LP64 architectures - in LLP64,
  * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
  * to be the only LLP64 architecture in current use.
  */
diff --git a/src/Android.mk b/src/Android.mk
index ec3fc96..7f1efa2 100644
--- a/src/Android.mk
+++ b/src/Android.mk
@@ -1,10 +1,5 @@
 LOCAL_PATH:= $(call my-dir)
 
-# Use Subzero as the Reactor JIT back-end on ARM, else LLVM.
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm))
-use_subzero := true
-endif
-
 COMMON_C_INCLUDES += \
 	bionic \
 	$(LOCAL_PATH)/../include \
@@ -26,6 +21,11 @@
 	$(LOCAL_PATH)/../third_party/LLVM/include
 endif
 
+# libnativewindow is introduced from O
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26 && echo O),O)
+COMMON_SHARED_LIBRARIES := libnativewindow
+endif
+
 # Marshmallow does not have stlport, but comes with libc++ by default
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23 && echo PreMarshmallow),PreMarshmallow)
 COMMON_C_INCLUDES += external/stlport/stlport
@@ -148,6 +148,7 @@
 LOCAL_SRC_FILES := $(COMMON_SRC_FILES)
 LOCAL_CFLAGS := $(COMMON_CFLAGS) -fomit-frame-pointer -ffunction-sections -fdata-sections -DANGLE_DISABLE_TRACE
 LOCAL_C_INCLUDES := $(COMMON_C_INCLUDES)
+LOCAL_SHARED_LIBRARIES := $(COMMON_SHARED_LIBRARIES)
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
@@ -157,6 +158,7 @@
 LOCAL_SRC_FILES := $(COMMON_SRC_FILES)
 LOCAL_CFLAGS := $(COMMON_CFLAGS) -UNDEBUG -g -O0 -DDEFAULT_THREAD_COUNT=1
 LOCAL_C_INCLUDES := $(COMMON_C_INCLUDES)
+LOCAL_SHARED_LIBRARIES := $(COMMON_SHARED_LIBRARIES)
 include $(BUILD_STATIC_LIBRARY)
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/src/D3D9/Direct3DQuery9.cpp b/src/D3D9/Direct3DQuery9.cpp
index f5d52a5..31d249e 100644
--- a/src/D3D9/Direct3DQuery9.cpp
+++ b/src/D3D9/Direct3DQuery9.cpp
@@ -169,7 +169,13 @@
 				device->setOcclusionEnabled(false);
 			}
 			break;
-		case D3DQUERYTYPE_TIMESTAMP:			if(flags != D3DISSUE_END) return INVALIDCALL(); break;
+		case D3DQUERYTYPE_TIMESTAMP:
+			if(flags == D3DISSUE_END)
+			{
+				timestamp = sw::Timer::counter();
+			}
+			else return INVALIDCALL();
+			break;
 		case D3DQUERYTYPE_TIMESTAMPDISJOINT:	if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
 		case D3DQUERYTYPE_TIMESTAMPFREQ:		if(flags != D3DISSUE_END) return INVALIDCALL(); break;
 		case D3DQUERYTYPE_PIPELINETIMINGS:		if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
@@ -227,7 +233,7 @@
 			case D3DQUERYTYPE_OCCLUSION:
 				*(DWORD*)data = query->data;
 				break;
-			case D3DQUERYTYPE_TIMESTAMP:			*(UINT64*)data = sw::Timer::counter(); break;     // FIXME: Verify behaviour
+			case D3DQUERYTYPE_TIMESTAMP:			*(UINT64*)data = timestamp; break;                // FIXME: Verify behaviour
 			case D3DQUERYTYPE_TIMESTAMPDISJOINT:	*(BOOL*)data = FALSE; break;                      // FIXME: Verify behaviour
 			case D3DQUERYTYPE_TIMESTAMPFREQ:		*(UINT64*)data = sw::Timer::frequency(); break;   // FIXME: Verify behaviour
 			case D3DQUERYTYPE_PIPELINETIMINGS:		UNIMPLEMENTED(); break;
diff --git a/src/D3D9/Direct3DQuery9.hpp b/src/D3D9/Direct3DQuery9.hpp
index 7c522f6..70778cf 100644
--- a/src/D3D9/Direct3DQuery9.hpp
+++ b/src/D3D9/Direct3DQuery9.hpp
@@ -49,7 +49,9 @@
 		Direct3DDevice9 *const device;
 		const D3DQUERYTYPE type;
 
-		sw::Query *query;
+		// TODO: create a union, or subclasses for each type.
+		sw::Query *query;   // D3DQUERYTYPE_OCCLUSION
+		UINT64 timestamp;   // D3DQUERYTYPE_TIMESTAMP
 	};
 }
 
diff --git a/src/Main/BUILD.gn b/src/Main/BUILD.gn
index dd85696..1f6d69c 100644
--- a/src/Main/BUILD.gn
+++ b/src/Main/BUILD.gn
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//ui/ozone/ozone.gni")
 import("../swiftshader.gni")
 
 # Need a separate config to ensure the warnings are added to the end.
@@ -46,7 +47,9 @@
     "SwiftConfig.cpp",
   ]
 
-  if (is_linux) {
+  if (use_ozone) {
+    sources += [ "FrameBufferOzone.cpp" ]
+  } else if (is_linux) {
     sources += [
       "FrameBufferX11.cpp",
       "libX11.cpp",
diff --git a/src/Main/FrameBufferAndroid.cpp b/src/Main/FrameBufferAndroid.cpp
index 49957c8..16e63ab 100644
--- a/src/Main/FrameBufferAndroid.cpp
+++ b/src/Main/FrameBufferAndroid.cpp
@@ -100,15 +100,22 @@
 
 		switch(buffer->format)
 		{
-		default: ALOGE("Unsupported buffer format %d", buffer->format); ASSERT(false);
-		case HAL_PIXEL_FORMAT_RGB_565: destFormat = FORMAT_R5G6B5; break;
-		case HAL_PIXEL_FORMAT_RGB_888: destFormat = FORMAT_R8G8B8; break;
+		case HAL_PIXEL_FORMAT_RGB_565:   destFormat = FORMAT_R5G6B5; break;
 		case HAL_PIXEL_FORMAT_RGBA_8888: destFormat = FORMAT_A8B8G8R8; break;
 #if ANDROID_PLATFORM_SDK_VERSION > 16
 		case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: destFormat = FORMAT_X8B8G8R8; break;
 #endif
 		case HAL_PIXEL_FORMAT_RGBX_8888: destFormat = FORMAT_X8B8G8R8; break;
 		case HAL_PIXEL_FORMAT_BGRA_8888: destFormat = FORMAT_A8R8G8B8; break;
+		case HAL_PIXEL_FORMAT_RGB_888:
+			// Frame buffers are expected to have 16-bit or 32-bit colors, not 24-bit.
+			ALOGE("Unsupported frame buffer format RGB_888"); ASSERT(false);
+			destFormat = FORMAT_R8G8B8;   // Wrong component order.
+			break;
+		default:
+			ALOGE("Unsupported frame buffer format %d", buffer->format); ASSERT(false);
+			destFormat = FORMAT_NULL;
+			break;
 		}
 
 		stride = buffer->stride * Surface::bytes(destFormat);
diff --git a/src/Main/FrameBufferOzone.cpp b/src/Main/FrameBufferOzone.cpp
new file mode 100644
index 0000000..a9de407
--- /dev/null
+++ b/src/Main/FrameBufferOzone.cpp
@@ -0,0 +1,54 @@
+// Copyright 2017 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "FrameBufferOzone.hpp"
+
+namespace sw
+{
+	FrameBufferOzone::FrameBufferOzone(intptr_t display, intptr_t window, int width, int height) : FrameBuffer(width, height, false, false)
+	{
+		buffer = sw::Surface::create(width, height, 1, destFormat, nullptr,
+		                             sw::Surface::pitchB(width, destFormat, true),
+		                             sw::Surface::sliceB(width, height, destFormat, true));
+	}
+
+	FrameBufferOzone::~FrameBufferOzone()
+	{
+		delete buffer;
+	}
+
+	void *FrameBufferOzone::lock()
+	{
+		locked = buffer->lockInternal(0, 0, 0, sw::LOCK_READWRITE, sw::PUBLIC);
+
+		return locked;
+	}
+
+	void FrameBufferOzone::unlock()
+	{
+		buffer->unlockInternal();
+
+		locked = nullptr;
+	}
+
+	void FrameBufferOzone::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
+	{
+		copy(source, sourceFormat, sourceStride);
+	}
+}
+
+NO_SANITIZE_FUNCTION sw::FrameBuffer *createFrameBuffer(void* display, intptr_t window, int width, int height)
+{
+	return new sw::FrameBufferOzone((intptr_t)display, window, width, height);
+}
diff --git a/src/Main/FrameBufferOzone.hpp b/src/Main/FrameBufferOzone.hpp
new file mode 100644
index 0000000..6843926
--- /dev/null
+++ b/src/Main/FrameBufferOzone.hpp
@@ -0,0 +1,40 @@
+// Copyright 2017 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef sw_FrameBufferOzone_hpp
+#define sw_FrameBufferOzone_hpp
+
+#include "Main/FrameBuffer.hpp"
+
+namespace sw
+{
+	class FrameBufferOzone : public FrameBuffer
+	{
+	public:
+		FrameBufferOzone(intptr_t display, intptr_t window, int width, int height);
+
+		~FrameBufferOzone() override;
+
+		void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);};
+		void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
+
+		void *lock() override;
+		void unlock() override;
+
+	private:
+		sw::Surface* buffer;
+	};
+}
+
+#endif   // sw_FrameBufferOzone_hpp
diff --git a/src/OpenGL/common/Image.hpp b/src/OpenGL/common/Image.hpp
index e13b19e..ecd6cd7 100644
--- a/src/OpenGL/common/Image.hpp
+++ b/src/OpenGL/common/Image.hpp
@@ -220,14 +220,16 @@
 	case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: return GL_RGB8;
 #endif
 	case HAL_PIXEL_FORMAT_RGBX_8888: return GL_RGB8;
-	case HAL_PIXEL_FORMAT_RGB_888:   return GL_NONE;   // Unsupported
 	case HAL_PIXEL_FORMAT_BGRA_8888: return GL_BGRA8_EXT;
 	case HAL_PIXEL_FORMAT_RGB_565:   return GL_RGB565;
 	case HAL_PIXEL_FORMAT_YV12:      return SW_YV12_BT601;
 #ifdef GRALLOC_MODULE_API_VERSION_0_2
 	case HAL_PIXEL_FORMAT_YCbCr_420_888: return SW_YV12_BT601;
 #endif
-	default:                         return GL_NONE;
+	case HAL_PIXEL_FORMAT_RGB_888:   // Unsupported.
+	default:
+		ALOGE("Unsupported EGL image format %d", halFormat); ASSERT(false);
+		return GL_NONE;
 	}
 }
 
@@ -240,14 +242,16 @@
 	case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: return GL_UNSIGNED_BYTE;
 #endif
 	case HAL_PIXEL_FORMAT_RGBX_8888: return GL_UNSIGNED_BYTE;
-	case HAL_PIXEL_FORMAT_RGB_888:   return GL_NONE;   // Unsupported
 	case HAL_PIXEL_FORMAT_BGRA_8888: return GL_UNSIGNED_BYTE;
 	case HAL_PIXEL_FORMAT_RGB_565:   return GL_UNSIGNED_SHORT_5_6_5;
 	case HAL_PIXEL_FORMAT_YV12:      return GL_UNSIGNED_BYTE;
 #ifdef GRALLOC_MODULE_API_VERSION_0_2
 	case HAL_PIXEL_FORMAT_YCbCr_420_888: return GL_UNSIGNED_BYTE;
 #endif
-	default:                         return GL_NONE;
+	case HAL_PIXEL_FORMAT_RGB_888:   // Unsupported.
+	default:
+		ALOGE("Unsupported EGL image format %d", halFormat); ASSERT(false);
+		return GL_NONE;
 	}
 }
 
diff --git a/src/OpenGL/compiler/Android.mk b/src/OpenGL/compiler/Android.mk
index 5bca1fe..da35aa0 100644
--- a/src/OpenGL/compiler/Android.mk
+++ b/src/OpenGL/compiler/Android.mk
@@ -69,7 +69,6 @@
 	SymbolTable.cpp \
 	TranslatorASM.cpp \
 	util.cpp \
-	ValidateGlobalInitializer.cpp \
 	ValidateLimitations.cpp \
 	ValidateSwitch.cpp \
 
diff --git a/src/OpenGL/compiler/BUILD.gn b/src/OpenGL/compiler/BUILD.gn
index 3341e1e..3759f1c 100644
--- a/src/OpenGL/compiler/BUILD.gn
+++ b/src/OpenGL/compiler/BUILD.gn
@@ -57,7 +57,6 @@
     "PoolAlloc.cpp",
     "SymbolTable.cpp",
     "TranslatorASM.cpp",
-    "ValidateGlobalInitializer.cpp",
     "ValidateLimitations.cpp",
     "ValidateSwitch.cpp",
     "debug.cpp",
diff --git a/src/OpenGL/compiler/Compiler.vcxproj b/src/OpenGL/compiler/Compiler.vcxproj
index 58a0e5a..c4f56bf 100644
--- a/src/OpenGL/compiler/Compiler.vcxproj
+++ b/src/OpenGL/compiler/Compiler.vcxproj
@@ -229,7 +229,6 @@
     <ClCompile Include="SymbolTable.cpp" />

     <ClCompile Include="TranslatorASM.cpp" />

     <ClCompile Include="util.cpp" />

-    <ClCompile Include="ValidateGlobalInitializer.cpp" />

     <ClCompile Include="ValidateLimitations.cpp" />

     <ClCompile Include="glslang_lex.cpp" />

     <ClCompile Include="glslang_tab.cpp" />

@@ -334,7 +333,6 @@
     <ClInclude Include="TranslatorASM.h" />

     <ClInclude Include="Types.h" />

     <ClInclude Include="util.h" />

-    <ClInclude Include="ValidateGlobalInitializer.h" />

     <ClInclude Include="ValidateLimitations.h" />

     <ClInclude Include="glslang_tab.h" />

     <ClInclude Include="ValidateSwitch.h" />

diff --git a/src/OpenGL/compiler/Compiler.vcxproj.filters b/src/OpenGL/compiler/Compiler.vcxproj.filters
index a4435bc..91d0749 100644
--- a/src/OpenGL/compiler/Compiler.vcxproj.filters
+++ b/src/OpenGL/compiler/Compiler.vcxproj.filters
@@ -86,9 +86,6 @@
     <ClCompile Include="ValidateSwitch.cpp">

       <Filter>Source Files</Filter>

     </ClCompile>

-    <ClCompile Include="ValidateGlobalInitializer.cpp">

-      <Filter>Source Files</Filter>

-    </ClCompile>

   </ItemGroup>

   <ItemGroup>

     <ClInclude Include="BaseTypes.h">

@@ -178,9 +175,6 @@
     <ClInclude Include="ValidateSwitch.h">

       <Filter>Header Files</Filter>

     </ClInclude>

-    <ClInclude Include="ValidateGlobalInitializer.h">

-      <Filter>Header Files</Filter>

-    </ClInclude>

   </ItemGroup>

   <ItemGroup>

     <CustomBuild Include="glslang.l">

diff --git a/src/OpenGL/compiler/ParseHelper.cpp b/src/OpenGL/compiler/ParseHelper.cpp
index 7cca42c..3fea084 100644
--- a/src/OpenGL/compiler/ParseHelper.cpp
+++ b/src/OpenGL/compiler/ParseHelper.cpp
@@ -19,7 +19,6 @@
 
 #include "glslang.h"
 #include "preprocessor/SourceLocation.h"
-#include "ValidateGlobalInitializer.h"
 #include "ValidateSwitch.h"
 
 ///////////////////////////////////////////////////////////////////////
@@ -1300,19 +1299,11 @@
 		return true;
 	}
 
-	bool globalInitWarning = false;
-	if(symbolTable.atGlobalLevel() && !ValidateGlobalInitializer(initializer, this, &globalInitWarning))
+	if(symbolTable.atGlobalLevel() && initializer->getQualifier() != EvqConstExpr)
 	{
-		// Error message does not completely match behavior with ESSL 1.00, but
-		// we want to steer developers towards only using constant expressions.
 		error(line, "global variable initializers must be constant expressions", "=");
 		return true;
 	}
-	if(globalInitWarning)
-	{
-		warning(line, "global variable initializers should be constant expressions "
-			"(uniforms and globals are allowed in global initializers for legacy compatibility)", "=");
-	}
 
 	//
 	// identifier must be of type constant, a global, or a temporary
diff --git a/src/OpenGL/compiler/ValidateGlobalInitializer.cpp b/src/OpenGL/compiler/ValidateGlobalInitializer.cpp
deleted file mode 100644
index 6c5fa86..0000000
--- a/src/OpenGL/compiler/ValidateGlobalInitializer.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "ValidateGlobalInitializer.h"
-
-#include "ParseHelper.h"
-
-namespace
-{
-
-class ValidateGlobalInitializerTraverser : public TIntermTraverser
-{
-public:
-	ValidateGlobalInitializerTraverser(const TParseContext *context);
-
-	void visitSymbol(TIntermSymbol *node) override;
-
-	bool isValid() const { return mIsValid; }
-	bool issueWarning() const { return mIssueWarning; }
-
-private:
-	const TParseContext *mContext;
-	bool mIsValid;
-	bool mIssueWarning;
-};
-
-void ValidateGlobalInitializerTraverser::visitSymbol(TIntermSymbol *node)
-{
-	const TSymbol *sym = mContext->symbolTable.find(node->getSymbol(), mContext->getShaderVersion());
-	if (sym->isVariable())
-	{
-		// ESSL 1.00 section 4.3 (or ESSL 3.00 section 4.3):
-		// Global initializers must be constant expressions.
-		const TVariable *var = static_cast<const TVariable *>(sym);
-		switch (var->getType().getQualifier())
-		{
-		case EvqConstExpr:
-			break;
-		case EvqGlobal:
-		case EvqTemporary:
-		case EvqUniform:
-			// We allow these cases to be compatible with legacy ESSL 1.00 content.
-			// Implement stricter rules for ESSL 3.00 since there's no legacy content to deal with.
-			if (mContext->getShaderVersion() >= 300)
-			{
-				mIsValid = false;
-			}
-			else
-			{
-				mIssueWarning = true;
-			}
-			break;
-		default:
-			mIsValid = false;
-		}
-	}
-}
-
-ValidateGlobalInitializerTraverser::ValidateGlobalInitializerTraverser(const TParseContext *context)
-	: TIntermTraverser(true, false, false),
-	  mContext(context),
-	  mIsValid(true),
-	  mIssueWarning(false)
-{
-}
-
-} // namespace
-
-bool ValidateGlobalInitializer(TIntermTyped *initializer, const TParseContext *context, bool *warning)
-{
-	ValidateGlobalInitializerTraverser validate(context);
-	initializer->traverse(&validate);
-	ASSERT(warning != nullptr);
-	*warning = validate.issueWarning();
-	return validate.isValid();
-}
-
diff --git a/src/OpenGL/compiler/ValidateGlobalInitializer.h b/src/OpenGL/compiler/ValidateGlobalInitializer.h
deleted file mode 100644
index 28c1293..0000000
--- a/src/OpenGL/compiler/ValidateGlobalInitializer.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_
-#define COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_
-
-class TIntermTyped;
-class TParseContext;
-
-// Returns true if the initializer is valid.
-bool ValidateGlobalInitializer(TIntermTyped *initializer, const TParseContext *context, bool *warning);
-
-#endif // COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_
diff --git a/src/OpenGL/libEGL/Android.mk b/src/OpenGL/libEGL/Android.mk
index 9317879..9fae01d 100644
--- a/src/OpenGL/libEGL/Android.mk
+++ b/src/OpenGL/libEGL/Android.mk
@@ -39,6 +39,11 @@
 	libcutils \
 	libhardware
 
+# libnativewindow is introduced from O
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26 && echo O),O)
+COMMON_SHARED_LIBRARIES += libnativewindow
+endif
+
 # gralloc1 is introduced from N MR1
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 25 && echo NMR1),NMR1)
 COMMON_CFLAGS += -DHAVE_GRALLOC1
diff --git a/src/OpenGL/libEGL/BUILD.gn b/src/OpenGL/libEGL/BUILD.gn
index 543c9cc..68a10bc 100644
--- a/src/OpenGL/libEGL/BUILD.gn
+++ b/src/OpenGL/libEGL/BUILD.gn
@@ -58,6 +58,10 @@
     "resource.h",
   ]
 
+  if (is_debug) {
+    sources += [ "../common/debug.cpp" ]
+  }
+
   if (is_mac) {
     sources += [ "OSXUtils.mm" ]
     libs = [
diff --git a/src/OpenGL/libGLES_CM/Android.mk b/src/OpenGL/libGLES_CM/Android.mk
index 8576661..38dbaf3 100644
--- a/src/OpenGL/libGLES_CM/Android.mk
+++ b/src/OpenGL/libGLES_CM/Android.mk
@@ -61,6 +61,11 @@
 	libcutils \
 	libhardware
 
+# libnativewindow is introduced from O
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26 && echo O),O)
+COMMON_SHARED_LIBRARIES += libnativewindow
+endif
+
 # gralloc1 is introduced from N MR1
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 25 && echo NMR1),NMR1)
 COMMON_CFLAGS += -DHAVE_GRALLOC1
diff --git a/src/OpenGL/libGLES_CM/Texture.cpp b/src/OpenGL/libGLES_CM/Texture.cpp
index 58b80d0..80a3886 100644
--- a/src/OpenGL/libGLES_CM/Texture.cpp
+++ b/src/OpenGL/libGLES_CM/Texture.cpp
@@ -476,19 +476,12 @@
 
 void Texture2D::bindTexImage(gl::Surface *surface)
 {
-	GLenum format;
-
 	switch(surface->getInternalFormat())
 	{
 	case sw::FORMAT_A8R8G8B8:
-		format = GL_BGRA_EXT;
-		break;
 	case sw::FORMAT_A8B8G8R8:
-		format = GL_RGBA;
-		break;
 	case sw::FORMAT_X8B8G8R8:
 	case sw::FORMAT_X8R8G8B8:
-		format = GL_RGB;
 		break;
 	default:
 		UNIMPLEMENTED();
diff --git a/src/OpenGL/libGLESv2/Android.mk b/src/OpenGL/libGLESv2/Android.mk
index 4ae7952..4e7d931 100644
--- a/src/OpenGL/libGLESv2/Android.mk
+++ b/src/OpenGL/libGLESv2/Android.mk
@@ -68,6 +68,11 @@
 	libcutils \
 	libhardware
 
+# libnativewindow is introduced from O
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26 && echo O),O)
+COMMON_SHARED_LIBRARIES += libnativewindow
+endif
+
 # gralloc1 is introduced from N MR1
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 25 && echo NMR1),NMR1)
 COMMON_CFLAGS += -DHAVE_GRALLOC1
diff --git a/src/OpenGL/libGLESv2/Device.cpp b/src/OpenGL/libGLESv2/Device.cpp
index 53c794c..a4ba15a 100644
--- a/src/OpenGL/libGLESv2/Device.cpp
+++ b/src/OpenGL/libGLESv2/Device.cpp
@@ -338,7 +338,7 @@
 		draw(type, 0, primitiveCount);
 	}
 
-	void Device::setPixelShader(PixelShader *pixelShader)
+	void Device::setPixelShader(const PixelShader *pixelShader)
 	{
 		this->pixelShader = pixelShader;
 		pixelShaderDirty = true;
@@ -429,7 +429,7 @@
 		scissorRect = rect;
 	}
 
-	void Device::setVertexShader(VertexShader *vertexShader)
+	void Device::setVertexShader(const VertexShader *vertexShader)
 	{
 		this->vertexShader = vertexShader;
 		vertexShaderDirty = true;
diff --git a/src/OpenGL/libGLESv2/Device.hpp b/src/OpenGL/libGLESv2/Device.hpp
index 13a10de..17c7925 100644
--- a/src/OpenGL/libGLESv2/Device.hpp
+++ b/src/OpenGL/libGLESv2/Device.hpp
@@ -62,14 +62,14 @@
 		egl::Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);
 		void drawIndexedPrimitive(sw::DrawType type, unsigned int indexOffset, unsigned int primitiveCount);
 		void drawPrimitive(sw::DrawType type, unsigned int primiveCount);
-		void setPixelShader(sw::PixelShader *shader);
+		void setPixelShader(const sw::PixelShader *shader);
 		void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
 		void setScissorEnable(bool enable);
 		void setRenderTarget(int index, egl::Image *renderTarget);
 		void setDepthBuffer(egl::Image *depthBuffer);
 		void setStencilBuffer(egl::Image *stencilBuffer);
 		void setScissorRect(const sw::Rect &rect);
-		void setVertexShader(sw::VertexShader *shader);
+		void setVertexShader(const sw::VertexShader *shader);
 		void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
 		void setViewport(const Viewport &viewport);
 
@@ -92,8 +92,8 @@
 		sw::Rect scissorRect;
 		bool scissorEnable;
 
-		sw::PixelShader *pixelShader;
-		sw::VertexShader *vertexShader;
+		const sw::PixelShader *pixelShader;
+		const sw::VertexShader *vertexShader;
 
 		bool pixelShaderDirty;
 		unsigned int pixelShaderConstantsFDirty;
diff --git a/src/OpenGL/libGLESv2/Texture.cpp b/src/OpenGL/libGLESv2/Texture.cpp
index f20b030..b0a46a5 100644
--- a/src/OpenGL/libGLESv2/Texture.cpp
+++ b/src/OpenGL/libGLESv2/Texture.cpp
@@ -652,21 +652,12 @@
 
 void Texture2D::bindTexImage(gl::Surface *surface)
 {
-	GLenum format;
-
 	switch(surface->getInternalFormat())
 	{
 	case sw::FORMAT_A8R8G8B8:
-	case sw::FORMAT_SRGB8_A8:
-		format = GL_BGRA_EXT;
-		break;
 	case sw::FORMAT_A8B8G8R8:
-		format = GL_RGBA;
-		break;
 	case sw::FORMAT_X8B8G8R8:
 	case sw::FORMAT_X8R8G8B8:
-	case sw::FORMAT_SRGB8_X8:
-		format = GL_RGB;
 		break;
 	default:
 		UNIMPLEMENTED();
diff --git a/src/Reactor/BUILD.gn b/src/Reactor/BUILD.gn
index 4bc15c5..aac9de5 100644
--- a/src/Reactor/BUILD.gn
+++ b/src/Reactor/BUILD.gn
@@ -17,7 +17,7 @@
 declare_args() {
   # Currently, Subzero is not used by default
   # LLVM is still the default backend
-  use_swiftshader_with_subzero = is_win || is_linux
+  use_swiftshader_with_subzero = is_win || is_linux || is_chromeos
 }
 
 # Need a separate config to ensure the warnings are added to the end.
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index c66e5a5..b299f6d 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "Nucleus.hpp"
+#include "Reactor.hpp"
 
 #include "llvm/Support/IRBuilder.h"
 #include "llvm/Function.h"
@@ -4438,7 +4438,11 @@
 		return T(Type_v2i32);
 	}
 
-	Int4::Int4(RValue<Byte4> cast)
+	Int4::Int4() : XYZW(this)
+	{
+	}
+
+	Int4::Int4(RValue<Byte4> cast) : XYZW(this)
 	{
 		if(CPUID::supportsSSE4_1())
 		{
@@ -4458,7 +4462,7 @@
 		}
 	}
 
-	Int4::Int4(RValue<SByte4> cast)
+	Int4::Int4(RValue<SByte4> cast) : XYZW(this)
 	{
 		if(CPUID::supportsSSE4_1())
 		{
@@ -4478,14 +4482,14 @@
 		}
 	}
 
-	Int4::Int4(RValue<Float4> cast)
+	Int4::Int4(RValue<Float4> cast) : XYZW(this)
 	{
 		Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
 
 		storeValue(xyzw);
 	}
 
-	Int4::Int4(RValue<Short4> cast)
+	Int4::Int4(RValue<Short4> cast) : XYZW(this)
 	{
 		if(CPUID::supportsSSE4_1())
 		{
@@ -4499,7 +4503,7 @@
 		}
 	}
 
-	Int4::Int4(RValue<UShort4> cast)
+	Int4::Int4(RValue<UShort4> cast) : XYZW(this)
 	{
 		if(CPUID::supportsSSE4_1())
 		{
@@ -4513,22 +4517,22 @@
 		}
 	}
 
-	Int4::Int4(int xyzw)
+	Int4::Int4(int xyzw) : XYZW(this)
 	{
 		constant(xyzw, xyzw, xyzw, xyzw);
 	}
 
-	Int4::Int4(int x, int yzw)
+	Int4::Int4(int x, int yzw) : XYZW(this)
 	{
 		constant(x, yzw, yzw, yzw);
 	}
 
-	Int4::Int4(int x, int y, int zw)
+	Int4::Int4(int x, int y, int zw) : XYZW(this)
 	{
 		constant(x, y, zw, zw);
 	}
 
-	Int4::Int4(int x, int y, int z, int w)
+	Int4::Int4(int x, int y, int z, int w) : XYZW(this)
 	{
 		constant(x, y, z, w);
 	}
@@ -4539,41 +4543,41 @@
 		storeValue(Nucleus::createConstantVector(constantVector, getType()));
 	}
 
-	Int4::Int4(RValue<Int4> rhs)
+	Int4::Int4(RValue<Int4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	Int4::Int4(const Int4 &rhs)
+	Int4::Int4(const Int4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Int4::Int4(const Reference<Int4> &rhs)
+	Int4::Int4(const Reference<Int4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Int4::Int4(RValue<UInt4> rhs)
+	Int4::Int4(RValue<UInt4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	Int4::Int4(const UInt4 &rhs)
+	Int4::Int4(const UInt4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Int4::Int4(const Reference<UInt4> &rhs)
+	Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
+	Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this)
 	{
 		int shuffle[4] = {0, 1, 4, 5};   // Real type is v4i32
 		Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
@@ -4581,7 +4585,7 @@
 		storeValue(packed);
 	}
 
-	Int4::Int4(RValue<Int> rhs)
+	Int4::Int4(RValue<Int> rhs) : XYZW(this)
 	{
 		Value *vector = loadValue();
 		Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
@@ -4592,12 +4596,12 @@
 		storeValue(replicate);
 	}
 
-	Int4::Int4(const Int &rhs)
+	Int4::Int4(const Int &rhs) : XYZW(this)
 	{
 		*this = RValue<Int>(rhs.loadValue());
 	}
 
-	Int4::Int4(const Reference<Int> &rhs)
+	Int4::Int4(const Reference<Int> &rhs) : XYZW(this)
 	{
 		*this = RValue<Int>(rhs.loadValue());
 	}
@@ -4850,7 +4854,11 @@
 		return T(llvm::VectorType::get(T(Int::getType()), 4));
 	}
 
-	UInt4::UInt4(RValue<Float4> cast)
+	UInt4::UInt4() : XYZW(this)
+	{
+	}
+
+	UInt4::UInt4(RValue<Float4> cast) : XYZW(this)
 	{
 		// Note: createFPToUI is broken, must perform conversion using createFPtoSI
 		// Value *xyzw = Nucleus::createFPToUI(cast.value, UInt4::getType());
@@ -4869,22 +4877,22 @@
 		storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
 	}
 
-	UInt4::UInt4(int xyzw)
+	UInt4::UInt4(int xyzw) : XYZW(this)
 	{
 		constant(xyzw, xyzw, xyzw, xyzw);
 	}
 
-	UInt4::UInt4(int x, int yzw)
+	UInt4::UInt4(int x, int yzw) : XYZW(this)
 	{
 		constant(x, yzw, yzw, yzw);
 	}
 
-	UInt4::UInt4(int x, int y, int zw)
+	UInt4::UInt4(int x, int y, int zw) : XYZW(this)
 	{
 		constant(x, y, zw, zw);
 	}
 
-	UInt4::UInt4(int x, int y, int z, int w)
+	UInt4::UInt4(int x, int y, int z, int w) : XYZW(this)
 	{
 		constant(x, y, z, w);
 	}
@@ -4895,41 +4903,41 @@
 		storeValue(Nucleus::createConstantVector(constantVector, getType()));
 	}
 
-	UInt4::UInt4(RValue<UInt4> rhs)
+	UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	UInt4::UInt4(const UInt4 &rhs)
+	UInt4::UInt4(const UInt4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	UInt4::UInt4(const Reference<UInt4> &rhs)
+	UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	UInt4::UInt4(RValue<Int4> rhs)
+	UInt4::UInt4(RValue<Int4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	UInt4::UInt4(const Int4 &rhs)
+	UInt4::UInt4(const Int4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	UInt4::UInt4(const Reference<Int4> &rhs)
+	UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
+	UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this)
 	{
 		int shuffle[4] = {0, 1, 4, 5};   // Real type is v4i32
 		Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
@@ -5414,7 +5422,7 @@
 		return T(Type_v2f32);
 	}
 
-	Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<Byte4> cast) : XYZW(this)
 	{
 		Value *a = Int4(cast).loadValue();
 		Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
@@ -5422,7 +5430,7 @@
 		storeValue(xyzw);
 	}
 
-	Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<SByte4> cast) : XYZW(this)
 	{
 		Value *a = Int4(cast).loadValue();
 		Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
@@ -5430,26 +5438,26 @@
 		storeValue(xyzw);
 	}
 
-	Float4::Float4(RValue<Short4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<Short4> cast) : XYZW(this)
 	{
 		Int4 c(cast);
 		storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
 	}
 
-	Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<UShort4> cast) : XYZW(this)
 	{
 		Int4 c(cast);
 		storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
 	}
 
-	Float4::Float4(RValue<Int4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<Int4> cast) : XYZW(this)
 	{
 		Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
 
 		storeValue(xyzw);
 	}
 
-	Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<UInt4> cast) : XYZW(this)
 	{
 		RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
 		                        As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
@@ -5457,26 +5465,26 @@
 		storeValue(result.value);
 	}
 
-	Float4::Float4() : FloatXYZW(this)
+	Float4::Float4() : XYZW(this)
 	{
 	}
 
-	Float4::Float4(float xyzw) : FloatXYZW(this)
+	Float4::Float4(float xyzw) : XYZW(this)
 	{
 		constant(xyzw, xyzw, xyzw, xyzw);
 	}
 
-	Float4::Float4(float x, float yzw) : FloatXYZW(this)
+	Float4::Float4(float x, float yzw) : XYZW(this)
 	{
 		constant(x, yzw, yzw, yzw);
 	}
 
-	Float4::Float4(float x, float y, float zw) : FloatXYZW(this)
+	Float4::Float4(float x, float y, float zw) : XYZW(this)
 	{
 		constant(x, y, zw, zw);
 	}
 
-	Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this)
+	Float4::Float4(float x, float y, float z, float w) : XYZW(this)
 	{
 		constant(x, y, z, w);
 	}
@@ -5487,24 +5495,24 @@
 		storeValue(Nucleus::createConstantVector(constantVector, getType()));
 	}
 
-	Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this)
+	Float4::Float4(RValue<Float4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	Float4::Float4(const Float4 &rhs) : FloatXYZW(this)
+	Float4::Float4(const Float4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this)
+	Float4::Float4(const Reference<Float4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Float4::Float4(RValue<Float> rhs) : FloatXYZW(this)
+	Float4::Float4(RValue<Float> rhs) : XYZW(this)
 	{
 		Value *vector = loadValue();
 		Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
@@ -5515,12 +5523,12 @@
 		storeValue(replicate);
 	}
 
-	Float4::Float4(const Float &rhs) : FloatXYZW(this)
+	Float4::Float4(const Float &rhs) : XYZW(this)
 	{
 		*this = RValue<Float>(rhs.loadValue());
 	}
 
-	Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this)
+	Float4::Float4(const Reference<Float> &rhs) : XYZW(this)
 	{
 		*this = RValue<Float>(rhs.loadValue());
 	}
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index 46973da..3f9fb3d 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -1304,7 +1304,454 @@
 
 //	RValue<UInt2> RoundInt(RValue<Float4> cast);
 
-	class Int4 : public LValue<Int4>
+	template<class T>
+	struct Scalar;
+
+	template<class Vector4>
+	struct XYZW;
+
+	template<class Vector4, int T>
+	class Swizzle2
+	{
+		friend Vector4;
+
+	public:
+		operator RValue<Vector4>() const;
+
+	private:
+		Vector4 *parent;
+	};
+
+	template<class Vector4, int T>
+	class Swizzle4
+	{
+	public:
+		operator RValue<Vector4>() const;
+
+	private:
+		Vector4 *parent;
+	};
+
+	template<class Vector4, int T>
+	class SwizzleMask4
+	{
+		friend XYZW<Vector4>;
+
+	public:
+		operator RValue<Vector4>() const;
+
+		RValue<Vector4> operator=(RValue<Vector4> rhs);
+		RValue<Vector4> operator=(RValue<typename Scalar<Vector4>::Type> rhs);
+
+	private:
+		Vector4 *parent;
+	};
+
+	template<>
+	struct Scalar<Float4>
+	{
+		using Type = Float;
+	};
+
+	template<>
+	struct Scalar<Int4>
+	{
+		using Type = Int;
+	};
+
+	template<>
+	struct Scalar<UInt4>
+	{
+		using Type = UInt;
+	};
+
+	template<class Vector4, int T>
+	class SwizzleMask1
+	{
+	public:
+		operator RValue<typename Scalar<Vector4>::Type>() const;
+		operator RValue<Vector4>() const;
+
+		RValue<Vector4> operator=(float x);
+		RValue<Vector4> operator=(RValue<Vector4> rhs);
+		RValue<Vector4> operator=(RValue<typename Scalar<Vector4>::Type> rhs);
+
+	private:
+		Float4 *parent;
+	};
+
+	template<class Vector4, int T>
+	class SwizzleMask2
+	{
+		friend class Float4;
+
+	public:
+		operator RValue<Vector4>() const;
+
+		RValue<Vector4> operator=(RValue<Vector4> rhs);
+
+	private:
+		Float4 *parent;
+	};
+
+	template<class Vector4>
+	struct XYZW
+	{
+		friend Vector4;
+
+	private:
+		XYZW(Vector4 *parent)
+		{
+			xyzw.parent = parent;
+		}
+
+	public:
+		union
+		{
+			SwizzleMask1<Vector4, 0x00> x;
+			SwizzleMask1<Vector4, 0x55> y;
+			SwizzleMask1<Vector4, 0xAA> z;
+			SwizzleMask1<Vector4, 0xFF> w;
+			Swizzle2<Vector4, 0x00>     xx;
+			Swizzle2<Vector4, 0x01>     yx;
+			Swizzle2<Vector4, 0x02>     zx;
+			Swizzle2<Vector4, 0x03>     wx;
+			SwizzleMask2<Vector4, 0x54> xy;
+			Swizzle2<Vector4, 0x55>     yy;
+			Swizzle2<Vector4, 0x56>     zy;
+			Swizzle2<Vector4, 0x57>     wy;
+			SwizzleMask2<Vector4, 0xA8> xz;
+			SwizzleMask2<Vector4, 0xA9> yz;
+			Swizzle2<Vector4, 0xAA>     zz;
+			Swizzle2<Vector4, 0xAB>     wz;
+			SwizzleMask2<Vector4, 0xFC> xw;
+			SwizzleMask2<Vector4, 0xFD> yw;
+			SwizzleMask2<Vector4, 0xFE> zw;
+			Swizzle2<Vector4, 0xFF>     ww;
+			Swizzle4<Vector4, 0x00>     xxx;
+			Swizzle4<Vector4, 0x01>     yxx;
+			Swizzle4<Vector4, 0x02>     zxx;
+			Swizzle4<Vector4, 0x03>     wxx;
+			Swizzle4<Vector4, 0x04>     xyx;
+			Swizzle4<Vector4, 0x05>     yyx;
+			Swizzle4<Vector4, 0x06>     zyx;
+			Swizzle4<Vector4, 0x07>     wyx;
+			Swizzle4<Vector4, 0x08>     xzx;
+			Swizzle4<Vector4, 0x09>     yzx;
+			Swizzle4<Vector4, 0x0A>     zzx;
+			Swizzle4<Vector4, 0x0B>     wzx;
+			Swizzle4<Vector4, 0x0C>     xwx;
+			Swizzle4<Vector4, 0x0D>     ywx;
+			Swizzle4<Vector4, 0x0E>     zwx;
+			Swizzle4<Vector4, 0x0F>     wwx;
+			Swizzle4<Vector4, 0x50>     xxy;
+			Swizzle4<Vector4, 0x51>     yxy;
+			Swizzle4<Vector4, 0x52>     zxy;
+			Swizzle4<Vector4, 0x53>     wxy;
+			Swizzle4<Vector4, 0x54>     xyy;
+			Swizzle4<Vector4, 0x55>     yyy;
+			Swizzle4<Vector4, 0x56>     zyy;
+			Swizzle4<Vector4, 0x57>     wyy;
+			Swizzle4<Vector4, 0x58>     xzy;
+			Swizzle4<Vector4, 0x59>     yzy;
+			Swizzle4<Vector4, 0x5A>     zzy;
+			Swizzle4<Vector4, 0x5B>     wzy;
+			Swizzle4<Vector4, 0x5C>     xwy;
+			Swizzle4<Vector4, 0x5D>     ywy;
+			Swizzle4<Vector4, 0x5E>     zwy;
+			Swizzle4<Vector4, 0x5F>     wwy;
+			Swizzle4<Vector4, 0xA0>     xxz;
+			Swizzle4<Vector4, 0xA1>     yxz;
+			Swizzle4<Vector4, 0xA2>     zxz;
+			Swizzle4<Vector4, 0xA3>     wxz;
+			SwizzleMask4<Vector4, 0xA4> xyz;
+			Swizzle4<Vector4, 0xA5>     yyz;
+			Swizzle4<Vector4, 0xA6>     zyz;
+			Swizzle4<Vector4, 0xA7>     wyz;
+			Swizzle4<Vector4, 0xA8>     xzz;
+			Swizzle4<Vector4, 0xA9>     yzz;
+			Swizzle4<Vector4, 0xAA>     zzz;
+			Swizzle4<Vector4, 0xAB>     wzz;
+			Swizzle4<Vector4, 0xAC>     xwz;
+			Swizzle4<Vector4, 0xAD>     ywz;
+			Swizzle4<Vector4, 0xAE>     zwz;
+			Swizzle4<Vector4, 0xAF>     wwz;
+			Swizzle4<Vector4, 0xF0>     xxw;
+			Swizzle4<Vector4, 0xF1>     yxw;
+			Swizzle4<Vector4, 0xF2>     zxw;
+			Swizzle4<Vector4, 0xF3>     wxw;
+			SwizzleMask4<Vector4, 0xF4> xyw;
+			Swizzle4<Vector4, 0xF5>     yyw;
+			Swizzle4<Vector4, 0xF6>     zyw;
+			Swizzle4<Vector4, 0xF7>     wyw;
+			SwizzleMask4<Vector4, 0xF8> xzw;
+			SwizzleMask4<Vector4, 0xF9> yzw;
+			Swizzle4<Vector4, 0xFA>     zzw;
+			Swizzle4<Vector4, 0xFB>     wzw;
+			Swizzle4<Vector4, 0xFC>     xww;
+			Swizzle4<Vector4, 0xFD>     yww;
+			Swizzle4<Vector4, 0xFE>     zww;
+			Swizzle4<Vector4, 0xFF>     www;
+			Swizzle4<Vector4, 0x00>     xxxx;
+			Swizzle4<Vector4, 0x01>     yxxx;
+			Swizzle4<Vector4, 0x02>     zxxx;
+			Swizzle4<Vector4, 0x03>     wxxx;
+			Swizzle4<Vector4, 0x04>     xyxx;
+			Swizzle4<Vector4, 0x05>     yyxx;
+			Swizzle4<Vector4, 0x06>     zyxx;
+			Swizzle4<Vector4, 0x07>     wyxx;
+			Swizzle4<Vector4, 0x08>     xzxx;
+			Swizzle4<Vector4, 0x09>     yzxx;
+			Swizzle4<Vector4, 0x0A>     zzxx;
+			Swizzle4<Vector4, 0x0B>     wzxx;
+			Swizzle4<Vector4, 0x0C>     xwxx;
+			Swizzle4<Vector4, 0x0D>     ywxx;
+			Swizzle4<Vector4, 0x0E>     zwxx;
+			Swizzle4<Vector4, 0x0F>     wwxx;
+			Swizzle4<Vector4, 0x10>     xxyx;
+			Swizzle4<Vector4, 0x11>     yxyx;
+			Swizzle4<Vector4, 0x12>     zxyx;
+			Swizzle4<Vector4, 0x13>     wxyx;
+			Swizzle4<Vector4, 0x14>     xyyx;
+			Swizzle4<Vector4, 0x15>     yyyx;
+			Swizzle4<Vector4, 0x16>     zyyx;
+			Swizzle4<Vector4, 0x17>     wyyx;
+			Swizzle4<Vector4, 0x18>     xzyx;
+			Swizzle4<Vector4, 0x19>     yzyx;
+			Swizzle4<Vector4, 0x1A>     zzyx;
+			Swizzle4<Vector4, 0x1B>     wzyx;
+			Swizzle4<Vector4, 0x1C>     xwyx;
+			Swizzle4<Vector4, 0x1D>     ywyx;
+			Swizzle4<Vector4, 0x1E>     zwyx;
+			Swizzle4<Vector4, 0x1F>     wwyx;
+			Swizzle4<Vector4, 0x20>     xxzx;
+			Swizzle4<Vector4, 0x21>     yxzx;
+			Swizzle4<Vector4, 0x22>     zxzx;
+			Swizzle4<Vector4, 0x23>     wxzx;
+			Swizzle4<Vector4, 0x24>     xyzx;
+			Swizzle4<Vector4, 0x25>     yyzx;
+			Swizzle4<Vector4, 0x26>     zyzx;
+			Swizzle4<Vector4, 0x27>     wyzx;
+			Swizzle4<Vector4, 0x28>     xzzx;
+			Swizzle4<Vector4, 0x29>     yzzx;
+			Swizzle4<Vector4, 0x2A>     zzzx;
+			Swizzle4<Vector4, 0x2B>     wzzx;
+			Swizzle4<Vector4, 0x2C>     xwzx;
+			Swizzle4<Vector4, 0x2D>     ywzx;
+			Swizzle4<Vector4, 0x2E>     zwzx;
+			Swizzle4<Vector4, 0x2F>     wwzx;
+			Swizzle4<Vector4, 0x30>     xxwx;
+			Swizzle4<Vector4, 0x31>     yxwx;
+			Swizzle4<Vector4, 0x32>     zxwx;
+			Swizzle4<Vector4, 0x33>     wxwx;
+			Swizzle4<Vector4, 0x34>     xywx;
+			Swizzle4<Vector4, 0x35>     yywx;
+			Swizzle4<Vector4, 0x36>     zywx;
+			Swizzle4<Vector4, 0x37>     wywx;
+			Swizzle4<Vector4, 0x38>     xzwx;
+			Swizzle4<Vector4, 0x39>     yzwx;
+			Swizzle4<Vector4, 0x3A>     zzwx;
+			Swizzle4<Vector4, 0x3B>     wzwx;
+			Swizzle4<Vector4, 0x3C>     xwwx;
+			Swizzle4<Vector4, 0x3D>     ywwx;
+			Swizzle4<Vector4, 0x3E>     zwwx;
+			Swizzle4<Vector4, 0x3F>     wwwx;
+			Swizzle4<Vector4, 0x40>     xxxy;
+			Swizzle4<Vector4, 0x41>     yxxy;
+			Swizzle4<Vector4, 0x42>     zxxy;
+			Swizzle4<Vector4, 0x43>     wxxy;
+			Swizzle4<Vector4, 0x44>     xyxy;
+			Swizzle4<Vector4, 0x45>     yyxy;
+			Swizzle4<Vector4, 0x46>     zyxy;
+			Swizzle4<Vector4, 0x47>     wyxy;
+			Swizzle4<Vector4, 0x48>     xzxy;
+			Swizzle4<Vector4, 0x49>     yzxy;
+			Swizzle4<Vector4, 0x4A>     zzxy;
+			Swizzle4<Vector4, 0x4B>     wzxy;
+			Swizzle4<Vector4, 0x4C>     xwxy;
+			Swizzle4<Vector4, 0x4D>     ywxy;
+			Swizzle4<Vector4, 0x4E>     zwxy;
+			Swizzle4<Vector4, 0x4F>     wwxy;
+			Swizzle4<Vector4, 0x50>     xxyy;
+			Swizzle4<Vector4, 0x51>     yxyy;
+			Swizzle4<Vector4, 0x52>     zxyy;
+			Swizzle4<Vector4, 0x53>     wxyy;
+			Swizzle4<Vector4, 0x54>     xyyy;
+			Swizzle4<Vector4, 0x55>     yyyy;
+			Swizzle4<Vector4, 0x56>     zyyy;
+			Swizzle4<Vector4, 0x57>     wyyy;
+			Swizzle4<Vector4, 0x58>     xzyy;
+			Swizzle4<Vector4, 0x59>     yzyy;
+			Swizzle4<Vector4, 0x5A>     zzyy;
+			Swizzle4<Vector4, 0x5B>     wzyy;
+			Swizzle4<Vector4, 0x5C>     xwyy;
+			Swizzle4<Vector4, 0x5D>     ywyy;
+			Swizzle4<Vector4, 0x5E>     zwyy;
+			Swizzle4<Vector4, 0x5F>     wwyy;
+			Swizzle4<Vector4, 0x60>     xxzy;
+			Swizzle4<Vector4, 0x61>     yxzy;
+			Swizzle4<Vector4, 0x62>     zxzy;
+			Swizzle4<Vector4, 0x63>     wxzy;
+			Swizzle4<Vector4, 0x64>     xyzy;
+			Swizzle4<Vector4, 0x65>     yyzy;
+			Swizzle4<Vector4, 0x66>     zyzy;
+			Swizzle4<Vector4, 0x67>     wyzy;
+			Swizzle4<Vector4, 0x68>     xzzy;
+			Swizzle4<Vector4, 0x69>     yzzy;
+			Swizzle4<Vector4, 0x6A>     zzzy;
+			Swizzle4<Vector4, 0x6B>     wzzy;
+			Swizzle4<Vector4, 0x6C>     xwzy;
+			Swizzle4<Vector4, 0x6D>     ywzy;
+			Swizzle4<Vector4, 0x6E>     zwzy;
+			Swizzle4<Vector4, 0x6F>     wwzy;
+			Swizzle4<Vector4, 0x70>     xxwy;
+			Swizzle4<Vector4, 0x71>     yxwy;
+			Swizzle4<Vector4, 0x72>     zxwy;
+			Swizzle4<Vector4, 0x73>     wxwy;
+			Swizzle4<Vector4, 0x74>     xywy;
+			Swizzle4<Vector4, 0x75>     yywy;
+			Swizzle4<Vector4, 0x76>     zywy;
+			Swizzle4<Vector4, 0x77>     wywy;
+			Swizzle4<Vector4, 0x78>     xzwy;
+			Swizzle4<Vector4, 0x79>     yzwy;
+			Swizzle4<Vector4, 0x7A>     zzwy;
+			Swizzle4<Vector4, 0x7B>     wzwy;
+			Swizzle4<Vector4, 0x7C>     xwwy;
+			Swizzle4<Vector4, 0x7D>     ywwy;
+			Swizzle4<Vector4, 0x7E>     zwwy;
+			Swizzle4<Vector4, 0x7F>     wwwy;
+			Swizzle4<Vector4, 0x80>     xxxz;
+			Swizzle4<Vector4, 0x81>     yxxz;
+			Swizzle4<Vector4, 0x82>     zxxz;
+			Swizzle4<Vector4, 0x83>     wxxz;
+			Swizzle4<Vector4, 0x84>     xyxz;
+			Swizzle4<Vector4, 0x85>     yyxz;
+			Swizzle4<Vector4, 0x86>     zyxz;
+			Swizzle4<Vector4, 0x87>     wyxz;
+			Swizzle4<Vector4, 0x88>     xzxz;
+			Swizzle4<Vector4, 0x89>     yzxz;
+			Swizzle4<Vector4, 0x8A>     zzxz;
+			Swizzle4<Vector4, 0x8B>     wzxz;
+			Swizzle4<Vector4, 0x8C>     xwxz;
+			Swizzle4<Vector4, 0x8D>     ywxz;
+			Swizzle4<Vector4, 0x8E>     zwxz;
+			Swizzle4<Vector4, 0x8F>     wwxz;
+			Swizzle4<Vector4, 0x90>     xxyz;
+			Swizzle4<Vector4, 0x91>     yxyz;
+			Swizzle4<Vector4, 0x92>     zxyz;
+			Swizzle4<Vector4, 0x93>     wxyz;
+			Swizzle4<Vector4, 0x94>     xyyz;
+			Swizzle4<Vector4, 0x95>     yyyz;
+			Swizzle4<Vector4, 0x96>     zyyz;
+			Swizzle4<Vector4, 0x97>     wyyz;
+			Swizzle4<Vector4, 0x98>     xzyz;
+			Swizzle4<Vector4, 0x99>     yzyz;
+			Swizzle4<Vector4, 0x9A>     zzyz;
+			Swizzle4<Vector4, 0x9B>     wzyz;
+			Swizzle4<Vector4, 0x9C>     xwyz;
+			Swizzle4<Vector4, 0x9D>     ywyz;
+			Swizzle4<Vector4, 0x9E>     zwyz;
+			Swizzle4<Vector4, 0x9F>     wwyz;
+			Swizzle4<Vector4, 0xA0>     xxzz;
+			Swizzle4<Vector4, 0xA1>     yxzz;
+			Swizzle4<Vector4, 0xA2>     zxzz;
+			Swizzle4<Vector4, 0xA3>     wxzz;
+			Swizzle4<Vector4, 0xA4>     xyzz;
+			Swizzle4<Vector4, 0xA5>     yyzz;
+			Swizzle4<Vector4, 0xA6>     zyzz;
+			Swizzle4<Vector4, 0xA7>     wyzz;
+			Swizzle4<Vector4, 0xA8>     xzzz;
+			Swizzle4<Vector4, 0xA9>     yzzz;
+			Swizzle4<Vector4, 0xAA>     zzzz;
+			Swizzle4<Vector4, 0xAB>     wzzz;
+			Swizzle4<Vector4, 0xAC>     xwzz;
+			Swizzle4<Vector4, 0xAD>     ywzz;
+			Swizzle4<Vector4, 0xAE>     zwzz;
+			Swizzle4<Vector4, 0xAF>     wwzz;
+			Swizzle4<Vector4, 0xB0>     xxwz;
+			Swizzle4<Vector4, 0xB1>     yxwz;
+			Swizzle4<Vector4, 0xB2>     zxwz;
+			Swizzle4<Vector4, 0xB3>     wxwz;
+			Swizzle4<Vector4, 0xB4>     xywz;
+			Swizzle4<Vector4, 0xB5>     yywz;
+			Swizzle4<Vector4, 0xB6>     zywz;
+			Swizzle4<Vector4, 0xB7>     wywz;
+			Swizzle4<Vector4, 0xB8>     xzwz;
+			Swizzle4<Vector4, 0xB9>     yzwz;
+			Swizzle4<Vector4, 0xBA>     zzwz;
+			Swizzle4<Vector4, 0xBB>     wzwz;
+			Swizzle4<Vector4, 0xBC>     xwwz;
+			Swizzle4<Vector4, 0xBD>     ywwz;
+			Swizzle4<Vector4, 0xBE>     zwwz;
+			Swizzle4<Vector4, 0xBF>     wwwz;
+			Swizzle4<Vector4, 0xC0>     xxxw;
+			Swizzle4<Vector4, 0xC1>     yxxw;
+			Swizzle4<Vector4, 0xC2>     zxxw;
+			Swizzle4<Vector4, 0xC3>     wxxw;
+			Swizzle4<Vector4, 0xC4>     xyxw;
+			Swizzle4<Vector4, 0xC5>     yyxw;
+			Swizzle4<Vector4, 0xC6>     zyxw;
+			Swizzle4<Vector4, 0xC7>     wyxw;
+			Swizzle4<Vector4, 0xC8>     xzxw;
+			Swizzle4<Vector4, 0xC9>     yzxw;
+			Swizzle4<Vector4, 0xCA>     zzxw;
+			Swizzle4<Vector4, 0xCB>     wzxw;
+			Swizzle4<Vector4, 0xCC>     xwxw;
+			Swizzle4<Vector4, 0xCD>     ywxw;
+			Swizzle4<Vector4, 0xCE>     zwxw;
+			Swizzle4<Vector4, 0xCF>     wwxw;
+			Swizzle4<Vector4, 0xD0>     xxyw;
+			Swizzle4<Vector4, 0xD1>     yxyw;
+			Swizzle4<Vector4, 0xD2>     zxyw;
+			Swizzle4<Vector4, 0xD3>     wxyw;
+			Swizzle4<Vector4, 0xD4>     xyyw;
+			Swizzle4<Vector4, 0xD5>     yyyw;
+			Swizzle4<Vector4, 0xD6>     zyyw;
+			Swizzle4<Vector4, 0xD7>     wyyw;
+			Swizzle4<Vector4, 0xD8>     xzyw;
+			Swizzle4<Vector4, 0xD9>     yzyw;
+			Swizzle4<Vector4, 0xDA>     zzyw;
+			Swizzle4<Vector4, 0xDB>     wzyw;
+			Swizzle4<Vector4, 0xDC>     xwyw;
+			Swizzle4<Vector4, 0xDD>     ywyw;
+			Swizzle4<Vector4, 0xDE>     zwyw;
+			Swizzle4<Vector4, 0xDF>     wwyw;
+			Swizzle4<Vector4, 0xE0>     xxzw;
+			Swizzle4<Vector4, 0xE1>     yxzw;
+			Swizzle4<Vector4, 0xE2>     zxzw;
+			Swizzle4<Vector4, 0xE3>     wxzw;
+			SwizzleMask4<Vector4, 0xE4> xyzw;
+			Swizzle4<Vector4, 0xE5>     yyzw;
+			Swizzle4<Vector4, 0xE6>     zyzw;
+			Swizzle4<Vector4, 0xE7>     wyzw;
+			Swizzle4<Vector4, 0xE8>     xzzw;
+			Swizzle4<Vector4, 0xE9>     yzzw;
+			Swizzle4<Vector4, 0xEA>     zzzw;
+			Swizzle4<Vector4, 0xEB>     wzzw;
+			Swizzle4<Vector4, 0xEC>     xwzw;
+			Swizzle4<Vector4, 0xED>     ywzw;
+			Swizzle4<Vector4, 0xEE>     zwzw;
+			Swizzle4<Vector4, 0xEF>     wwzw;
+			Swizzle4<Vector4, 0xF0>     xxww;
+			Swizzle4<Vector4, 0xF1>     yxww;
+			Swizzle4<Vector4, 0xF2>     zxww;
+			Swizzle4<Vector4, 0xF3>     wxww;
+			Swizzle4<Vector4, 0xF4>     xyww;
+			Swizzle4<Vector4, 0xF5>     yyww;
+			Swizzle4<Vector4, 0xF6>     zyww;
+			Swizzle4<Vector4, 0xF7>     wyww;
+			Swizzle4<Vector4, 0xF8>     xzww;
+			Swizzle4<Vector4, 0xF9>     yzww;
+			Swizzle4<Vector4, 0xFA>     zzww;
+			Swizzle4<Vector4, 0xFB>     wzww;
+			Swizzle4<Vector4, 0xFC>     xwww;
+			Swizzle4<Vector4, 0xFD>     ywww;
+			Swizzle4<Vector4, 0xFE>     zwww;
+			Swizzle4<Vector4, 0xFF>     wwww;
+		};
+	};
+
+	class Int4 : public LValue<Int4>, public XYZW<Int4>
 	{
 	public:
 		explicit Int4(RValue<Byte4> cast);
@@ -1313,7 +1760,7 @@
 		explicit Int4(RValue<Short4> cast);
 		explicit Int4(RValue<UShort4> cast);
 
-		Int4() = default;
+		Int4();
 		Int4(int xyzw);
 		Int4(int x, int yzw);
 		Int4(int x, int y, int zw);
@@ -1390,12 +1837,12 @@
 	RValue<Int> SignMask(RValue<Int4> x);
 	RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select);
 
-	class UInt4 : public LValue<UInt4>
+	class UInt4 : public LValue<UInt4>, public XYZW<UInt4>
 	{
 	public:
 		explicit UInt4(RValue<Float4> cast);
 
-		UInt4() = default;
+		UInt4();
 		UInt4(int xyzw);
 		UInt4(int x, int yzw);
 		UInt4(int x, int y, int zw);
@@ -1466,72 +1913,6 @@
 //	RValue<UInt4> RoundInt(RValue<Float4> cast);
 	RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y);
 
-	template<int T>
-	class Swizzle2Float4
-	{
-		friend class Float4;
-
-	public:
-		operator RValue<Float4>() const;
-
-	private:
-		Float4 *parent;
-	};
-
-	template<int T>
-	class SwizzleFloat4
-	{
-	public:
-		operator RValue<Float4>() const;
-
-	private:
-		Float4 *parent;
-	};
-
-	template<int T>
-	class SwizzleMaskFloat4
-	{
-		friend struct FloatXYZW;
-
-	public:
-		operator RValue<Float4>() const;
-
-		RValue<Float4> operator=(RValue<Float4> rhs);
-		RValue<Float4> operator=(RValue<Float> rhs);
-
-	private:
-		Float4 *parent;
-	};
-
-	template<int T>
-	class SwizzleMask1Float4
-	{
-	public:
-		operator RValue<Float>() const;
-		operator RValue<Float4>() const;
-
-		RValue<Float4> operator=(float x);
-		RValue<Float4> operator=(RValue<Float4> rhs);
-		RValue<Float4> operator=(RValue<Float> rhs);
-
-	private:
-		Float4 *parent;
-	};
-
-	template<int T>
-	class SwizzleMask2Float4
-	{
-		friend class Float4;
-
-	public:
-		operator RValue<Float4>() const;
-
-		RValue<Float4> operator=(RValue<Float4> rhs);
-
-	private:
-		Float4 *parent;
-	};
-
 	class Float : public LValue<Float>
 	{
 	public:
@@ -1545,7 +1926,7 @@
 		Float(const Reference<Float> &rhs);
 
 		template<int T>
-		Float(const SwizzleMask1Float4<T> &rhs);
+		Float(const SwizzleMask1<Float4, T> &rhs);
 
 	//	RValue<Float> operator=(float rhs);   // FIXME: Implement
 		RValue<Float> operator=(RValue<Float> rhs);
@@ -1553,7 +1934,7 @@
 		RValue<Float> operator=(const Reference<Float> &rhs);
 
 		template<int T>
-		RValue<Float> operator=(const SwizzleMask1Float4<T> &rhs);
+		RValue<Float> operator=(const SwizzleMask1<Float4, T> &rhs);
 
 		static Type *getType();
 	};
@@ -1607,7 +1988,7 @@
 	//	Float2(const Reference<Float> &rhs);
 
 	//	template<int T>
-	//	Float2(const SwizzleMask1Float4<T> &rhs);
+	//	Float2(const SwizzleMask1<T> &rhs);
 
 	//	RValue<Float2> operator=(float replicate);
 	//	RValue<Float2> operator=(RValue<Float2> rhs);
@@ -1618,7 +1999,7 @@
 	//	RValue<Float2> operator=(const Reference<Float> &rhs);
 
 	//	template<int T>
-	//	RValue<Float2> operator=(const SwizzleMask1Float4<T> &rhs);
+	//	RValue<Float2> operator=(const SwizzleMask1<T> &rhs);
 
 		static Type *getType();
 	};
@@ -1642,363 +2023,7 @@
 //	RValue<Float2> Swizzle(RValue<Float2> x, unsigned char select);
 //	RValue<Float2> Mask(Float2 &lhs, RValue<Float2> rhs, unsigned char select);
 
-	struct FloatXYZW
-	{
-		friend class Float4;
-
-	private:
-		FloatXYZW(Float4 *parent)
-		{
-			xyzw.parent = parent;
-		}
-
-	public:
-		union
-		{
-			SwizzleMask1Float4<0x00> x;
-			SwizzleMask1Float4<0x55> y;
-			SwizzleMask1Float4<0xAA> z;
-			SwizzleMask1Float4<0xFF> w;
-			Swizzle2Float4<0x00>     xx;
-			Swizzle2Float4<0x01>     yx;
-			Swizzle2Float4<0x02>     zx;
-			Swizzle2Float4<0x03>     wx;
-			SwizzleMask2Float4<0x54> xy;
-			Swizzle2Float4<0x55>     yy;
-			Swizzle2Float4<0x56>     zy;
-			Swizzle2Float4<0x57>     wy;
-			SwizzleMask2Float4<0xA8> xz;
-			SwizzleMask2Float4<0xA9> yz;
-			Swizzle2Float4<0xAA>     zz;
-			Swizzle2Float4<0xAB>     wz;
-			SwizzleMask2Float4<0xFC> xw;
-			SwizzleMask2Float4<0xFD> yw;
-			SwizzleMask2Float4<0xFE> zw;
-			Swizzle2Float4<0xFF>     ww;
-			SwizzleFloat4<0x00>      xxx;
-			SwizzleFloat4<0x01>      yxx;
-			SwizzleFloat4<0x02>      zxx;
-			SwizzleFloat4<0x03>      wxx;
-			SwizzleFloat4<0x04>      xyx;
-			SwizzleFloat4<0x05>      yyx;
-			SwizzleFloat4<0x06>      zyx;
-			SwizzleFloat4<0x07>      wyx;
-			SwizzleFloat4<0x08>      xzx;
-			SwizzleFloat4<0x09>      yzx;
-			SwizzleFloat4<0x0A>      zzx;
-			SwizzleFloat4<0x0B>      wzx;
-			SwizzleFloat4<0x0C>      xwx;
-			SwizzleFloat4<0x0D>      ywx;
-			SwizzleFloat4<0x0E>      zwx;
-			SwizzleFloat4<0x0F>      wwx;
-			SwizzleFloat4<0x50>      xxy;
-			SwizzleFloat4<0x51>      yxy;
-			SwizzleFloat4<0x52>      zxy;
-			SwizzleFloat4<0x53>      wxy;
-			SwizzleFloat4<0x54>      xyy;
-			SwizzleFloat4<0x55>      yyy;
-			SwizzleFloat4<0x56>      zyy;
-			SwizzleFloat4<0x57>      wyy;
-			SwizzleFloat4<0x58>      xzy;
-			SwizzleFloat4<0x59>      yzy;
-			SwizzleFloat4<0x5A>      zzy;
-			SwizzleFloat4<0x5B>      wzy;
-			SwizzleFloat4<0x5C>      xwy;
-			SwizzleFloat4<0x5D>      ywy;
-			SwizzleFloat4<0x5E>      zwy;
-			SwizzleFloat4<0x5F>      wwy;
-			SwizzleFloat4<0xA0>      xxz;
-			SwizzleFloat4<0xA1>      yxz;
-			SwizzleFloat4<0xA2>      zxz;
-			SwizzleFloat4<0xA3>      wxz;
-			SwizzleMaskFloat4<0xA4>  xyz;
-			SwizzleFloat4<0xA5>      yyz;
-			SwizzleFloat4<0xA6>      zyz;
-			SwizzleFloat4<0xA7>      wyz;
-			SwizzleFloat4<0xA8>      xzz;
-			SwizzleFloat4<0xA9>      yzz;
-			SwizzleFloat4<0xAA>      zzz;
-			SwizzleFloat4<0xAB>      wzz;
-			SwizzleFloat4<0xAC>      xwz;
-			SwizzleFloat4<0xAD>      ywz;
-			SwizzleFloat4<0xAE>      zwz;
-			SwizzleFloat4<0xAF>      wwz;
-			SwizzleFloat4<0xF0>      xxw;
-			SwizzleFloat4<0xF1>      yxw;
-			SwizzleFloat4<0xF2>      zxw;
-			SwizzleFloat4<0xF3>      wxw;
-			SwizzleMaskFloat4<0xF4>  xyw;
-			SwizzleFloat4<0xF5>      yyw;
-			SwizzleFloat4<0xF6>      zyw;
-			SwizzleFloat4<0xF7>      wyw;
-			SwizzleMaskFloat4<0xF8>  xzw;
-			SwizzleMaskFloat4<0xF9>  yzw;
-			SwizzleFloat4<0xFA>      zzw;
-			SwizzleFloat4<0xFB>      wzw;
-			SwizzleFloat4<0xFC>      xww;
-			SwizzleFloat4<0xFD>      yww;
-			SwizzleFloat4<0xFE>      zww;
-			SwizzleFloat4<0xFF>      www;
-			SwizzleFloat4<0x00>      xxxx;
-			SwizzleFloat4<0x01>      yxxx;
-			SwizzleFloat4<0x02>      zxxx;
-			SwizzleFloat4<0x03>      wxxx;
-			SwizzleFloat4<0x04>      xyxx;
-			SwizzleFloat4<0x05>      yyxx;
-			SwizzleFloat4<0x06>      zyxx;
-			SwizzleFloat4<0x07>      wyxx;
-			SwizzleFloat4<0x08>      xzxx;
-			SwizzleFloat4<0x09>      yzxx;
-			SwizzleFloat4<0x0A>      zzxx;
-			SwizzleFloat4<0x0B>      wzxx;
-			SwizzleFloat4<0x0C>      xwxx;
-			SwizzleFloat4<0x0D>      ywxx;
-			SwizzleFloat4<0x0E>      zwxx;
-			SwizzleFloat4<0x0F>      wwxx;
-			SwizzleFloat4<0x10>      xxyx;
-			SwizzleFloat4<0x11>      yxyx;
-			SwizzleFloat4<0x12>      zxyx;
-			SwizzleFloat4<0x13>      wxyx;
-			SwizzleFloat4<0x14>      xyyx;
-			SwizzleFloat4<0x15>      yyyx;
-			SwizzleFloat4<0x16>      zyyx;
-			SwizzleFloat4<0x17>      wyyx;
-			SwizzleFloat4<0x18>      xzyx;
-			SwizzleFloat4<0x19>      yzyx;
-			SwizzleFloat4<0x1A>      zzyx;
-			SwizzleFloat4<0x1B>      wzyx;
-			SwizzleFloat4<0x1C>      xwyx;
-			SwizzleFloat4<0x1D>      ywyx;
-			SwizzleFloat4<0x1E>      zwyx;
-			SwizzleFloat4<0x1F>      wwyx;
-			SwizzleFloat4<0x20>      xxzx;
-			SwizzleFloat4<0x21>      yxzx;
-			SwizzleFloat4<0x22>      zxzx;
-			SwizzleFloat4<0x23>      wxzx;
-			SwizzleFloat4<0x24>      xyzx;
-			SwizzleFloat4<0x25>      yyzx;
-			SwizzleFloat4<0x26>      zyzx;
-			SwizzleFloat4<0x27>      wyzx;
-			SwizzleFloat4<0x28>      xzzx;
-			SwizzleFloat4<0x29>      yzzx;
-			SwizzleFloat4<0x2A>      zzzx;
-			SwizzleFloat4<0x2B>      wzzx;
-			SwizzleFloat4<0x2C>      xwzx;
-			SwizzleFloat4<0x2D>      ywzx;
-			SwizzleFloat4<0x2E>      zwzx;
-			SwizzleFloat4<0x2F>      wwzx;
-			SwizzleFloat4<0x30>      xxwx;
-			SwizzleFloat4<0x31>      yxwx;
-			SwizzleFloat4<0x32>      zxwx;
-			SwizzleFloat4<0x33>      wxwx;
-			SwizzleFloat4<0x34>      xywx;
-			SwizzleFloat4<0x35>      yywx;
-			SwizzleFloat4<0x36>      zywx;
-			SwizzleFloat4<0x37>      wywx;
-			SwizzleFloat4<0x38>      xzwx;
-			SwizzleFloat4<0x39>      yzwx;
-			SwizzleFloat4<0x3A>      zzwx;
-			SwizzleFloat4<0x3B>      wzwx;
-			SwizzleFloat4<0x3C>      xwwx;
-			SwizzleFloat4<0x3D>      ywwx;
-			SwizzleFloat4<0x3E>      zwwx;
-			SwizzleFloat4<0x3F>      wwwx;
-			SwizzleFloat4<0x40>      xxxy;
-			SwizzleFloat4<0x41>      yxxy;
-			SwizzleFloat4<0x42>      zxxy;
-			SwizzleFloat4<0x43>      wxxy;
-			SwizzleFloat4<0x44>      xyxy;
-			SwizzleFloat4<0x45>      yyxy;
-			SwizzleFloat4<0x46>      zyxy;
-			SwizzleFloat4<0x47>      wyxy;
-			SwizzleFloat4<0x48>      xzxy;
-			SwizzleFloat4<0x49>      yzxy;
-			SwizzleFloat4<0x4A>      zzxy;
-			SwizzleFloat4<0x4B>      wzxy;
-			SwizzleFloat4<0x4C>      xwxy;
-			SwizzleFloat4<0x4D>      ywxy;
-			SwizzleFloat4<0x4E>      zwxy;
-			SwizzleFloat4<0x4F>      wwxy;
-			SwizzleFloat4<0x50>      xxyy;
-			SwizzleFloat4<0x51>      yxyy;
-			SwizzleFloat4<0x52>      zxyy;
-			SwizzleFloat4<0x53>      wxyy;
-			SwizzleFloat4<0x54>      xyyy;
-			SwizzleFloat4<0x55>      yyyy;
-			SwizzleFloat4<0x56>      zyyy;
-			SwizzleFloat4<0x57>      wyyy;
-			SwizzleFloat4<0x58>      xzyy;
-			SwizzleFloat4<0x59>      yzyy;
-			SwizzleFloat4<0x5A>      zzyy;
-			SwizzleFloat4<0x5B>      wzyy;
-			SwizzleFloat4<0x5C>      xwyy;
-			SwizzleFloat4<0x5D>      ywyy;
-			SwizzleFloat4<0x5E>      zwyy;
-			SwizzleFloat4<0x5F>      wwyy;
-			SwizzleFloat4<0x60>      xxzy;
-			SwizzleFloat4<0x61>      yxzy;
-			SwizzleFloat4<0x62>      zxzy;
-			SwizzleFloat4<0x63>      wxzy;
-			SwizzleFloat4<0x64>      xyzy;
-			SwizzleFloat4<0x65>      yyzy;
-			SwizzleFloat4<0x66>      zyzy;
-			SwizzleFloat4<0x67>      wyzy;
-			SwizzleFloat4<0x68>      xzzy;
-			SwizzleFloat4<0x69>      yzzy;
-			SwizzleFloat4<0x6A>      zzzy;
-			SwizzleFloat4<0x6B>      wzzy;
-			SwizzleFloat4<0x6C>      xwzy;
-			SwizzleFloat4<0x6D>      ywzy;
-			SwizzleFloat4<0x6E>      zwzy;
-			SwizzleFloat4<0x6F>      wwzy;
-			SwizzleFloat4<0x70>      xxwy;
-			SwizzleFloat4<0x71>      yxwy;
-			SwizzleFloat4<0x72>      zxwy;
-			SwizzleFloat4<0x73>      wxwy;
-			SwizzleFloat4<0x74>      xywy;
-			SwizzleFloat4<0x75>      yywy;
-			SwizzleFloat4<0x76>      zywy;
-			SwizzleFloat4<0x77>      wywy;
-			SwizzleFloat4<0x78>      xzwy;
-			SwizzleFloat4<0x79>      yzwy;
-			SwizzleFloat4<0x7A>      zzwy;
-			SwizzleFloat4<0x7B>      wzwy;
-			SwizzleFloat4<0x7C>      xwwy;
-			SwizzleFloat4<0x7D>      ywwy;
-			SwizzleFloat4<0x7E>      zwwy;
-			SwizzleFloat4<0x7F>      wwwy;
-			SwizzleFloat4<0x80>      xxxz;
-			SwizzleFloat4<0x81>      yxxz;
-			SwizzleFloat4<0x82>      zxxz;
-			SwizzleFloat4<0x83>      wxxz;
-			SwizzleFloat4<0x84>      xyxz;
-			SwizzleFloat4<0x85>      yyxz;
-			SwizzleFloat4<0x86>      zyxz;
-			SwizzleFloat4<0x87>      wyxz;
-			SwizzleFloat4<0x88>      xzxz;
-			SwizzleFloat4<0x89>      yzxz;
-			SwizzleFloat4<0x8A>      zzxz;
-			SwizzleFloat4<0x8B>      wzxz;
-			SwizzleFloat4<0x8C>      xwxz;
-			SwizzleFloat4<0x8D>      ywxz;
-			SwizzleFloat4<0x8E>      zwxz;
-			SwizzleFloat4<0x8F>      wwxz;
-			SwizzleFloat4<0x90>      xxyz;
-			SwizzleFloat4<0x91>      yxyz;
-			SwizzleFloat4<0x92>      zxyz;
-			SwizzleFloat4<0x93>      wxyz;
-			SwizzleFloat4<0x94>      xyyz;
-			SwizzleFloat4<0x95>      yyyz;
-			SwizzleFloat4<0x96>      zyyz;
-			SwizzleFloat4<0x97>      wyyz;
-			SwizzleFloat4<0x98>      xzyz;
-			SwizzleFloat4<0x99>      yzyz;
-			SwizzleFloat4<0x9A>      zzyz;
-			SwizzleFloat4<0x9B>      wzyz;
-			SwizzleFloat4<0x9C>      xwyz;
-			SwizzleFloat4<0x9D>      ywyz;
-			SwizzleFloat4<0x9E>      zwyz;
-			SwizzleFloat4<0x9F>      wwyz;
-			SwizzleFloat4<0xA0>      xxzz;
-			SwizzleFloat4<0xA1>      yxzz;
-			SwizzleFloat4<0xA2>      zxzz;
-			SwizzleFloat4<0xA3>      wxzz;
-			SwizzleFloat4<0xA4>      xyzz;
-			SwizzleFloat4<0xA5>      yyzz;
-			SwizzleFloat4<0xA6>      zyzz;
-			SwizzleFloat4<0xA7>      wyzz;
-			SwizzleFloat4<0xA8>      xzzz;
-			SwizzleFloat4<0xA9>      yzzz;
-			SwizzleFloat4<0xAA>      zzzz;
-			SwizzleFloat4<0xAB>      wzzz;
-			SwizzleFloat4<0xAC>      xwzz;
-			SwizzleFloat4<0xAD>      ywzz;
-			SwizzleFloat4<0xAE>      zwzz;
-			SwizzleFloat4<0xAF>      wwzz;
-			SwizzleFloat4<0xB0>      xxwz;
-			SwizzleFloat4<0xB1>      yxwz;
-			SwizzleFloat4<0xB2>      zxwz;
-			SwizzleFloat4<0xB3>      wxwz;
-			SwizzleFloat4<0xB4>      xywz;
-			SwizzleFloat4<0xB5>      yywz;
-			SwizzleFloat4<0xB6>      zywz;
-			SwizzleFloat4<0xB7>      wywz;
-			SwizzleFloat4<0xB8>      xzwz;
-			SwizzleFloat4<0xB9>      yzwz;
-			SwizzleFloat4<0xBA>      zzwz;
-			SwizzleFloat4<0xBB>      wzwz;
-			SwizzleFloat4<0xBC>      xwwz;
-			SwizzleFloat4<0xBD>      ywwz;
-			SwizzleFloat4<0xBE>      zwwz;
-			SwizzleFloat4<0xBF>      wwwz;
-			SwizzleFloat4<0xC0>      xxxw;
-			SwizzleFloat4<0xC1>      yxxw;
-			SwizzleFloat4<0xC2>      zxxw;
-			SwizzleFloat4<0xC3>      wxxw;
-			SwizzleFloat4<0xC4>      xyxw;
-			SwizzleFloat4<0xC5>      yyxw;
-			SwizzleFloat4<0xC6>      zyxw;
-			SwizzleFloat4<0xC7>      wyxw;
-			SwizzleFloat4<0xC8>      xzxw;
-			SwizzleFloat4<0xC9>      yzxw;
-			SwizzleFloat4<0xCA>      zzxw;
-			SwizzleFloat4<0xCB>      wzxw;
-			SwizzleFloat4<0xCC>      xwxw;
-			SwizzleFloat4<0xCD>      ywxw;
-			SwizzleFloat4<0xCE>      zwxw;
-			SwizzleFloat4<0xCF>      wwxw;
-			SwizzleFloat4<0xD0>      xxyw;
-			SwizzleFloat4<0xD1>      yxyw;
-			SwizzleFloat4<0xD2>      zxyw;
-			SwizzleFloat4<0xD3>      wxyw;
-			SwizzleFloat4<0xD4>      xyyw;
-			SwizzleFloat4<0xD5>      yyyw;
-			SwizzleFloat4<0xD6>      zyyw;
-			SwizzleFloat4<0xD7>      wyyw;
-			SwizzleFloat4<0xD8>      xzyw;
-			SwizzleFloat4<0xD9>      yzyw;
-			SwizzleFloat4<0xDA>      zzyw;
-			SwizzleFloat4<0xDB>      wzyw;
-			SwizzleFloat4<0xDC>      xwyw;
-			SwizzleFloat4<0xDD>      ywyw;
-			SwizzleFloat4<0xDE>      zwyw;
-			SwizzleFloat4<0xDF>      wwyw;
-			SwizzleFloat4<0xE0>      xxzw;
-			SwizzleFloat4<0xE1>      yxzw;
-			SwizzleFloat4<0xE2>      zxzw;
-			SwizzleFloat4<0xE3>      wxzw;
-			SwizzleMaskFloat4<0xE4>  xyzw;
-			SwizzleFloat4<0xE5>      yyzw;
-			SwizzleFloat4<0xE6>      zyzw;
-			SwizzleFloat4<0xE7>      wyzw;
-			SwizzleFloat4<0xE8>      xzzw;
-			SwizzleFloat4<0xE9>      yzzw;
-			SwizzleFloat4<0xEA>      zzzw;
-			SwizzleFloat4<0xEB>      wzzw;
-			SwizzleFloat4<0xEC>      xwzw;
-			SwizzleFloat4<0xED>      ywzw;
-			SwizzleFloat4<0xEE>      zwzw;
-			SwizzleFloat4<0xEF>      wwzw;
-			SwizzleFloat4<0xF0>      xxww;
-			SwizzleFloat4<0xF1>      yxww;
-			SwizzleFloat4<0xF2>      zxww;
-			SwizzleFloat4<0xF3>      wxww;
-			SwizzleFloat4<0xF4>      xyww;
-			SwizzleFloat4<0xF5>      yyww;
-			SwizzleFloat4<0xF6>      zyww;
-			SwizzleFloat4<0xF7>      wyww;
-			SwizzleFloat4<0xF8>      xzww;
-			SwizzleFloat4<0xF9>      yzww;
-			SwizzleFloat4<0xFA>      zzww;
-			SwizzleFloat4<0xFB>      wzww;
-			SwizzleFloat4<0xFC>      xwww;
-			SwizzleFloat4<0xFD>      ywww;
-			SwizzleFloat4<0xFE>      zwww;
-			SwizzleFloat4<0xFF>      wwww;
-		};
-	};
-
-	class Float4 : public LValue<Float4>, public FloatXYZW
+	class Float4 : public LValue<Float4>, public XYZW<Float4>
 	{
 	public:
 		explicit Float4(RValue<Byte4> cast);
@@ -2021,17 +2046,17 @@
 		Float4(const Reference<Float> &rhs);
 
 		template<int T>
-		Float4(const SwizzleMask1Float4<T> &rhs);
+		Float4(const SwizzleMask1<Float4, T> &rhs);
 		template<int T>
-		Float4(const SwizzleFloat4<T> &rhs);
+		Float4(const Swizzle4<Float4, T> &rhs);
 		template<int X, int Y>
-		Float4(const Swizzle2Float4<X> &x, const Swizzle2Float4<Y> &y);
+		Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y);
 		template<int X, int Y>
-		Float4(const SwizzleMask2Float4<X> &x, const Swizzle2Float4<Y> &y);
+		Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y);
 		template<int X, int Y>
-		Float4(const Swizzle2Float4<X> &x, const SwizzleMask2Float4<Y> &y);
+		Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y);
 		template<int X, int Y>
-		Float4(const SwizzleMask2Float4<X> &x, const SwizzleMask2Float4<Y> &y);
+		Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y);
 
 		RValue<Float4> operator=(float replicate);
 		RValue<Float4> operator=(RValue<Float4> rhs);
@@ -2042,9 +2067,9 @@
 		RValue<Float4> operator=(const Reference<Float> &rhs);
 
 		template<int T>
-		RValue<Float4> operator=(const SwizzleMask1Float4<T> &rhs);
+		RValue<Float4> operator=(const SwizzleMask1<Float4, T> &rhs);
 		template<int T>
-		RValue<Float4> operator=(const SwizzleFloat4<T> &rhs);
+		RValue<Float4> operator=(const Swizzle4<Float4, T> &rhs);
 
 		static Type *getType();
 
@@ -2336,144 +2361,144 @@
 		value = ref.loadValue();
 	}
 
-	template<int T>
-	Swizzle2Float4<T>::operator RValue<Float4>() const
+	template<class Vector4, int T>
+	Swizzle2<Vector4, T>::operator RValue<Vector4>() const
 	{
 		Value *vector = parent->loadValue();
 
-		return Swizzle(RValue<Float4>(vector), T);
+		return Swizzle(RValue<Vector4>(vector), T);
 	}
 
-	template<int T>
-	SwizzleFloat4<T>::operator RValue<Float4>() const
+	template<class Vector4, int T>
+	Swizzle4<Vector4, T>::operator RValue<Vector4>() const
 	{
 		Value *vector = parent->loadValue();
 
-		return Swizzle(RValue<Float4>(vector), T);
+		return Swizzle(RValue<Vector4>(vector), T);
 	}
 
-	template<int T>
-	SwizzleMaskFloat4<T>::operator RValue<Float4>() const
+	template<class Vector4, int T>
+	SwizzleMask4<Vector4, T>::operator RValue<Vector4>() const
 	{
 		Value *vector = parent->loadValue();
 
-		return Swizzle(RValue<Float4>(vector), T);
+		return Swizzle(RValue<Vector4>(vector), T);
 	}
 
-	template<int T>
-	RValue<Float4> SwizzleMaskFloat4<T>::operator=(RValue<Float4> rhs)
+	template<class Vector4, int T>
+	RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<Vector4> rhs)
 	{
 		return Mask(*parent, rhs, T);
 	}
 
-	template<int T>
-	RValue<Float4> SwizzleMaskFloat4<T>::operator=(RValue<Float> rhs)
+	template<class Vector4, int T>
+	RValue<Vector4> SwizzleMask4<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs)
 	{
-		return Mask(*parent, Float4(rhs), T);
+		return Mask(*parent, Vector4(rhs), T);
 	}
 
-	template<int T>
-	SwizzleMask1Float4<T>::operator RValue<Float>() const   // FIXME: Call a non-template function
+	template<class Vector4, int T>
+	SwizzleMask1<Vector4, T>::operator RValue<typename Scalar<Vector4>::Type>() const   // FIXME: Call a non-template function
 	{
 		return Extract(*parent, T & 0x3);
 	}
 
-	template<int T>
-	SwizzleMask1Float4<T>::operator RValue<Float4>() const
+	template<class Vector4, int T>
+	SwizzleMask1<Vector4, T>::operator RValue<Vector4>() const
 	{
 		Value *vector = parent->loadValue();
 
-		return Swizzle(RValue<Float4>(vector), T);
+		return Swizzle(RValue<Vector4>(vector), T);
 	}
 
-	template<int T>
-	RValue<Float4> SwizzleMask1Float4<T>::operator=(float x)
+	template<class Vector4, int T>
+	RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(float x)
 	{
 		return *parent = Insert(*parent, Float(x), T & 0x3);
 	}
 
-	template<int T>
-	RValue<Float4> SwizzleMask1Float4<T>::operator=(RValue<Float4> rhs)
+	template<class Vector4, int T>
+	RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<Vector4> rhs)
 	{
 		return Mask(*parent, Float4(rhs), T);
 	}
 
-	template<int T>
-	RValue<Float4> SwizzleMask1Float4<T>::operator=(RValue<Float> rhs)   // FIXME: Call a non-template function
+	template<class Vector4, int T>
+	RValue<Vector4> SwizzleMask1<Vector4, T>::operator=(RValue<typename Scalar<Vector4>::Type> rhs)   // FIXME: Call a non-template function
 	{
 		return *parent = Insert(*parent, rhs, T & 0x3);
 	}
 
-	template<int T>
-	SwizzleMask2Float4<T>::operator RValue<Float4>() const
+	template<class Vector4, int T>
+	SwizzleMask2<Vector4, T>::operator RValue<Vector4>() const
 	{
 		Value *vector = parent->loadValue();
 
 		return Swizzle(RValue<Float4>(vector), T);
 	}
 
-	template<int T>
-	RValue<Float4> SwizzleMask2Float4<T>::operator=(RValue<Float4> rhs)
+	template<class Vector4, int T>
+	RValue<Vector4> SwizzleMask2<Vector4, T>::operator=(RValue<Vector4> rhs)
 	{
 		return Mask(*parent, Float4(rhs), T);
 	}
 
 	template<int T>
-	Float::Float(const SwizzleMask1Float4<T> &rhs)
+	Float::Float(const SwizzleMask1<Float4, T> &rhs)
 	{
 		*this = rhs.operator RValue<Float>();
 	}
 
 	template<int T>
-	RValue<Float> Float::operator=(const SwizzleMask1Float4<T> &rhs)
+	RValue<Float> Float::operator=(const SwizzleMask1<Float4, T> &rhs)
 	{
 		return *this = rhs.operator RValue<Float>();
 	}
 
 	template<int T>
-	Float4::Float4(const SwizzleMask1Float4<T> &rhs) : FloatXYZW(this)
+	Float4::Float4(const SwizzleMask1<Float4, T> &rhs) : XYZW(this)
 	{
 		*this = rhs.operator RValue<Float4>();
 	}
 
 	template<int T>
-	Float4::Float4(const SwizzleFloat4<T> &rhs) : FloatXYZW(this)
+	Float4::Float4(const Swizzle4<Float4, T> &rhs) : XYZW(this)
 	{
 		*this = rhs.operator RValue<Float4>();
 	}
 
 	template<int X, int Y>
-	Float4::Float4(const Swizzle2Float4<X> &x, const Swizzle2Float4<Y> &y) : FloatXYZW(this)
+	Float4::Float4(const Swizzle2<Float4, X> &x, const Swizzle2<Float4, Y> &y) : XYZW(this)
 	{
 		*this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
 	}
 
 	template<int X, int Y>
-	Float4::Float4(const SwizzleMask2Float4<X> &x, const Swizzle2Float4<Y> &y) : FloatXYZW(this)
+	Float4::Float4(const SwizzleMask2<Float4, X> &x, const Swizzle2<Float4, Y> &y) : XYZW(this)
 	{
 		*this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
 	}
 
 	template<int X, int Y>
-	Float4::Float4(const Swizzle2Float4<X> &x, const SwizzleMask2Float4<Y> &y) : FloatXYZW(this)
+	Float4::Float4(const Swizzle2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y) : XYZW(this)
 	{
 		*this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
 	}
 
 	template<int X, int Y>
-	Float4::Float4(const SwizzleMask2Float4<X> &x, const SwizzleMask2Float4<Y> &y) : FloatXYZW(this)
+	Float4::Float4(const SwizzleMask2<Float4, X> &x, const SwizzleMask2<Float4, Y> &y) : XYZW(this)
 	{
 		*this = ShuffleLowHigh(*x.parent, *y.parent, (X & 0xF) | (Y & 0xF) << 4);
 	}
 
 	template<int T>
-	RValue<Float4> Float4::operator=(const SwizzleMask1Float4<T> &rhs)
+	RValue<Float4> Float4::operator=(const SwizzleMask1<Float4, T> &rhs)
 	{
 		return *this = rhs.operator RValue<Float4>();
 	}
 
 	template<int T>
-	RValue<Float4> Float4::operator=(const SwizzleFloat4<T> &rhs)
+	RValue<Float4> Float4::operator=(const Swizzle4<Float4, T> &rhs)
 	{
 		return *this = rhs.operator RValue<Float4>();
 	}
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index 7e607d9..a770981 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -12,10 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "Nucleus.hpp"
-
 #include "Reactor.hpp"
-#include "Routine.hpp"
 
 #include "Optimizer.hpp"
 
@@ -45,7 +42,7 @@
 #endif
 #endif
 
-#include <mutex>
+//#include <mutex>
 #include <limits>
 #include <iostream>
 #include <cassert>
@@ -2838,7 +2835,7 @@
 		{
 			#if defined(__i386__) || defined(__x86_64__)
 				// SSE2 doesn't support byte vector shifts, so shift as shorts and recombine.
-				RValue<Short4> hi = (As<Short4>(lhs) >> rhs) & Short4(0xFF00);
+				RValue<Short4> hi = (As<Short4>(lhs) >> rhs) & Short4(0xFF00u);
 				RValue<Short4> lo = As<Short4>(As<UShort4>((As<Short4>(lhs) << 8) >> rhs) >> 8);
 
 				return As<SByte8>(hi | lo);
@@ -5535,7 +5532,11 @@
 		return T(Type_v2i32);
 	}
 
-	Int4::Int4(RValue<Byte4> cast)
+	Int4::Int4() : XYZW(this)
+	{
+	}
+
+	Int4::Int4(RValue<Byte4> cast) : XYZW(this)
 	{
 		Value *x = Nucleus::createBitCast(cast.value, Int::getType());
 		Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
@@ -5553,7 +5554,7 @@
 		storeValue(f);
 	}
 
-	Int4::Int4(RValue<SByte4> cast)
+	Int4::Int4(RValue<SByte4> cast) : XYZW(this)
 	{
 		Value *x = Nucleus::createBitCast(cast.value, Int::getType());
 		Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
@@ -5569,14 +5570,14 @@
 		*this = As<Int4>(e) >> 24;
 	}
 
-	Int4::Int4(RValue<Float4> cast)
+	Int4::Int4(RValue<Float4> cast) : XYZW(this)
 	{
 		Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
 
 		storeValue(xyzw);
 	}
 
-	Int4::Int4(RValue<Short4> cast)
+	Int4::Int4(RValue<Short4> cast) : XYZW(this)
 	{
 		int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
 		Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
@@ -5584,7 +5585,7 @@
 		*this = As<Int4>(c) >> 16;
 	}
 
-	Int4::Int4(RValue<UShort4> cast)
+	Int4::Int4(RValue<UShort4> cast) : XYZW(this)
 	{
 		int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
 		Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
@@ -5592,22 +5593,22 @@
 		storeValue(d);
 	}
 
-	Int4::Int4(int xyzw)
+	Int4::Int4(int xyzw) : XYZW(this)
 	{
 		constant(xyzw, xyzw, xyzw, xyzw);
 	}
 
-	Int4::Int4(int x, int yzw)
+	Int4::Int4(int x, int yzw) : XYZW(this)
 	{
 		constant(x, yzw, yzw, yzw);
 	}
 
-	Int4::Int4(int x, int y, int zw)
+	Int4::Int4(int x, int y, int zw) : XYZW(this)
 	{
 		constant(x, y, zw, zw);
 	}
 
-	Int4::Int4(int x, int y, int z, int w)
+	Int4::Int4(int x, int y, int z, int w) : XYZW(this)
 	{
 		constant(x, y, z, w);
 	}
@@ -5618,41 +5619,41 @@
 		storeValue(Nucleus::createConstantVector(constantVector, getType()));
 	}
 
-	Int4::Int4(RValue<Int4> rhs)
+	Int4::Int4(RValue<Int4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	Int4::Int4(const Int4 &rhs)
+	Int4::Int4(const Int4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Int4::Int4(const Reference<Int4> &rhs)
+	Int4::Int4(const Reference<Int4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Int4::Int4(RValue<UInt4> rhs)
+	Int4::Int4(RValue<UInt4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	Int4::Int4(const UInt4 &rhs)
+	Int4::Int4(const UInt4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Int4::Int4(const Reference<UInt4> &rhs)
+	Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
+	Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this)
 	{
 		int shuffle[4] = {0, 1, 4, 5};   // Real type is v4i32
 		Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
@@ -5660,7 +5661,7 @@
 		storeValue(packed);
 	}
 
-	Int4::Int4(RValue<Int> rhs)
+	Int4::Int4(RValue<Int> rhs) : XYZW(this)
 	{
 		Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType());
 
@@ -5670,12 +5671,12 @@
 		storeValue(replicate);
 	}
 
-	Int4::Int4(const Int &rhs)
+	Int4::Int4(const Int &rhs) : XYZW(this)
 	{
 		*this = RValue<Int>(rhs.loadValue());
 	}
 
-	Int4::Int4(const Reference<Int> &rhs)
+	Int4::Int4(const Reference<Int> &rhs) : XYZW(this)
 	{
 		*this = RValue<Int>(rhs.loadValue());
 	}
@@ -6000,7 +6001,11 @@
 		return T(Ice::IceType_v4i32);
 	}
 
-	UInt4::UInt4(RValue<Float4> cast)
+	UInt4::UInt4() : XYZW(this)
+	{
+	}
+
+	UInt4::UInt4(RValue<Float4> cast) : XYZW(this)
 	{
 		// Smallest positive value representable in UInt, but not in Int
 		const unsigned int ustart = 0x80000000u;
@@ -6016,22 +6021,22 @@
 		storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
 	}
 
-	UInt4::UInt4(int xyzw)
+	UInt4::UInt4(int xyzw) : XYZW(this)
 	{
 		constant(xyzw, xyzw, xyzw, xyzw);
 	}
 
-	UInt4::UInt4(int x, int yzw)
+	UInt4::UInt4(int x, int yzw) : XYZW(this)
 	{
 		constant(x, yzw, yzw, yzw);
 	}
 
-	UInt4::UInt4(int x, int y, int zw)
+	UInt4::UInt4(int x, int y, int zw) : XYZW(this)
 	{
 		constant(x, y, zw, zw);
 	}
 
-	UInt4::UInt4(int x, int y, int z, int w)
+	UInt4::UInt4(int x, int y, int z, int w) : XYZW(this)
 	{
 		constant(x, y, z, w);
 	}
@@ -6042,41 +6047,41 @@
 		storeValue(Nucleus::createConstantVector(constantVector, getType()));
 	}
 
-	UInt4::UInt4(RValue<UInt4> rhs)
+	UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	UInt4::UInt4(const UInt4 &rhs)
+	UInt4::UInt4(const UInt4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	UInt4::UInt4(const Reference<UInt4> &rhs)
+	UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	UInt4::UInt4(RValue<Int4> rhs)
+	UInt4::UInt4(RValue<Int4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	UInt4::UInt4(const Int4 &rhs)
+	UInt4::UInt4(const Int4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	UInt4::UInt4(const Reference<Int4> &rhs)
+	UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
+	UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this)
 	{
 		int shuffle[4] = {0, 1, 4, 5};   // Real type is v4i32
 		Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
@@ -6572,7 +6577,7 @@
 		return T(Type_v2f32);
 	}
 
-	Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<Byte4> cast) : XYZW(this)
 	{
 		Value *a = Int4(cast).loadValue();
 		Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
@@ -6580,7 +6585,7 @@
 		storeValue(xyzw);
 	}
 
-	Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<SByte4> cast) : XYZW(this)
 	{
 		Value *a = Int4(cast).loadValue();
 		Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
@@ -6588,26 +6593,26 @@
 		storeValue(xyzw);
 	}
 
-	Float4::Float4(RValue<Short4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<Short4> cast) : XYZW(this)
 	{
 		Int4 c(cast);
 		storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
 	}
 
-	Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<UShort4> cast) : XYZW(this)
 	{
 		Int4 c(cast);
 		storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
 	}
 
-	Float4::Float4(RValue<Int4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<Int4> cast) : XYZW(this)
 	{
 		Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
 
 		storeValue(xyzw);
 	}
 
-	Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this)
+	Float4::Float4(RValue<UInt4> cast) : XYZW(this)
 	{
 		RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
 		                        As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
@@ -6615,26 +6620,26 @@
 		storeValue(result.value);
 	}
 
-	Float4::Float4() : FloatXYZW(this)
+	Float4::Float4() : XYZW(this)
 	{
 	}
 
-	Float4::Float4(float xyzw) : FloatXYZW(this)
+	Float4::Float4(float xyzw) : XYZW(this)
 	{
 		constant(xyzw, xyzw, xyzw, xyzw);
 	}
 
-	Float4::Float4(float x, float yzw) : FloatXYZW(this)
+	Float4::Float4(float x, float yzw) : XYZW(this)
 	{
 		constant(x, yzw, yzw, yzw);
 	}
 
-	Float4::Float4(float x, float y, float zw) : FloatXYZW(this)
+	Float4::Float4(float x, float y, float zw) : XYZW(this)
 	{
 		constant(x, y, zw, zw);
 	}
 
-	Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this)
+	Float4::Float4(float x, float y, float z, float w) : XYZW(this)
 	{
 		constant(x, y, z, w);
 	}
@@ -6645,24 +6650,24 @@
 		storeValue(Nucleus::createConstantVector(constantVector, getType()));
 	}
 
-	Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this)
+	Float4::Float4(RValue<Float4> rhs) : XYZW(this)
 	{
 		storeValue(rhs.value);
 	}
 
-	Float4::Float4(const Float4 &rhs) : FloatXYZW(this)
+	Float4::Float4(const Float4 &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this)
+	Float4::Float4(const Reference<Float4> &rhs) : XYZW(this)
 	{
 		Value *value = rhs.loadValue();
 		storeValue(value);
 	}
 
-	Float4::Float4(RValue<Float> rhs) : FloatXYZW(this)
+	Float4::Float4(RValue<Float> rhs) : XYZW(this)
 	{
 		Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType());
 
@@ -6672,12 +6677,12 @@
 		storeValue(replicate);
 	}
 
-	Float4::Float4(const Float &rhs) : FloatXYZW(this)
+	Float4::Float4(const Float &rhs) : XYZW(this)
 	{
 		*this = RValue<Float>(rhs.loadValue());
 	}
 
-	Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this)
+	Float4::Float4(const Reference<Float> &rhs) : XYZW(this)
 	{
 		*this = RValue<Float>(rhs.loadValue());
 	}
diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp
index 252d744..32e2027 100644
--- a/src/Renderer/Renderer.cpp
+++ b/src/Renderer/Renderer.cpp
@@ -2474,9 +2474,9 @@
 		loadConstants(shader);
 	}
 
-	void Renderer::setPixelShaderConstantF(int index, const float value[4], int count)
+	void Renderer::setPixelShaderConstantF(unsigned int index, const float value[4], unsigned int count)
 	{
-		for(int i = 0; i < DRAW_COUNT; i++)
+		for(unsigned int i = 0; i < DRAW_COUNT; i++)
 		{
 			if(drawCall[i]->psDirtyConstF < index + count)
 			{
@@ -2484,16 +2484,16 @@
 			}
 		}
 
-		for(int i = 0; i < count; i++)
+		for(unsigned int i = 0; i < count; i++)
 		{
 			PixelProcessor::setFloatConstant(index + i, value);
 			value += 4;
 		}
 	}
 
-	void Renderer::setPixelShaderConstantI(int index, const int value[4], int count)
+	void Renderer::setPixelShaderConstantI(unsigned int index, const int value[4], unsigned int count)
 	{
-		for(int i = 0; i < DRAW_COUNT; i++)
+		for(unsigned int i = 0; i < DRAW_COUNT; i++)
 		{
 			if(drawCall[i]->psDirtyConstI < index + count)
 			{
@@ -2501,16 +2501,16 @@
 			}
 		}
 
-		for(int i = 0; i < count; i++)
+		for(unsigned int i = 0; i < count; i++)
 		{
 			PixelProcessor::setIntegerConstant(index + i, value);
 			value += 4;
 		}
 	}
 
-	void Renderer::setPixelShaderConstantB(int index, const int *boolean, int count)
+	void Renderer::setPixelShaderConstantB(unsigned int index, const int *boolean, unsigned int count)
 	{
-		for(int i = 0; i < DRAW_COUNT; i++)
+		for(unsigned int i = 0; i < DRAW_COUNT; i++)
 		{
 			if(drawCall[i]->psDirtyConstB < index + count)
 			{
@@ -2518,16 +2518,16 @@
 			}
 		}
 
-		for(int i = 0; i < count; i++)
+		for(unsigned int i = 0; i < count; i++)
 		{
 			PixelProcessor::setBooleanConstant(index + i, *boolean);
 			boolean++;
 		}
 	}
 
-	void Renderer::setVertexShaderConstantF(int index, const float value[4], int count)
+	void Renderer::setVertexShaderConstantF(unsigned int index, const float value[4], unsigned int count)
 	{
-		for(int i = 0; i < DRAW_COUNT; i++)
+		for(unsigned int i = 0; i < DRAW_COUNT; i++)
 		{
 			if(drawCall[i]->vsDirtyConstF < index + count)
 			{
@@ -2535,16 +2535,16 @@
 			}
 		}
 
-		for(int i = 0; i < count; i++)
+		for(unsigned int i = 0; i < count; i++)
 		{
 			VertexProcessor::setFloatConstant(index + i, value);
 			value += 4;
 		}
 	}
 
-	void Renderer::setVertexShaderConstantI(int index, const int value[4], int count)
+	void Renderer::setVertexShaderConstantI(unsigned int index, const int value[4], unsigned int count)
 	{
-		for(int i = 0; i < DRAW_COUNT; i++)
+		for(unsigned int i = 0; i < DRAW_COUNT; i++)
 		{
 			if(drawCall[i]->vsDirtyConstI < index + count)
 			{
@@ -2552,16 +2552,16 @@
 			}
 		}
 
-		for(int i = 0; i < count; i++)
+		for(unsigned int i = 0; i < count; i++)
 		{
 			VertexProcessor::setIntegerConstant(index + i, value);
 			value += 4;
 		}
 	}
 
-	void Renderer::setVertexShaderConstantB(int index, const int *boolean, int count)
+	void Renderer::setVertexShaderConstantB(unsigned int index, const int *boolean, unsigned int count)
 	{
-		for(int i = 0; i < DRAW_COUNT; i++)
+		for(unsigned int i = 0; i < DRAW_COUNT; i++)
 		{
 			if(drawCall[i]->vsDirtyConstB < index + count)
 			{
@@ -2569,7 +2569,7 @@
 			}
 		}
 
-		for(int i = 0; i < count; i++)
+		for(unsigned int i = 0; i < count; i++)
 		{
 			VertexProcessor::setBooleanConstant(index + i, *boolean);
 			boolean++;
diff --git a/src/Renderer/Renderer.hpp b/src/Renderer/Renderer.hpp
index d796475..e33f828 100644
--- a/src/Renderer/Renderer.hpp
+++ b/src/Renderer/Renderer.hpp
@@ -237,13 +237,13 @@
 		Resource* vUniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
 		Resource* transformFeedbackBuffers[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS];
 
-		int vsDirtyConstF;
-		int vsDirtyConstI;
-		int vsDirtyConstB;
+		unsigned int vsDirtyConstF;
+		unsigned int vsDirtyConstI;
+		unsigned int vsDirtyConstB;
 
-		int psDirtyConstF;
-		int psDirtyConstI;
-		int psDirtyConstB;
+		unsigned int psDirtyConstF;
+		unsigned int psDirtyConstI;
+		unsigned int psDirtyConstB;
 
 		std::list<Query*> *queries;
 
@@ -371,13 +371,13 @@
 		void setPixelShader(const PixelShader *shader);
 		void setVertexShader(const VertexShader *shader);
 
-		void setPixelShaderConstantF(int index, const float value[4], int count = 1);
-		void setPixelShaderConstantI(int index, const int value[4], int count = 1);
-		void setPixelShaderConstantB(int index, const int *boolean, int count = 1);
+		void setPixelShaderConstantF(unsigned int index, const float value[4], unsigned int count = 1);
+		void setPixelShaderConstantI(unsigned int index, const int value[4], unsigned int count = 1);
+		void setPixelShaderConstantB(unsigned int index, const int *boolean, unsigned int count = 1);
 
-		void setVertexShaderConstantF(int index, const float value[4], int count = 1);
-		void setVertexShaderConstantI(int index, const int value[4], int count = 1);
-		void setVertexShaderConstantB(int index, const int *boolean, int count = 1);
+		void setVertexShaderConstantF(unsigned int index, const float value[4], unsigned int count = 1);
+		void setVertexShaderConstantI(unsigned int index, const int value[4], unsigned int count = 1);
+		void setVertexShaderConstantB(unsigned int index, const int *boolean, unsigned int count = 1);
 
 		// Viewport & Clipper
 		void setViewport(const Viewport &viewport);
diff --git a/src/Shader/Constants.cpp b/src/Shader/Constants.cpp
index b7b2fb9..e02ba03 100644
--- a/src/Shader/Constants.cpp
+++ b/src/Shader/Constants.cpp
@@ -247,11 +247,6 @@
 			mask565Q[i][1] =
 			mask565Q[i][2] =
 			mask565Q[i][3] = (i & 0x1 ? 0x001F : 0) | (i & 0x2 ? 0x07E0 : 0) | (i & 0x4 ? 0xF800 : 0);
-
-			invMask565Q[i][0] =
-			invMask565Q[i][1] =
-			invMask565Q[i][2] =
-			invMask565Q[i][3] = ~mask565Q[i][0];
 		}
 
 		for(int i = 0; i < 4; i++)
@@ -261,20 +256,10 @@
 			maskW01Q[i][2] =  -(i >> 0 & 1);
 			maskW01Q[i][3] =  -(i >> 1 & 1);
 
-			invMaskW01Q[i][0] = ~maskW01Q[i][0];
-			invMaskW01Q[i][1] = ~maskW01Q[i][1];
-			invMaskW01Q[i][2] = ~maskW01Q[i][2];
-			invMaskW01Q[i][3] = ~maskW01Q[i][3];
-
 			maskD01X[i][0] =  -(i >> 0 & 1);
 			maskD01X[i][1] =  -(i >> 1 & 1);
 			maskD01X[i][2] =  -(i >> 0 & 1);
 			maskD01X[i][3] =  -(i >> 1 & 1);
-
-			invMaskD01X[i][0] = ~maskD01X[i][0];
-			invMaskD01X[i][1] = ~maskD01X[i][1];
-			invMaskD01X[i][2] = ~maskD01X[i][2];
-			invMaskD01X[i][3] = ~maskD01X[i][3];
 		}
 
 		for(int i = 0; i < 256; i++)
diff --git a/src/Shader/Constants.hpp b/src/Shader/Constants.hpp
index e40ad5e..5210643 100644
--- a/src/Shader/Constants.hpp
+++ b/src/Shader/Constants.hpp
@@ -64,11 +64,8 @@
 		qword2 invMaskQ01X[16];
 		qword2 invMaskQ23X[16];
 		word4 maskW01Q[4];
-		word4 invMaskW01Q[4];
 		dword4 maskD01X[4];
-		dword4 invMaskD01X[4];
 		word4 mask565Q[8];
-		word4 invMask565Q[8];
 
 		unsigned short sRGBtoLinear8_12[256];
 		unsigned short sRGBtoLinear6_12[64];
diff --git a/src/Shader/PixelRoutine.cpp b/src/Shader/PixelRoutine.cpp
index 16e4692..44fafd3 100644
--- a/src/Shader/PixelRoutine.cpp
+++ b/src/Shader/PixelRoutine.cpp
@@ -1573,7 +1573,7 @@
 				{
 					Int masked = value;
 					c01 &= *Pointer<Int>(constants + OFFSET(Constants,mask565Q[bgraWriteMask & 0x7][0]));
-					masked &= *Pointer<Int>(constants + OFFSET(Constants,invMask565Q[bgraWriteMask & 0x7][0]));
+					masked &= *Pointer<Int>(constants + OFFSET(Constants,mask565Q[~bgraWriteMask & 0x7][0]));
 					c01 |= masked;
 				}
 
@@ -1591,7 +1591,7 @@
 				{
 					Int masked = value;
 					c23 &= *Pointer<Int>(constants + OFFSET(Constants,mask565Q[bgraWriteMask & 0x7][0]));
-					masked &= *Pointer<Int>(constants + OFFSET(Constants,invMask565Q[bgraWriteMask & 0x7][0]));
+					masked &= *Pointer<Int>(constants + OFFSET(Constants,mask565Q[~bgraWriteMask & 0x7][0]));
 					c23 |= masked;
 				}
 
@@ -1791,7 +1791,7 @@
 				{
 					Short4 masked = value;
 					current.x &= *Pointer<Short4>(constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0]));
-					masked &= *Pointer<Short4>(constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0]));
+					masked &= *Pointer<Short4>(constants + OFFSET(Constants,maskW01Q[~rgbaWriteMask & 0x3][0]));
 					current.x |= masked;
 				}
 
@@ -1808,7 +1808,7 @@
 				{
 					Short4 masked = value;
 					current.y &= *Pointer<Short4>(constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0]));
-					masked &= *Pointer<Short4>(constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0]));
+					masked &= *Pointer<Short4>(constants + OFFSET(Constants,maskW01Q[~rgbaWriteMask & 0x3][0]));
 					current.y |= masked;
 				}
 
@@ -2389,7 +2389,7 @@
 			{
 				Float4 masked = value;
 				oC.x = As<Float4>(As<Int4>(oC.x) & *Pointer<Int4>(constants + OFFSET(Constants,maskD01X[rgbaWriteMask & 0x3][0])));
-				masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(constants + OFFSET(Constants,invMaskD01X[rgbaWriteMask & 0x3][0])));
+				masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(constants + OFFSET(Constants,maskD01X[~rgbaWriteMask & 0x3][0])));
 				oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked));
 			}
 
@@ -2408,7 +2408,7 @@
 
 				masked = value;
 				oC.y = As<Float4>(As<Int4>(oC.y) & *Pointer<Int4>(constants + OFFSET(Constants,maskD01X[rgbaWriteMask & 0x3][0])));
-				masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(constants + OFFSET(Constants,invMaskD01X[rgbaWriteMask & 0x3][0])));
+				masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(constants + OFFSET(Constants,maskD01X[~rgbaWriteMask & 0x3][0])));
 				oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked));
 			}
 
diff --git a/src/swiftshader.gni b/src/swiftshader.gni
index 253d405..9148762 100644
--- a/src/swiftshader.gni
+++ b/src/swiftshader.gni
@@ -13,19 +13,9 @@
 }
 
 if (is_debug) {
-  # always build release version of SwiftShader for performance reasons
-  configs_to_delete += [
-    "//build/config:debug",
-    "//build/config/compiler:default_optimization",
-  ]
-  configs_to_add += [
-    "//build/config:release",
-    "//build/config/compiler:optimize",
-  ]
-  if (is_win) {
-    configs_to_delete += [ "//build/config/win:default_crt" ]
-    configs_to_add += [ "//build/config/win:release_crt" ]
-  }
+  # always build optimized version of SwiftShader for performance reasons
+  configs_to_delete += [ "//build/config/compiler:default_optimization" ]
+  configs_to_add += [ "//build/config/compiler:optimize" ]
 }
 
 configs_to_delete += [ "//build/config/compiler:chromium_code" ]