Snap for 6877830 from 16dbce711df7ed86dd4f2960af335c461c0d6127 to sdk-release

Change-Id: I84aa10c1578e6da24300aa015c749e4a39fdcd36
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index 86c10c8..1e849fb 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -10,7 +10,7 @@
             ],
             "defines": [
                 "HOST_BUILD",
-                "GOLDFISH_VULKAN"
+                "GFXSTREAM"
             ],
             "macFrameworkPath": [
                 "/System/Library/Frameworks",
@@ -24,4 +24,4 @@
         }
     ],
     "version": 4
-}
\ No newline at end of file
+}
diff --git a/Android.mk b/Android.mk
index 90d028b..c0b270a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -35,7 +35,7 @@
 EMUGL_COMMON_CFLAGS := -DWITH_GLES2
 
 # Whether or not to build the Vulkan library.
-BUILD_EMULATOR_VULKAN := false
+GFXSTREAM := false
 
 # Host build
 ifeq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
@@ -43,7 +43,7 @@
 GOLDFISH_OPENGL_SHOULD_BUILD := true
 GOLDFISH_OPENGL_LIB_SUFFIX := _host
 
-BUILD_EMULATOR_VULKAN := true
+GFXSTREAM := true
 
 # Set modern defaults for the codename, version, etc.
 PLATFORM_VERSION_CODENAME:=Q
@@ -63,7 +63,7 @@
     -DGL_GLEXT_PROTOTYPES \
     -fvisibility=default \
     -DPAGE_SIZE=4096 \
-    -DGOLDFISH_VULKAN \
+    -DGFXSTREAM \
     -Wno-unused-parameter
 
 endif # GOLDFISH_OPENGL_BUILD_FOR_HOST
@@ -100,8 +100,8 @@
 endif
 
 ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 27 && echo isApi28OrHigher),isApi28OrHigher)
-    BUILD_EMULATOR_VULKAN := true
-    EMUGL_COMMON_CFLAGS += -DGOLDFISH_VULKAN
+    GFXSTREAM := true
+    EMUGL_COMMON_CFLAGS += -DGFXSTREAM
 endif
 
 # Include common definitions used by all the modules included later
@@ -133,6 +133,11 @@
 include $(GOLDFISH_OPENGL_PATH)/shared/qemupipe/Android.mk
 include $(GOLDFISH_OPENGL_PATH)/shared/gralloc_cb/Android.mk
 include $(GOLDFISH_OPENGL_PATH)/shared/GoldfishAddressSpace/Android.mk
+
+ifeq (true,$(GFXSTREAM)) # android-emu
+    include $(GOLDFISH_OPENGL_PATH)/android-emu/Android.mk
+endif
+
 include $(GOLDFISH_OPENGL_PATH)/shared/OpenglCodecCommon/Android.mk
 
 # Encoder shared libraries
@@ -140,8 +145,7 @@
 include $(GOLDFISH_OPENGL_PATH)/system/GLESv2_enc/Android.mk
 include $(GOLDFISH_OPENGL_PATH)/system/renderControl_enc/Android.mk
 
-ifeq (true,$(BUILD_EMULATOR_VULKAN)) # Vulkan libs
-    include $(GOLDFISH_OPENGL_PATH)/android-emu/Android.mk
+ifeq (true,$(GFXSTREAM)) # Vulkan libs
     include $(GOLDFISH_OPENGL_PATH)/system/vulkan_enc/Android.mk
 endif
 
@@ -159,7 +163,7 @@
 
 include $(GOLDFISH_OPENGL_PATH)/system/egl/Android.mk
 
-ifeq (true,$(BUILD_EMULATOR_VULKAN)) # Vulkan libs
+ifeq (true,$(GFXSTREAM)) # Vulkan libs
     include $(GOLDFISH_OPENGL_PATH)/system/vulkan/Android.mk
 endif
 
diff --git a/BUILD.gn b/BUILD.gn
index 0d08d95..76bf904 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -2,32 +2,32 @@
   sources = [
     "android-emu/android/base/AlignedBuf.cpp",
     "android-emu/android/base/AlignedBuf.h",
-    "android-emu/android/base/Pool.cpp",
-    "android-emu/android/base/Pool.h",
-    "android-emu/android/base/ring_buffer.c",
     "android-emu/android/base/AndroidSubAllocator.cpp",
     "android-emu/android/base/AndroidSubAllocator.h",
+    "android-emu/android/base/Pool.cpp",
+    "android-emu/android/base/Pool.h",
+    "android-emu/android/base/Tracing.cpp",
+    "android-emu/android/base/Tracing.h",
     "android-emu/android/base/files/MemStream.cpp",
     "android-emu/android/base/files/MemStream.h",
     "android-emu/android/base/files/Stream.cpp",
     "android-emu/android/base/files/Stream.h",
     "android-emu/android/base/files/StreamSerializing.cpp",
     "android-emu/android/base/files/StreamSerializing.h",
+    "android-emu/android/base/ring_buffer.c",
     "android-emu/android/base/synchronization/AndroidConditionVariable.h",
     "android-emu/android/base/synchronization/AndroidLock.h",
-    "android-emu/android/base/synchronization/AndroidMessageChannel.h",
     "android-emu/android/base/synchronization/AndroidMessageChannel.cpp",
+    "android-emu/android/base/synchronization/AndroidMessageChannel.h",
+    "android-emu/android/base/threads/AndroidFunctorThread.cpp",
     "android-emu/android/base/threads/AndroidFunctorThread.h",
     "android-emu/android/base/threads/AndroidThread.h",
     "android-emu/android/base/threads/AndroidThreadStore.h",
-    "android-emu/android/base/threads/AndroidThreadTypes.h",
-    "android-emu/android/base/threads/AndroidWorkPool.h",
-    "android-emu/android/base/threads/AndroidFunctorThread.cpp",
     "android-emu/android/base/threads/AndroidThreadStore.h",
+    "android-emu/android/base/threads/AndroidThreadTypes.h",
     "android-emu/android/base/threads/AndroidThread_pthread.cpp",
     "android-emu/android/base/threads/AndroidWorkPool.cpp",
-    "android-emu/android/base/Tracing.cpp",
-    "android-emu/android/base/Tracing.h",
+    "android-emu/android/base/threads/AndroidWorkPool.h",
     "shared/GoldfishAddressSpace/goldfish_address_space.cpp",
     "shared/GoldfishAddressSpace/goldfish_address_space.h",
     "shared/OpenglCodecCommon/ChecksumCalculator.cpp",
@@ -37,8 +37,8 @@
     "shared/OpenglCodecCommon/goldfish_dma.cpp",
     "shared/OpenglCodecCommon/goldfish_dma.h",
     "shared/gralloc_cb/include/gralloc_cb_bp.h",
-    "shared/qemupipe/include/qemu_pipe_bp.h",
     "shared/qemupipe/include-types/qemu_pipe_types_bp.h",
+    "shared/qemupipe/include/qemu_pipe_bp.h",
     "shared/qemupipe/qemu_pipe_common.cpp",
     "shared/qemupipe/qemu_pipe_guest.cpp",
     "system/OpenglSystemCommon/AddressSpaceStream.cpp",
@@ -95,7 +95,7 @@
 
   defines = [
     "LOG_TAG=\"goldfish_vulkan\"",
-    "GOLDFISH_VULKAN",
+    "GFXSTREAM",
     "GOLDFISH_NO_GL",
     "VK_USE_PLATFORM_FUCHSIA",
     "PLATFORM_SDK_VERSION=1",
@@ -116,6 +116,7 @@
     "-Wno-unused-function",
     "-Wno-unused-value",
     "-Wno-unused-variable",
+    "-Wno-conversion",
   ]
 
   ldflags = [ "-static-libstdc++" ]
@@ -131,17 +132,15 @@
 
     include_dirs += [
       "fuchsia/include",
-      "//third_party/Vulkan-Headers/include"
+      "//third_party/Vulkan-Headers/include",
     ]
 
-    libs = [
-      "zircon"
-    ]
+    libs = [ "zircon" ]
 
     deps = [
-      "//sdk/fidl/fuchsia.hardware.goldfish",
+      "//sdk/fidl/fuchsia.hardware.goldfish:fuchsia.hardware.goldfish_llcpp",
       "//sdk/fidl/fuchsia.logger:fuchsia.logger_llcpp",
-      "//sdk/fidl/fuchsia.sysmem",
+      "//sdk/fidl/fuchsia.sysmem:fuchsia.sysmem_llcpp",
       "//zircon/public/lib/zx",
       "//zircon/system/ulib/syslog:syslog-static",
       "//zircon/system/ulib/trace:trace-with-static-engine",
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 80c99c4..d3442ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,15 +2,15 @@
 # instead run make from .../device/generic/goldfish-opengl
 # which will re-generate this file.
 set(GOLDFISH_DEVICE_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
-android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/./Android.mk" "a370ddecca4c7d13811527b2f1f30e2f0ef5153a58edeb36eeb306c41efb9158")
+android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/./Android.mk" "4ef1864208e48039ca8ead2df33a20d5eb6ac512fc456cd2fd701011071c29fe")
 add_subdirectory(shared/qemupipe)
 add_subdirectory(shared/gralloc_cb)
 add_subdirectory(shared/GoldfishAddressSpace)
+add_subdirectory(android-emu)
 add_subdirectory(shared/OpenglCodecCommon)
 add_subdirectory(system/GLESv1_enc)
 add_subdirectory(system/GLESv2_enc)
 add_subdirectory(system/renderControl_enc)
-add_subdirectory(android-emu)
 add_subdirectory(system/vulkan_enc)
 add_subdirectory(system/OpenglSystemCommon)
 add_subdirectory(system/GLESv1)
diff --git a/android-emu/CMakeLists.txt b/android-emu/CMakeLists.txt
index cfdf39b..74d5e46 100644
--- a/android-emu/CMakeLists.txt
+++ b/android-emu/CMakeLists.txt
@@ -5,6 +5,6 @@
 set(androidemu_src android/base/AlignedBuf.cpp android/base/files/MemStream.cpp android/base/files/Stream.cpp android/base/files/StreamSerializing.cpp android/base/Pool.cpp android/base/ring_buffer.c android/base/StringFormat.cpp android/base/AndroidSubAllocator.cpp android/base/synchronization/AndroidMessageChannel.cpp android/base/threads/AndroidFunctorThread.cpp android/base/threads/AndroidThreadStore.cpp android/base/threads/AndroidThread_pthread.cpp android/base/threads/AndroidWorkPool.cpp android/base/Tracing.cpp android/utils/debug.c)
 android_add_library(TARGET androidemu SHARED LICENSE Apache-2.0 SRC android/base/AlignedBuf.cpp android/base/files/MemStream.cpp android/base/files/Stream.cpp android/base/files/StreamSerializing.cpp android/base/Pool.cpp android/base/ring_buffer.c android/base/StringFormat.cpp android/base/AndroidSubAllocator.cpp android/base/synchronization/AndroidMessageChannel.cpp android/base/threads/AndroidFunctorThread.cpp android/base/threads/AndroidThreadStore.cpp android/base/threads/AndroidThread_pthread.cpp android/base/threads/AndroidWorkPool.cpp android/base/Tracing.cpp android/utils/debug.c)
 target_include_directories(androidemu PRIVATE ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(androidemu PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"androidemu\"")
+target_compile_definitions(androidemu PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"androidemu\"")
 target_compile_options(androidemu PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-fstrict-aliasing")
-target_link_libraries(androidemu PRIVATE cutils utils log OpenglCodecCommon_host android-emu-shared PRIVATE qemupipe_host)
\ No newline at end of file
+target_link_libraries(androidemu PRIVATE cutils utils log android-emu-shared)
\ No newline at end of file
diff --git a/android-emu/android/base/Tracing.cpp b/android-emu/android/base/Tracing.cpp
index a4c097f..5909042 100644
--- a/android-emu/android/base/Tracing.cpp
+++ b/android-emu/android/base/Tracing.cpp
@@ -16,6 +16,8 @@
 
 #if defined(__ANDROID__) || defined(HOST_BUILD)
 
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+
 #include <cutils/trace.h>
 
 #define VK_TRACE_TAG ATRACE_TAG_GRAPHICS
diff --git a/android-emu/android/base/containers/EntityManager.h b/android-emu/android/base/containers/EntityManager.h
new file mode 100644
index 0000000..e01496f
--- /dev/null
+++ b/android-emu/android/base/containers/EntityManager.h
@@ -0,0 +1,585 @@
+// Copyright (C) 2019 The Android Open Source Project
+//
+// 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.
+#pragma once
+
+#include "android/base/containers/Lookup.h"
+#include "android/base/Optional.h"
+
+#include <functional>
+#include <unordered_map>
+#include <vector>
+
+#include <inttypes.h>
+#include <stdio.h>
+
+#define ENTITY_MANAGER_DEBUG 0
+
+#if ENTITY_MANAGER_DEBUG
+
+#define EM_DBG(fmt,...) fprintf(stderr, "%s:%d " fmt "\n", __func__, __LINE__, ##__VA_ARGS__);
+
+#else
+#define EM_DBG(...)
+#endif
+
+#define INVALID_ENTITY_HANDLE 0
+#define INVALID_COMPONENT_HANDLE 0
+
+namespace android {
+namespace base {
+
+// EntityManager: A way to represent an abstrat space of objects with handles.
+// Each handle is associated with data of type Item for quick access from handles to data.
+// Otherwise, entity data is spread through ComponentManagers.
+template<size_t indexBits,
+         size_t generationBits,
+         size_t typeBits,
+         class Item>
+class EntityManager {
+public:
+
+    static_assert(indexBits == 64 - generationBits - typeBits,
+                  "bits of index, generation, and type must add to 64");
+
+    // https://stackoverflow.com/questions/45225925/create-bitmask-based-on-a-pattern-as-constexpr
+    // There is another answer based on a function that returns constexpr but
+    // it doesn't actually fold to a constant when given a constant argument,
+    // according to godbolt.
+    template<class T, int count> struct bit_repeater;
+    template<class T>
+    struct bit_repeater<T, 1> {
+        static constexpr T value = 0x1;
+    };
+    template<class T, int count>
+    struct bit_repeater {
+        static constexpr T value = (bit_repeater<T, count-1>::value << 1) | 0x1;
+    };
+
+    static constexpr uint64_t indexMaskBase = bit_repeater<uint64_t, indexBits>().value;
+    static constexpr uint64_t generationMaskBase = bit_repeater<uint64_t, generationBits>().value;
+    static constexpr uint64_t typeMaskBase = bit_repeater<uint64_t, typeBits>().value;
+
+    static constexpr uint64_t indexMask = indexMaskBase;
+    static constexpr uint64_t generationMask = generationMaskBase << indexBits;
+    static constexpr uint64_t typeMask = typeMaskBase << (indexBits + generationBits);
+
+    using EntityHandle = uint64_t;
+    using IteratorFunc = std::function<void(bool live, EntityHandle h, Item& item)>;
+    using ConstIteratorFunc = std::function<void(bool live, EntityHandle h, const Item& item)>;
+
+    static size_t getHandleIndex(EntityHandle h) {
+        return static_cast<size_t>(h & indexMask);
+    }
+
+    static size_t getHandleGeneration(EntityHandle h) {
+        return static_cast<size_t>((h & generationMask) >> indexBits);
+    }
+
+    static size_t getHandleType(EntityHandle h) {
+        return static_cast<size_t>((h & typeMask) >> (indexBits + generationBits));
+    }
+
+    static EntityHandle makeHandle(
+        size_t index,
+        size_t generation,
+        size_t type) {
+        EntityHandle res = (index & indexMask);
+        res |= (((uint64_t)generation) << indexBits) & generationMask;
+        res |= (((uint64_t)type) << (indexBits + generationBits)) & typeMask;
+        return res;
+    }
+
+    static EntityHandle withIndex(EntityHandle h, size_t i) {
+        return makeHandle(i, getHandleGeneration(h), getHandleType(h));
+    }
+
+    static EntityHandle withGeneration(EntityHandle h, size_t nextGen) {
+        return makeHandle(getHandleIndex(h), nextGen, getHandleType(h));
+    }
+
+    static EntityHandle withType(EntityHandle h, size_t newType) {
+        return makeHandle(getHandleIndex(h), getHandleGeneration(h), newType);
+    }
+
+    EntityManager() : EntityManager(0) { }
+
+    ~EntityManager() { clear(); }
+
+    struct EntityEntry {
+        EntityHandle handle = 0;
+        size_t nextFreeIndex = 0;
+        // 0 is a special generation for brand new entries
+        // that are not used yet
+        size_t liveGeneration = 1;
+        Item item;
+    };
+
+    void clear() {
+        mEntries.clear();
+        mFirstFreeIndex = 0;
+        mLiveEntries = 0;
+    }
+
+    EntityHandle add(const Item& item, size_t type) {
+
+        if (!type) return INVALID_ENTITY_HANDLE;
+
+        uint64_t maxElements = (1ULL << indexBits);
+        if (mLiveEntries == maxElements) return INVALID_ENTITY_HANDLE;
+
+        uint64_t newIndex = mFirstFreeIndex;
+
+        EM_DBG("newIndex/firstFree: %zu type: %zu", newIndex, type);
+
+        uint64_t neededCapacity = newIndex + 1;
+        if (maxElements < neededCapacity) return INVALID_ENTITY_HANDLE;
+
+        uint64_t currentCapacity = mEntries.size();
+        uint64_t nextCapacity = neededCapacity << 1;
+        if (nextCapacity > maxElements) nextCapacity = maxElements;
+
+        EM_DBG("needed/current/next capacity: %zu %zu %zu",
+               neededCapacity,
+               currentCapacity,
+               nextCapacity);
+
+        if (neededCapacity > mEntries.size()) {
+            mEntries.resize((size_t)nextCapacity);
+            for (size_t i = currentCapacity; i < nextCapacity; ++i) {
+                mEntries[i].handle = makeHandle(i, 0, type);
+                mEntries[i].nextFreeIndex = i + 1;
+                EM_DBG("new un-init entry: index %zu nextFree %zu",
+                       i, i + 1);
+            }
+        }
+
+        mEntries[newIndex].handle =
+            makeHandle(newIndex, mEntries[newIndex].liveGeneration, type);
+        mEntries[newIndex].item = item;
+
+        mFirstFreeIndex = mEntries[newIndex].nextFreeIndex;
+        EM_DBG("created. new first free: %zu", mFirstFreeIndex);
+
+        ++mLiveEntries;
+
+        EM_DBG("result handle: 0x%llx", (unsigned long long)mEntries[newIndex].handle);
+
+        return mEntries[newIndex].handle;
+    }
+
+    EntityHandle addFixed(EntityHandle fixedHandle, const Item& item, size_t type) {
+        // 3 cases:
+        // 1. handle is not allocated and doesn't correspond to mFirstFreeIndex
+        bool isFreeListNonHead = false;
+        // 2. handle already exists (replace)
+        bool isAlloced = false;
+        // 3. index(handle) == mFirstFreeIndex
+        bool isFreeListHead = false;
+
+        if (!type) return INVALID_ENTITY_HANDLE;
+
+        uint64_t maxElements = (1ULL << indexBits);
+        if (mLiveEntries == maxElements) return INVALID_ENTITY_HANDLE;
+
+        uint64_t newIndex = getHandleIndex(fixedHandle);
+
+        EM_DBG("newIndex/firstFree: %zu type: %zu", newIndex, type);
+
+        uint64_t neededCapacity = newIndex + 1;
+
+        if (maxElements < neededCapacity) return INVALID_ENTITY_HANDLE;
+
+        uint64_t currentCapacity = mEntries.size();
+        uint64_t nextCapacity = neededCapacity << 1;
+        if (nextCapacity > maxElements) nextCapacity = maxElements;
+
+        EM_DBG("needed/current/next capacity: %zu %zu %zu",
+               neededCapacity,
+               currentCapacity,
+               nextCapacity);
+
+        if (neededCapacity > mEntries.size()) {
+            mEntries.resize((size_t)nextCapacity);
+            for (size_t i = currentCapacity; i < nextCapacity; ++i) {
+                mEntries[i].handle = makeHandle(i, 0, type);
+                mEntries[i].nextFreeIndex = i + 1;
+                EM_DBG("new un-init entry: index %zu nextFree %zu",
+                       i, i + 1);
+            }
+        }
+
+        // Now we ensured that there is enough space to talk about the entry of
+        // this |fixedHandle|.
+        if (mFirstFreeIndex == newIndex) {
+            isFreeListHead = true;
+        } else {
+            auto& entry = mEntries[newIndex];
+            if (entry.liveGeneration == getHandleGeneration(entry.handle)) {
+                isAlloced = true;
+            } else {
+                isFreeListNonHead = true;
+            }
+        }
+
+        mEntries[newIndex].handle = fixedHandle;
+        mEntries[newIndex].liveGeneration = getHandleGeneration(fixedHandle);
+        mEntries[newIndex].item = item;
+
+        EM_DBG("new index: %zu", newIndex);
+
+        if (isFreeListHead) {
+
+            EM_DBG("first free index reset from %zu to %zu",
+                    mFirstFreeIndex, mEntries[newIndex].nextFreeIndex);
+
+            mFirstFreeIndex = mEntries[newIndex].nextFreeIndex;
+
+            ++mLiveEntries;
+
+        } else if (isAlloced) {
+            // Already replaced whatever is there, and since it's already allocated,
+            // no need to update freelist.
+            EM_DBG("entry at %zu already alloced. replacing.", newIndex);
+        } else if (isFreeListNonHead) {
+            // Go through the freelist and skip over the entry we just added.
+            uint64_t prevEntryIndex = mFirstFreeIndex;
+
+            EM_DBG("in free list but not head. reorganizing freelist. "
+                   "start at %zu -> %zu",
+                   mFirstFreeIndex, mEntries[prevEntryIndex].nextFreeIndex);
+
+            while (mEntries[prevEntryIndex].nextFreeIndex != newIndex) {
+                EM_DBG("next: %zu -> %zu",
+                       prevEntryIndex,
+                       mEntries[prevEntryIndex].nextFreeIndex);
+                prevEntryIndex =
+                    mEntries[prevEntryIndex].nextFreeIndex;
+            }
+
+            EM_DBG("finished. set prev entry %zu to new entry's next, %zu",
+                    prevEntryIndex, mEntries[newIndex].nextFreeIndex);
+
+            mEntries[prevEntryIndex].nextFreeIndex =
+                mEntries[newIndex].nextFreeIndex;
+
+            ++mLiveEntries;
+        }
+
+        return fixedHandle;
+    }
+    void remove(EntityHandle h) {
+
+        if (get(h) == nullptr) return;
+
+        uint64_t index = getHandleIndex(h);
+
+        EM_DBG("remove handle: 0x%llx -> index %zu", (unsigned long long)h, index);
+
+        auto& entry = mEntries[index];
+
+        EM_DBG("handle gen: %zu entry gen: %zu", getHandleGeneration(h), entry.liveGeneration);
+
+        ++entry.liveGeneration;
+        if ((entry.liveGeneration == 0) ||
+            (entry.liveGeneration == (1ULL << generationBits))) {
+            entry.liveGeneration = 1;
+        }
+
+        entry.nextFreeIndex = mFirstFreeIndex;
+
+        mFirstFreeIndex = index;
+
+        EM_DBG("new first free: %zu next free: %zu", mFirstFreeIndex, entry.nextFreeIndex);
+
+        --mLiveEntries;
+    }
+
+    Item* get(EntityHandle h) {
+        uint64_t index = getHandleIndex(h);
+        if (index >= mEntries.size()) return nullptr;
+
+        auto& entry = mEntries[index];
+        if (entry.liveGeneration != getHandleGeneration(h)) return nullptr;
+
+        return &entry.item;
+    }
+
+    bool isLive(EntityHandle h) const {
+        uint64_t index = getHandleIndex(h);
+        if (index >= mEntries.size()) return false;
+
+        const auto& entry = mEntries[index];
+
+        return (entry.liveGeneration == getHandleGeneration(h));
+    }
+
+    void forEachEntry(IteratorFunc func) {
+        for (auto& entry: mEntries) {
+            auto handle = entry.handle;
+            bool live = isLive(handle);
+            auto& item = entry.item;
+            func(live, handle, item);
+        }
+    }
+
+    void forEachLiveEntry(IteratorFunc func) {
+        for (auto& entry: mEntries) {
+            auto handle = entry.handle;
+            bool live = isLive(handle);
+
+            if (!live) continue;
+
+            auto& item = entry.item;
+            func(live, handle, item);
+        }
+    }
+
+    void forEachLiveEntry_const(ConstIteratorFunc func) const {
+        for (auto& entry: mEntries) {
+            auto handle = entry.handle;
+            bool live = isLive(handle);
+
+            if (!live) continue;
+
+            const auto& item = entry.item;
+            func(live, handle, item);
+        }
+    }
+
+private:
+    EntityManager(size_t initialItems) :
+        mEntries(initialItems),
+        mFirstFreeIndex(0),
+        mLiveEntries(0) { }
+
+    std::vector<EntityEntry> mEntries;
+    uint64_t mFirstFreeIndex;
+    uint64_t mLiveEntries;
+};
+
+// Tracks components over a given space of entities.
+// Looking up by entity index is slower, but takes less space overall versus
+// a flat array that parallels the entities.
+template<size_t indexBits,
+         size_t generationBits,
+         size_t typeBits,
+         class Data>
+class ComponentManager {
+public:
+
+    static_assert(64 == (indexBits + generationBits + typeBits),
+                  "bits of index, generation, and type must add to 64");
+
+    using ComponentHandle = uint64_t;
+    using EntityHandle = uint64_t;
+    using ComponentIteratorFunc = std::function<void(bool, ComponentHandle componentHandle, EntityHandle entityHandle, Data& data)>;
+    using ConstComponentIteratorFunc = std::function<void(bool, ComponentHandle componentHandle, EntityHandle entityHandle, const Data& data)>;
+
+    // Adds the given |data| and associates it with EntityHandle.
+    // We can also opt-in to immediately tracking the handle in the reverse mapping,
+    // which has an upfront cost in runtime.
+    // Many uses of ComponentManager don't really need to track the associated entity handle,
+    // so it is opt-in.
+
+    ComponentHandle add(
+        EntityHandle h,
+        const Data& data,
+        size_t type,
+        bool tracked = false) {
+
+        InternalItem item = { h, data, tracked };
+        auto res = static_cast<ComponentHandle>(mData.add(item, type));
+
+        if (tracked) {
+            mEntityToComponentMap[h] = res;
+        }
+
+        return res;
+    }
+
+    void clear() {
+        mData.clear();
+        mEntityToComponentMap.clear();
+    }
+
+    // If we didn't explicitly track, just fail.
+    ComponentHandle getComponentHandle(EntityHandle h) const {
+        auto componentHandlePtr = android::base::find(mEntityToComponentMap, h);
+        if (!componentHandlePtr) return INVALID_COMPONENT_HANDLE;
+        return *componentHandlePtr;
+    }
+
+    EntityHandle getEntityHandle(ComponentHandle h) const {
+        return mData.get(h)->entityHandle;
+    }
+
+    void removeByEntity(EntityHandle h) {
+        auto componentHandle = getComponentHandle(h);
+        removeByComponent(componentHandle);
+    }
+
+    void removeByComponent(ComponentHandle h) {
+        auto item = mData.get(h);
+
+        if (!item) return;
+        if (item->tracked) {
+            mEntityToComponentMap.erase(item->entityHandle);
+        }
+
+        mData.remove(h);
+    }
+
+    Data* getByEntity(EntityHandle h) {
+        return getByComponent(getComponentHandle(h));
+    }
+
+    Data* getByComponent(ComponentHandle h) {
+        auto item = mData.get(h);
+        if (!item) return nullptr;
+        return &(item->data);
+    }
+
+    void forEachComponent(ComponentIteratorFunc func) {
+        mData.forEachEntry(
+            [func](bool live, typename InternalEntityManager::EntityHandle componentHandle, InternalItem& item) {
+                func(live, componentHandle, item.entityHandle, item.data);
+        });
+    }
+
+    void forEachLiveComponent(ComponentIteratorFunc func) {
+        mData.forEachLiveEntry(
+            [func](bool live, typename InternalEntityManager::EntityHandle componentHandle, InternalItem& item) {
+                func(live, componentHandle, item.entityHandle, item.data);
+        });
+    }
+
+    void forEachLiveComponent_const(ConstComponentIteratorFunc func) const {
+        mData.forEachLiveEntry_const(
+            [func](bool live, typename InternalEntityManager::EntityHandle componentHandle, const InternalItem& item) {
+                func(live, componentHandle, item.entityHandle, item.data);
+        });
+    }
+
+private:
+    struct InternalItem {
+        EntityHandle entityHandle;
+        Data data;
+        bool tracked;
+    };
+
+    using InternalEntityManager = EntityManager<indexBits, generationBits, typeBits, InternalItem>;
+    using EntityToComponentMap = std::unordered_map<EntityHandle, ComponentHandle>;
+
+    mutable InternalEntityManager mData;
+    EntityToComponentMap mEntityToComponentMap;
+};
+
+// ComponentManager, but unpacked; uses the same index space as the associated
+// entities. Takes more space by default, but not more if all entities have this component.
+template<size_t indexBits,
+         size_t generationBits,
+         size_t typeBits,
+         class Data>
+class UnpackedComponentManager {
+public:
+    using ComponentHandle = uint64_t;
+    using EntityHandle = uint64_t;
+    using ComponentIteratorFunc =
+        std::function<void(bool, ComponentHandle componentHandle, EntityHandle entityHandle, Data& data)>;
+    using ConstComponentIteratorFunc =
+        std::function<void(bool, ComponentHandle componentHandle, EntityHandle entityHandle, const Data& data)>;
+
+    EntityHandle add(EntityHandle h, const Data& data) {
+
+        size_t index = indexOfEntity(h);
+
+        if (index + 1 > mItems.size()) {
+            mItems.resize((index + 1) * 2);
+        }
+
+        mItems[index].live = true;
+        mItems[index].handle = h;
+        mItems[index].data = data;
+
+        return h;
+    }
+
+    void clear() {
+        mItems.clear();
+    }
+
+    void remove(EntityHandle h) {
+        size_t index = indexOfEntity(h);
+        if (index >= mItems.size()) return;
+        mItems[index].live = false;
+    }
+
+    Data* get(EntityHandle h) {
+        size_t index = indexOfEntity(h);
+
+        if (index + 1 > mItems.size()) {
+            mItems.resize((index + 1) * 2);
+        }
+
+        auto item = mItems.data() + index;
+        if (!item->live) return nullptr;
+        return &item->data;
+    }
+
+    const Data* get_const(EntityHandle h) const {
+        size_t index = indexOfEntity(h);
+
+        if (index + 1 > mItems.size()) {
+            return nullptr;
+        }
+
+        auto item = mItems.data() + index;
+        if (!item->live) return nullptr;
+        return &item->data;
+    }
+
+    void forEachComponent(ComponentIteratorFunc func) {
+        for (auto& item : mItems) {
+            func(item.live, item.handle, item.handle, item.data);
+        }
+    }
+
+    void forEachLiveComponent(ComponentIteratorFunc func) {
+        for (auto& item : mItems) {
+            if (item.live) func(item.live, item.handle, item.handle, item.data);
+        }
+    }
+
+    void forEachLiveComponent_const(ConstComponentIteratorFunc func) const {
+        for (auto& item : mItems) {
+            if (item.live) func(item.live, item.handle, item.handle, item.data);
+        }
+    }
+
+private:
+    static size_t indexOfEntity(EntityHandle h) {
+        return EntityManager<indexBits, generationBits, typeBits, int>::getHandleIndex(h);
+    }
+
+    struct InternalItem {
+        bool live = false;
+        EntityHandle handle = 0;
+        Data data;
+    };
+
+    std::vector<InternalItem> mItems;
+};
+
+} // namespace android
+} // namespace base
diff --git a/android-emu/android/base/containers/HybridComponentManager.h b/android-emu/android/base/containers/HybridComponentManager.h
new file mode 100644
index 0000000..02c6224
--- /dev/null
+++ b/android-emu/android/base/containers/HybridComponentManager.h
@@ -0,0 +1,132 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// 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.
+#pragma once
+
+#include "android/base/containers/Lookup.h"
+#include "android/base/containers/EntityManager.h"
+
+#include <unordered_map>
+
+namespace android {
+namespace base {
+
+template <size_t maxIndex,
+          class IndexType, // must be castable to uint64_t
+          class Data>
+class HybridComponentManager {
+public:
+    using UCM = UnpackedComponentManager<32, 16, 16, Data>;
+    using EM = EntityManager<32, 16, 16, Data>;
+    using IterFunc = typename UCM::ComponentIteratorFunc;
+    using ConstIterFunc = typename UCM::ConstComponentIteratorFunc;
+    using Handle = typename EM::EntityHandle;
+
+    void add(IndexType index, const Data& data) {
+        uint64_t index_u64 = (uint64_t)index;
+        if (index_u64 < maxIndex) {
+            auto internal_handle = index2Handle(index_u64);
+            mComponentManager.add(internal_handle, data);
+        } else {
+            mMap[index] = data;
+        }
+
+    }
+
+    void clear() {
+        mComponentManager.clear();
+        mMap.clear();
+    }
+
+    void remove(IndexType index) {
+        uint64_t index_u64 = (uint64_t)index;
+        if (index_u64 < maxIndex) {
+            auto internal_handle = index2Handle(index_u64);
+            mComponentManager.remove(internal_handle);
+        } else {
+            mMap.erase(index);
+        }
+    }
+
+    Data* get(IndexType index) {
+        uint64_t index_u64 = (uint64_t)index;
+        if (index_u64 < maxIndex) {
+            auto internal_handle = index2Handle(index_u64);
+            return mComponentManager.get(internal_handle);
+        } else {
+            return android::base::find(mMap, index);
+        }
+    }
+
+    const Data* get_const(IndexType index) const {
+        uint64_t index_u64 = (uint64_t)index;
+        if (index_u64 < maxIndex) {
+            auto internal_handle = index2Handle(index_u64);
+            return mComponentManager.get_const(internal_handle);
+        } else {
+            return android::base::find(mMap, index);
+        }
+    }
+
+    Data* getExceptZero(IndexType index) {
+        Data* res = get(index);
+        if (!res) return nullptr;
+        if (!(*res)) return nullptr;
+        return res;
+    }
+
+    const Data* getExceptZero_const(IndexType index) const {
+        const Data* res = get_const(index);
+        if (!res) return nullptr;
+        if (!(*res)) return nullptr;
+        return res;
+    }
+
+    void forEach(IterFunc func) {
+        mComponentManager.forEach(func);
+
+        for (auto it : mMap) {
+            auto handle = index2Handle(it.first);
+            func(true /* live */, handle, handle, it.second);
+        }
+    }
+
+    void forEachLive(IterFunc func) {
+        mComponentManager.forEachLiveComponent(func);
+
+        for (auto it : mMap) {
+            auto handle = index2Handle(it.first);
+            func(true /* live */, handle, handle, it.second);
+        }
+    }
+
+    void forEachLive_const(ConstIterFunc func) const {
+        mComponentManager.forEachLiveComponent_const(func);
+
+        for (const auto it : mMap) {
+            auto handle = index2Handle(it.first);
+            func(true /* live */, handle, handle, it.second);
+        }
+    }
+
+private:
+    static Handle index2Handle(uint64_t index) {
+        return EM::makeHandle((uint32_t)index, 1, 1);
+    }
+
+    UCM mComponentManager;
+    std::unordered_map<IndexType, Data> mMap;
+};
+
+} // namespace android
+} // namespace base
diff --git a/android-emu/android/base/containers/Lookup.h b/android-emu/android/base/containers/Lookup.h
new file mode 100644
index 0000000..8043286
--- /dev/null
+++ b/android-emu/android/base/containers/Lookup.h
@@ -0,0 +1,168 @@
+// Copyright 2016 The Android Open Source Project
+//
+// This software is licensed under the terms of the GNU General Public
+// License version 2, as published by the Free Software Foundation, and
+// may be copied, distributed, and modified under those terms.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+#pragma once
+
+#include "android/base/TypeTraits.h"
+
+#include <initializer_list>
+#include <set>
+#include <map>
+#include <unordered_map>
+#include <unordered_set>
+#include <utility>
+
+// A set of convenience functions for map and set lookups. They allow a simpler
+// syntax, e.g.
+//   if (auto val = find(map, "key")) {
+//       <process the value>
+//   }
+// ... or
+//   auto value = find(funcThatReturnsMap(), "other_key");
+//   if (!value) ...
+//
+// Note: these don't work for multimaps, as there's no single value
+//  to return (and, more importantly, as those are completely useless).
+
+namespace android {
+namespace base {
+
+// Helper predicates that check if the template argument is a map / set /
+// a mutlikey collection of any kind.
+// These are used as a constraints for the lookup functions to get better error
+// messages if the arguments don't support the map interface.
+template <class T>
+using is_any_map = std::integral_constant<
+        bool,
+        is_template_instantiation_of<T, std::map>::value ||
+                is_template_instantiation_of<T, std::unordered_map>::value>;
+
+template <class T>
+using is_any_set = std::integral_constant<
+        bool,
+        is_template_instantiation_of<T, std::set>::value ||
+                is_template_instantiation_of<T, std::unordered_set>::value>;
+
+template <class T>
+using is_any_multikey = std::integral_constant<
+        bool,
+        is_template_instantiation_of<T, std::multimap>::value ||
+                is_template_instantiation_of<T, std::unordered_multimap>::value ||
+                is_template_instantiation_of<T, std::multiset>::value ||
+                is_template_instantiation_of<T, std::unordered_multiset>::value>;
+
+template <class T, class = enable_if<is_any_map<T>>>
+const typename T::mapped_type* find(const T& map,
+                                    const typename T::key_type& key) {
+    const auto it = map.find(key);
+    if (it == map.end()) {
+        return nullptr;
+    }
+
+    return &it->second;
+}
+
+// Version that returns a modifiable value.
+template <class T, class = enable_if<is_any_map<T>>>
+typename T::mapped_type* find(T& map, const typename T::key_type& key) {
+    auto it = map.find(key);
+    if (it == map.end()) {
+        return nullptr;
+    }
+
+    return &it->second;
+}
+
+// Version with a default, returns a _copy_ because of the possible fallback
+// to a default - it might be destroyed after the call.
+template <class T,
+          class U = typename T::mapped_type,
+          class = enable_if_c<
+                  is_any_map<T>::value &&
+                  std::is_convertible<U, typename T::mapped_type>::value>>
+typename T::mapped_type findOrDefault(const T& map,
+                                      const typename T::key_type& key,
+                                      U&& defaultVal = {}) {
+    if (auto valPtr = find(map, key)) {
+        return *valPtr;
+    }
+    return defaultVal;
+}
+
+// Version that finds the first of the values passed in |keys| in the order they
+// are passed. E.g., the following code finds '2' as the first value in |keys|:
+//   set<int> s = {1, 2, 3};
+//   auto val = findFirstOf(s, {2, 1});
+//   EXPECT_EQ(2, *val);
+template <class T, class = enable_if<is_any_map<T>>>
+const typename T::mapped_type* findFirstOf(
+        const T& map,
+        std::initializer_list<typename T::key_type> keys) {
+    for (const auto& key : keys) {
+        if (const auto valPtr = find(map, key)) {
+            return valPtr;
+        }
+    }
+    return nullptr;
+}
+
+template <class T, class = enable_if<is_any_map<T>>>
+typename T::mapped_type* findFirstOf(
+        T& map,
+        std::initializer_list<typename T::key_type> keys) {
+    for (const auto& key : keys) {
+        if (const auto valPtr = find(map, key)) {
+            return valPtr;
+        }
+    }
+    return nullptr;
+}
+
+// Version that finds first of the passed |key| values or returns the
+// |defaultVal| if none were found.
+template <class T,
+          class U,
+          class = enable_if_c<
+                  is_any_map<T>::value &&
+                  std::is_convertible<U, typename T::mapped_type>::value>>
+typename T::mapped_type findFirstOfOrDefault(
+        const T& map,
+        std::initializer_list<typename T::key_type> keys,
+        U&& defaultVal) {
+    if (const auto valPtr = findFirstOf(map, keys)) {
+        return *valPtr;
+    }
+    return std::forward<U>(defaultVal);
+}
+
+template <class T,
+          class = enable_if_c<is_any_map<T>::value || is_any_set<T>::value ||
+                              is_any_multikey<T>::value>>
+bool contains(const T& c, const typename T::key_type& key) {
+    const auto it = c.find(key);
+    return it != c.end();
+}
+
+template <class T,
+          class = enable_if_c<is_any_map<T>::value || is_any_set<T>::value ||
+                              is_any_multikey<T>::value>>
+bool containsAnyOf(const T& c,
+                   std::initializer_list<typename T::key_type> keys) {
+    for (const auto& key : keys) {
+        if (contains(c, key)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+}  // namespace base
+}  // namespace android
diff --git a/host/include/libOpenglRender/IOStream.h b/host/include/libOpenglRender/IOStream.h
index 9173d31..c7cc0ea 100644
--- a/host/include/libOpenglRender/IOStream.h
+++ b/host/include/libOpenglRender/IOStream.h
@@ -17,6 +17,7 @@
 #define __IO_STREAM_H__
 
 #include <stdlib.h>
+#include <stdint.h>
 #include <stdio.h>
 
 #include "ErrorLog.h"
@@ -28,6 +29,19 @@
         m_iostreamBuf = NULL;
         m_bufsize = bufSize;
         m_free = 0;
+        m_refcount = 1;
+    }
+
+    void incRef() {
+        __atomic_add_fetch(&m_refcount, 1, __ATOMIC_SEQ_CST);
+    }
+
+    bool decRef() {
+        if (0 == __atomic_sub_fetch(&m_refcount, 1, __ATOMIC_SEQ_CST)) {
+            delete this;
+            return true;
+        }
+        return false;
     }
 
     virtual size_t idealAllocSize(size_t len) {
@@ -104,6 +118,7 @@
     unsigned char *m_iostreamBuf;
     size_t m_bufsize;
     size_t m_free;
+    uint32_t m_refcount;
 };
 
 //
diff --git a/shared/GoldfishAddressSpace/CMakeLists.txt b/shared/GoldfishAddressSpace/CMakeLists.txt
index c89a436..b14bdfe 100644
--- a/shared/GoldfishAddressSpace/CMakeLists.txt
+++ b/shared/GoldfishAddressSpace/CMakeLists.txt
@@ -5,6 +5,6 @@
 set(GoldfishAddressSpace_host_src goldfish_address_space.cpp)
 android_add_library(TARGET GoldfishAddressSpace_host LICENSE Apache-2.0 SRC goldfish_address_space.cpp)
 target_include_directories(GoldfishAddressSpace_host PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(GoldfishAddressSpace_host PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"goldfish-address-space\"")
+target_compile_definitions(GoldfishAddressSpace_host PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"goldfish-address-space\"")
 target_compile_options(GoldfishAddressSpace_host PRIVATE "-fvisibility=default" "-Wno-unused-parameter")
 target_link_libraries(GoldfishAddressSpace_host PRIVATE log android-emu-shared)
\ No newline at end of file
diff --git a/shared/GoldfishAddressSpace/include/goldfish_address_space.h b/shared/GoldfishAddressSpace/include/goldfish_address_space.h
index ad5e3cb..1d2e14b 100644
--- a/shared/GoldfishAddressSpace/include/goldfish_address_space.h
+++ b/shared/GoldfishAddressSpace/include/goldfish_address_space.h
@@ -19,7 +19,7 @@
 #include <stddef.h>
 
 #ifdef __Fuchsia__
-#include <fuchsia/hardware/goldfish/cpp/fidl.h>
+#include <fuchsia/hardware/goldfish/llcpp/fidl.h>
 #endif
 
 class GoldfishAddressSpaceBlock;
@@ -67,8 +67,12 @@
     static void closeHandle(address_space_handle_t handle);
 
 #ifdef __Fuchsia__
-    fuchsia::hardware::goldfish::AddressSpaceDeviceSyncPtr m_device;
-    fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr m_child_driver;
+    std::unique_ptr<
+        llcpp::fuchsia::hardware::goldfish::AddressSpaceDevice::SyncClient>
+        m_device;
+    std::unique_ptr<
+        llcpp::fuchsia::hardware::goldfish::AddressSpaceChildDriver::SyncClient>
+        m_child_driver;
 #else // __Fuchsia__
     address_space_handle_t m_handle;
 #endif // !__Fuchsia__
@@ -100,7 +104,8 @@
     GoldfishAddressSpaceBlock &operator=(const GoldfishAddressSpaceBlock &);
 
 #ifdef __Fuchsia__
-    fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr* m_driver;
+    llcpp::fuchsia::hardware::goldfish::AddressSpaceChildDriver::SyncClient*
+        m_driver;
     uint32_t  m_vmo;
 #else // __Fuchsia__
     address_space_handle_t m_handle;
diff --git a/shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl b/shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl
index a8a70af..e6f7539 100644
--- a/shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl
+++ b/shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl
@@ -619,9 +619,9 @@
         return false;
     }
 
-    drm_virtgpu_map map = {
-        .handle = create.bo_handle,
-    };
+    drm_virtgpu_map map;
+    memset(&map, 0, sizeof(map));
+    map.handle = create.bo_handle;
 
     ret = drmIoctl(fd, DRM_IOCTL_VIRTGPU_MAP, &map);
     if (ret) {
@@ -694,18 +694,18 @@
         abort();
     }
 
-    struct drm_virtgpu_map map_info = {
-        .handle = drm_rc_blob.bo_handle,
-    };
+    drm_virtgpu_map map;
+    memset(&map, 0, sizeof(map));
+    map.handle = drm_rc_blob.bo_handle;
 
-    res = drmIoctl(fd, DRM_IOCTL_VIRTGPU_MAP, &map_info);
+    res = drmIoctl(fd, DRM_IOCTL_VIRTGPU_MAP, &map);
     if (res) {
         ALOGE("%s: Failed to virtgpu map: sterror: %s errno: %d\n", __func__,
                 strerror(errno), errno);
         abort();
     }
 
-    void* directMappedAddr = mmap64(0, size, PROT_WRITE, MAP_SHARED, fd, map_info.offset);
+    void* directMappedAddr = mmap64(0, size, PROT_WRITE, MAP_SHARED, fd, map.offset);
 
     if (!directMappedAddr) {
         ALOGE("%s: mmap of virtio gpu resource failed\n", __func__);
diff --git a/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl b/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
index 9c4f3fa..d484347 100644
--- a/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
+++ b/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
@@ -32,13 +32,16 @@
 
 #include <unordered_map>
 
+#define GET_STATUS_SAFE(result, member) \
+    ((result).ok() ? ((result).Unwrap()->member) : ZX_OK)
+
 using android::base::guest::AutoLock;
 using android::base::guest::Lock;
 
-using fuchsia::hardware::goldfish::AddressSpaceDeviceSyncPtr;
-using fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr;
-using fuchsia::hardware::goldfish::AddressSpaceChildDriverType;
-using fuchsia::hardware::goldfish::AddressSpaceChildDriverPingMessage;
+using llcpp::fuchsia::hardware::goldfish::AddressSpaceChildDriver;
+using llcpp::fuchsia::hardware::goldfish::AddressSpaceDevice;
+using llcpp::fuchsia::hardware::goldfish::AddressSpaceChildDriverType;
+using llcpp::fuchsia::hardware::goldfish::AddressSpaceChildDriverPingMessage;
 
 GoldfishAddressSpaceBlockProvider::GoldfishAddressSpaceBlockProvider(GoldfishAddressSpaceSubdeviceType subdevice) {
 
@@ -53,17 +56,24 @@
               __FUNCTION__);
         return;
     }
-    m_device.Bind(std::move(channel));
+    m_device = std::make_unique<AddressSpaceDevice::SyncClient>(std::move(channel));
 
-    zx_status_t status = (*m_device).OpenChildDriver(
-        static_cast<fuchsia::hardware::goldfish::AddressSpaceChildDriverType>(0 /* graphics */),
-        m_child_driver.NewRequest());
-
+    zx::channel child_driver_server, child_driver_client;
+    zx_status_t status = zx::channel::create(0, &child_driver_server, &child_driver_client);
     if (status != ZX_OK) {
-        ALOGE("%s: failed to open child driver: %d",
-              __FUNCTION__, status);
+        ALOGE("%s: zx_channel_create failed: %d", __FUNCTION__, status);
         return;
     }
+
+    auto result = m_device->OpenChildDriver(
+        static_cast<AddressSpaceChildDriverType>(0 /* graphics */),
+        std::move(child_driver_server));
+    if (!result.ok()) {
+        ALOGE("%s: failed to open child driver: %d",
+              __FUNCTION__, result.status());
+        return;
+    }
+    m_child_driver = std::make_unique<AddressSpaceChildDriver::SyncClient>(std::move(child_driver_client));
 }
 
 GoldfishAddressSpaceBlockProvider::~GoldfishAddressSpaceBlockProvider()
@@ -72,7 +82,7 @@
 
 bool GoldfishAddressSpaceBlockProvider::is_opened() const
 {
-    return m_device.is_bound();
+    return !!m_device;
 }
 
 // void GoldfishAddressSpaceBlockProvider::close() - not implemented
@@ -116,18 +126,17 @@
         return false;
     }
 
-    fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr* driver = &provider->m_child_driver;
+    AddressSpaceChildDriver::SyncClient* driver = provider->m_child_driver.get();
 
-    int32_t res = ZX_OK;
-    zx::vmo vmo;
-    zx_status_t status = (*driver)->AllocateBlock(size, &res, &m_phys_addr, &vmo);
-    if (status != ZX_OK || res != ZX_OK) {
-        ALOGE("%s: allocate block failed: %d:%d", __func__, status, res);
+    auto result = driver->AllocateBlock(size);
+    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+        ALOGE("%s: allocate block failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
         return false;
     }
+    m_phys_addr = result.Unwrap()->paddr;
+    m_vmo = result.Unwrap()->vmo.release();
 
     m_size = size;
-    m_vmo = vmo.release();
     m_offset = 0;
     m_is_shared_mapping = false;
 
@@ -180,11 +189,11 @@
               (unsigned long long)m_size,
               (unsigned long long)m_offset, status);
         return NULL;
-    } else {
-        m_mmaped_ptr = (void*)ptr;
-        m_host_addr = host_addr;
-        return guestPtr();
     }
+
+    m_mmaped_ptr = (void*)ptr;
+    m_host_addr = host_addr;
+    return guestPtr();
 }
 
 void *GoldfishAddressSpaceBlock::guestPtr() const
@@ -209,15 +218,16 @@
             ALOGE("%s: unsupported: GoldfishAddressSpaceBlock destroy() for shared regions\n", __func__);
             abort();
             // int32_t res = ZX_OK;
-            // zx_status_t status = (*m_driver)->UnclaimShared(m_offset, &res);
-            // if (status != ZX_OK || res != ZX_OK) {
-            //     ALOGE("%s: unclaim shared block failed: %d:%d", __func__, status, res);
+            // auto result = m_driver->UnclaimShared(m_offset);
+            // if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+            //     ALOGE("%s: unclaim shared block failed: %d:%d", __func__,
+            //           result.status(), GET_STATUS_SAFE(result, res));
             // }
         } else {
-            int32_t res = ZX_OK;
-            zx_status_t status = (*m_driver)->DeallocateBlock(m_phys_addr, &res);
-            if (status != ZX_OK || res != ZX_OK) {
-                ALOGE("%s: deallocate block failed: %d:%d", __func__, status, res);
+            auto result = m_driver->DeallocateBlock(m_phys_addr);
+            if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+                ALOGE("%s: deallocate block failed: %d:%d", __func__,
+                      result.status(), GET_STATUS_SAFE(result, res));
             }
         }
         m_driver = NULL;
@@ -291,16 +301,15 @@
               __FUNCTION__);
         return 0;
     }
-    fuchsia::hardware::goldfish::AddressSpaceDeviceSyncPtr*
-        deviceSync = new fuchsia::hardware::goldfish::AddressSpaceDeviceSyncPtr;
-    deviceSync->Bind(std::move(channel));
+    AddressSpaceDevice::SyncClient*
+        deviceSync = new AddressSpaceDevice::SyncClient(std::move(channel));
     return (address_space_handle_t)deviceSync;
 }
 
 void goldfish_address_space_close(address_space_handle_t handle) {
-    fuchsia::hardware::goldfish::AddressSpaceDeviceSyncPtr* deviceSync =
+    AddressSpaceDevice::SyncClient* deviceSync =
         reinterpret_cast<
-            fuchsia::hardware::goldfish::AddressSpaceDeviceSyncPtr*>(handle);
+            AddressSpaceDevice::SyncClient*>(handle);
     delete deviceSync;
 }
 
@@ -308,16 +317,23 @@
     address_space_handle_t handle, GoldfishAddressSpaceSubdeviceType type,
     address_space_handle_t* handle_out) {
 
-    fuchsia::hardware::goldfish::AddressSpaceDeviceSyncPtr* deviceSync =
+    AddressSpaceDevice::SyncClient* deviceSync =
         reinterpret_cast<
-            fuchsia::hardware::goldfish::AddressSpaceDeviceSyncPtr*>(handle);
+            AddressSpaceDevice::SyncClient*>(handle);
 
-    fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr*
-        childSync = new fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr;
+    zx::channel child_driver_server, child_driver_client;
+    zx_status_t status = zx::channel::create(0, &child_driver_server, &child_driver_client);    
+    if (status != ZX_OK) {
+        ALOGE("%s: zx_channel_create failed: %d", __FUNCTION__, status);
+        return false;
+    }
 
-    zx_status_t res = (*(*deviceSync)).OpenChildDriver(
-        static_cast<fuchsia::hardware::goldfish::AddressSpaceChildDriverType>(type),
-        (*childSync).NewRequest());
+    deviceSync->OpenChildDriver(
+        static_cast<AddressSpaceChildDriverType>(type),
+        std::move(child_driver_server));
+
+    AddressSpaceChildDriver::SyncClient*
+        childSync = new AddressSpaceChildDriver::SyncClient(std::move(child_driver_client));
 
     // On creating a subdevice, in our use cases we wont be needing the
     // original device sync anymore, so get rid of it.
@@ -331,17 +347,18 @@
 bool goldfish_address_space_allocate(
     address_space_handle_t handle,
     size_t size, uint64_t* phys_addr, uint64_t* offset) {
-    fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr* deviceSync =
+    AddressSpaceChildDriver::SyncClient* deviceSync =
         reinterpret_cast<
-            fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr*>(handle);
+            AddressSpaceChildDriver::SyncClient*>(handle);
 
-    int32_t res = ZX_OK;
     zx::vmo vmo;
-    zx_status_t status = (*(*deviceSync)).AllocateBlock(size, &res, phys_addr, &vmo);
-    if (status != ZX_OK || res != ZX_OK) {
-        ALOGE("%s: allocate block failed: %d:%d", __func__, status, res);
+    auto result = deviceSync->AllocateBlock(size);
+    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+        ALOGE("%s: allocate block failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
         return false;
     }
+    *phys_addr = result.Unwrap()->paddr;
+    vmo = std::move(result.Unwrap()->vmo);
 
     *offset = 0;
 
@@ -360,14 +377,13 @@
     if (info.vmo == ZX_HANDLE_INVALID) return false;
     zx_handle_close(info.vmo);
 
-    fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr* deviceSync =
+    AddressSpaceChildDriver::SyncClient* deviceSync =
         reinterpret_cast<
-            fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr*>(handle);
+            AddressSpaceChildDriver::SyncClient*>(handle);
 
-    int32_t res = ZX_OK;
-    zx_status_t status = (*(*deviceSync)).DeallocateBlock(info.phys_addr, &res);
-    if (status != ZX_OK || res != ZX_OK) {
-        ALOGE("%s: deallocate block failed: %d:%d", __func__, status, res);
+    auto result = deviceSync->DeallocateBlock(info.phys_addr);
+    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+        ALOGE("%s: deallocate block failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
         return false;
     }
 
@@ -377,12 +393,17 @@
 bool goldfish_address_space_claim_shared(
     address_space_handle_t handle, uint64_t offset, uint64_t size) {
 
-    fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr* deviceSync =
+    AddressSpaceChildDriver::SyncClient* deviceSync =
         reinterpret_cast<
-            fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr*>(handle);
+            AddressSpaceChildDriver::SyncClient*>(handle);
+
     zx::vmo vmo;
-    zx_status_t res;
-    zx_status_t status = (*(*deviceSync)).ClaimSharedBlock(offset, size, &res, &vmo);
+    auto result = deviceSync->ClaimSharedBlock(offset, size);
+    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+        ALOGE("%s: claim shared failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
+        return false;
+    }
+    vmo = std::move(result.Unwrap()->vmo);
 
     VmoStore::Info info = {
         vmo.release(),
@@ -390,21 +411,20 @@
 
     getVmoStore()->add(offset, info);
 
-    if (status != ZX_OK) return false;
-
     return true;
 }
 
 bool goldfish_address_space_unclaim_shared(
     address_space_handle_t handle, uint64_t offset) {
-    fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr* deviceSync =
+    AddressSpaceChildDriver::SyncClient* deviceSync =
         reinterpret_cast<
-            fuchsia::hardware::goldfish::AddressSpaceChildDriverSyncPtr*>(handle);
-    zx::vmo vmo;
-    zx_status_t res;
-    zx_status_t status = (*(*deviceSync)).UnclaimSharedBlock(offset, &res);
+            AddressSpaceChildDriver::SyncClient*>(handle);
 
-    if (status != ZX_OK) return false;
+    auto result = deviceSync->UnclaimSharedBlock(offset);
+    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+        ALOGE("%s: unclaim shared failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
+        return false;
+    }
 
     getVmoStore()->remove(offset);
     return true;
@@ -442,17 +462,16 @@
     AddressSpaceChildDriverPingMessage fuchsiaPing =
         *(AddressSpaceChildDriverPingMessage*)ping;
 
-    AddressSpaceChildDriverSyncPtr* deviceSync =
+    AddressSpaceChildDriver::SyncClient* deviceSync =
         reinterpret_cast<
-            AddressSpaceChildDriverSyncPtr*>(handle);
+            AddressSpaceChildDriver::SyncClient*>(handle);
 
     AddressSpaceChildDriverPingMessage res;
-    zx_status_t pingStatus;
-    zx_status_t status = (*(*deviceSync)).Ping(fuchsiaPing, &pingStatus, &res);
-
-    if (pingStatus != ZX_OK) {
+    auto result = deviceSync->Ping(fuchsiaPing);
+    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
         return false;
     }
+    res = std::move(result.Unwrap()->ping);
 
     *ping = *(struct address_space_ping*)(&res);
     return true;
diff --git a/shared/OpenglCodecCommon/Android.mk b/shared/OpenglCodecCommon/Android.mk
index d9970d5..46d3fda 100644
--- a/shared/OpenglCodecCommon/Android.mk
+++ b/shared/OpenglCodecCommon/Android.mk
@@ -13,6 +13,7 @@
         SocketStream.cpp \
         TcpStream.cpp \
         auto_goldfish_dma_context.cpp \
+        etc.cpp \
 
 ifeq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
 
@@ -40,10 +41,16 @@
 LOCAL_CFLAGS += -DLOG_TAG=\"eglCodecCommon\"
 LOCAL_CFLAGS += -Wno-unused-private-field
 
-$(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog)
 
 ifeq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
-$(call emugl-export,SHARED_LIBRARIES,android-emu-shared)
+$(call emugl-import,libandroidemu)
+$(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog)
+else
+ifeq (true,$(GFXSTREAM))
+$(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog libandroidemu)
+else
+$(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog)
+endif
 endif
 
 $(call emugl-export,C_INCLUDES,$(LOCAL_PATH))
diff --git a/shared/OpenglCodecCommon/CMakeLists.txt b/shared/OpenglCodecCommon/CMakeLists.txt
index 6a1ac4a..545525f 100644
--- a/shared/OpenglCodecCommon/CMakeLists.txt
+++ b/shared/OpenglCodecCommon/CMakeLists.txt
@@ -1,10 +1,10 @@
 # This is an autogenerated file! Do not edit!
 # instead run make from .../device/generic/goldfish-opengl
 # which will re-generate this file.
-android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon/Android.mk" "87f5c2c694647e3a38b4da1b4c653b99cd27d934b60ecd43aff59d3765daabfd")
-set(OpenglCodecCommon_host_src GLClientState.cpp GLESTextureUtils.cpp ChecksumCalculator.cpp GLSharedGroup.cpp glUtils.cpp IndexRangeCache.cpp SocketStream.cpp TcpStream.cpp auto_goldfish_dma_context.cpp goldfish_dma_host.cpp)
-android_add_library(TARGET OpenglCodecCommon_host SHARED LICENSE Apache-2.0 SRC GLClientState.cpp GLESTextureUtils.cpp ChecksumCalculator.cpp GLSharedGroup.cpp glUtils.cpp IndexRangeCache.cpp SocketStream.cpp TcpStream.cpp auto_goldfish_dma_context.cpp goldfish_dma_host.cpp)
-target_include_directories(OpenglCodecCommon_host PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(OpenglCodecCommon_host PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"eglCodecCommon\"")
+android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon/Android.mk" "a9f19fd167bcc8bf102e288cccc0c4a780fa6671ff52f1f94c3b5b26d7482728")
+set(OpenglCodecCommon_host_src GLClientState.cpp GLESTextureUtils.cpp ChecksumCalculator.cpp GLSharedGroup.cpp glUtils.cpp IndexRangeCache.cpp SocketStream.cpp TcpStream.cpp auto_goldfish_dma_context.cpp etc.cpp goldfish_dma_host.cpp)
+android_add_library(TARGET OpenglCodecCommon_host SHARED LICENSE Apache-2.0 SRC GLClientState.cpp GLESTextureUtils.cpp ChecksumCalculator.cpp GLSharedGroup.cpp glUtils.cpp IndexRangeCache.cpp SocketStream.cpp TcpStream.cpp auto_goldfish_dma_context.cpp etc.cpp goldfish_dma_host.cpp)
+target_include_directories(OpenglCodecCommon_host PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(OpenglCodecCommon_host PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"eglCodecCommon\"")
 target_compile_options(OpenglCodecCommon_host PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-unused-private-field")
-target_link_libraries(OpenglCodecCommon_host PRIVATE android-emu-shared cutils utils log PRIVATE qemupipe_host)
\ No newline at end of file
+target_link_libraries(OpenglCodecCommon_host PRIVATE cutils utils log androidemu android-emu-shared PRIVATE qemupipe_host)
\ No newline at end of file
diff --git a/shared/OpenglCodecCommon/GLClientState.cpp b/shared/OpenglCodecCommon/GLClientState.cpp
index a31f697..6775831 100644
--- a/shared/OpenglCodecCommon/GLClientState.cpp
+++ b/shared/OpenglCodecCommon/GLClientState.cpp
@@ -32,12 +32,12 @@
 #endif
 
 // Don't include these in the .h file, or we get weird compile errors.
+#include <GLES2/gl2ext.h>
 #include <GLES3/gl3.h>
 #include <GLES3/gl31.h>
 
 void GLClientState::init() {
     m_initialized = false;
-    m_nLocations = CODEC_MAX_VERTEX_ATTRIBUTES;
 
     m_arrayBuffer = 0;
     m_arrayBuffer_lastEncode = 0;
@@ -48,7 +48,6 @@
     m_vaoAttribBindingHasVboCache = 0;
     m_noClientArraysCache = 0;
 
-    m_max_vertex_attrib_bindings = m_nLocations;
     addVertexArrayObject(0);
     setVertexArrayObject(0);
     // init gl constans;
@@ -78,13 +77,9 @@
     m_drawIndirectBuffer = 0;
     m_shaderStorageBuffer = 0;
 
-    m_transformFeedbackActiveUnpaused = false;
-
-    // to be modified later when these are queried from host.
-    m_max_transform_feedback_separate_attribs = 0;
-    m_max_uniform_buffer_bindings = 0;
-    m_max_atomic_counter_buffer_bindings = 0;
-    m_max_shader_storage_buffer_bindings = 0;
+    m_transformFeedbackActive = false;
+    m_transformFeedbackUnpaused = false;
+    m_transformFeedbackVaryingsCountForLinking = 0;
 
     m_activeTexture = 0;
     m_currentProgram = 0;
@@ -108,14 +103,28 @@
     m_tex.textureRecs = NULL;
 
     mRboState.boundRenderbuffer = 0;
-    mRboState.boundRenderbufferIndex = 0;
 
     mFboState.boundDrawFramebuffer = 0;
     mFboState.boundReadFramebuffer = 0;
     mFboState.drawFboCheckStatus = GL_NONE;
     mFboState.readFboCheckStatus = GL_NONE;
 
-    m_maxVertexAttribsDirty = true;
+    m_extensions_set = false;
+
+#ifdef GFXSTREAM
+    // The default transform feedback buffer object
+    // The default sampler object
+    GLuint defaultId = 0;
+    setExistence(ObjectType::TransformFeedback, true, 1, &defaultId);
+
+    mBoundTransformFeedbackValidity.id = 0;
+    mBoundTransformFeedbackValidity.valid = true;
+
+    // query must take id that was created via glGenQueries
+    mBoundQueryValidity_AnySamplesPassed.valid = false;
+    mBoundQueryValidity_AnySamplesPassedConservative.valid = false;
+    mBoundQueryValidity_TransformFeedbackPrimitivesWritten.valid = false;
+#endif
 }
 
 GLClientState::GLClientState()
@@ -225,10 +234,10 @@
     m_vaoMap.insert(
             VAOStateMap::value_type(
                 name,
-                VAOState(0, m_nLocations, std::max(m_nLocations, m_max_vertex_attrib_bindings))));
+                VAOState(0, CODEC_MAX_VERTEX_ATTRIBUTES, CODEC_MAX_VERTEX_ATTRIBUTES)));
     VertexAttribStateVector& attribState =
         m_vaoMap.find(name)->second.attribState;
-    for (int i = 0; i < m_nLocations; i++) {
+    for (int i = 0; i < CODEC_MAX_VERTEX_ATTRIBUTES; i++) {
         attribState[i].enabled = 0;
         attribState[i].enableDirty = false;
         attribState[i].data = 0;
@@ -421,6 +430,222 @@
     }
 }
 
+#ifdef GFXSTREAM
+
+void GLClientState::addBuffer(GLuint id) {
+    mBufferIds.add(id);
+    mBufferIds.set(id, true);
+    mHostMappedBufferDirty.add(id);
+}
+
+void GLClientState::removeBuffer(GLuint id) {
+    mHostMappedBufferDirty.remove(id);
+    mBufferIds.remove(id);
+}
+
+bool GLClientState::bufferIdExists(GLuint id) const {
+    return mBufferIds.get(id);
+}
+
+void GLClientState::setBufferHostMapDirty(GLuint id, bool dirty) {
+    mHostMappedBufferDirty.set(id, dirty);
+}
+
+bool GLClientState::isBufferHostMapDirty(GLuint id) const {
+    return mHostMappedBufferDirty.get(id);
+}
+
+void GLClientState::setExistence(ObjectType type, bool exists, GLsizei count, const GLuint* ids) {
+    if (type == ObjectType::Sampler) {
+        SamplerInfo::ScopedView view(mSamplerInfo);
+        if (exists) {
+            for (GLsizei i = 0; i < count; ++i) {
+                view.addFresh(ids[i]);
+            }
+        } else {
+            for (GLsizei i = 0; i < count; ++i) {
+                view.unref(ids[i]);
+            }
+        }
+    } else {
+        ExistenceMap* existenceMap = &mBufferIds;
+
+        switch (type) {
+            case ObjectType::Buffer:
+                existenceMap = &mBufferIds;
+                break;
+            case ObjectType::TransformFeedback:
+                existenceMap = &mTransformFeedbackIds;
+                break;
+            case ObjectType::Query:
+                existenceMap = &mQueryIds;
+                for (GLsizei i = 0; i < count; ++i) {
+                    // reset the last query target
+                    mLastQueryTargets.add(ids[i], 0);
+                }
+                break;
+            case ObjectType::Sampler:
+            default:
+                ALOGE("%s: Unreachable code\n", __func__);
+                abort();
+        }
+
+        if (exists) {
+            for (GLsizei i = 0; i < count; ++i) {
+                existenceMap->add(ids[i]);
+                existenceMap->set(ids[i], true);
+            }
+        } else {
+            for (GLsizei i = 0; i < count; ++i) {
+                existenceMap->remove(ids[i]);
+            }
+        }
+    }
+}
+
+bool GLClientState::queryExistence(ObjectType type, GLuint id) const {
+    switch (type) {
+        case ObjectType::Buffer:
+            return mBufferIds.get(id);
+        case ObjectType::TransformFeedback:
+            return mTransformFeedbackIds.get(id);
+        case ObjectType::Sampler:
+            return samplerExists(id);
+        case ObjectType::Query:
+            return mQueryIds.get(id);
+        default:
+            ALOGD("%s: unknown object type: 0x%x\n", __func__, type);
+            abort();
+    }
+}
+
+bool GLClientState::samplerExists(GLuint id) const {
+    if (!id) return true;
+    SamplerInfo::ScopedView view(mSamplerInfo);
+    return view.samplerExists(id);
+}
+
+bool GLClientState::tryBind(GLenum target, GLuint id) {
+    if (0 == id) { // unbind operation
+        switch (target) {
+            case GL_TRANSFORM_FEEDBACK:
+                mBoundTransformFeedbackValidity.id = 0;
+                mBoundTransformFeedbackValidity.valid = true;
+                break;
+            case GL_ANY_SAMPLES_PASSED:
+                mBoundQueryValidity_AnySamplesPassed.id = 0;
+                mBoundQueryValidity_AnySamplesPassed.valid = false;
+                break;
+            case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
+                mBoundQueryValidity_AnySamplesPassedConservative.id = 0;
+                mBoundQueryValidity_AnySamplesPassedConservative.valid = false;
+                break;
+            case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+                mBoundQueryValidity_TransformFeedbackPrimitivesWritten.id = 0;
+                mBoundQueryValidity_TransformFeedbackPrimitivesWritten.valid = false;
+                break;
+            default:
+                ALOGE("%s: target 0x%x not yet supported in new state tracking model\n", __func__, target);
+                abort();
+        }
+        return true;
+    }
+
+    switch (target) {
+        case GL_TRANSFORM_FEEDBACK:
+            if (!queryExistence(ObjectType::TransformFeedback, id)) return false;
+            break;
+        case GL_ANY_SAMPLES_PASSED:
+        case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
+        case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+            if (!queryExistence(ObjectType::Query, id)) {
+                return false;
+            }
+            break;
+        default:
+            ALOGE("%s: target 0x%x not yet supported in new state tracking model\n", __func__, target);
+            abort();
+    }
+
+    // valid bind
+    switch (target) {
+    case GL_TRANSFORM_FEEDBACK:
+        mBoundTransformFeedbackValidity.id = id;
+        mBoundTransformFeedbackValidity.valid = true;
+        break;
+    case GL_ANY_SAMPLES_PASSED:
+        mBoundQueryValidity_AnySamplesPassed.id = id;
+        mBoundQueryValidity_AnySamplesPassed.valid = true;
+        break;
+    case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
+        mBoundQueryValidity_AnySamplesPassedConservative.id = id;
+        mBoundQueryValidity_AnySamplesPassedConservative.valid = true;
+        break;
+    case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+        mBoundQueryValidity_TransformFeedbackPrimitivesWritten.id = id;
+        mBoundQueryValidity_TransformFeedbackPrimitivesWritten.valid = true;
+        break;
+    default:
+        ALOGE("%s: target 0x%x not yet supported in new state tracking model\n", __func__, target);
+        abort();
+    }
+    return true;
+}
+
+bool GLClientState::isBoundTargetValid(GLenum target) {
+    switch (target) {
+    case GL_TRANSFORM_FEEDBACK:
+        return mBoundTransformFeedbackValidity.valid;
+    case GL_ANY_SAMPLES_PASSED:
+        return mBoundQueryValidity_AnySamplesPassed.valid;
+    case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
+        return mBoundQueryValidity_AnySamplesPassedConservative.valid;
+    case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+        return mBoundQueryValidity_TransformFeedbackPrimitivesWritten.valid;
+    default:
+        ALOGE("%s: target 0x%x not yet supported in new state tracking model\n", __func__, target);
+        abort();
+    }
+}
+
+bool GLClientState::isQueryBound(GLenum target) {
+    switch (target) {
+    case GL_ANY_SAMPLES_PASSED:
+        return mBoundQueryValidity_AnySamplesPassed.valid;
+    case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
+        return mBoundQueryValidity_AnySamplesPassedConservative.valid;
+    case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+        return mBoundQueryValidity_TransformFeedbackPrimitivesWritten.valid;
+    default:
+        return false;
+    }
+}
+
+bool GLClientState::isQueryObjectActive(GLuint id) {
+    if (mBoundQueryValidity_AnySamplesPassed.valid &&
+        (id == mBoundQueryValidity_AnySamplesPassed.id))
+        return true;
+    if (mBoundQueryValidity_AnySamplesPassedConservative.valid &&
+        (id == mBoundQueryValidity_AnySamplesPassedConservative.id))
+        return true;
+    if (mBoundQueryValidity_TransformFeedbackPrimitivesWritten.valid &&
+        (id == mBoundQueryValidity_TransformFeedbackPrimitivesWritten.id))
+        return true;
+    return false;
+}
+
+void GLClientState::setLastQueryTarget(GLenum target, GLuint id) {
+    mLastQueryTargets.add(id, target);
+}
+
+GLenum GLClientState::getLastQueryTarget(GLuint id) {
+    auto targetPtr = mLastQueryTargets.get_const(id);
+    if (!targetPtr) return 0;
+    return *targetPtr;
+}
+
+#else // GFXSTREAM
+
 void GLClientState::addBuffer(GLuint id) {
     mBufferIds.insert(id);
 }
@@ -433,6 +658,70 @@
     return mBufferIds.find(id) != mBufferIds.end();
 }
 
+void GLClientState::setBufferHostMapDirty(GLuint id, bool dirty) {
+    (void)id;
+    (void)dirty;
+}
+
+bool GLClientState::isBufferHostMapDirty(GLuint id) const {
+    (void)id;
+    return true;
+}
+
+void GLClientState::setExistence(ObjectType, bool, GLsizei, const GLuint*) {
+    // no-op in non-gfxstream
+}
+
+#endif // !GFXSTREAM
+
+void GLClientState::setBoundPixelPackBufferDirtyForHostMap() {
+    if (m_pixelPackBuffer)
+        setBufferHostMapDirty(m_pixelPackBuffer, true /* dirty */);
+}
+
+void GLClientState::setBoundTransformFeedbackBuffersDirtyForHostMap() {
+    if (m_transformFeedbackBuffer)
+        setBufferHostMapDirty(
+            m_transformFeedbackBuffer,
+            true /* dirty */);
+
+    for (size_t i = 0; i < m_indexedTransformFeedbackBuffers.size(); ++i)
+        if (m_indexedTransformFeedbackBuffers[i].buffer)
+            setBufferHostMapDirty(
+                m_indexedTransformFeedbackBuffers[i].buffer,
+                true /* dirty */);
+}
+
+void GLClientState::setBoundShaderStorageBuffersDirtyForHostMap() {
+    if (m_glesMajorVersion == 3 && m_glesMinorVersion == 0) return;
+
+    if (m_shaderStorageBuffer)
+        setBufferHostMapDirty(
+            m_shaderStorageBuffer,
+            true /* dirty */);
+
+    for (size_t i = 0; i < m_indexedShaderStorageBuffers.size(); ++i)
+        if (m_indexedShaderStorageBuffers[i].buffer)
+            setBufferHostMapDirty(
+                m_indexedShaderStorageBuffers[i].buffer,
+                true /* dirty */);
+}
+
+void GLClientState::setBoundAtomicCounterBuffersDirtyForHostMap() {
+    if (m_glesMajorVersion == 3 && m_glesMinorVersion == 0) return;
+
+    if (m_atomicCounterBuffer)
+        setBufferHostMapDirty(
+            m_atomicCounterBuffer,
+            true /* dirty */);
+
+    for (size_t i = 0; i < m_indexedAtomicCounterBuffers.size(); ++i)
+        if (m_indexedAtomicCounterBuffers[i].buffer)
+            setBufferHostMapDirty(
+                m_indexedAtomicCounterBuffers[i].buffer,
+                true /* dirty */);
+}
+
 void GLClientState::unBindBuffer(GLuint id) {
     if (m_arrayBuffer == id) {
         m_arrayBuffer = 0;
@@ -619,6 +908,47 @@
     }
 }
 
+int GLClientState::getMaxTextureSize() const {
+    return m_hostDriverCaps.max_texture_size;
+}
+
+int GLClientState::getMaxTextureSize3D() const {
+    return m_hostDriverCaps.max_texture_size_3d;
+}
+
+int GLClientState::getMaxTextureSizeCubeMap() const {
+    return m_hostDriverCaps.max_texture_size_cube_map;
+}
+
+int GLClientState::getLog2MaxTextureSize() const {
+    return m_log2MaxTextureSize;
+}
+
+void GLClientState::postDraw() {
+    setBoundTransformFeedbackBuffersDirtyForHostMap();
+    setBoundShaderStorageBuffersDirtyForHostMap();
+    setBoundAtomicCounterBuffersDirtyForHostMap();
+}
+
+void GLClientState::postReadPixels() {
+    setBoundPixelPackBufferDirtyForHostMap();
+}
+
+void GLClientState::postDispatchCompute() {
+    setBoundShaderStorageBuffersDirtyForHostMap();
+    setBoundAtomicCounterBuffersDirtyForHostMap();
+}
+
+bool GLClientState::shouldSkipHostMapBuffer(GLenum target) {
+    GLuint id = getBuffer(target);
+    return !isBufferHostMapDirty(id);
+}
+
+void GLClientState::onHostMappedBuffer(GLenum target) {
+    GLuint id = getBuffer(target);
+    setBufferHostMapDirty(id, false /* not dirty */);
+}
+
 int GLClientState::getBuffer(GLenum target) {
     int ret=0;
     switch (target) {
@@ -699,6 +1029,50 @@
     }
 }
 
+bool GLClientState::isTexture(GLuint tex_name) const {
+    return getTextureRec(tex_name);
+}
+
+bool GLClientState::isTextureWithStorage(GLuint tex_name) const {
+    TextureRec* rec = getTextureRec(tex_name);
+    if (!rec) return false;
+    return rec->hasStorage;
+}
+
+bool GLClientState::isTextureCubeMap(GLuint tex_name) const {
+    TextureRec* texrec = getTextureRec(tex_name);
+    if (!texrec) return false;
+    switch (texrec->target) {
+        case GL_TEXTURE_CUBE_MAP:
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool GLClientState::isRenderbuffer(GLuint name) const {
+    if (!name) return false;
+
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    return view.hasRbo(name);
+}
+
+bool GLClientState::isRenderbufferThatWasBound(GLuint name) const {
+    if (!name) return true;
+
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    if (!view.hasRbo(name)) return false;
+
+    const RboProps* props = view.get_const(name);
+    return props->previouslyBound;
+}
+
 void GLClientState::getClientStatePointer(GLenum pname, GLvoid** params)
 {
     GLenum which_state = -1;
@@ -1001,8 +1375,14 @@
     }
 }
 
-void GLClientState::bindSampler(GLuint unit, GLuint sampler) {
+bool GLClientState::bindSampler(GLuint unit, GLuint sampler) {
+    SamplerInfo::ScopedView view(mSamplerInfo);
+    view.ref(sampler);
+    if (m_tex.unit[unit].boundSampler) {
+        view.unref(sampler);
+    }
     m_tex.unit[unit].boundSampler = sampler;
+    return true;
 }
 
 bool GLClientState::isSamplerBindNoOp(GLuint unit, GLuint sampler) {
@@ -1052,7 +1432,7 @@
     if (texture && target != texrec->target &&
         (target != GL_TEXTURE_EXTERNAL_OES &&
          texrec->target != GL_TEXTURE_EXTERNAL_OES)) {
-        ALOGD("%s: issue GL_INVALID_OPERATION: target 0x%x texrectarget 0x%x texture %u", __FUNCTION__, target, texrec->target, texture);
+        return GL_INVALID_OPERATION;
     }
 
     switch (target) {
@@ -1086,10 +1466,23 @@
 void GLClientState::setBoundEGLImage(GLenum target, GLeglImageOES image) {
     (void)image;
 
-    GLuint texture = getBoundTexture(target);
-    TextureRec* texrec = getTextureRec(texture);
-    if (!texrec) return;
-    texrec->boundEGLImage = true;
+    if (target == GL_RENDERBUFFER) {
+        if (!boundRenderbuffer()) return;
+        setBoundRenderbufferEGLImageBacked();
+        setBoundRenderbufferFormat(GL_RGBA);
+        setBoundRenderbufferSamples(0);
+        setBoundRenderbufferDimensions(1, 1);
+    } else {
+        GLuint texture = getBoundTexture(target);
+        TextureRec* texrec = getTextureRec(texture);
+        if (!texrec) return;
+        texrec->boundEGLImage = true;
+        setBoundTextureInternalFormat(target, GL_RGBA);
+        setBoundTextureFormat(target, GL_RGBA);
+        setBoundTextureType(target, GL_UNSIGNED_BYTE);
+        setBoundTextureSamples(target, 0);
+        setBoundTextureDims(target, target, 0, 1, 1, 1);
+    }
 }
 
 TextureRec* GLClientState::addTextureRec(GLuint id, GLenum target)
@@ -1101,7 +1494,14 @@
     tex->multisamples = 0;
     tex->immutable = false;
     tex->boundEGLImage = false;
-    tex->dims = new TextureDims;
+    tex->hasStorage = false;
+    tex->dims = new TextureDims[6];
+    tex->hasCubeNegX = false;
+    tex->hasCubePosX = false;
+    tex->hasCubeNegY = false;
+    tex->hasCubePosY = false;
+    tex->hasCubeNegZ = false;
+    tex->hasCubePosZ = false;
 
     (*(m_tex.textureRecs))[id] = tex;
     return tex;
@@ -1137,13 +1537,49 @@
     texrec->type = type;
 }
 
-void GLClientState::setBoundTextureDims(GLenum target, GLsizei level, GLsizei width, GLsizei height, GLsizei depth) {
+static size_t textureDimArrayOfCubeTarget(GLenum cubetarget) {
+    switch (cubetarget) {
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+            return 0;
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+            return 1;
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+            return 2;
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+            return 3;
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+            return 4;
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+            return 5;
+    }
+    return 0;
+}
+
+void GLClientState::setBoundTextureDims(GLenum target, GLenum cubetarget, GLsizei level, GLsizei width, GLsizei height, GLsizei depth) {
     GLuint texture = getBoundTexture(target);
     TextureRec* texrec = getTextureRec(texture);
     if (!texrec) {
         return;
     }
 
+    texrec->hasStorage = true;
+
+    size_t indexToSet = 0;
+
+    if (target == GL_TEXTURE_CUBE_MAP) {
+        if (-1 == cubetarget) {
+            setBoundTextureDims(target, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, width, height, depth);
+            setBoundTextureDims(target, GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, width, height, depth);
+            setBoundTextureDims(target, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, width, height, depth);
+            setBoundTextureDims(target, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, width, height, depth);
+            setBoundTextureDims(target, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, width, height, depth);
+            setBoundTextureDims(target, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, width, height, depth);
+            return;
+        }
+        indexToSet = textureDimArrayOfCubeTarget(cubetarget);
+    }
+
+
     if (level == -1) {
         GLsizei curr_width = width;
         GLsizei curr_height = height;
@@ -1151,9 +1587,9 @@
         GLsizei curr_level = 0;
 
         while (true) {
-            texrec->dims->widths[curr_level] = curr_width;
-            texrec->dims->heights[curr_level] = curr_height;
-            texrec->dims->depths[curr_level] = curr_depth;
+            texrec->dims[indexToSet].widths[curr_level] = curr_width;
+            texrec->dims[indexToSet].heights[curr_level] = curr_height;
+            texrec->dims[indexToSet].depths[curr_level] = curr_depth;
             if (curr_width >> 1 == 0 &&
                 curr_height >> 1 == 0 &&
                 ((target == GL_TEXTURE_3D && curr_depth == 0) ||
@@ -1169,10 +1605,12 @@
         }
 
     } else {
-        texrec->dims->widths[level] = width;
-        texrec->dims->heights[level] = height;
-        texrec->dims->depths[level] = depth;
+        texrec->dims[indexToSet].widths[level] = width;
+        texrec->dims[indexToSet].heights[level] = height;
+        texrec->dims[indexToSet].depths[level] = depth;
     }
+
+    setFboCompletenessDirtyForTexture(texture);
 }
 
 void GLClientState::setBoundTextureSamples(GLenum target, GLsizei samples) {
@@ -1182,11 +1620,48 @@
     texrec->multisamples = samples;
 }
 
+void GLClientState::addTextureCubeMapImage(GLenum stateTarget, GLenum cubeTarget) {
+    if (stateTarget != GL_TEXTURE_CUBE_MAP) return;
+
+    GLuint texture = getBoundTexture(stateTarget);
+    TextureRec* texrec = getTextureRec(texture);
+    if (!texrec) return;
+
+    switch (cubeTarget) {
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+            texrec->hasCubeNegX = true;
+            return;
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+            texrec->hasCubePosX = true;
+            return;
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+            texrec->hasCubeNegY = true;
+            return;
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+            texrec->hasCubePosY = true;
+            return;
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+            texrec->hasCubeNegZ = true;
+            return;
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+            texrec->hasCubePosZ = true;
+            return;
+    }
+}
+
 void GLClientState::setBoundTextureImmutableFormat(GLenum target) {
     GLuint texture = getBoundTexture(target);
     TextureRec* texrec = getTextureRec(texture);
     if (!texrec) return;
     texrec->immutable = true;
+    if (target == GL_TEXTURE_CUBE_MAP) {
+        texrec->hasCubeNegX = true;
+        texrec->hasCubePosX = true;
+        texrec->hasCubeNegY = true;
+        texrec->hasCubePosY = true;
+        texrec->hasCubeNegZ = true;
+        texrec->hasCubePosZ = true;
+    }
 }
 
 bool GLClientState::isBoundTextureImmutableFormat(GLenum target) const {
@@ -1196,6 +1671,41 @@
     return texrec->immutable;
 }
 
+bool GLClientState::isBoundTextureComplete(GLenum target) const {
+    GLuint texture = getBoundTexture(target);
+    TextureRec* texrec = getTextureRec(texture);
+    if (!texrec) return false;
+
+    if (texrec->immutable) return true;
+    if (!texrec->hasStorage) return true;
+
+    if (target == GL_TEXTURE_CUBE_MAP) {
+        if (!(texrec->hasCubeNegX &&
+             texrec->hasCubePosX &&
+             texrec->hasCubeNegY &&
+             texrec->hasCubePosY &&
+             texrec->hasCubeNegZ &&
+             texrec->hasCubePosZ)) return false;
+
+        size_t currBaseLevel = texrec->dims[0].widths.begin()->first;
+        size_t currWidth = texrec->dims[0].widths.begin()->second;
+        size_t currHeight = texrec->dims[0].heights.begin()->second;
+        for (size_t i = 1; i < 6; ++i) {
+            size_t nextLevel = texrec->dims[i].widths.begin()->first;
+            size_t nextWidth = texrec->dims[i].widths.begin()->second;
+            size_t nextHeight = texrec->dims[i].heights.begin()->second;
+            if (currBaseLevel != nextLevel) return false;
+            if (currWidth != nextWidth) return false;
+            if (currHeight != nextHeight) return false;
+        }
+
+        return true;
+    }
+
+    return true;
+}
+
+
 GLuint GLClientState::getBoundTexture(GLenum target) const
 {
     switch (target) {
@@ -1216,6 +1726,219 @@
     }
 }
 
+GLuint GLClientState::getBoundFramebuffer(GLenum target) const
+{
+    switch (target) {
+    case GL_FRAMEBUFFER:
+    case GL_DRAW_FRAMEBUFFER:
+        return mFboState.boundDrawFramebuffer;
+    case GL_READ_FRAMEBUFFER:
+        return mFboState.boundReadFramebuffer;
+    default:
+        return 0;
+    }
+}
+
+GLenum GLClientState::checkFramebufferCompleteness(GLenum target) {
+    // Default framebuffer is complete
+    // TODO: Check the case where the default framebuffer is 0x0
+    if (0 == boundFramebuffer(target)) return GL_FRAMEBUFFER_COMPLETE;
+
+    bool hasAttachment = false;
+    FboProps& props = boundFboProps(target);
+
+    if (!props.completenessDirty) {
+        return props.cachedCompleteness;
+    }
+
+    int currentSamples = -1;
+
+    for (int i = 0; i < getMaxColorAttachments(); i++) {
+        if (!props.colorAttachmenti_hasTex[i] &&
+            !props.colorAttachmenti_hasRbo[i]) continue;
+
+        GLenum attachmentRes = checkFramebufferAttachmentCompleteness(target, glUtilsColorAttachmentName(i), &currentSamples);
+        if (attachmentRes != GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
+            hasAttachment = true;
+        }
+        if (attachmentRes) {
+            ALOGD("%s: color attachment %d not complete: 0x%x\n", __func__, i, attachmentRes);
+            return attachmentRes;
+        }
+    }
+
+    bool hasDepth = (props.depthAttachment_hasTexObj || props.depthAttachment_hasRbo || props.depthstencilAttachment_hasTexObj || props.depthstencilAttachment_hasRbo);
+    bool hasStencil = (props.stencilAttachment_hasTexObj || props.stencilAttachment_hasRbo || props.depthstencilAttachment_hasTexObj || props.depthstencilAttachment_hasRbo);
+
+    if (hasDepth) {
+        GLenum depthAttachmentRes = checkFramebufferAttachmentCompleteness(target, GL_DEPTH_ATTACHMENT, &currentSamples);
+        if (depthAttachmentRes != GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
+            hasAttachment = true;
+        }
+        if (depthAttachmentRes) {
+            ALOGD("%s: depth attachment not complete: 0x%x\n", __func__, depthAttachmentRes);
+            return depthAttachmentRes;
+        }
+    }
+
+    if (hasStencil) {
+        GLenum stencilAttachmentRes = checkFramebufferAttachmentCompleteness(target, GL_STENCIL_ATTACHMENT, &currentSamples);
+        if (stencilAttachmentRes != GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
+            hasAttachment = true;
+        }
+        if (stencilAttachmentRes) {
+            ALOGD("%s: stencil attachment not complete: 0x%x\n", __func__, stencilAttachmentRes);
+            return stencilAttachmentRes;
+        }
+    }
+
+    if (hasDepth && hasStencil) {
+        // In gles3, depth/stencil must use the same image.
+        if (m_glesMajorVersion > 2) {
+            if ((props.depthAttachment_hasTexObj && props.stencilAttachment_hasRbo) ||
+                (props.stencilAttachment_hasTexObj && props.depthAttachment_hasRbo)) {
+                ALOGD("%s: GL_FRAMEBUFFER_UNSUPPORTED: using different types of depth/stencil attachment images in GLES 3+\n", __func__);
+                return GL_FRAMEBUFFER_UNSUPPORTED;
+            }
+            if (props.depthAttachment_hasTexObj) {
+                if (props.depthAttachment_texture != props.stencilAttachment_texture) {
+                    ALOGD("%s: GL_FRAMEBUFFER_UNSUPPORTED: using different texture images for depth and stencil attachments in GLES 3+\n", __func__);
+                    return GL_FRAMEBUFFER_UNSUPPORTED;
+                }
+            }
+            if (props.depthAttachment_hasRbo) {
+                if (props.depthAttachment_rbo != props.stencilAttachment_rbo) {
+                    ALOGD("%s: GL_FRAMEBUFFER_UNSUPPORTED: using different renderbuffers for depth and stencil attachments in GLES 3+\n", __func__);
+                    return GL_FRAMEBUFFER_UNSUPPORTED;
+                }
+            }
+        }
+    }
+
+    if (!hasAttachment) {
+        return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
+    }
+
+    props.completenessDirty = false;
+    props.cachedCompleteness = GL_FRAMEBUFFER_COMPLETE;
+    return GL_FRAMEBUFFER_COMPLETE;
+}
+
+GLenum GLClientState::checkFramebufferAttachmentCompleteness(GLenum target, GLenum attachment, int* currentSamples) const {
+    FboFormatInfo fbo_format_info;
+    getBoundFramebufferFormat(target, attachment, &fbo_format_info);
+
+    // Check format and renderability
+    bool renderable = false;
+    switch (fbo_format_info.type) {
+        case FBO_ATTACHMENT_RENDERBUFFER:
+            switch (attachment) {
+                case GL_DEPTH_ATTACHMENT:
+                    renderable = fbo_format_info.rb_external || depthRenderableFormat(fbo_format_info.rb_format);
+                    break;
+                case GL_STENCIL_ATTACHMENT:
+                    renderable = fbo_format_info.rb_external || stencilRenderableFormat(fbo_format_info.rb_format);
+                    break;
+                default:
+                    renderable = fbo_format_info.rb_external || colorRenderableFormat(
+                            fbo_format_info.rb_format,
+                            GL_UNSIGNED_BYTE,
+                            m_glesMajorVersion, m_glesMinorVersion,
+                            m_has_color_buffer_float_extension,
+                            m_has_color_buffer_half_float_extension);
+                    if (!renderable) {
+                        ALOGD("%s: rbo not color renderable. format: 0x%x\n", __func__, fbo_format_info.rb_format); }
+                    break;
+            }
+            break;
+        case FBO_ATTACHMENT_TEXTURE:
+            switch (attachment) {
+                case GL_DEPTH_ATTACHMENT:
+                    renderable = fbo_format_info.tex_external || depthRenderableFormat(fbo_format_info.tex_internalformat);
+                    break;
+                case GL_STENCIL_ATTACHMENT:
+                    renderable = fbo_format_info.tex_external || stencilRenderableFormat(fbo_format_info.tex_internalformat);
+                    break;
+                default:
+                    renderable = fbo_format_info.tex_external || colorRenderableFormat(
+                            fbo_format_info.tex_internalformat,
+                            fbo_format_info.tex_type,
+                            m_glesMajorVersion, m_glesMinorVersion,
+                            m_has_color_buffer_float_extension,
+                            m_has_color_buffer_half_float_extension);
+                    if (!renderable) {
+                        ALOGD("%s: tex not color renderable. format: 0x%x type 0x%x maj min %d %d floatext %d hfloatext %d\n", __func__, fbo_format_info.tex_internalformat, fbo_format_info.tex_type, m_glesMajorVersion, m_glesMinorVersion, m_has_color_buffer_float_extension, m_has_color_buffer_half_float_extension);
+                    }
+                    break;
+            }
+            break;
+        case FBO_ATTACHMENT_NONE:
+        default:
+            return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
+    }
+
+    if (!renderable) return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
+
+    // Check dimensions
+    GLuint id;
+    switch (fbo_format_info.type) {
+    case FBO_ATTACHMENT_RENDERBUFFER:
+        id = getFboAttachmentRboId(target, attachment);
+        if (!fbo_format_info.rb_external) {
+            if (0 == queryRboWidth(id) || 0 == queryRboHeight(id)) {
+                ALOGD("%s: rbo has zero dimension\n", __func__);
+                return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
+            }
+        }
+        break;
+    case FBO_ATTACHMENT_TEXTURE:
+        id = getFboAttachmentTextureId(target, attachment);
+        if (!fbo_format_info.tex_external) {
+            if (0 == queryTexWidth(fbo_format_info.tex_level, id) || 0 == queryTexHeight(fbo_format_info.tex_level, id)) {
+                ALOGD("%s: texture has zero dimension\n", __func__);
+                return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
+            }
+            GLsizei depth = queryTexDepth(fbo_format_info.tex_level, id);
+            if (fbo_format_info.tex_layer >= depth) {
+                ALOGD("%s: texture layer/zoffset too high, wanted %d but only have %d layers\n", __func__,
+                      fbo_format_info.tex_layer, depth);
+                return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
+            }
+        }
+        break;
+    case FBO_ATTACHMENT_NONE:
+    default:
+        return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
+    }
+
+    // Check samples
+    int currSamplesVal = *currentSamples;
+    bool firstTime = -1 == currSamplesVal;
+    int samplesThisAttachment = 0;
+    switch (fbo_format_info.type) {
+    case FBO_ATTACHMENT_RENDERBUFFER:
+        samplesThisAttachment = fbo_format_info.rb_multisamples;
+        break;
+    case FBO_ATTACHMENT_TEXTURE:
+        samplesThisAttachment = fbo_format_info.tex_multisamples;
+        break;
+    case FBO_ATTACHMENT_NONE:
+        break;
+    default:
+        return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
+    }
+
+    if (firstTime) {
+        *currentSamples = samplesThisAttachment;
+    } else {
+        if (samplesThisAttachment != currSamplesVal) {
+            return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
+        }
+    }
+
+    return 0;
+}
+
 // BEGIN driver workarounds-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 // (>' ')><(' '<)(>' ')><(' '<)(>' ')><(' '<)(>' ')><(' '<)(>' ')><(' '<)(>' ')>
 
@@ -1284,6 +2007,10 @@
 
 void GLClientState::deleteTextures(GLsizei n, const GLuint* textures)
 {
+    for (const GLuint* texture = textures; texture != textures + n; texture++) {
+        setFboCompletenessDirtyForTexture(*texture);
+    }
+
     // Updating the textures array could be made more efficient when deleting
     // several textures:
     // - compacting the array could be done in a single pass once the deleted
@@ -1293,7 +2020,7 @@
     for (const GLuint* texture = textures; texture != textures + n; texture++) {
         texrec = getTextureRec(*texture);
         if (texrec && texrec->dims) {
-            delete texrec->dims;
+            delete [] texrec->dims;
         }
         if (texrec) {
             m_tex.textureRecs->erase(*texture);
@@ -1315,20 +2042,10 @@
 // RBO//////////////////////////////////////////////////////////////////////////
 
 void GLClientState::addFreshRenderbuffer(GLuint name) {
-    // if underlying opengl says these are fresh names,
-    // but we are keeping a stale one, reset it.
-    RboProps props;
-    props.target = GL_RENDERBUFFER;
-    props.name = name;
-    props.format = GL_NONE;
-    props.multisamples = 0;
-    props.previouslyBound = false;
+    if (!name) return;
 
-    if (usedRenderbufferName(name)) {
-        mRboState.rboData[getRboIndex(name)] = props;
-    } else {
-        mRboState.rboData.push_back(props);
-    }
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    view.addFresh(name);
 }
 
 void GLClientState::addRenderbuffers(GLsizei n, GLuint* renderbuffers) {
@@ -1337,84 +2054,87 @@
     }
 }
 
-size_t GLClientState::getRboIndex(GLuint name) const {
-    for (size_t i = 0; i < mRboState.rboData.size(); i++) {
-        if (mRboState.rboData[i].name == name) {
-            return i;
-        }
-    }
-    return -1;
-}
-
 void GLClientState::removeRenderbuffers(GLsizei n, const GLuint* renderbuffers) {
-    size_t bound_rbo_idx = getRboIndex(boundRboProps_const().name);
-
     std::vector<GLuint> to_remove;
     for (size_t i = 0; i < n; i++) {
         if (renderbuffers[i] != 0) { // Never remove the zero rb.
-            to_remove.push_back(getRboIndex(renderbuffers[i]));
+            to_remove.push_back(renderbuffers[i]);
+            setFboCompletenessDirtyForRbo(renderbuffers[i]);
         }
     }
 
-    for (size_t i = 0; i < to_remove.size(); i++) {
-        mRboState.rboData[to_remove[i]] = mRboState.rboData.back();
-        mRboState.rboData.pop_back();
+    bool unbindCurrent = false;
+    {
+        RenderbufferInfo::ScopedView view(mRboState.rboData);
+        for (size_t i = 0; i < to_remove.size(); i++) {
+            view.unref(to_remove[i]);
+        }
+        for (size_t i = 0; i < to_remove.size(); i++) {
+            if (mRboState.boundRenderbuffer == renderbuffers[i]) {
+                unbindCurrent = true;
+                break;
+            }
+        }
     }
 
-    // If we just deleted the currently bound rb,
-    // bind the zero rb
-    if (getRboIndex(boundRboProps_const().name) != bound_rbo_idx) {
+    if (unbindCurrent) {
         bindRenderbuffer(GL_RENDERBUFFER, 0);
     }
 }
 
 bool GLClientState::usedRenderbufferName(GLuint name) const {
-    for (size_t i = 0; i < mRboState.rboData.size(); i++) {
-        if (mRboState.rboData[i].name == name) {
-            return true;
-        }
-    }
-    return false;
-}
+    if (!name) return false;
 
-void GLClientState::setBoundRenderbufferIndex() {
-    for (size_t i = 0; i < mRboState.rboData.size(); i++) {
-        if (mRboState.rboData[i].name == mRboState.boundRenderbuffer) {
-            mRboState.boundRenderbufferIndex = i;
-            break;
-        }
-    }
-}
-
-RboProps& GLClientState::boundRboProps() {
-    return mRboState.rboData[mRboState.boundRenderbufferIndex];
-}
-
-const RboProps& GLClientState::boundRboProps_const() const {
-    return mRboState.rboData[mRboState.boundRenderbufferIndex];
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    return view.get_const(name) != 0;
 }
 
 void GLClientState::bindRenderbuffer(GLenum target, GLuint name) {
-    // If unused, add it.
-    if (!usedRenderbufferName(name)) {
-        addFreshRenderbuffer(name);
+
+    (void)target; // Must be GL_RENDERBUFFER
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    if (name != mRboState.boundRenderbuffer) {
+        view.unref(mRboState.boundRenderbuffer);
     }
+
     mRboState.boundRenderbuffer = name;
-    setBoundRenderbufferIndex();
-    boundRboProps().target = target;
-    boundRboProps().previouslyBound = true;
+
+    if (!name) return;
+
+    view.bind(name);
 }
 
 GLuint GLClientState::boundRenderbuffer() const {
-    return boundRboProps_const().name;
+    return mRboState.boundRenderbuffer;
 }
 
 void GLClientState::setBoundRenderbufferFormat(GLenum format) {
-    boundRboProps().format = format;
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    RboProps* props = view.get(mRboState.boundRenderbuffer);
+    if (!props) return;
+    props->format = format;
 }
 
 void GLClientState::setBoundRenderbufferSamples(GLsizei samples) {
-    boundRboProps().multisamples = samples;
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    RboProps* props = view.get(mRboState.boundRenderbuffer);
+    if (!props) return;
+    props->multisamples = samples;
+}
+
+void GLClientState::setBoundRenderbufferDimensions(GLsizei width, GLsizei height) {
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    RboProps* props = view.get(mRboState.boundRenderbuffer);
+    if (!props) return;
+    props->width = width;
+    props->height = height;
+}
+
+void GLClientState::setBoundRenderbufferEGLImageBacked() {
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    RboProps* props = view.get(mRboState.boundRenderbuffer);
+    if (!props) return;
+    props->boundEGLImage = true;
 }
 
 // FBO//////////////////////////////////////////////////////////////////////////
@@ -1422,11 +2142,38 @@
 // Format querying
 
 GLenum GLClientState::queryRboFormat(GLuint rbo_name) const {
-    return mRboState.rboData[getRboIndex(rbo_name)].format;
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    const RboProps* props = view.get(rbo_name);
+    if (!props) return 0;
+    return props->format;
 }
 
 GLsizei GLClientState::queryRboSamples(GLuint rbo_name) const {
-    return mRboState.rboData[getRboIndex(rbo_name)].multisamples;
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    const RboProps* props = view.get(rbo_name);
+    if (!props) return 0;
+    return props->multisamples;
+}
+
+GLsizei GLClientState::queryRboWidth(GLuint rbo_name) const {
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    const RboProps* props = view.get(rbo_name);
+    if (!props) return 0;
+    return props->width;
+}
+
+GLsizei GLClientState::queryRboHeight(GLuint rbo_name) const {
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    const RboProps* props = view.get(rbo_name);
+    if (!props) return 0;
+    return props->height;
+}
+
+bool GLClientState::queryRboEGLImageBacked(GLuint rbo_name) const {
+    RenderbufferInfo::ScopedView view(mRboState.rboData);
+    const RboProps* props = view.get(rbo_name);
+    if (!props) return 0;
+    return props->boundEGLImage;
 }
 
 GLint GLClientState::queryTexInternalFormat(GLuint tex_name) const {
@@ -1493,10 +2240,12 @@
     res_info->type = FBO_ATTACHMENT_NONE;
     res_info->rb_format = GL_NONE;
     res_info->rb_multisamples = 0;
+    res_info->rb_external = false;
     res_info->tex_internalformat = -1;
     res_info->tex_format = GL_NONE;
     res_info->tex_type = GL_NONE;
     res_info->tex_multisamples = 0;
+    res_info->tex_external = false;
 
     int colorAttachmentIndex =
         glUtilsColorAttachmentIndex(attachment);
@@ -1510,8 +2259,13 @@
             res_info->rb_multisamples =
                 queryRboSamples(
                         props.colorAttachmenti_rbos[colorAttachmentIndex]);
+            res_info->rb_external =
+                queryRboEGLImageBacked(
+                        props.colorAttachmenti_rbos[colorAttachmentIndex]);
         } else if (props.colorAttachmenti_hasTex[colorAttachmentIndex]) {
             res_info->type = FBO_ATTACHMENT_TEXTURE;
+            res_info->tex_external = queryTexEGLImageBacked(
+                    props.colorAttachmenti_textures[colorAttachmentIndex]);
             res_info->tex_internalformat =
                 queryTexInternalFormat(
                         props.colorAttachmenti_textures[colorAttachmentIndex]);
@@ -1522,6 +2276,8 @@
                 queryTexType(props.colorAttachmenti_textures[colorAttachmentIndex]);
             res_info->tex_multisamples =
                 queryTexSamples(props.colorAttachmenti_textures[colorAttachmentIndex]);
+            res_info->tex_level = props.colorAttachmenti_texture_levels[colorAttachmentIndex];
+            res_info->tex_layer = props.colorAttachmenti_texture_layers[colorAttachmentIndex];
         } else {
             res_info->type = FBO_ATTACHMENT_NONE;
         }
@@ -1535,13 +2291,19 @@
             res_info->rb_multisamples =
                 queryRboSamples(
                         props.depthAttachment_rbo);
+            res_info->rb_external =
+                queryRboEGLImageBacked(
+                        props.depthAttachment_rbo);
         } else if (props.depthAttachment_hasTexObj) {
             res_info->type = FBO_ATTACHMENT_TEXTURE;
+            res_info->tex_external = queryTexEGLImageBacked(props.depthAttachment_texture);
             res_info->tex_internalformat = queryTexInternalFormat(props.depthAttachment_texture);
             res_info->tex_format = queryTexFormat(props.depthAttachment_texture);
             res_info->tex_type = queryTexType(props.depthAttachment_texture);
             res_info->tex_multisamples =
                 queryTexSamples(props.depthAttachment_texture);
+            res_info->tex_level = props.depthAttachment_texture_level;
+            res_info->tex_layer = props.depthAttachment_texture_layer;
         } else {
             res_info->type = FBO_ATTACHMENT_NONE;
         }
@@ -1553,13 +2315,19 @@
             res_info->rb_multisamples =
                 queryRboSamples(
                         props.stencilAttachment_rbo);
+            res_info->rb_external =
+                queryRboEGLImageBacked(
+                        props.stencilAttachment_rbo);
         } else if (props.stencilAttachment_hasTexObj) {
             res_info->type = FBO_ATTACHMENT_TEXTURE;
+            res_info->tex_external = queryTexEGLImageBacked(props.stencilAttachment_texture);
             res_info->tex_internalformat = queryTexInternalFormat(props.stencilAttachment_texture);
             res_info->tex_format = queryTexFormat(props.stencilAttachment_texture);
             res_info->tex_type = queryTexType(props.stencilAttachment_texture);
             res_info->tex_multisamples =
                 queryTexSamples(props.stencilAttachment_texture);
+            res_info->tex_level = props.depthAttachment_texture_level;
+            res_info->tex_layer = props.depthAttachment_texture_layer;
         } else {
             res_info->type = FBO_ATTACHMENT_NONE;
         }
@@ -1571,13 +2339,19 @@
             res_info->rb_multisamples =
                 queryRboSamples(
                         props.depthstencilAttachment_rbo);
+            res_info->rb_external =
+                queryRboEGLImageBacked(
+                        props.depthstencilAttachment_rbo);
         } else if (props.depthstencilAttachment_hasTexObj) {
             res_info->type = FBO_ATTACHMENT_TEXTURE;
+            res_info->tex_external = queryTexEGLImageBacked(props.depthstencilAttachment_texture);
             res_info->tex_internalformat = queryTexInternalFormat(props.depthstencilAttachment_texture);
             res_info->tex_format = queryTexFormat(props.depthstencilAttachment_texture);
             res_info->tex_type = queryTexType(props.depthstencilAttachment_texture);
             res_info->tex_multisamples =
                 queryTexSamples(props.depthstencilAttachment_texture);
+            res_info->tex_level = props.depthAttachment_texture_level;
+            res_info->tex_layer = props.depthAttachment_texture_layer;
         } else {
             res_info->type = FBO_ATTACHMENT_NONE;
         }
@@ -1591,13 +2365,52 @@
     return info.type;
 }
 
-
 int GLClientState::getMaxColorAttachments() const {
-    return m_max_color_attachments;
+    return m_hostDriverCaps.max_color_attachments;
 }
 
 int GLClientState::getMaxDrawBuffers() const {
-    return m_max_draw_buffers;
+    return m_hostDriverCaps.max_draw_buffers;
+}
+
+#define UNIFORM_VALIDATION_ERR_COND(cond, code) if (cond) { *err = code; return; }
+
+#define UNIFORM_VALIDATION_INFO_VAR_NAME info
+
+#define UNIFORM_VALIDATION_TYPE_VIOLATION_FOR_FLOATS \
+    (!(UNIFORM_VALIDATION_INFO_VAR_NAME->isBool) && (UNIFORM_VALIDATION_INFO_VAR_NAME->isInt || UNIFORM_VALIDATION_INFO_VAR_NAME->isSampler))
+
+#define UNIFORM_VALIDATION_TYPE_VIOLATION_FOR_INTS \
+    (!(UNIFORM_VALIDATION_INFO_VAR_NAME->isBool) && (!UNIFORM_VALIDATION_TYPE_VIOLATION_FOR_FLOATS || UNIFORM_VALIDATION_INFO_VAR_NAME->isUnsigned))
+
+#define UNIFORM_VALIDATION_TYPE_VIOLATION_FOR_UNSIGNED_INTS \
+    (!(UNIFORM_VALIDATION_INFO_VAR_NAME->isBool) && (!UNIFORM_VALIDATION_TYPE_VIOLATION_FOR_FLOATS || !(UNIFORM_VALIDATION_INFO_VAR_NAME->isUnsigned)))
+
+#define UNIFORM_VALIDATION_INLINING
+
+void GLClientState::validateUniform(bool isFloat, bool isUnsigned, GLint columns, GLint rows, GLint location, GLsizei count, GLenum* err) {
+    UNIFORM_VALIDATION_ERR_COND(!m_currentProgram && !m_currentShaderProgram, GL_INVALID_OPERATION);
+    if (-1 == location) return; \
+    auto info = currentUniformValidationInfo.get_const(location); \
+    UNIFORM_VALIDATION_ERR_COND(!info || !info->valid, GL_INVALID_OPERATION); \
+    UNIFORM_VALIDATION_ERR_COND(columns != info->columns || rows != info->rows, GL_INVALID_OPERATION); \
+    UNIFORM_VALIDATION_ERR_COND(count > 1 && !info->isArray, GL_INVALID_OPERATION);
+    if (isFloat) {
+        UNIFORM_VALIDATION_ERR_COND(UNIFORM_VALIDATION_TYPE_VIOLATION_FOR_FLOATS, GL_INVALID_OPERATION);
+    } else {
+        if (isUnsigned) {
+            UNIFORM_VALIDATION_ERR_COND(UNIFORM_VALIDATION_TYPE_VIOLATION_FOR_UNSIGNED_INTS, GL_INVALID_OPERATION);
+        } else {
+            UNIFORM_VALIDATION_ERR_COND(UNIFORM_VALIDATION_TYPE_VIOLATION_FOR_INTS, GL_INVALID_OPERATION);
+        }
+    }
+}
+
+bool GLClientState::isAttribIndexUsedByProgram(int index) {
+    auto info = currentAttribValidationInfo.get_const(index);
+    if (!info) return false;
+    if (!info->validInProgram) return false;
+    return true;
 }
 
 void GLClientState::addFreshFramebuffer(GLuint name) {
@@ -1605,22 +2418,32 @@
     props.name = name;
     props.previouslyBound = false;
 
-    props.colorAttachmenti_textures.resize(m_max_color_attachments, 0);
+    props.completenessDirty = true;
+
+    props.colorAttachmenti_textures.resize(m_hostDriverCaps.max_color_attachments, 0);
+    props.colorAttachmenti_texture_levels.resize(m_hostDriverCaps.max_color_attachments, 0);
+    props.colorAttachmenti_texture_layers.resize(m_hostDriverCaps.max_color_attachments, 0);
+
+    props.depthAttachment_texture_level = 0;
+    props.depthAttachment_texture_layer = 0;
+    props.stencilAttachment_texture_level = 0;
+    props.stencilAttachment_texture_layer = 0;
+
     props.depthAttachment_texture = 0;
     props.stencilAttachment_texture = 0;
     props.depthstencilAttachment_texture = 0;
 
-    props.colorAttachmenti_hasTex.resize(m_max_color_attachments, false);
+    props.colorAttachmenti_hasTex.resize(m_hostDriverCaps.max_color_attachments, false);
     props.depthAttachment_hasTexObj = false;
     props.stencilAttachment_hasTexObj = false;
     props.depthstencilAttachment_hasTexObj = false;
 
-    props.colorAttachmenti_rbos.resize(m_max_color_attachments, 0);
+    props.colorAttachmenti_rbos.resize(m_hostDriverCaps.max_color_attachments, 0);
     props.depthAttachment_rbo = 0;
     props.stencilAttachment_rbo = 0;
     props.depthstencilAttachment_rbo = 0;
 
-    props.colorAttachmenti_hasRbo.resize(m_max_color_attachments, false);
+    props.colorAttachmenti_hasRbo.resize(m_hostDriverCaps.max_color_attachments, false);
     props.depthAttachment_hasRbo = false;
     props.stencilAttachment_hasRbo = false;
     props.depthstencilAttachment_hasRbo = false;
@@ -1729,32 +2552,46 @@
 
 void GLClientState::attachTextureObject(
         GLenum target,
-        GLenum attachment, GLuint texture) {
+        GLenum attachment, GLuint texture, GLint level, GLint layer) {
+
+    bool attach = texture != 0;
 
     int colorAttachmentIndex =
         glUtilsColorAttachmentIndex(attachment);
 
+    boundFboProps(target).completenessDirty = true;
+
     if (colorAttachmentIndex != -1) {
         boundFboProps(target).colorAttachmenti_textures[colorAttachmentIndex] = texture;
-        boundFboProps(target).colorAttachmenti_hasTex[colorAttachmentIndex] = true;
+        boundFboProps(target).colorAttachmenti_texture_levels[colorAttachmentIndex] = level;
+        boundFboProps(target).colorAttachmenti_texture_layers[colorAttachmentIndex] = layer;
+        boundFboProps(target).colorAttachmenti_hasTex[colorAttachmentIndex] = attach;
     }
 
     switch (attachment) {
     case GL_DEPTH_ATTACHMENT:
         boundFboProps(target).depthAttachment_texture = texture;
-        boundFboProps(target).depthAttachment_hasTexObj = true;
+        boundFboProps(target).depthAttachment_texture_level = level;
+        boundFboProps(target).depthAttachment_texture_layer = layer;
+        boundFboProps(target).depthAttachment_hasTexObj = attach;
         break;
     case GL_STENCIL_ATTACHMENT:
         boundFboProps(target).stencilAttachment_texture = texture;
-        boundFboProps(target).stencilAttachment_hasTexObj = true;
+        boundFboProps(target).stencilAttachment_texture_level = level;
+        boundFboProps(target).stencilAttachment_texture_layer = layer;
+        boundFboProps(target).stencilAttachment_hasTexObj = attach;
         break;
     case GL_DEPTH_STENCIL_ATTACHMENT:
         boundFboProps(target).depthstencilAttachment_texture = texture;
-        boundFboProps(target).depthstencilAttachment_hasTexObj = true;
+        boundFboProps(target).depthstencilAttachment_hasTexObj = attach;
         boundFboProps(target).stencilAttachment_texture = texture;
-        boundFboProps(target).stencilAttachment_hasTexObj = true;
+        boundFboProps(target).stencilAttachment_hasTexObj = attach;
         boundFboProps(target).depthAttachment_texture = texture;
-        boundFboProps(target).depthAttachment_hasTexObj = true;
+        boundFboProps(target).depthAttachment_hasTexObj = attach;
+        boundFboProps(target).depthAttachment_texture_level = level;
+        boundFboProps(target).depthAttachment_texture_layer = layer;
+        boundFboProps(target).stencilAttachment_texture_level = level;
+        boundFboProps(target).stencilAttachment_texture_layer = layer;
         break;
     }
 }
@@ -1786,7 +2623,7 @@
 // RBOs for FBOs////////////////////////////////////////////////////////////////
 
 void GLClientState::detachRbo(GLuint renderbuffer) {
-    for (int i = 0; i < m_max_color_attachments; i++) {
+    for (int i = 0; i < m_hostDriverCaps.max_color_attachments; i++) {
         detachRboFromFbo(GL_DRAW_FRAMEBUFFER, glUtilsColorAttachmentName(i), renderbuffer);
         detachRboFromFbo(GL_READ_FRAMEBUFFER, glUtilsColorAttachmentName(i), renderbuffer);
     }
@@ -1805,6 +2642,8 @@
     int colorAttachmentIndex =
         glUtilsColorAttachmentIndex(attachment);
 
+    boundFboProps(target).completenessDirty = true;
+
     if (colorAttachmentIndex != -1) {
         if (boundFboProps(target).colorAttachmenti_hasRbo[colorAttachmentIndex] &&
             boundFboProps(target).colorAttachmenti_rbos[colorAttachmentIndex] == renderbuffer) {
@@ -1850,30 +2689,34 @@
 
 void GLClientState::attachRbo(GLenum target, GLenum attachment, GLuint renderbuffer) {
 
+    bool attach = 0 != renderbuffer;
+
     int colorAttachmentIndex =
         glUtilsColorAttachmentIndex(attachment);
 
+    boundFboProps(target).completenessDirty = true;
+
     if (colorAttachmentIndex != -1) {
         boundFboProps(target).colorAttachmenti_rbos[colorAttachmentIndex] = renderbuffer;
-        boundFboProps(target).colorAttachmenti_hasRbo[colorAttachmentIndex] = true;
+        boundFboProps(target).colorAttachmenti_hasRbo[colorAttachmentIndex] = attach;
     }
 
     switch (attachment) {
     case GL_DEPTH_ATTACHMENT:
         boundFboProps(target).depthAttachment_rbo = renderbuffer;
-        boundFboProps(target).depthAttachment_hasRbo = true;
+        boundFboProps(target).depthAttachment_hasRbo = attach;
         break;
     case GL_STENCIL_ATTACHMENT:
         boundFboProps(target).stencilAttachment_rbo = renderbuffer;
-        boundFboProps(target).stencilAttachment_hasRbo = true;
+        boundFboProps(target).stencilAttachment_hasRbo = attach;
         break;
     case GL_DEPTH_STENCIL_ATTACHMENT:
         boundFboProps(target).depthAttachment_rbo = renderbuffer;
-        boundFboProps(target).depthAttachment_hasRbo = true;
+        boundFboProps(target).depthAttachment_hasRbo = attach;
         boundFboProps(target).stencilAttachment_rbo = renderbuffer;
-        boundFboProps(target).stencilAttachment_hasRbo = true;
+        boundFboProps(target).stencilAttachment_hasRbo = attach;
         boundFboProps(target).depthstencilAttachment_rbo = renderbuffer;
-        boundFboProps(target).depthstencilAttachment_hasRbo = true;
+        boundFboProps(target).depthstencilAttachment_hasRbo = attach;
         break;
     }
 }
@@ -1902,6 +2745,80 @@
     return res;
 }
 
+void GLClientState::setFboCompletenessDirtyForTexture(GLuint texture) {
+    std::map<GLuint, FboProps>::iterator it = mFboState.fboData.begin();
+    while (it != mFboState.fboData.end()) {
+        FboProps& props = it->second;
+        for (int i = 0; i < m_hostDriverCaps.max_color_attachments; ++i) {
+            if (props.colorAttachmenti_hasTex[i]) {
+                if (texture == props.colorAttachmenti_textures[i]) {
+                    props.completenessDirty = true;
+                    return;
+                }
+            }
+        }
+
+        if (props.depthAttachment_hasTexObj) {
+            if (texture == props.depthAttachment_texture) {
+                    props.completenessDirty = true;
+                    return;
+            }
+        }
+
+        if (props.stencilAttachment_hasTexObj) {
+            if (texture == props.stencilAttachment_texture) {
+                props.completenessDirty = true;
+                return;
+            }
+        }
+
+        if (props.depthstencilAttachment_hasTexObj) {
+            if (texture == props.depthstencilAttachment_texture) {
+                props.completenessDirty = true;
+                return;
+            }
+        }
+        ++it;
+    }
+}
+
+void GLClientState::setFboCompletenessDirtyForRbo(GLuint rbo) {
+    std::map<GLuint, FboProps>::iterator it = mFboState.fboData.begin();
+    while (it != mFboState.fboData.end()) {
+        FboProps& props = it->second;
+        for (int i = 0; i < m_hostDriverCaps.max_color_attachments; ++i) {
+            if (props.colorAttachmenti_hasTex[i]) {
+                if (rbo == props.colorAttachmenti_rbos[i]) {
+                    props.completenessDirty = true;
+                    return;
+                }
+            }
+        }
+
+        if (props.depthAttachment_hasTexObj) {
+            if (rbo == props.depthAttachment_rbo) {
+                    props.completenessDirty = true;
+                    return;
+            }
+        }
+
+        if (props.stencilAttachment_hasTexObj) {
+            if (rbo == props.stencilAttachment_rbo) {
+                props.completenessDirty = true;
+                return;
+            }
+        }
+
+        if (props.depthstencilAttachment_hasRbo) {
+            if (rbo == props.depthstencilAttachment_rbo) {
+                props.completenessDirty = true;
+                return;
+            }
+        }
+        ++it;
+    }
+}
+
 bool GLClientState::attachmentHasObject(GLenum target, GLenum attachment) const {
     bool res = true; // liberal
 
@@ -1977,22 +2894,63 @@
     return 0;
 }
 
-void GLClientState::setTransformFeedbackActiveUnpaused(bool activeUnpaused) {
-    m_transformFeedbackActiveUnpaused = activeUnpaused;
+void GLClientState::setTransformFeedbackActive(bool active) {
+    m_transformFeedbackActive = active;
+}
+
+void GLClientState::setTransformFeedbackUnpaused(bool unpaused) {
+    m_transformFeedbackUnpaused = unpaused;
+}
+
+void GLClientState::setTransformFeedbackVaryingsCountForLinking(uint32_t count) {
+    m_transformFeedbackVaryingsCountForLinking = count;
+}
+
+bool GLClientState::getTransformFeedbackActive() const {
+    return m_transformFeedbackActive;
+}
+
+bool GLClientState::getTransformFeedbackUnpaused() const {
+    return m_transformFeedbackUnpaused;
 }
 
 bool GLClientState::getTransformFeedbackActiveUnpaused() const {
-    return m_transformFeedbackActiveUnpaused;
+    return m_transformFeedbackActive && m_transformFeedbackUnpaused;
+}
+
+uint32_t GLClientState::getTransformFeedbackVaryingsCountForLinking() const {
+    return m_transformFeedbackVaryingsCountForLinking;
 }
 
 void GLClientState::setTextureData(SharedTextureDataMap* sharedTexData) {
     m_tex.textureRecs = sharedTexData;
 }
 
+void GLClientState::setRenderbufferInfo(RenderbufferInfo* rbInfo) {
+    mRboState.rboData = rbInfo;
+}
+
+void GLClientState::setSamplerInfo(SamplerInfo* samplerInfo) {
+    mSamplerInfo = samplerInfo;
+}
+
+bool GLClientState::compressedTexImageSizeCompatible(GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize) {
+    bool error = false;
+    GLsizei compressedSize = GLESTextureUtils::getCompressedImageSize(internalformat, width, height, depth, &error);
+    if (error) return false;
+    return imageSize == compressedSize;
+}
+
 void GLClientState::fromMakeCurrent() {
     if (mFboState.fboData.find(0) == mFboState.fboData.end()) {
         addFreshFramebuffer(0);
     }
+
+    if (!samplerExists(0)) {
+        GLuint id = 0;
+        setExistence(ObjectType::Sampler, true, 1, &id);
+    }
+
     FboProps& default_fb_props = mFboState.fboData[0];
     default_fb_props.colorAttachmenti_hasRbo[0] = true;
     default_fb_props.depthAttachment_hasRbo = true;
@@ -2001,30 +2959,30 @@
 }
 
 void GLClientState::initFromCaps(
-    int max_transform_feedback_separate_attribs,
-    int max_uniform_buffer_bindings,
-    int max_atomic_counter_buffer_bindings,
-    int max_shader_storage_buffer_bindings,
-    int max_vertex_attrib_bindings,
-    int max_color_attachments,
-    int max_draw_buffers) {
+    const HostDriverCaps& caps) {
+    m_hostDriverCaps = caps;
 
-    m_max_vertex_attrib_bindings = max_vertex_attrib_bindings;
+    // Override some of them
+    m_hostDriverCaps.max_vertex_attribs = CODEC_MAX_VERTEX_ATTRIBUTES;
+    m_hostDriverCaps.max_vertex_attrib_bindings = m_hostDriverCaps.max_vertex_attribs;
+
+    // Derive some other settings
+    m_log2MaxTextureSize = 0;
+    uint32_t current = 1;
+    while (current < m_hostDriverCaps.max_texture_size) {
+        current = current << 1;
+        ++m_log2MaxTextureSize;
+    }
 
     if (m_glesMajorVersion >= 3) {
-        m_max_transform_feedback_separate_attribs = max_transform_feedback_separate_attribs;
-        m_max_uniform_buffer_bindings = max_uniform_buffer_bindings;
-        m_max_atomic_counter_buffer_bindings = max_atomic_counter_buffer_bindings;
-        m_max_shader_storage_buffer_bindings = max_shader_storage_buffer_bindings;
-
-        if (m_max_transform_feedback_separate_attribs)
-            m_indexedTransformFeedbackBuffers.resize(m_max_transform_feedback_separate_attribs);
-        if (m_max_uniform_buffer_bindings)
-            m_indexedUniformBuffers.resize(m_max_uniform_buffer_bindings);
-        if (m_max_atomic_counter_buffer_bindings)
-            m_indexedAtomicCounterBuffers.resize(m_max_atomic_counter_buffer_bindings);
-        if (m_max_shader_storage_buffer_bindings)
-            m_indexedShaderStorageBuffers.resize(m_max_shader_storage_buffer_bindings);
+        if (m_hostDriverCaps.max_transform_feedback_separate_attribs)
+            m_indexedTransformFeedbackBuffers.resize(m_hostDriverCaps.max_transform_feedback_separate_attribs);
+        if (m_hostDriverCaps.max_uniform_buffer_bindings)
+            m_indexedUniformBuffers.resize(m_hostDriverCaps.max_uniform_buffer_bindings);
+        if (m_hostDriverCaps.max_atomic_counter_buffer_bindings)
+            m_indexedAtomicCounterBuffers.resize(m_hostDriverCaps.max_atomic_counter_buffer_bindings);
+        if (m_hostDriverCaps.max_shader_storage_buffer_bindings)
+            m_indexedShaderStorageBuffers.resize(m_hostDriverCaps.max_shader_storage_buffer_bindings);
 
         BufferBinding buf0Binding;
         buf0Binding.buffer = 0;
@@ -2043,10 +3001,6 @@
             m_indexedShaderStorageBuffers[i] = buf0Binding;
     }
 
-    m_max_color_attachments = max_color_attachments;
-    m_max_draw_buffers = max_draw_buffers;
-
-    addFreshRenderbuffer(0);
     addFreshFramebuffer(0);
 
     m_initialized = true;
@@ -2055,3 +3009,60 @@
 bool GLClientState::needsInitFromCaps() const {
     return !m_initialized;
 }
+
+void GLClientState::setExtensions(const std::string& extensions) {
+    if (!m_extensions_set) m_extensions = extensions;
+
+    m_has_color_buffer_float_extension =
+        hasExtension("GL_EXT_color_buffer_float");
+    m_has_color_buffer_half_float_extension =
+        hasExtension("GL_EXT_color_buffer_half_float");
+    m_extensions_set = true;
+}
+
+bool GLClientState::hasExtension(const char* ext) const {
+    return m_extensions.find(ext) != std::string::npos;
+}
+
+using android::base::guest::AutoLock;
+using android::base::guest::Lock;
+
+// A process-wide fence registry (because we can use fence sync objects across multiple contexts)
+struct FenceRegistry {
+    Lock lock;
+    PredicateMap<uint64_t, false> existence;
+
+    void onFenceCreated(GLsync sync) {
+        AutoLock scopedLock(lock);
+        uint64_t asUint64 = (uint64_t)(uintptr_t)(sync);
+        existence.add(asUint64);
+        existence.set(asUint64, true);
+    }
+
+    void onFenceDestroyed(GLsync sync) {
+        AutoLock scopedLock(lock);
+        uint64_t asUint64 = (uint64_t)(uintptr_t)(sync);
+        existence.remove(asUint64);
+    }
+
+    bool exists(GLsync sync) {
+        AutoLock scopedLock(lock);
+        uint64_t asUint64 = (uint64_t)(uintptr_t)(sync);
+        return existence.get(asUint64);
+    }
+};
+
+static FenceRegistry sFenceRegistry;
+
+void GLClientState::onFenceCreated(GLsync sync) {
+    sFenceRegistry.onFenceCreated(sync);
+}
+
+void GLClientState::onFenceDestroyed(GLsync sync) {
+    sFenceRegistry.onFenceDestroyed(sync);
+}
+
+bool GLClientState::fenceExists(GLsync sync) {
+    return sFenceRegistry.exists(sync);
+}
+
diff --git a/shared/OpenglCodecCommon/GLClientState.h b/shared/OpenglCodecCommon/GLClientState.h
index b7f5655..6beeb96 100644
--- a/shared/OpenglCodecCommon/GLClientState.h
+++ b/shared/OpenglCodecCommon/GLClientState.h
@@ -22,6 +22,10 @@
 #define GL_APIENTRYP
 #endif
 
+#ifdef GFXSTREAM
+#include "StateTrackingSupport.h"
+#endif
+
 #include "TextureSharedData.h"
 
 #include <GLES/gl.h>
@@ -37,6 +41,36 @@
 #include <vector>
 #include <map>
 #include <set>
+#include <string>
+
+// Caps of host driver that make it easy to validate stuff
+struct HostDriverCaps {
+    // ES 2
+    int max_vertex_attribs;
+    int max_combined_texture_image_units;
+    int max_color_attachments;
+
+    int max_texture_size;
+    int max_texture_size_cube_map;
+    int max_renderbuffer_size;
+
+    // ES 3.0
+    int max_draw_buffers;
+
+    int ubo_offset_alignment;
+    int max_uniform_buffer_bindings;
+    int max_transform_feedback_separate_attribs;
+
+    int max_texture_size_3d;
+    int max_array_texture_layers;
+
+    // ES 3.1
+    int max_atomic_counter_buffer_bindings;
+    int max_shader_storage_buffer_bindings;
+    int max_vertex_attrib_bindings;
+    int max_vertex_attrib_stride;
+    int ssbo_offset_alignment;
+};
 
 // Tracking framebuffer objects:
 // which framebuffer is bound,
@@ -45,7 +79,17 @@
 struct FboProps {
     GLuint name;
     bool previouslyBound;
+    bool completenessDirty;
+    GLenum cachedCompleteness;
     std::vector<GLuint> colorAttachmenti_textures;
+    std::vector<GLint> colorAttachmenti_texture_levels;
+    std::vector<GLint> colorAttachmenti_texture_layers;
+
+    GLint depthAttachment_texture_level;
+    GLint depthAttachment_texture_layer;
+    GLint stencilAttachment_texture_level;
+    GLint stencilAttachment_texture_layer;
+
     GLuint depthAttachment_texture;
     GLuint stencilAttachment_texture;
     GLuint depthstencilAttachment_texture;
@@ -66,15 +110,6 @@
     bool depthstencilAttachment_hasRbo;
 };
 
-// Same for Rbo's
-struct RboProps {
-    GLenum target;
-    GLuint name;
-    GLenum format;
-    GLsizei multisamples;
-    bool previouslyBound;
-};
-
 // Enum for describing whether a framebuffer attachment
 // is a texture or renderbuffer.
 enum FboAttachmentType {
@@ -88,15 +123,27 @@
     FboAttachmentType type;
     GLenum rb_format;
     GLsizei rb_multisamples;
+    bool rb_external;
 
     GLint tex_internalformat;
     GLenum tex_format;
     GLenum tex_type;
     GLsizei tex_multisamples;
+    GLint tex_level;
+    GLint tex_layer;
+    bool tex_external;
 };
 
 class GLClientState {
 public:
+    // TODO: Unify everything in here
+    typedef enum {
+        Buffer,
+        TransformFeedback,
+        Sampler,
+        Query,
+    } ObjectType;
+
     typedef enum {
         VERTEX_LOCATION = 0,
         NORMAL_LOCATION = 1,
@@ -199,7 +246,7 @@
     GLClientState();
     GLClientState(int majorVersion, int minorVersion);
     ~GLClientState();
-    int nLocations() { return m_nLocations; }
+    int nLocations() { return CODEC_MAX_VERTEX_ATTRIBUTES; }
     const PixelStoreState *pixelStoreState() { return &m_pixelStore; }
     int setPixelStore(GLenum param, GLint value);
     GLuint currentVertexArrayObject() const { return m_currVaoState.vaoId(); }
@@ -230,22 +277,52 @@
     int getLocation(GLenum loc);
     void setActiveTexture(int texUnit) {m_activeTexture = texUnit; };
     int getActiveTexture() const { return m_activeTexture; }
-    void setMaxVertexAttribs(int val) {
-        m_maxVertexAttribs = val;
-        m_maxVertexAttribsDirty = false;
-    }
 
     void addBuffer(GLuint id);
     void removeBuffer(GLuint id);
     bool bufferIdExists(GLuint id) const;
     void unBindBuffer(GLuint id);
 
+    void setBufferHostMapDirty(GLuint id, bool dirty);
+    bool isBufferHostMapDirty(GLuint id) const;
+
+    void setExistence(ObjectType type, bool exists, GLsizei count, const GLuint* ids);
+    bool queryExistence(ObjectType type, GLuint id) const;
+    bool samplerExists(GLuint id) const;
+    bool tryBind(GLenum target, GLuint id);
+    bool isBoundTargetValid(GLenum target);
+    bool isQueryBound(GLenum target);
+    bool isQueryObjectActive(GLuint id);
+    void setLastQueryTarget(GLenum target, GLuint id);
+    GLenum getLastQueryTarget(GLuint id);
+
+    static void onFenceCreated(GLsync sync);
+    static void onFenceDestroyed(GLsync sync);
+    static bool fenceExists(GLsync sync);
+
+    void setBoundPixelPackBufferDirtyForHostMap();
+    void setBoundTransformFeedbackBuffersDirtyForHostMap();
+    void setBoundShaderStorageBuffersDirtyForHostMap();
+    void setBoundAtomicCounterBuffersDirtyForHostMap();
+
     int bindBuffer(GLenum target, GLuint id);
     void bindIndexedBuffer(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size, GLintptr stride, GLintptr effectiveStride);
     int getMaxIndexedBufferBindings(GLenum target) const;
     bool isNonIndexedBindNoOp(GLenum target, GLuint buffer);
     bool isIndexedBindNoOp(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size, GLintptr stride, GLintptr effectiveStride);
 
+    int getMaxTextureSize() const;
+    int getMaxTextureSize3D() const;
+    int getMaxTextureSizeCubeMap() const;
+    int getLog2MaxTextureSize() const;
+
+    void postDraw();
+    void postReadPixels();
+    void postDispatchCompute();
+
+    bool shouldSkipHostMapBuffer(GLenum target);
+    void onHostMappedBuffer(GLenum target);
+
     int getBuffer(GLenum target);
     GLuint getLastEncodedBufferBind(GLenum target);
     void setLastEncodedBufferBind(GLenum target, GLuint id);
@@ -313,7 +390,7 @@
     // glDisable(GL_TEXTURE_(2D|EXTERNAL_OES))
     void disableTextureTarget(GLenum target);
 
-    void bindSampler(GLuint unit, GLuint sampler);
+    bool bindSampler(GLuint unit, GLuint sampler);
     bool isSamplerBindNoOp(GLuint unit, GLuint sampler);
     void onDeleteSamplers(GLsizei n, const GLuint* samplers);
 
@@ -338,6 +415,15 @@
 
     // Return the texture currently bound to GL_TEXTURE_(2D|EXTERNAL_OES).
     GLuint getBoundTexture(GLenum target) const;
+    // Return bound framebuffer for target
+    GLuint getBoundFramebuffer(GLenum target) const;
+
+    // Check framebuffer completeness
+    GLenum checkFramebufferCompleteness(GLenum target);
+    // |currentSamples|: threads through the current sample count of attachments so far,
+    // for validating consistent number of samples across attachments
+    GLenum checkFramebufferAttachmentCompleteness(GLenum target, GLenum attachment, int* currentSamples) const;
+
     // Other publicly-visible texture queries
     GLenum queryTexLastBoundTarget(GLuint name) const;
     GLenum queryTexFormat(GLuint name) const;
@@ -364,12 +450,14 @@
     void setBoundTextureInternalFormat(GLenum target, GLint format);
     void setBoundTextureFormat(GLenum target, GLenum format);
     void setBoundTextureType(GLenum target, GLenum type);
-    void setBoundTextureDims(GLenum target, GLsizei level, GLsizei width, GLsizei height, GLsizei depth);
+    void setBoundTextureDims(GLenum target, GLenum cubetarget, GLsizei level, GLsizei width, GLsizei height, GLsizei depth);
     void setBoundTextureSamples(GLenum target, GLsizei samples);
+    void addTextureCubeMapImage(GLenum stateTarget, GLenum cubeTarget);
 
     // glTexStorage2D disallows any change in texture format after it is set for a particular texture.
     void setBoundTextureImmutableFormat(GLenum target);
     bool isBoundTextureImmutableFormat(GLenum target) const;
+    bool isBoundTextureComplete(GLenum target) const;
 
     // glDeleteTextures(...)
     // Remove references to the to-be-deleted textures.
@@ -383,6 +471,8 @@
     GLuint boundRenderbuffer() const;
     void setBoundRenderbufferFormat(GLenum format);
     void setBoundRenderbufferSamples(GLsizei samples);
+    void setBoundRenderbufferDimensions(GLsizei width, GLsizei height);
+    void setBoundRenderbufferEGLImageBacked();
 
     // Frame buffer objects
     void addFramebuffers(GLsizei n, GLuint* framebuffers);
@@ -394,7 +484,7 @@
     GLuint boundFramebuffer(GLenum target) const;
 
     // Texture object -> FBO
-    void attachTextureObject(GLenum target, GLenum attachment, GLuint texture);
+    void attachTextureObject(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
     GLuint getFboAttachmentTextureId(GLenum target, GLenum attachment) const;
 
     // RBO -> FBO
@@ -407,11 +497,24 @@
     bool attachmentHasObject(GLenum target, GLenum attachment) const;
     GLuint objectOfAttachment(GLenum target, GLenum attachment) const;
 
+    // Dirty FBO completeness
+    void setFboCompletenessDirtyForTexture(GLuint texture);
+    void setFboCompletenessDirtyForRbo(GLuint rbo_name);
+
     // Transform feedback state
-    void setTransformFeedbackActiveUnpaused(bool activeUnpaused);
+    void setTransformFeedbackActive(bool active);
+    void setTransformFeedbackUnpaused(bool unpaused);
+    void setTransformFeedbackVaryingsCountForLinking(uint32_t count);
+    bool getTransformFeedbackActive() const;
+    bool getTransformFeedbackUnpaused() const;
     bool getTransformFeedbackActiveUnpaused() const;
+    uint32_t getTransformFeedbackVaryingsCountForLinking() const;
 
     void setTextureData(SharedTextureDataMap* sharedTexData);
+    void setRenderbufferInfo(RenderbufferInfo* rbInfo);
+    void setSamplerInfo(SamplerInfo* samplerInfo);
+
+    bool compressedTexImageSizeCompatible(GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize);
     // set eglsurface property on default framebuffer
     // if coming from eglMakeCurrent
     void fromMakeCurrent();
@@ -420,14 +523,10 @@
     // accurate values for indexed buffers
     // and # render targets.
     void initFromCaps(
-        int max_transform_feedback_separate_attribs,
-        int max_uniform_buffer_bindings,
-        int max_atomic_counter_buffer_bindings,
-        int max_shader_storage_buffer_bindings,
-        int max_vertex_attrib_bindings,
-        int max_color_attachments,
-        int max_draw_buffers);
+        const HostDriverCaps& caps);
     bool needsInitFromCaps() const;
+    void setExtensions(const std::string& extensions);
+    bool hasExtension(const char* ext) const;
 
     // Queries the format backing the current framebuffer.
     // Type differs depending on whether the attachment
@@ -441,12 +540,52 @@
             GLenum attachment) const;
     int getMaxColorAttachments() const;
     int getMaxDrawBuffers() const;
+
+    // Uniform/attribute validation info
+    UniformValidationInfo currentUniformValidationInfo;
+    AttribValidationInfo currentAttribValidationInfo;;
+
+    // Uniform validation api
+    void validateUniform(bool isFloat, bool isUnsigned, GLint columns, GLint rows, GLint location, GLsizei count, GLenum* err);
+    // Attrib validation
+    bool isAttribIndexUsedByProgram(int attribIndex);
+
 private:
     void init();
     bool m_initialized;
     PixelStoreState m_pixelStore;
 
+#ifdef GFXSTREAM
+    using DirtyMap = PredicateMap<uint32_t, true>;
+
+    ExistenceMap mBufferIds;
+    ExistenceMap mTransformFeedbackIds;
+    SamplerInfo* mSamplerInfo;
+    ExistenceMap mQueryIds;
+    LastQueryTargetInfo mLastQueryTargets;
+
+    // Bound query target validity and tracking
+    struct BoundTargetInfo {
+        GLuint id;
+        bool valid;
+    };
+   
+    // Transform feedback
+    BoundTargetInfo mBoundTransformFeedbackValidity;
+
+    // Queries
+    // GL_ANY_SAMPLES_PASSED
+    BoundTargetInfo mBoundQueryValidity_AnySamplesPassed;
+    // GL_ANY_SAMPLES_PASSED_CONSERVATIVE
+    BoundTargetInfo mBoundQueryValidity_AnySamplesPassedConservative;
+    // GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
+    BoundTargetInfo mBoundQueryValidity_TransformFeedbackPrimitivesWritten;
+
+    // Dirty maps
+    DirtyMap mHostMappedBufferDirty;
+#else
     std::set<GLuint> mBufferIds;
+#endif
 
     // GL_ARRAY_BUFFER_BINDING is separate from VAO state
     GLuint m_arrayBuffer;
@@ -475,23 +614,23 @@
     GLuint m_drawIndirectBuffer;
     GLuint m_shaderStorageBuffer;
 
-    bool m_transformFeedbackActiveUnpaused;
+    bool m_transformFeedbackActive;
+    bool m_transformFeedbackUnpaused;
+    uint32_t m_transformFeedbackVaryingsCountForLinking;
 
-    int m_max_transform_feedback_separate_attribs;
-    int m_max_uniform_buffer_bindings;
-    int m_max_atomic_counter_buffer_bindings;
-    int m_max_shader_storage_buffer_bindings;
-    int m_max_vertex_attrib_bindings;
+    HostDriverCaps m_hostDriverCaps;
+    bool m_extensions_set;
+    std::string m_extensions;
+    bool m_has_color_buffer_float_extension;
+    bool m_has_color_buffer_half_float_extension;
     std::vector<BufferBinding> m_indexedTransformFeedbackBuffers;
     std::vector<BufferBinding> m_indexedUniformBuffers;
     std::vector<BufferBinding> m_indexedAtomicCounterBuffers;
     std::vector<BufferBinding> m_indexedShaderStorageBuffers;
+    int m_log2MaxTextureSize;
 
     int m_glesMajorVersion;
     int m_glesMinorVersion;
-    int m_maxVertexAttribs;
-    bool m_maxVertexAttribsDirty;
-    int m_nLocations;
     int m_activeTexture;
     GLint m_currentProgram;
     GLint m_currentShaderProgram;
@@ -546,19 +685,14 @@
     GLenum copyTexImageNeededTarget(GLenum target, GLint level,
                                     GLenum internalformat);
 
-    int m_max_color_attachments;
-    int m_max_draw_buffers;
     struct RboState {
         GLuint boundRenderbuffer;
-        size_t boundRenderbufferIndex;
-        std::vector<RboProps> rboData;
+        // Connects to share group.
+        // Expected that share group lifetime outlives this context.
+        RenderbufferInfo* rboData;
     };
     RboState mRboState;
     void addFreshRenderbuffer(GLuint name);
-    void setBoundRenderbufferIndex();
-    size_t getRboIndex(GLuint name) const;
-    RboProps& boundRboProps();
-    const RboProps& boundRboProps_const() const;
 
     struct FboState {
         GLuint boundDrawFramebuffer;
@@ -576,6 +710,9 @@
     // Querying framebuffer format
     GLenum queryRboFormat(GLuint name) const;
     GLsizei queryRboSamples(GLuint name) const;
+    GLsizei queryRboWidth(GLuint name) const;
+    GLsizei queryRboHeight(GLuint name) const;
+    bool queryRboEGLImageBacked(GLuint name) const;
     GLenum queryTexType(GLuint name) const;
     GLsizei queryTexSamples(GLuint name) const;
 
@@ -584,6 +721,13 @@
     TextureRec* getTextureRec(GLuint id) const;
 
 public:
+    bool isTexture(GLuint name) const;
+    bool isTextureWithStorage(GLuint name) const;
+    bool isTextureWithTarget(GLuint name) const;
+    bool isTextureCubeMap(GLuint name) const;
+    bool isRenderbuffer(GLuint name) const;
+    bool isRenderbufferThatWasBound(GLuint name) const;
+
     void getClientStatePointer(GLenum pname, GLvoid** params);
 
     template <class T>
@@ -815,12 +959,8 @@
             break;
             }
         case GL_MAX_VERTEX_ATTRIBS: {
-            if (m_maxVertexAttribsDirty) {
-                isClientStateParam = false;
-            } else {
-                *out = m_maxVertexAttribs;
-                isClientStateParam = true;
-            }
+            *out = CODEC_MAX_VERTEX_ATTRIBUTES;
+            isClientStateParam = true;
             break;
         }
         }
diff --git a/shared/OpenglCodecCommon/GLESTextureUtils.cpp b/shared/OpenglCodecCommon/GLESTextureUtils.cpp
index cedcda8..8b4c0c2 100644
--- a/shared/OpenglCodecCommon/GLESTextureUtils.cpp
+++ b/shared/OpenglCodecCommon/GLESTextureUtils.cpp
@@ -1,6 +1,8 @@
 #include "GLESTextureUtils.h"
 
 #include "glUtils.h"
+#include "etc.h"
+#include "astc-codec.h"
 
 #if PLATFORM_SDK_VERSION < 26
 #include <cutils/log.h>
@@ -8,6 +10,36 @@
 #include <log/log.h>
 #endif
 
+#define ASTC_FORMATS_LIST(EXPAND_MACRO) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, astc_codec::FootprintType::k4x4, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_5x4_KHR, astc_codec::FootprintType::k5x4, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, astc_codec::FootprintType::k5x5, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_6x5_KHR, astc_codec::FootprintType::k6x5, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, astc_codec::FootprintType::k6x6, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_8x5_KHR, astc_codec::FootprintType::k8x5, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_8x6_KHR, astc_codec::FootprintType::k8x6, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, astc_codec::FootprintType::k8x8, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_10x5_KHR, astc_codec::FootprintType::k10x5, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_10x6_KHR, astc_codec::FootprintType::k10x6, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_10x8_KHR, astc_codec::FootprintType::k10x8, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, astc_codec::FootprintType::k10x10, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_12x10_KHR, astc_codec::FootprintType::k12x10, false) \
+    EXPAND_MACRO(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, astc_codec::FootprintType::k12x12, false) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, astc_codec::FootprintType::k4x4, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, astc_codec::FootprintType::k5x4, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, astc_codec::FootprintType::k5x5, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, astc_codec::FootprintType::k6x5, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, astc_codec::FootprintType::k6x6, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, astc_codec::FootprintType::k8x5, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, astc_codec::FootprintType::k8x6, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, astc_codec::FootprintType::k8x8, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, astc_codec::FootprintType::k10x5, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, astc_codec::FootprintType::k10x6, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, astc_codec::FootprintType::k10x8, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, astc_codec::FootprintType::k10x10, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, astc_codec::FootprintType::k12x10, true) \
+    EXPAND_MACRO(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, astc_codec::FootprintType::k12x12, true) \
+
 namespace GLESTextureUtils {
 
 // Based on computations in
@@ -332,6 +364,8 @@
         int* packingPixelImageSize,
         int* packingTotalImageSize) {
 
+    (void)depth;
+
     int widthTotal = (packRowLength == 0) ? width : packRowLength;
     int totalRowSize = computePitch(widthTotal, format, type, packAlignment);
     int pixelsOnlyRowSize = computePitch(width, format, type, packAlignment);
@@ -352,4 +386,184 @@
     if (packingTotalImageSize) *packingTotalImageSize = totalImageSize;
 }
 
+bool isEtcFormat(GLenum internalformat) {
+    switch (internalformat) {
+    case GL_ETC1_RGB8_OES:
+    case GL_COMPRESSED_RGB8_ETC2:
+    case GL_COMPRESSED_SRGB8_ETC2:
+    case GL_COMPRESSED_RGBA8_ETC2_EAC:
+    case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+    case GL_COMPRESSED_R11_EAC:
+    case GL_COMPRESSED_SIGNED_R11_EAC:
+    case GL_COMPRESSED_RG11_EAC:
+    case GL_COMPRESSED_SIGNED_RG11_EAC:
+    case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+    case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+        return true;
+    }
+    return false;
+}
+
+bool isEtc2Format(GLenum internalformat) {
+    return internalformat != GL_ETC1_RGB8_OES &&
+        isEtcFormat(internalformat);
+}
+
+ETC2ImageFormat getEtcFormat(GLenum internalformat) {
+    ETC2ImageFormat etcFormat = EtcRGB8;
+    switch (internalformat) {
+        case GL_COMPRESSED_RGB8_ETC2:
+        case GL_ETC1_RGB8_OES:
+            break;
+        case GL_COMPRESSED_RGBA8_ETC2_EAC:
+            etcFormat = EtcRGBA8;
+            break;
+        case GL_COMPRESSED_SRGB8_ETC2:
+            break;
+        case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+            etcFormat = EtcRGBA8;
+            break;
+        case GL_COMPRESSED_R11_EAC:
+            etcFormat = EtcR11;
+            break;
+        case GL_COMPRESSED_SIGNED_R11_EAC:
+            etcFormat = EtcSignedR11;
+            break;
+        case GL_COMPRESSED_RG11_EAC:
+            etcFormat = EtcRG11;
+            break;
+        case GL_COMPRESSED_SIGNED_RG11_EAC:
+            etcFormat = EtcSignedRG11;
+            break;
+        case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+            etcFormat = EtcRGB8A1;
+            break;
+        case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+            etcFormat = EtcRGB8A1;
+            break;
+    }
+    return etcFormat;
+}
+
+bool isAstcFormat(GLenum internalformat) {
+    switch (internalformat) {
+#define ASTC_FORMAT(typeName, footprintType, srgbValue) \
+        case typeName:
+
+        ASTC_FORMATS_LIST(ASTC_FORMAT)
+#undef ASTC_FORMAT
+            return true;
+        default:
+            return false;
+    }
+}
+
+void getAstcFormatInfo(GLenum internalformat,
+                       astc_codec::FootprintType* footprint,
+                       bool* srgb) {
+    switch (internalformat) {
+#define ASTC_FORMAT(typeName, footprintType, srgbValue) \
+        case typeName: \
+            *footprint = footprintType; *srgb = srgbValue; break; \
+
+        ASTC_FORMATS_LIST(ASTC_FORMAT)
+#undef ASTC_FORMAT
+        default:
+            ALOGE("%s: invalid astc format: 0x%x\n", __func__, internalformat);
+            abort();
+    }
+}
+
+int getAstcFootprintWidth(astc_codec::FootprintType footprint) {
+    switch (footprint) {
+        case astc_codec::FootprintType::k4x4: return 4;
+        case astc_codec::FootprintType::k5x4: return 5;
+        case astc_codec::FootprintType::k5x5: return 5;
+        case astc_codec::FootprintType::k6x5: return 6;
+        case astc_codec::FootprintType::k6x6: return 6;
+        case astc_codec::FootprintType::k8x5: return 8;
+        case astc_codec::FootprintType::k8x6: return 8;
+        case astc_codec::FootprintType::k10x5: return 10;
+        case astc_codec::FootprintType::k10x6: return 10;
+        case astc_codec::FootprintType::k8x8: return 8;
+        case astc_codec::FootprintType::k10x8: return 10;
+        case astc_codec::FootprintType::k10x10: return 10;
+        case astc_codec::FootprintType::k12x10: return 12;
+        case astc_codec::FootprintType::k12x12: return 12;
+        default:
+            ALOGE("%s: invalid astc footprint: 0x%x\n", __func__, footprint);
+            abort();
+    }
+}
+
+int getAstcFootprintHeight(astc_codec::FootprintType footprint) {
+    switch (footprint) {
+        case astc_codec::FootprintType::k4x4: return 4;
+        case astc_codec::FootprintType::k5x4: return 4;
+        case astc_codec::FootprintType::k5x5: return 5;
+        case astc_codec::FootprintType::k6x5: return 5;
+        case astc_codec::FootprintType::k6x6: return 6;
+        case astc_codec::FootprintType::k8x5: return 5;
+        case astc_codec::FootprintType::k8x6: return 6;
+        case astc_codec::FootprintType::k10x5: return 5;
+        case astc_codec::FootprintType::k10x6: return 6;
+        case astc_codec::FootprintType::k8x8: return 8;
+        case astc_codec::FootprintType::k10x8: return 8;
+        case astc_codec::FootprintType::k10x10: return 10;
+        case astc_codec::FootprintType::k12x10: return 10;
+        case astc_codec::FootprintType::k12x12: return 12;
+        default:
+            ALOGE("%s: invalid astc footprint: 0x%x\n", __func__, footprint);
+            abort();
+    }
+}
+
+GLsizei getAstcCompressedSize(GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool* error) {
+    bool srgb;
+    astc_codec::FootprintType footprintType;
+    getAstcFormatInfo(internalformat, &footprintType, &srgb);
+
+    int fpWidth = getAstcFootprintWidth(footprintType);
+    int fpHeight = getAstcFootprintHeight(footprintType);
+
+    if (width == 0 || height == 0 || depth == 0) {
+        *error = true;
+        return 0;
+    }
+
+    const size_t blocks_wide = (width + fpWidth - 1) / fpWidth;
+    if (blocks_wide == 0) {
+        *error = true;
+        return 0;
+    }
+
+    const size_t expected_block_count =
+        ((width + fpWidth - 1) / fpWidth) *
+        ((height + fpHeight - 1) / fpHeight);
+
+    const size_t kPhysBlockSizeBytes = 16;
+
+    GLsizei res = kPhysBlockSizeBytes * expected_block_count * depth;
+
+    return res;
+}
+
+GLsizei getCompressedImageSize(GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool* error) {
+    if (isEtcFormat(internalformat)) {
+        GLsizei total = 0;
+        GLsizei one = etc_get_encoded_data_size(getEtcFormat(internalformat), width, height);
+        for (GLsizei i = 0; i < depth; ++i) {
+            total += one;
+        }
+        return total;
+    }
+
+    if (isAstcFormat(internalformat)) {
+        return getAstcCompressedSize(internalformat, width, height, depth, error);
+    }
+
+    ALOGE("%s: Unknown compressed internal format: 0x%x\n", __func__, internalformat);
+    abort();
+}
+
 } // namespace GLESTextureUtils
diff --git a/shared/OpenglCodecCommon/GLESTextureUtils.h b/shared/OpenglCodecCommon/GLESTextureUtils.h
index 1d26b3a..c2948bd 100644
--- a/shared/OpenglCodecCommon/GLESTextureUtils.h
+++ b/shared/OpenglCodecCommon/GLESTextureUtils.h
@@ -71,5 +71,12 @@
         int* packingPixelImageSize,
         int* packingTotalImageSize);
 
+// For calculating compressed sizes of ETC/EAC formatted images in the guest.
+GLsizei getCompressedImageSize(GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool* error);
+
+// Format queries
+bool isEtc2Format(GLenum internalformat);
+bool isAstcFormat(GLenum internalformat);
+
 } // namespace GLESTextureUtils
 #endif
diff --git a/shared/OpenglCodecCommon/GLSharedGroup.cpp b/shared/OpenglCodecCommon/GLSharedGroup.cpp
index 5273e4c..e2ed36c 100755
--- a/shared/OpenglCodecCommon/GLSharedGroup.cpp
+++ b/shared/OpenglCodecCommon/GLSharedGroup.cpp
@@ -17,6 +17,7 @@
 #include "GLSharedGroup.h"
 
 #include "KeyedVectorUtils.h"
+#include "glUtils.h"
 
 /**** BufferData ****/
 
@@ -36,17 +37,26 @@
 
 /**** ProgramData ****/
 ProgramData::ProgramData() : m_numIndexes(0),
+                             m_numAttributes(0),
                              m_initialized(false) {
     m_Indexes = NULL;
+    m_attribIndexes = NULL;
+    m_refcount = 1;
+    m_linkStatus = 0;
+    m_activeUniformBlockCount = 0;
+    m_transformFeedbackVaryingsCount = 0;
 }
 
-void ProgramData::initProgramData(GLuint numIndexes) {
+void ProgramData::initProgramData(GLuint numIndexes, GLuint numAttributes) {
     m_initialized = true;
     m_numIndexes = numIndexes;
+    m_numAttributes = numAttributes;
 
     delete [] m_Indexes;
+    delete [] m_attribIndexes;
 
     m_Indexes = new IndexInfo[numIndexes];
+    m_attribIndexes = new AttribInfo[m_numAttributes];
 }
 
 bool ProgramData::isInitialized() {
@@ -56,6 +66,7 @@
 ProgramData::~ProgramData() {
 
     delete [] m_Indexes;
+    delete [] m_attribIndexes;
 
     m_Indexes = NULL;
 }
@@ -73,6 +84,16 @@
     m_Indexes[index].samplerValue = 0;
 }
 
+void ProgramData::setAttribInfo(
+    GLuint index, GLint attribLoc, GLint size, GLenum type) {
+
+    if (index >= m_numAttributes) return;
+
+    m_attribIndexes[index].attribLoc = attribLoc;
+    m_attribIndexes[index].size = size;
+    m_attribIndexes[index].type = type;
+}
+
 void ProgramData::setIndexFlags(GLuint index, GLuint flags) {
 
     if (index >= m_numIndexes) return;
@@ -104,6 +125,16 @@
     return 0;
 }
 
+bool ProgramData::isValidUniformLocation(GLint location) {
+    for (GLuint i = 0; i < m_numIndexes; ++i) {
+        if (location >= m_Indexes[i].base &&
+            location < m_Indexes[i].base + m_Indexes[i].size)
+            return true;
+    }
+
+    return false;
+}
+
 GLint ProgramData::getNextSamplerUniform(
     GLint index, GLint* val, GLenum* target) {
 
@@ -154,15 +185,18 @@
     return false;
 }
 
-bool ProgramData::attachShader(GLuint shader) {
+bool ProgramData::attachShader(GLuint shader, GLenum shaderType) {
     size_t n = m_shaders.size();
 
     for (size_t i = 0; i < n; i++) {
         if (m_shaders[i] == shader) {
             return false;
+        } else if (m_shaderTypes[i] == shaderType) {
+            return false;
         }
     }
     m_shaders.push_back(shader);
+    m_shaderTypes.push_back(shaderType);
     return true;
 }
 
@@ -172,6 +206,7 @@
     for (size_t i = 0; i < n; i++) {
         if (m_shaders[i] == shader) {
             m_shaders.erase(m_shaders.begin() + i);
+            m_shaderTypes.erase(m_shaderTypes.begin() + i);
             return true;
         }
     }
@@ -179,6 +214,55 @@
     return false;
 }
 
+UniformValidationInfo ProgramData::compileValidationInfo(bool* error) const {
+    UniformValidationInfo res;
+    if (!m_Indexes) {
+        *error = true;
+        return res;
+    }
+
+    for (GLuint i = 0; i < m_numIndexes; ++i) {
+        if (m_Indexes[i].base < 0) continue;
+
+        UniformLocationInfo info = {
+            .valid = true,
+            .columns = getColumnsOfType(m_Indexes[i].type),
+            .rows = getRowsOfType(m_Indexes[i].type),
+            .isSampler = isSamplerType(m_Indexes[i].type),
+            .isInt = isIntegerType(m_Indexes[i].type),
+            .isArray = m_Indexes[i].size > 1,
+            .isUnsigned = isUnsignedIntType(m_Indexes[i].type),
+            .isBool = isBoolType(m_Indexes[i].type),
+        };
+        for (GLuint j = 0; j < m_Indexes[i].size; ++j) {
+            res.add(m_Indexes[i].base + j, info);
+        }
+    }
+
+    return res;
+}
+
+AttribValidationInfo ProgramData::compileAttribValidationInfo(bool* error) const {
+    AttribValidationInfo res;
+    if (!m_attribIndexes) {
+        *error = true;
+        return res;
+    }
+
+    for (GLuint i = 0; i < m_numAttributes; ++i) {
+        if (m_attribIndexes[i].attribLoc < 0) continue;
+
+        AttribIndexInfo info = {
+            .validInProgram = true,
+        };
+
+        for (GLuint j = 0; j < getAttributeCountOfType(m_attribIndexes[i].type) * m_attribIndexes[i].size ; ++j) {
+            res.add(m_attribIndexes[i].attribLoc + j, info);
+        }
+    }
+
+    return res;
+}
 /***** GLSharedGroup ****/
 
 GLSharedGroup::GLSharedGroup() { }
@@ -212,6 +296,14 @@
     return &m_textureRecs;
 }
 
+RenderbufferInfo* GLSharedGroup::getRenderbufferInfo() {
+    return &m_renderbufferInfo;
+}
+
+SamplerInfo* GLSharedGroup::getSamplerInfo() {
+    return &m_samplerInfo;
+}
+
 void GLSharedGroup::addBufferData(GLuint bufferId, GLsizeiptr size, const void* data) {
 
     android::AutoMutex _lock(m_lock);
@@ -302,16 +394,37 @@
     m_programs[program] = new ProgramData();
 }
 
-void GLSharedGroup::initProgramData(GLuint program, GLuint numIndexes) {
+void GLSharedGroup::initProgramData(GLuint program, GLuint numIndexes, GLuint numAttributes) {
 
     android::AutoMutex _lock(m_lock);
 
     ProgramData* pData = findObjectOrDefault(m_programs, program);
     if (pData) {
-        pData->initProgramData(numIndexes);
+        pData->initProgramData(numIndexes, numAttributes);
     }
 }
 
+void GLSharedGroup::refProgramData(GLuint program) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData = findObjectOrDefault(m_programs, program);
+    if (!pData) return;
+    pData->incRef();
+}
+
+void GLSharedGroup::onUseProgram(GLuint previous, GLuint next) {
+    if (previous == next) return;
+
+    android::AutoMutex _lock(m_lock);
+
+    if (previous) {
+        deleteProgramDataLocked(previous);
+    }
+
+    ProgramData* pData = findObjectOrDefault(m_programs, next);
+    if (!pData) return;
+    pData->incRef();
+}
+
 bool GLSharedGroup::isProgramInitialized(GLuint program) {
 
     android::AutoMutex _lock(m_lock);
@@ -337,14 +450,23 @@
 }
 
 void GLSharedGroup::deleteProgramData(GLuint program) {
-
     android::AutoMutex _lock(m_lock);
+    deleteProgramDataLocked(program);
+}
+
+void GLSharedGroup::deleteProgramDataLocked(GLuint program) {
 
     ProgramData* pData = findObjectOrDefault(m_programs, program);
 
-    if (pData) delete pData;
-
-    m_programs.erase(program);
+    if (pData && pData->decRef()) {
+        size_t numShaders = pData->getNumShaders();
+        for (size_t i = 0; i < numShaders; ++i) {
+            // changes the first one
+            detachShaderLocked(program, pData->getShader(0));
+        }
+        delete pData;
+        m_programs.erase(program);
+    }
 
     if (m_shaderProgramIdMap.find(program) ==
         m_shaderProgramIdMap.end()) return;
@@ -360,31 +482,43 @@
 }
 
 // No such thing for separable shader programs.
-void GLSharedGroup::attachShader(GLuint program, GLuint shader) {
-
+bool GLSharedGroup::attachShader(GLuint program, GLuint shader) {
     android::AutoMutex _lock(m_lock);
 
     ProgramData* pData = findObjectOrDefault(m_programs, program);
     ShaderData* sData = findObjectOrDefault(m_shaders, shader);
 
+    bool res = false;
+
     if (pData && sData) {
-        if (pData->attachShader(shader)) {
+        res = pData->attachShader(shader, sData->shaderType);
+        if (res) {
             refShaderDataLocked(shader);
         }
     }
+
+    return res;
 }
 
-void GLSharedGroup::detachShader(GLuint program, GLuint shader) {
-
+bool GLSharedGroup::detachShader(GLuint program, GLuint shader) {
     android::AutoMutex _lock(m_lock);
+    return detachShaderLocked(program, shader);
+}
 
+bool GLSharedGroup::detachShaderLocked(GLuint program, GLuint shader) {
     ProgramData* pData = findObjectOrDefault(m_programs, program);
     ShaderData* sData = findObjectOrDefault(m_shaders, shader);
+
+    bool res = false;
+
     if (pData && sData) {
-        if (pData->detachShader(shader)) {
+        res = pData->detachShader(shader);
+        if (res) {
             unrefShaderDataLocked(shader);
         }
     }
+
+    return res;
 }
 
 // Not needed/used for separate shader programs.
@@ -422,6 +556,19 @@
     }
 }
 
+void GLSharedGroup::setProgramAttribInfo(
+    GLuint program, GLuint index, GLint attribLoc,
+    GLint size, GLenum type, const char* name) {
+
+    android::AutoMutex _lock(m_lock);
+
+    ProgramData* pData = getProgramDataLocked(program);
+
+    if (pData) {
+        pData->setAttribInfo(index,attribLoc,size,type);
+    }
+}
+
 GLenum GLSharedGroup::getProgramUniformType(GLuint program, GLint location) {
 
     android::AutoMutex _lock(m_lock);
@@ -509,6 +656,19 @@
     return false;
 }
 
+bool GLSharedGroup::isProgramUniformLocationValid(GLuint program, GLint location) {
+    if (location < 0) return false;
+
+    android::AutoMutex _lock(m_lock);
+
+    ProgramData* pData =
+        findObjectOrDefault(m_programs, program);
+
+    if (!pData) return false;
+
+    return pData->isValidUniformLocation(location);
+}
+
 bool GLSharedGroup::isShader(GLuint shader) {
 
     android::AutoMutex _lock(m_lock);
@@ -518,7 +678,7 @@
     return pData != NULL;
 }
 
-bool GLSharedGroup::addShaderData(GLuint shader) {
+bool GLSharedGroup::addShaderData(GLuint shader, GLenum shaderType) {
 
     android::AutoMutex _lock(m_lock);
 
@@ -527,6 +687,7 @@
     if (data) {
         m_shaders[shader] = data;
         data->refcount = 1;
+        data->shaderType = shaderType;
     }
 
     return data != NULL;
@@ -562,6 +723,21 @@
     }
 }
 
+ProgramData* GLSharedGroup::getProgramDataLocked(GLuint program) {
+    // Check the space of normal programs, then separable ones
+    ProgramData* pData = findObjectOrDefault(m_programs, program);
+
+    if (pData) return pData;
+
+    std::map<GLuint, uint32_t>::const_iterator it =
+        m_shaderProgramIdMap.find(program);
+    if (it == m_shaderProgramIdMap.end()) return NULL;
+
+    ShaderProgramData* spData = findObjectOrDefault(m_shaderPrograms, it->second);
+    if (!spData) return NULL;
+    return &spData->programData;
+}
+
 uint32_t GLSharedGroup::addNewShaderProgramData() {
 
     android::AutoMutex _lock(m_lock);
@@ -569,8 +745,6 @@
     ShaderProgramData* data = new ShaderProgramData;
     uint32_t currId = m_shaderProgramId;
 
-    ALOGD("%s: new data %p id %u", __FUNCTION__, data, currId);
-
     m_shaderPrograms[currId] = data;
     m_shaderProgramId++;
     return currId;
@@ -590,8 +764,6 @@
 
     ShaderProgramData* res = findObjectOrDefault(m_shaderPrograms, id);
 
-    ALOGD("%s: id=%u res=%p", __FUNCTION__, id, res);
-
     return res;
 }
 
@@ -630,9 +802,9 @@
     m_shaderProgramIdMap.erase(shaderProgramName);
 }
 
-void GLSharedGroup::initShaderProgramData(GLuint shaderProgram, GLuint numIndices) {
+void GLSharedGroup::initShaderProgramData(GLuint shaderProgram, GLuint numIndices, GLuint numAttributes) {
     ShaderProgramData* spData = getShaderProgramData(shaderProgram);
-    spData->programData.initProgramData(numIndices);
+    spData->programData.initProgramData(numIndices, numAttributes);
 }
 
 void GLSharedGroup::setShaderProgramIndexInfo(
@@ -662,3 +834,101 @@
         }
     }
 }
+
+UniformValidationInfo GLSharedGroup::getUniformValidationInfo(GLuint program) {
+    UniformValidationInfo res;
+
+    android::AutoMutex _lock(m_lock);
+
+    ProgramData* pData =
+        getProgramDataLocked(program);
+
+    if (!pData) return res;
+
+    bool error; (void)error;
+    return pData->compileValidationInfo(&error);
+}
+
+AttribValidationInfo GLSharedGroup::getAttribValidationInfo(GLuint program) {
+    AttribValidationInfo res;
+
+    android::AutoMutex _lock(m_lock);
+
+    ProgramData* pData =
+        getProgramDataLocked(program);
+
+    if (!pData) return res;
+
+    bool error; (void)error;
+    return pData->compileAttribValidationInfo(&error);
+}
+
+void GLSharedGroup::setProgramLinkStatus(GLuint program, GLint linkStatus) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData =
+        getProgramDataLocked(program);
+    if (!pData) return;
+    pData->setLinkStatus(linkStatus);
+}
+
+GLint GLSharedGroup::getProgramLinkStatus(GLuint program) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData = getProgramDataLocked(program);
+    if (!pData) return 0;
+    return pData->getLinkStatus();
+}
+
+void GLSharedGroup::setActiveUniformBlockCountForProgram(GLuint program, GLint count) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData =
+        getProgramDataLocked(program);
+
+    if (!pData) return;
+
+    pData->setActiveUniformBlockCount(count);
+}
+
+GLint GLSharedGroup::getActiveUniformBlockCount(GLuint program) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData =
+        getProgramDataLocked(program);
+
+    if (!pData) return 0;
+
+    return pData->getActiveUniformBlockCount();
+}
+
+void GLSharedGroup::setTransformFeedbackVaryingsCountForProgram(GLuint program, GLint count) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData = getProgramDataLocked(program);
+    if (!pData) return;
+    pData->setTransformFeedbackVaryingsCount(count);
+}
+
+GLint GLSharedGroup::getTransformFeedbackVaryingsCountForProgram(GLuint program) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData = getProgramDataLocked(program);
+    if (!pData) return 0;
+    return pData->getTransformFeedbackVaryingsCount();
+}
+
+int GLSharedGroup::getActiveUniformsCountForProgram(GLuint program) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData =
+        getProgramDataLocked(program);
+
+    if (!pData) return 0;
+
+    return pData->getActiveUniformsCount();
+}
+
+int GLSharedGroup::getActiveAttributesCountForProgram(GLuint program) {
+    android::AutoMutex _lock(m_lock);
+    ProgramData* pData =
+        getProgramDataLocked(program);
+
+    if (!pData) return 0;
+
+    return pData->getActiveAttributesCount();
+}
+
diff --git a/shared/OpenglCodecCommon/GLSharedGroup.h b/shared/OpenglCodecCommon/GLSharedGroup.h
index bbee27a..807a006 100755
--- a/shared/OpenglCodecCommon/GLSharedGroup.h
+++ b/shared/OpenglCodecCommon/GLSharedGroup.h
@@ -40,6 +40,7 @@
 #include "auto_goldfish_dma_context.h"
 #include "IndexRangeCache.h"
 #include "SmartPtr.h"
+#include "StateTrackingSupport.h"
 
 struct BufferData {
     BufferData();
@@ -75,11 +76,26 @@
         GLint samplerValue; // only set for sampler uniforms
     } IndexInfo;
 
+    typedef struct _AttribInfo {
+        GLint attribLoc;
+        GLint size;
+        GLenum type;
+    } AttribInfo;
+
     GLuint m_numIndexes;
+    GLuint m_numAttributes;
     IndexInfo* m_Indexes;
+    AttribInfo* m_attribIndexes;
     bool m_initialized;
 
     std::vector<GLuint> m_shaders;
+    std::vector<GLenum> m_shaderTypes;
+
+    uint32_t m_refcount;
+    GLint m_linkStatus;
+
+    uint32_t m_activeUniformBlockCount;
+    uint32_t m_transformFeedbackVaryingsCount;;
 
 public:
     enum {
@@ -87,21 +103,58 @@
     };
 
     ProgramData();
-    void initProgramData(GLuint numIndexes);
+    void initProgramData(GLuint numIndexes, GLuint numAttributes);
     bool isInitialized();
     virtual ~ProgramData();
     void setIndexInfo(GLuint index, GLint base, GLint size, GLenum type);
+    void setAttribInfo(GLuint index, GLint base, GLint size, GLenum type);
     void setIndexFlags(GLuint index, GLuint flags);
     GLuint getIndexForLocation(GLint location);
     GLenum getTypeForLocation(GLint location);
+    bool isValidUniformLocation(GLint location);
 
     GLint getNextSamplerUniform(GLint index, GLint* val, GLenum* target);
     bool setSamplerUniform(GLint appLoc, GLint val, GLenum* target);
 
-    bool attachShader(GLuint shader);
+    bool attachShader(GLuint shader, GLenum shaderType);
     bool detachShader(GLuint shader);
     size_t getNumShaders() const { return m_shaders.size(); }
     GLuint getShader(size_t i) const { return m_shaders[i]; }
+
+    void incRef() { ++m_refcount; }
+    bool decRef() {
+        --m_refcount;
+        return 0 == m_refcount;
+    }
+
+    UniformValidationInfo compileValidationInfo(bool* error) const;
+    AttribValidationInfo compileAttribValidationInfo(bool* error) const;
+    void setLinkStatus(GLint status) { m_linkStatus = status; }
+    GLint getLinkStatus() { return m_linkStatus; }
+
+    void setActiveUniformBlockCount(uint32_t count) {
+        m_activeUniformBlockCount = count;
+    }
+
+    uint32_t getActiveUniformBlockCount() const {
+        return m_activeUniformBlockCount;
+    }
+
+    void setTransformFeedbackVaryingsCount(uint32_t count) {
+        m_transformFeedbackVaryingsCount = count;
+    }
+
+    uint32_t getTransformFeedbackVaryingsCount() const {
+        return m_transformFeedbackVaryingsCount;
+    }
+
+    GLuint getActiveUniformsCount() const {
+        return m_numIndexes;
+    }
+
+    GLuint getActiveAttributesCount() const {
+        return m_numAttributes;
+    }
 };
 
 struct ShaderData {
@@ -109,6 +162,7 @@
     StringList samplerExternalNames;
     int refcount;
     std::vector<std::string> sources;
+    GLenum shaderType;
 };
 
 class ShaderProgramData {
@@ -125,6 +179,8 @@
     std::map<GLuint, ShaderData*> m_shaders;
     std::map<uint32_t, ShaderProgramData*> m_shaderPrograms;
     std::map<GLuint, uint32_t> m_shaderProgramIdMap;
+    RenderbufferInfo m_renderbufferInfo;
+    SamplerInfo m_samplerInfo;
 
     mutable android::Mutex m_lock;
 
@@ -133,12 +189,15 @@
 
     uint32_t m_shaderProgramId;
 
+    ProgramData* getProgramDataLocked(GLuint program);
 public:
     GLSharedGroup();
     ~GLSharedGroup();
     bool isShaderOrProgramObject(GLuint obj);
     BufferData * getBufferData(GLuint bufferId);
     SharedTextureDataMap* getTextureData();
+    RenderbufferInfo* getRenderbufferInfo();
+    SamplerInfo* getSamplerInfo();
     void    addBufferData(GLuint bufferId, GLsizeiptr size, const void* data);
     void    updateBufferData(GLuint bufferId, GLsizeiptr size, const void* data);
     void    setBufferUsage(GLuint bufferId, GLenum usage);
@@ -151,17 +210,23 @@
     bool    isProgram(GLuint program);
     bool    isProgramInitialized(GLuint program);
     void    addProgramData(GLuint program); 
-    void    initProgramData(GLuint program, GLuint numIndexes);
-    void    attachShader(GLuint program, GLuint shader);
-    void    detachShader(GLuint program, GLuint shader);
+    void    initProgramData(GLuint program, GLuint numIndexes, GLuint numAttributes);
+    void    refProgramData(GLuint program);
+    void    onUseProgram(GLuint previous, GLuint next);
+    bool    attachShader(GLuint program, GLuint shader);
+    bool    detachShader(GLuint program, GLuint shader);
+    bool    detachShaderLocked(GLuint program, GLuint shader);
     void    deleteProgramData(GLuint program);
+    void    deleteProgramDataLocked(GLuint program);
     void    setProgramIndexInfo(GLuint program, GLuint index, GLint base, GLint size, GLenum type, const char* name);
+    void    setProgramAttribInfo(GLuint program, GLuint index, GLint attribLoc, GLint size, GLenum type, const char* name);
     GLenum  getProgramUniformType(GLuint program, GLint location);
     GLint   getNextSamplerUniform(GLuint program, GLint index, GLint* val, GLenum* target) const;
     bool    setSamplerUniform(GLuint program, GLint appLoc, GLint val, GLenum* target);
+    bool    isProgramUniformLocationValid(GLuint program, GLint location);
 
     bool    isShader(GLuint shader);
-    bool    addShaderData(GLuint shader);
+    bool    addShaderData(GLuint shader, GLenum shaderType);
     // caller must hold a reference to the shader as long as it holds the pointer
     ShaderData* getShaderData(GLuint shader);
     void    unrefShaderData(GLuint shader);
@@ -173,8 +238,24 @@
     ShaderProgramData* getShaderProgramData(GLuint shaderProgramName);
     void deleteShaderProgramDataById(uint32_t id);
     void deleteShaderProgramData(GLuint shaderProgramName);
-    void initShaderProgramData(GLuint shaderProgram, GLuint numIndices);
+    void initShaderProgramData(GLuint shaderProgram, GLuint numIndices, GLuint numAttributes);
     void setShaderProgramIndexInfo(GLuint shaderProgram, GLuint index, GLint base, GLint size, GLenum type, const char* name);
+
+    // Validation info
+    UniformValidationInfo getUniformValidationInfo(GLuint program);
+    AttribValidationInfo getAttribValidationInfo(GLuint program);
+
+    void setProgramLinkStatus(GLuint program, GLint linkStatus);
+    GLint getProgramLinkStatus(GLuint program);
+
+    void setActiveUniformBlockCountForProgram(GLuint program, GLint numBlocks);
+    GLint getActiveUniformBlockCount(GLuint program);
+
+    void setTransformFeedbackVaryingsCountForProgram(GLuint program, GLint count);
+    GLint getTransformFeedbackVaryingsCountForProgram(GLuint program);
+
+    int getActiveUniformsCountForProgram(GLuint program);
+    int getActiveAttributesCountForProgram(GLuint program);
 };
 
 typedef SmartPtr<GLSharedGroup> GLSharedGroupPtr; 
diff --git a/shared/OpenglCodecCommon/StateTrackingSupport.h b/shared/OpenglCodecCommon/StateTrackingSupport.h
new file mode 100644
index 0000000..b742c13
--- /dev/null
+++ b/shared/OpenglCodecCommon/StateTrackingSupport.h
@@ -0,0 +1,245 @@
+/*
+* Copyright (C) 2020 The Android Open Source Project
+*
+* 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 _STATE_TRACKING_SUPPORT_H_
+#define _STATE_TRACKING_SUPPORT_H_
+
+#include "android/base/containers/HybridComponentManager.h"
+#include "android/base/synchronization/AndroidLock.h"
+
+#include <GLES2/gl2.h>
+
+template <class IndexType, bool initialIsTrue>
+class PredicateMap {
+public:
+    static const uint64_t kBitsPerEntry = 64;
+    void add(IndexType objId) {
+        static const uint64_t kNone = 0ULL;
+        static const uint64_t kAll = ~kNone;
+        IndexType index = objId / kBitsPerEntry;
+        if (!mStorage.get_const(index)) {
+            mStorage.add(index, initialIsTrue ? kAll : kNone);
+        }
+    }
+
+    void remove(IndexType objId) {
+        if (initialIsTrue) {
+            set(objId, true);
+        } else {
+            set(objId, false);
+        }
+    }
+
+    void set(IndexType objId, bool predicate) {
+        IndexType index = objId / kBitsPerEntry;
+
+        if (!mStorage.get_const(index)) return;
+
+        uint64_t* current = mStorage.get(index);
+
+        uint64_t flag = 1ULL << (objId % kBitsPerEntry);
+
+        if (predicate) {
+            *current = *current | flag;
+        } else {
+            *current = *current & (~flag);
+        }
+    }
+
+    bool get(IndexType objId) const {
+        IndexType index = objId / kBitsPerEntry;
+
+        const uint64_t* current = mStorage.get_const(index);
+
+        if (!current) return initialIsTrue;
+
+        uint64_t flag = 1ULL << (objId % kBitsPerEntry);
+        return (flag & (*current)) != 0;
+    }
+
+private:
+    using Storage = android::base::HybridComponentManager<10000, IndexType, uint64_t>;
+    Storage mStorage;
+};
+
+// Structures for fast validation of uniforms/attribs.
+
+struct UniformLocationInfo {
+    bool valid = false;
+    uint32_t columns;
+    uint32_t rows;
+    bool isSampler;
+    bool isInt;
+    bool isArray;
+    bool isUnsigned;
+    bool isBool;
+};
+
+struct AttribIndexInfo {
+    bool validInProgram = false;
+};
+
+using UniformValidationInfo = android::base::HybridComponentManager<1000, uint32_t, UniformLocationInfo>;
+using AttribValidationInfo = android::base::HybridComponentManager<16, uint32_t, AttribIndexInfo>;
+
+using LastQueryTargetInfo = android::base::HybridComponentManager<1000, uint32_t, uint32_t>;
+
+using ExistenceMap = PredicateMap<uint32_t, false>;
+
+struct RboProps {
+    GLenum format;
+    GLsizei multisamples;
+    GLsizei width;
+    GLsizei height;
+    bool previouslyBound;
+    uint32_t refcount;
+    bool boundEGLImage;
+};
+
+struct SamplerProps {
+    uint32_t refcount;
+};
+
+template <class T>
+class ScopedLockedView {
+public:
+    ScopedLockedView(T* info) : mInfo(info) {
+        mInfo->lock();
+    }
+    virtual ~ScopedLockedView() {
+        mInfo->unlock();
+    }
+protected:
+    T* mInfo;
+
+    T* internalInfo() { return mInfo; }
+    const T* internalInfo_const() const { return mInfo; }
+};
+
+struct RenderbufferInfo {
+    android::base::guest::Lock infoLock;
+    android::base::HybridComponentManager<1000, uint32_t, RboProps> component;
+
+    void lock() { infoLock.lock(); }
+    void unlock() { infoLock.unlock(); }
+
+    class ScopedView : public ScopedLockedView<RenderbufferInfo> {
+        public:
+            ScopedView(RenderbufferInfo* info) : ScopedLockedView<RenderbufferInfo>(info) { }
+            bool hasRbo(GLuint id) const {
+                const RboProps* info = internalInfo_const()->component.get_const(id);
+                if (!info) return false;
+                return 0 != info->refcount;
+            }
+            virtual ~ScopedView() = default;
+            RboProps* get(GLuint id) {
+                return internalInfo()->component.get(id);
+            }
+            const RboProps* get_const(GLuint id) {
+                return internalInfo_const()->component.get_const(id);
+            }
+            void addFresh(GLuint id) {
+                RboProps props;
+                props.format = GL_NONE;
+                props.multisamples = 0;
+                props.width = 0;
+                props.height = 0;
+                props.previouslyBound = false;
+                props.refcount = 1;
+                props.boundEGLImage = false;
+                internalInfo()->component.add(id, props);
+            }
+            RboProps* bind(GLuint id) {
+                if (!hasRbo(id)) addFresh(id);
+                ref(id);
+                RboProps* res = get(id);
+                res->previouslyBound = true;
+                return res;
+            }
+            void ref(GLuint id) {
+                RboProps* props = get(id);
+                if (!props) return;
+                ++props->refcount;
+            }
+            bool unref(GLuint id) {
+                RboProps* props = get(id);
+                if (!props) return false;
+                if (!props->refcount) return false;
+                --props->refcount;
+                bool gone = 0 == props->refcount;
+                if (gone) {
+                    props->format = 0;
+                    props->multisamples = 0;
+                    props->width = 0;
+                    props->height = 0;
+                    props->previouslyBound = false;
+                    props->boundEGLImage = false;
+                }
+                return gone;
+            }
+    };
+};
+
+struct SamplerInfo {
+    android::base::guest::Lock infoLock;
+    android::base::HybridComponentManager<1000, uint32_t, SamplerProps> component;
+
+    void lock() { infoLock.lock(); }
+    void unlock() { infoLock.unlock(); }
+
+    class ScopedView : public ScopedLockedView<SamplerInfo> {
+        public:
+            ScopedView(SamplerInfo* info) : ScopedLockedView<SamplerInfo>(info) { }
+            bool samplerExists(GLuint id) const {
+                const SamplerProps* info = internalInfo_const()->component.get_const(id);
+                if (!info) return false;
+                return 0 != info->refcount;
+            }
+            virtual ~ScopedView() = default;
+            SamplerProps* get(GLuint id) {
+                return internalInfo()->component.get(id);
+            }
+            const SamplerProps* get_const(GLuint id) {
+                return internalInfo_const()->component.get_const(id);
+            }
+            void addFresh(GLuint id) {
+                SamplerProps props;
+                props.refcount = 1;
+                internalInfo()->component.add(id, props);
+            }
+            SamplerProps* bind(GLuint id) {
+                if (!samplerExists(id)) return 0;
+                ref(id);
+                SamplerProps* res = get(id);
+                return res;
+            }
+            void ref(GLuint id) {
+                SamplerProps* props = get(id);
+                if (!props) return;
+                ++props->refcount;
+            }
+            bool unref(GLuint id) {
+                SamplerProps* props = get(id);
+                if (!props) return false;
+                if (!props->refcount) return false;
+                --props->refcount;
+                bool gone = 0 == props->refcount;
+                return gone;
+            }
+    };
+};
+
+
+#endif
diff --git a/shared/OpenglCodecCommon/TextureSharedData.h b/shared/OpenglCodecCommon/TextureSharedData.h
index 1372f7a..96827ef 100644
--- a/shared/OpenglCodecCommon/TextureSharedData.h
+++ b/shared/OpenglCodecCommon/TextureSharedData.h
@@ -35,6 +35,13 @@
     TextureDims* dims;
     bool immutable;
     bool boundEGLImage;
+    bool hasStorage;
+    bool hasCubeNegX;
+    bool hasCubePosX;
+    bool hasCubeNegY;
+    bool hasCubePosY;
+    bool hasCubeNegZ;
+    bool hasCubePosZ;
 };
 
 typedef std::map<GLuint, TextureRec*> SharedTextureDataMap;
diff --git a/shared/OpenglCodecCommon/astc-codec.h b/shared/OpenglCodecCommon/astc-codec.h
new file mode 100644
index 0000000..e15fe47
--- /dev/null
+++ b/shared/OpenglCodecCommon/astc-codec.h
@@ -0,0 +1,47 @@
+// Copyright 2018 Google LLC
+//
+// 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
+//
+//     https://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 ASTC_CODEC_ASTC_CODEC_H_
+#define ASTC_CODEC_ASTC_CODEC_H_
+
+namespace astc_codec {
+
+// These are the valid ASTC footprints according to the specification in
+// Section C.2.7.
+enum FootprintType {
+  k4x4,
+  k5x4,
+  k5x5,
+  k6x5,
+  k6x6,
+  k8x5,
+  k8x6,
+  k10x5,
+  k10x6,
+  k8x8,
+  k10x8,
+  k10x10,
+  k12x10,
+  k12x12,
+
+  kCount
+};
+
+struct AstcFootprint {
+    AstcFootprint(int width, int height);
+};
+
+}  // namespace astc_codec
+
+#endif  // ASTC_CODEC_ASTC_CODEC_H_
diff --git a/shared/OpenglCodecCommon/etc.cpp b/shared/OpenglCodecCommon/etc.cpp
new file mode 100644
index 0000000..dea3228
--- /dev/null
+++ b/shared/OpenglCodecCommon/etc.cpp
@@ -0,0 +1,1031 @@
+// Copyright 2009 Google Inc.
+//
+// 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 "etc.h"
+
+#include <algorithm>
+#include <assert.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdio.h>
+
+typedef uint16_t etc1_uint16;
+
+/* From http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
+
+ The number of bits that represent a 4x4 texel block is 64 bits if
+ <internalformat> is given by ETC1_RGB8_OES.
+
+ The data for a block is a number of bytes,
+
+ {q0, q1, q2, q3, q4, q5, q6, q7}
+
+ where byte q0 is located at the lowest memory address and q7 at
+ the highest. The 64 bits specifying the block is then represented
+ by the following 64 bit integer:
+
+ int64bit = 256*(256*(256*(256*(256*(256*(256*q0+q1)+q2)+q3)+q4)+q5)+q6)+q7;
+
+ ETC1_RGB8_OES:
+
+ a) bit layout in bits 63 through 32 if diffbit = 0
+
+ 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
+ -----------------------------------------------
+ | base col1 | base col2 | base col1 | base col2 |
+ | R1 (4bits)| R2 (4bits)| G1 (4bits)| G2 (4bits)|
+ -----------------------------------------------
+
+ 47 46 45 44 43 42 41 40 39 38 37 36 35 34  33  32
+ ---------------------------------------------------
+ | base col1 | base col2 | table  | table  |diff|flip|
+ | B1 (4bits)| B2 (4bits)| cw 1   | cw 2   |bit |bit |
+ ---------------------------------------------------
+
+
+ b) bit layout in bits 63 through 32 if diffbit = 1
+
+ 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
+ -----------------------------------------------
+ | base col1    | dcol 2 | base col1    | dcol 2 |
+ | R1' (5 bits) | dR2    | G1' (5 bits) | dG2    |
+ -----------------------------------------------
+
+ 47 46 45 44 43 42 41 40 39 38 37 36 35 34  33  32
+ ---------------------------------------------------
+ | base col 1   | dcol 2 | table  | table  |diff|flip|
+ | B1' (5 bits) | dB2    | cw 1   | cw 2   |bit |bit |
+ ---------------------------------------------------
+
+
+ c) bit layout in bits 31 through 0 (in both cases)
+
+ 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
+ -----------------------------------------------
+ |       most significant pixel index bits       |
+ | p| o| n| m| l| k| j| i| h| g| f| e| d| c| b| a|
+ -----------------------------------------------
+
+ 15 14 13 12 11 10  9  8  7  6  5  4  3   2   1  0
+ --------------------------------------------------
+ |         least significant pixel index bits       |
+ | p| o| n| m| l| k| j| i| h| g| f| e| d| c | b | a |
+ --------------------------------------------------
+
+
+ Add table 3.17.2: Intensity modifier sets for ETC1 compressed textures:
+
+ table codeword                modifier table
+ ------------------        ----------------------
+ 0                     -8  -2  2   8
+ 1                    -17  -5  5  17
+ 2                    -29  -9  9  29
+ 3                    -42 -13 13  42
+ 4                    -60 -18 18  60
+ 5                    -80 -24 24  80
+ 6                   -106 -33 33 106
+ 7                   -183 -47 47 183
+
+
+ Add table 3.17.3 Mapping from pixel index values to modifier values for
+ ETC1 compressed textures:
+
+ pixel index value
+ ---------------
+ msb     lsb           resulting modifier value
+ -----   -----          -------------------------
+ 1       1            -b (large negative value)
+ 1       0            -a (small negative value)
+ 0       0             a (small positive value)
+ 0       1             b (large positive value)
+
+ ETC2 codec:
+     from https://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.4.pdf
+     page 289
+ */
+
+static const int kRGBModifierTable[] = {
+/* 0 */2, 8, -2, -8,
+/* 1 */5, 17, -5, -17,
+/* 2 */9, 29, -9, -29,
+/* 3 */13, 42, -13, -42,
+/* 4 */18, 60, -18, -60,
+/* 5 */24, 80, -24, -80,
+/* 6 */33, 106, -33, -106,
+/* 7 */47, 183, -47, -183 };
+
+static const int kRGBOpaqueModifierTable[] = {
+/* 0 */0, 8, 0, -8,
+/* 1 */0, 17, 0, -17,
+/* 2 */0, 29, 0, -29,
+/* 3 */0, 42, 0, -42,
+/* 4 */0, 60, 0, -60,
+/* 5 */0, 80, 0, -80,
+/* 6 */0, 106, 0, -106,
+/* 7 */0, 183, 0, -183 };
+
+static const int kAlphaModifierTable[] = {
+/* 0 */ -3, -6, -9, -15, 2, 5, 8, 14,
+/* 1 */ -3, -7, -10, -13, 2, 6, 9, 12,
+/* 2 */ -2, -5, -8, -13, 1, 4, 7, 12,
+/* 3 */ -2, -4, -6, -13, 1, 3, 5, 12,
+/* 4 */ -3, -6, -8, -12, 2, 5, 7, 11,
+/* 5 */ -3, -7, -9, -11, 2, 6, 8, 10,
+/* 6 */ -4, -7, -8, -11, 3, 6, 7, 10,
+/* 7 */ -3, -5, -8, -11, 2, 4, 7, 10,
+/* 8 */ -2, -6, -8, -10, 1, 5, 7, 9,
+/* 9 */ -2, -5, -8, -10, 1, 4, 7, 9,
+/* 10 */ -2, -4, -8, -10, 1, 3, 7, 9,
+/* 11 */ -2, -5, -7, -10, 1, 4, 6, 9,
+/* 12 */ -3, -4, -7, -10, 2, 3, 6, 9,
+/* 13 */ -1, -2, -3, -10, 0, 1, 2, 9,
+/* 14 */ -4, -6, -8, -9, 3, 5, 7, 8,
+/* 15 */ -3, -5, -7, -9, 2, 4, 6, 8
+};
+
+static const int kLookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
+
+static inline int clamp(int x) {
+    return (x >= 0 ? (x < 255 ? x : 255) : 0);
+}
+
+static inline int clamp2047(int x) {
+    return (x >= 0 ? (x < 2047 ? x : 2047) : 0);
+}
+
+static inline int clampSigned1023(int x) {
+    return (x >= -1023 ? (x < 1023 ? x : 1023) : -1023);
+}
+
+static
+inline int convert4To8(int b) {
+    int c = b & 0xf;
+    return (c << 4) | c;
+}
+
+static
+inline int convert5To8(int b) {
+    int c = b & 0x1f;
+    return (c << 3) | (c >> 2);
+}
+
+static
+inline int convert6To8(int b) {
+    int c = b & 0x3f;
+    return (c << 2) | (c >> 4);
+}
+
+static
+inline int convert7To8(int b) {
+    int c = b & 0x7f;
+    return (c << 1) | (c >> 6);
+}
+
+static
+inline int divideBy255(int d) {
+    return (d + 128 + (d >> 8)) >> 8;
+}
+
+static
+inline int convert8To4(int b) {
+    int c = b & 0xff;
+    return divideBy255(c * 15);
+}
+
+static
+inline int convert8To5(int b) {
+    int c = b & 0xff;
+    return divideBy255(c * 31);
+}
+
+static
+inline int convertDiff(int base, int diff) {
+    return convert5To8((0x1f & base) + kLookup[0x7 & diff]);
+}
+static
+int isOverflowed(int base, int diff) {
+    int val = (0x1f & base) + kLookup[0x7 & diff];
+    return val < 0 || val >= 32;
+}
+
+static
+void decode_subblock(etc1_byte* pOut, int r, int g, int b, const int* table,
+        etc1_uint32 low, bool second, bool flipped, bool isPunchthroughAlpha,
+        bool opaque) {
+    int baseX = 0;
+    int baseY = 0;
+    int channels = isPunchthroughAlpha ? 4 : 3;
+    if (second) {
+        if (flipped) {
+            baseY = 2;
+        } else {
+            baseX = 2;
+        }
+    }
+    for (int i = 0; i < 8; i++) {
+        int x, y;
+        if (flipped) {
+            x = baseX + (i >> 1);
+            y = baseY + (i & 1);
+        } else {
+            x = baseX + (i >> 2);
+            y = baseY + (i & 3);
+        }
+        int k = y + (x * 4);
+        int msb = ((low >> (k + 15)) & 2);
+        int lsb = ((low >> k) & 1);
+        etc1_byte* q = pOut + channels * (x + 4 * y);
+        if (isPunchthroughAlpha && !opaque && msb && !lsb) {
+            // rgba all 0
+            memset(q, 0, 4);
+            q += 4;
+        } else {
+            int offset = lsb | msb;
+            int delta = table[offset];
+            *q++ = clamp(r + delta);
+            *q++ = clamp(g + delta);
+            *q++ = clamp(b + delta);
+            if (isPunchthroughAlpha) {
+                *q++ = 255;
+            }
+        }
+    }
+}
+
+static void etc2_T_H_index(const int* clrTable, etc1_uint32 low,
+                           bool isPunchthroughAlpha, bool opaque,
+                           etc1_byte* pOut) {
+    etc1_byte* q = pOut;
+    for (int y = 0; y < 4; y++) {
+        for (int x = 0; x < 4; x++) {
+            int k = y + x * 4;
+            int msb = (low >> (k + 15)) & 2;
+            int lsb = (low >> k) & 1;
+            if (isPunchthroughAlpha && !opaque && msb && !lsb) {
+                // rgba all 0
+                memset(q, 0, 4);
+                q += 4;
+            } else {
+                int offset = lsb | msb;
+                for (int c = 0; c < 3; c++) {
+                    *q++ = clrTable[offset*3 + c];
+                }
+                if (isPunchthroughAlpha) {
+                    *q++ = 255;
+                }
+            }
+        }
+    }
+}
+
+// ETC2 codec:
+//     from https://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.4.pdf
+//     page 289
+
+static void etc2_decode_block_T(etc1_uint32 high, etc1_uint32 low,
+        bool isPunchthroughAlpha, bool opaque, etc1_byte* pOut) {
+    const int LUT[] = {3, 6, 11, 16, 23, 32, 41, 64};
+    int r1, r2, g1, g2, b1, b2;
+    r1 = convert4To8((((high >> 27) & 3) << 2) | ((high >> 24) & 3));
+    g1 = convert4To8(high >> 20);
+    b1 = convert4To8(high >> 16);
+    r2 = convert4To8(high >> 12);
+    g2 = convert4To8(high >> 8);
+    b2 = convert4To8(high >> 4);
+    // 3 bits intense modifier
+    int intenseIdx = (((high >> 2) & 3) << 1) | (high & 1);
+    int intenseMod = LUT[intenseIdx];
+    int clrTable[12];
+    clrTable[0] = r1;
+    clrTable[1] = g1;
+    clrTable[2] = b1;
+    clrTable[3] = clamp(r2 + intenseMod);
+    clrTable[4] = clamp(g2 + intenseMod);
+    clrTable[5] = clamp(b2 + intenseMod);
+    clrTable[6] = r2;
+    clrTable[7] = g2;
+    clrTable[8] = b2;
+    clrTable[9] = clamp(r2 - intenseMod);
+    clrTable[10] = clamp(g2 - intenseMod);
+    clrTable[11] = clamp(b2 - intenseMod);
+    etc2_T_H_index(clrTable, low, isPunchthroughAlpha, opaque, pOut);
+}
+
+static void etc2_decode_block_H(etc1_uint32 high, etc1_uint32 low,
+        bool isPunchthroughAlpha, bool opaque, etc1_byte* pOut) {
+    const int LUT[] = {3, 6, 11, 16, 23, 32, 41, 64};
+    int r1, r2, g1, g2, b1, b2;
+    r1 = convert4To8(high >> 27);
+    g1 = convert4To8((high >> 24) << 1 | ((high >> 20) & 1));
+    b1 = convert4To8((high >> 19) << 3 | ((high >> 15) & 7));
+    r2 = convert4To8(high >> 11);
+    g2 = convert4To8(high >> 7);
+    b2 = convert4To8(high >> 3);
+    // 3 bits intense modifier
+    int intenseIdx = high & 4;
+    intenseIdx |= (high & 1) << 1;
+    intenseIdx |= (((r1 << 16) | (g1 << 8) | b1) >= ((r2 << 16) | (g2 << 8) | b2));
+    int intenseMod = LUT[intenseIdx];
+    int clrTable[12];
+    clrTable[0] = clamp(r1 + intenseMod);
+    clrTable[1] = clamp(g1 + intenseMod);
+    clrTable[2] = clamp(b1 + intenseMod);
+    clrTable[3] = clamp(r1 - intenseMod);
+    clrTable[4] = clamp(g1 - intenseMod);
+    clrTable[5] = clamp(b1 - intenseMod);
+    clrTable[6] = clamp(r2 + intenseMod);
+    clrTable[7] = clamp(g2 + intenseMod);
+    clrTable[8] = clamp(b2 + intenseMod);
+    clrTable[9] = clamp(r2 - intenseMod);
+    clrTable[10] = clamp(g2 - intenseMod);
+    clrTable[11] = clamp(b2 - intenseMod);
+    etc2_T_H_index(clrTable, low, isPunchthroughAlpha, opaque, pOut);
+}
+
+static void etc2_decode_block_P(etc1_uint32 high, etc1_uint32 low,
+        bool isPunchthroughAlpha, etc1_byte* pOut) {
+    int ro, go, bo, rh, gh, bh, rv, gv, bv;
+    uint64_t data = high;
+    data = data << 32 | low;
+    ro = convert6To8(data >> 57);
+    go = convert7To8((data >> 56 << 6) | ((data >> 49) & 63));
+    bo = convert6To8((data >> 48 << 5)
+            | (((data >> 43) & 3 ) << 3)
+            | ((data >> 39) & 7));
+    rh = convert6To8((data >> 34 << 1) | ((data >> 32) & 1));
+    gh = convert7To8(data >> 25);
+    bh = convert6To8(data >> 19);
+    rv = convert6To8(data >> 13);
+    gv = convert7To8(data >> 6);
+    bv = convert6To8(data);
+    etc1_byte* q = pOut;
+    for (int i = 0; i < 16; i++) {
+        int y = i >> 2;
+        int x = i & 3;
+        *q++ = clamp((x * (rh - ro) + y * (rv - ro) + 4 * ro + 2) >> 2);
+        *q++ = clamp((x * (gh - go) + y * (gv - go) + 4 * go + 2) >> 2);
+        *q++ = clamp((x * (bh - bo) + y * (bv - bo) + 4 * bo + 2) >> 2);
+        if (isPunchthroughAlpha) *q++ = 255;
+    }
+}
+
+// Input is an ETC1 / ETC2 compressed version of the data.
+// Output is a 4 x 4 square of 3-byte pixels in form R, G, B
+// ETC2 codec:
+//     from https://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.4.pdf
+//     page 289
+
+void etc2_decode_rgb_block(const etc1_byte* pIn, bool isPunchthroughAlpha,
+                           etc1_byte* pOut) {
+    etc1_uint32 high = (pIn[0] << 24) | (pIn[1] << 16) | (pIn[2] << 8) | pIn[3];
+    etc1_uint32 low = (pIn[4] << 24) | (pIn[5] << 16) | (pIn[6] << 8) | pIn[7];
+    bool opaque = (high >> 1) & 1;
+    int r1, r2, g1, g2, b1, b2;
+    if (isPunchthroughAlpha || high & 2) {
+        // differential
+        int rBase = high >> 27;
+        int gBase = high >> 19;
+        int bBase = high >> 11;
+        if (isOverflowed(rBase, high >> 24)) {
+            etc2_decode_block_T(high, low, isPunchthroughAlpha, opaque, pOut);
+            return;
+        }
+        if (isOverflowed(gBase, high >> 16)) {
+            etc2_decode_block_H(high, low, isPunchthroughAlpha, opaque, pOut);
+            return;
+        }
+        if (isOverflowed(bBase, high >> 8)) {
+            etc2_decode_block_P(high, low, isPunchthroughAlpha, pOut);
+            return;
+        }
+        r1 = convert5To8(rBase);
+        r2 = convertDiff(rBase, high >> 24);
+        g1 = convert5To8(gBase);
+        g2 = convertDiff(gBase, high >> 16);
+        b1 = convert5To8(bBase);
+        b2 = convertDiff(bBase, high >> 8);
+    } else {
+        // not differential
+        r1 = convert4To8(high >> 28);
+        r2 = convert4To8(high >> 24);
+        g1 = convert4To8(high >> 20);
+        g2 = convert4To8(high >> 16);
+        b1 = convert4To8(high >> 12);
+        b2 = convert4To8(high >> 8);
+    }
+    int tableIndexA = 7 & (high >> 5);
+    int tableIndexB = 7 & (high >> 2);
+    const int* rgbModifierTable = opaque || !isPunchthroughAlpha ?
+                                  kRGBModifierTable : kRGBOpaqueModifierTable;
+    const int* tableA = rgbModifierTable + tableIndexA * 4;
+    const int* tableB = rgbModifierTable + tableIndexB * 4;
+    bool flipped = (high & 1) != 0;
+    decode_subblock(pOut, r1, g1, b1, tableA, low, false, flipped,
+                    isPunchthroughAlpha, opaque);
+    decode_subblock(pOut, r2, g2, b2, tableB, low, true, flipped,
+                    isPunchthroughAlpha, opaque);
+}
+
+void eac_decode_single_channel_block(const etc1_byte* pIn,
+                                     int decodedElementBytes, bool isSigned,
+                                     etc1_byte* pOut) {
+    assert(decodedElementBytes == 1 || decodedElementBytes == 2 || decodedElementBytes == 4);
+    int base_codeword = isSigned ? reinterpret_cast<const char*>(pIn)[0]
+                                 : pIn[0];
+    if (base_codeword == -128) base_codeword = -127;
+    int multiplier = pIn[1] >> 4;
+    int tblIdx = pIn[1] & 15;
+    const int* table = kAlphaModifierTable + tblIdx * 8;
+    const etc1_byte* p = pIn + 2;
+    // position in a byte of the next 3-bit index:
+    // | a a a | b b b | c c c | d d d ...
+    // | byte               | byte...
+    int bitOffset = 5;
+    for (int i = 0; i < 16; i ++) {
+        // flip x, y in output
+        int outIdx = (i % 4) * 4 + i / 4;
+        etc1_byte* q = pOut + outIdx * decodedElementBytes;
+
+        int modifier = 0;
+        if (bitOffset < 0) { // (Part of) the index is in the next byte.
+            modifier += p[0] << (-bitOffset);
+            p ++;
+            bitOffset += 8;
+        }
+        modifier += p[0] >> bitOffset;
+        modifier &= 7;
+        bitOffset -= 3; // move to the next index
+        if (bitOffset == -3) {
+            bitOffset = 5;
+            p++;
+        }
+        int modifierValue = table[modifier];
+        int decoded = base_codeword + modifierValue * multiplier;
+        if (decodedElementBytes == 1) {
+            *q = clamp(decoded);
+        } else { // decodedElementBytes == 4
+            decoded *= 8;
+            if (multiplier == 0) {
+                decoded += modifierValue;
+            }
+            if (isSigned) {
+                decoded = clampSigned1023(decoded);
+                reinterpret_cast<float*>(q)[0] = (float)decoded / 1023.0;
+            } else {
+                decoded += 4;
+                decoded = clamp2047(decoded);
+                reinterpret_cast<float*>(q)[0] = (float)decoded / 2047.0;
+            }
+        }
+    }
+}
+
+typedef struct {
+    etc1_uint32 high;
+    etc1_uint32 low;
+    etc1_uint32 score; // Lower is more accurate
+} etc_compressed;
+
+static
+inline void take_best(etc_compressed* a, const etc_compressed* b) {
+    if (a->score > b->score) {
+        *a = *b;
+    }
+}
+
+static
+void etc_average_colors_subblock(const etc1_byte* pIn, etc1_uint32 inMask,
+        etc1_byte* pColors, bool flipped, bool second) {
+    int r = 0;
+    int g = 0;
+    int b = 0;
+
+    if (flipped) {
+        int by = 0;
+        if (second) {
+            by = 2;
+        }
+        for (int y = 0; y < 2; y++) {
+            int yy = by + y;
+            for (int x = 0; x < 4; x++) {
+                int i = x + 4 * yy;
+                if (inMask & (1 << i)) {
+                    const etc1_byte* p = pIn + i * 3;
+                    r += *(p++);
+                    g += *(p++);
+                    b += *(p++);
+                }
+            }
+        }
+    } else {
+        int bx = 0;
+        if (second) {
+            bx = 2;
+        }
+        for (int y = 0; y < 4; y++) {
+            for (int x = 0; x < 2; x++) {
+                int xx = bx + x;
+                int i = xx + 4 * y;
+                if (inMask & (1 << i)) {
+                    const etc1_byte* p = pIn + i * 3;
+                    r += *(p++);
+                    g += *(p++);
+                    b += *(p++);
+                }
+            }
+        }
+    }
+    pColors[0] = (etc1_byte)((r + 4) >> 3);
+    pColors[1] = (etc1_byte)((g + 4) >> 3);
+    pColors[2] = (etc1_byte)((b + 4) >> 3);
+}
+
+static
+inline int square(int x) {
+    return x * x;
+}
+
+static etc1_uint32 chooseModifier(const etc1_byte* pBaseColors,
+        const etc1_byte* pIn, etc1_uint32 *pLow, int bitIndex,
+        const int* pModifierTable) {
+    etc1_uint32 bestScore = ~0;
+    int bestIndex = 0;
+    int pixelR = pIn[0];
+    int pixelG = pIn[1];
+    int pixelB = pIn[2];
+    int r = pBaseColors[0];
+    int g = pBaseColors[1];
+    int b = pBaseColors[2];
+    for (int i = 0; i < 4; i++) {
+        int modifier = pModifierTable[i];
+        int decodedG = clamp(g + modifier);
+        etc1_uint32 score = (etc1_uint32) (6 * square(decodedG - pixelG));
+        if (score >= bestScore) {
+            continue;
+        }
+        int decodedR = clamp(r + modifier);
+        score += (etc1_uint32) (3 * square(decodedR - pixelR));
+        if (score >= bestScore) {
+            continue;
+        }
+        int decodedB = clamp(b + modifier);
+        score += (etc1_uint32) square(decodedB - pixelB);
+        if (score < bestScore) {
+            bestScore = score;
+            bestIndex = i;
+        }
+    }
+    etc1_uint32 lowMask = (((bestIndex >> 1) << 16) | (bestIndex & 1))
+            << bitIndex;
+    *pLow |= lowMask;
+    return bestScore;
+}
+
+static
+void etc_encode_subblock_helper(const etc1_byte* pIn, etc1_uint32 inMask,
+        etc_compressed* pCompressed, bool flipped, bool second,
+        const etc1_byte* pBaseColors, const int* pModifierTable) {
+    int score = pCompressed->score;
+    if (flipped) {
+        int by = 0;
+        if (second) {
+            by = 2;
+        }
+        for (int y = 0; y < 2; y++) {
+            int yy = by + y;
+            for (int x = 0; x < 4; x++) {
+                int i = x + 4 * yy;
+                if (inMask & (1 << i)) {
+                    score += chooseModifier(pBaseColors, pIn + i * 3,
+                            &pCompressed->low, yy + x * 4, pModifierTable);
+                }
+            }
+        }
+    } else {
+        int bx = 0;
+        if (second) {
+            bx = 2;
+        }
+        for (int y = 0; y < 4; y++) {
+            for (int x = 0; x < 2; x++) {
+                int xx = bx + x;
+                int i = xx + 4 * y;
+                if (inMask & (1 << i)) {
+                    score += chooseModifier(pBaseColors, pIn + i * 3,
+                            &pCompressed->low, y + xx * 4, pModifierTable);
+                }
+            }
+        }
+    }
+    pCompressed->score = score;
+}
+
+static bool inRange4bitSigned(int color) {
+    return color >= -4 && color <= 3;
+}
+
+static void etc_encodeBaseColors(etc1_byte* pBaseColors,
+        const etc1_byte* pColors, etc_compressed* pCompressed) {
+    int r1, g1, b1, r2, g2, b2; // 8 bit base colors for sub-blocks
+    bool differential;
+    {
+        int r51 = convert8To5(pColors[0]);
+        int g51 = convert8To5(pColors[1]);
+        int b51 = convert8To5(pColors[2]);
+        int r52 = convert8To5(pColors[3]);
+        int g52 = convert8To5(pColors[4]);
+        int b52 = convert8To5(pColors[5]);
+
+        r1 = convert5To8(r51);
+        g1 = convert5To8(g51);
+        b1 = convert5To8(b51);
+
+        int dr = r52 - r51;
+        int dg = g52 - g51;
+        int db = b52 - b51;
+
+        differential = inRange4bitSigned(dr) && inRange4bitSigned(dg)
+                && inRange4bitSigned(db);
+        if (differential) {
+            r2 = convert5To8(r51 + dr);
+            g2 = convert5To8(g51 + dg);
+            b2 = convert5To8(b51 + db);
+            pCompressed->high |= (r51 << 27) | ((7 & dr) << 24) | (g51 << 19)
+                    | ((7 & dg) << 16) | (b51 << 11) | ((7 & db) << 8) | 2;
+        }
+    }
+
+    if (!differential) {
+        int r41 = convert8To4(pColors[0]);
+        int g41 = convert8To4(pColors[1]);
+        int b41 = convert8To4(pColors[2]);
+        int r42 = convert8To4(pColors[3]);
+        int g42 = convert8To4(pColors[4]);
+        int b42 = convert8To4(pColors[5]);
+        r1 = convert4To8(r41);
+        g1 = convert4To8(g41);
+        b1 = convert4To8(b41);
+        r2 = convert4To8(r42);
+        g2 = convert4To8(g42);
+        b2 = convert4To8(b42);
+        pCompressed->high |= (r41 << 28) | (r42 << 24) | (g41 << 20) | (g42
+                << 16) | (b41 << 12) | (b42 << 8);
+    }
+    pBaseColors[0] = r1;
+    pBaseColors[1] = g1;
+    pBaseColors[2] = b1;
+    pBaseColors[3] = r2;
+    pBaseColors[4] = g2;
+    pBaseColors[5] = b2;
+}
+
+static
+void etc_encode_block_helper(const etc1_byte* pIn, etc1_uint32 inMask,
+        const etc1_byte* pColors, etc_compressed* pCompressed, bool flipped) {
+    pCompressed->score = ~0;
+    pCompressed->high = (flipped ? 1 : 0);
+    pCompressed->low = 0;
+
+    etc1_byte pBaseColors[6];
+
+    etc_encodeBaseColors(pBaseColors, pColors, pCompressed);
+
+    int originalHigh = pCompressed->high;
+
+    const int* pModifierTable = kRGBModifierTable;
+    for (int i = 0; i < 8; i++, pModifierTable += 4) {
+        etc_compressed temp;
+        temp.score = 0;
+        temp.high = originalHigh | (i << 5);
+        temp.low = 0;
+        etc_encode_subblock_helper(pIn, inMask, &temp, flipped, false,
+                pBaseColors, pModifierTable);
+        take_best(pCompressed, &temp);
+    }
+    pModifierTable = kRGBModifierTable;
+    etc_compressed firstHalf = *pCompressed;
+    for (int i = 0; i < 8; i++, pModifierTable += 4) {
+        etc_compressed temp;
+        temp.score = firstHalf.score;
+        temp.high = firstHalf.high | (i << 2);
+        temp.low = firstHalf.low;
+        etc_encode_subblock_helper(pIn, inMask, &temp, flipped, true,
+                pBaseColors + 3, pModifierTable);
+        if (i == 0) {
+            *pCompressed = temp;
+        } else {
+            take_best(pCompressed, &temp);
+        }
+    }
+}
+
+static void writeBigEndian(etc1_byte* pOut, etc1_uint32 d) {
+    pOut[0] = (etc1_byte)(d >> 24);
+    pOut[1] = (etc1_byte)(d >> 16);
+    pOut[2] = (etc1_byte)(d >> 8);
+    pOut[3] = (etc1_byte) d;
+}
+
+// Input is a 4 x 4 square of 3-byte pixels in form R, G, B
+// inmask is a 16-bit mask where bit (1 << (x + y * 4)) tells whether the corresponding (x,y)
+// pixel is valid or not. Invalid pixel color values are ignored when compressing.
+// Output is an ETC1 compressed version of the data.
+
+void etc1_encode_block(const etc1_byte* pIn, etc1_uint32 inMask,
+        etc1_byte* pOut) {
+    etc1_byte colors[6];
+    etc1_byte flippedColors[6];
+    etc_average_colors_subblock(pIn, inMask, colors, false, false);
+    etc_average_colors_subblock(pIn, inMask, colors + 3, false, true);
+    etc_average_colors_subblock(pIn, inMask, flippedColors, true, false);
+    etc_average_colors_subblock(pIn, inMask, flippedColors + 3, true, true);
+
+    etc_compressed a, b;
+    etc_encode_block_helper(pIn, inMask, colors, &a, false);
+    etc_encode_block_helper(pIn, inMask, flippedColors, &b, true);
+    take_best(&a, &b);
+    writeBigEndian(pOut, a.high);
+    writeBigEndian(pOut + 4, a.low);
+}
+
+// Return the size of the encoded image data (does not include size of PKM header).
+
+etc1_uint32 etc1_get_encoded_data_size(etc1_uint32 width, etc1_uint32 height) {
+    return (((width + 3) & ~3) * ((height + 3) & ~3)) >> 1;
+}
+
+etc1_uint32 etc_get_encoded_data_size(ETC2ImageFormat format, etc1_uint32 width,
+                                      etc1_uint32 height) {
+    etc1_uint32 size = ((width + 3) & ~3) * ((height + 3) & ~3);
+    switch (format) {
+        case EtcRGB8:
+        case EtcRGB8A1:
+        case EtcR11:
+        case EtcSignedR11:
+            return size >> 1;
+        case EtcRG11:
+        case EtcSignedRG11:
+        case EtcRGBA8:
+            return size;
+        default:
+            assert(0);
+            return 0;
+    }
+}
+
+etc1_uint32 etc_get_decoded_pixel_size(ETC2ImageFormat format) {
+    switch (format) {
+        case EtcRGB8:
+            return 3;
+        case EtcRGBA8:
+            return 4;
+        case EtcRGB8A1:
+        case EtcR11:
+        case EtcSignedR11:
+            return 4;
+        case EtcRG11:
+        case EtcSignedRG11:
+            return 8;
+        default:
+            assert(0);
+            return 0;
+    }
+}
+
+// Encode an entire image.
+// pIn - pointer to the image data. Formatted such that the Red component of
+//       pixel (x,y) is at pIn + pixelSize * x + stride * y + redOffset;
+// pOut - pointer to encoded data. Must be large enough to store entire encoded image.
+
+int etc1_encode_image(const etc1_byte* pIn, etc1_uint32 width, etc1_uint32 height,
+        etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte* pOut) {
+    if (pixelSize < 2 || pixelSize > 3) {
+        return -1;
+    }
+    static const unsigned short kYMask[] = { 0x0, 0xf, 0xff, 0xfff, 0xffff };
+    static const unsigned short kXMask[] = { 0x0, 0x1111, 0x3333, 0x7777,
+            0xffff };
+    etc1_byte block[ETC1_DECODED_BLOCK_SIZE];
+    etc1_byte encoded[ETC1_ENCODED_BLOCK_SIZE];
+
+    etc1_uint32 encodedWidth = (width + 3) & ~3;
+    etc1_uint32 encodedHeight = (height + 3) & ~3;
+
+    for (etc1_uint32 y = 0; y < encodedHeight; y += 4) {
+        etc1_uint32 yEnd = height - y;
+        if (yEnd > 4) {
+            yEnd = 4;
+        }
+        int ymask = kYMask[yEnd];
+        for (etc1_uint32 x = 0; x < encodedWidth; x += 4) {
+            etc1_uint32 xEnd = width - x;
+            if (xEnd > 4) {
+                xEnd = 4;
+            }
+            int mask = ymask & kXMask[xEnd];
+            for (etc1_uint32 cy = 0; cy < yEnd; cy++) {
+                etc1_byte* q = block + (cy * 4) * 3;
+                const etc1_byte* p = pIn + pixelSize * x + stride * (y + cy);
+                if (pixelSize == 3) {
+                    memcpy(q, p, xEnd * 3);
+                } else {
+                    for (etc1_uint32 cx = 0; cx < xEnd; cx++) {
+                        int pixel = (p[1] << 8) | p[0];
+                        *q++ = convert5To8(pixel >> 11);
+                        *q++ = convert6To8(pixel >> 5);
+                        *q++ = convert5To8(pixel);
+                        p += pixelSize;
+                    }
+                }
+            }
+            etc1_encode_block(block, mask, encoded);
+            memcpy(pOut, encoded, sizeof(encoded));
+            pOut += sizeof(encoded);
+        }
+    }
+    return 0;
+}
+
+// Decode an entire image.
+// pIn - pointer to encoded data.
+// pOut - pointer to the image data. Will be written such that the Red component of
+//       pixel (x,y) is at pIn + pixelSize * x + stride * y + redOffset. Must be
+//        large enough to store entire image.
+
+
+int etc2_decode_image(const etc1_byte* pIn, ETC2ImageFormat format,
+        etc1_byte* pOut,
+        etc1_uint32 width, etc1_uint32 height,
+        etc1_uint32 stride) {
+    etc1_byte block[std::max({ETC1_DECODED_BLOCK_SIZE,
+                              ETC2_DECODED_RGB8A1_BLOCK_SIZE,
+                              EAC_DECODED_R11_BLOCK_SIZE,
+                              EAC_DECODED_RG11_BLOCK_SIZE})];
+    etc1_byte alphaBlock[EAC_DECODED_ALPHA_BLOCK_SIZE];
+
+    etc1_uint32 encodedWidth = (width + 3) & ~3;
+    etc1_uint32 encodedHeight = (height + 3) & ~3;
+
+    int pixelSize = etc_get_decoded_pixel_size(format);
+    bool isSigned = (format == EtcSignedR11 || format == EtcSignedRG11);
+
+    for (etc1_uint32 y = 0; y < encodedHeight; y += 4) {
+        etc1_uint32 yEnd = height - y;
+        if (yEnd > 4) {
+            yEnd = 4;
+        }
+        for (etc1_uint32 x = 0; x < encodedWidth; x += 4) {
+            etc1_uint32 xEnd = width - x;
+            if (xEnd > 4) {
+                xEnd = 4;
+            }
+            switch (format) {
+                case EtcRGBA8:
+                    eac_decode_single_channel_block(pIn, 1, false, alphaBlock);
+                    pIn += EAC_ENCODE_ALPHA_BLOCK_SIZE;
+                    // Do not break
+                    // Fall through to EtcRGB8 to decode the RGB part
+                    [[fallthrough]];
+                case EtcRGB8:
+                    etc2_decode_rgb_block(pIn, false, block);
+                    pIn += ETC1_ENCODED_BLOCK_SIZE;
+                    break;
+                case EtcRGB8A1:
+                    etc2_decode_rgb_block(pIn, true, block);
+                    pIn += ETC1_ENCODED_BLOCK_SIZE;
+                    break;
+                case EtcR11:
+                case EtcSignedR11:
+                    eac_decode_single_channel_block(pIn, 4, isSigned, block);
+                    pIn += EAC_ENCODE_R11_BLOCK_SIZE;
+                    break;
+                case EtcRG11:
+                case EtcSignedRG11:
+                    // r channel
+                    eac_decode_single_channel_block(pIn, 4, isSigned, block);
+                    pIn += EAC_ENCODE_R11_BLOCK_SIZE;
+                    // g channel
+                    eac_decode_single_channel_block(pIn, 4, isSigned,
+                            block + EAC_DECODED_R11_BLOCK_SIZE);
+                    pIn += EAC_ENCODE_R11_BLOCK_SIZE;
+                    break;
+                default:
+                    assert(0);
+            }
+            for (etc1_uint32 cy = 0; cy < yEnd; cy++) {
+                etc1_byte* p = pOut + pixelSize * x + stride * (y + cy);
+                switch (format) {
+                    case EtcRGB8:
+                    case EtcRGB8A1:
+                    case EtcR11:
+                    case EtcSignedR11: {
+                            const etc1_byte* q = block + (cy * 4) * pixelSize;
+                            memcpy(p, q, xEnd * pixelSize);
+                        }
+                        break;
+                    case EtcRG11:
+                    case EtcSignedRG11: {
+                            const etc1_byte* r = block + cy * EAC_DECODED_R11_BLOCK_SIZE / 4;
+                            const etc1_byte* g = block + cy * EAC_DECODED_R11_BLOCK_SIZE / 4 + EAC_DECODED_R11_BLOCK_SIZE;
+                            int channelSize = pixelSize / 2;
+                            for (etc1_uint32 cx = 0; cx < xEnd; cx++) {
+                                memcpy(p, r, channelSize);
+                                p += channelSize;
+                                r += channelSize;
+                                memcpy(p, g, channelSize);
+                                p += channelSize;
+                                g += channelSize;
+                            }
+                        }
+                        break;
+                    case EtcRGBA8: {
+                            const etc1_byte* q = block + (cy * 4) * 3;
+                            const etc1_byte* qa = alphaBlock + cy * 4;
+                            for (etc1_uint32 cx = 0; cx < xEnd; cx++) {
+                                // copy rgb data
+                                memcpy(p, q, 3);
+                                p += 3;
+                                q += 3;
+                                *p++ = *qa++;
+                            }
+                        }
+                        break;
+                    default:
+                        assert(0);
+                }
+            }
+        }
+    }
+    return 0;
+}
+
+static const char kMagic[] = { 'P', 'K', 'M', ' ', '1', '0' };
+
+static const etc1_uint32 ETC1_PKM_FORMAT_OFFSET = 6;
+static const etc1_uint32 ETC1_PKM_ENCODED_WIDTH_OFFSET = 8;
+static const etc1_uint32 ETC1_PKM_ENCODED_HEIGHT_OFFSET = 10;
+static const etc1_uint32 ETC1_PKM_WIDTH_OFFSET = 12;
+static const etc1_uint32 ETC1_PKM_HEIGHT_OFFSET = 14;
+
+static const etc1_uint32 ETC1_RGB_NO_MIPMAPS = 0;
+
+static void writeBEUint16(etc1_byte* pOut, etc1_uint32 data) {
+    pOut[0] = (etc1_byte) (data >> 8);
+    pOut[1] = (etc1_byte) data;
+}
+
+static etc1_uint32 readBEUint16(const etc1_byte* pIn) {
+    return (pIn[0] << 8) | pIn[1];
+}
+
+// Format a PKM header
+
+void etc1_pkm_format_header(etc1_byte* pHeader, etc1_uint32 width, etc1_uint32 height) {
+    memcpy(pHeader, kMagic, sizeof(kMagic));
+    etc1_uint32 encodedWidth = (width + 3) & ~3;
+    etc1_uint32 encodedHeight = (height + 3) & ~3;
+    writeBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET, ETC1_RGB_NO_MIPMAPS);
+    writeBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET, encodedWidth);
+    writeBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET, encodedHeight);
+    writeBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET, width);
+    writeBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET, height);
+}
+
+// Check if a PKM header is correctly formatted.
+
+etc1_bool etc1_pkm_is_valid(const etc1_byte* pHeader) {
+    if (memcmp(pHeader, kMagic, sizeof(kMagic))) {
+        return false;
+    }
+    etc1_uint32 format = readBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET);
+    etc1_uint32 encodedWidth = readBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET);
+    etc1_uint32 encodedHeight = readBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET);
+    etc1_uint32 width = readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET);
+    etc1_uint32 height = readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET);
+    return format == ETC1_RGB_NO_MIPMAPS &&
+            encodedWidth >= width && encodedWidth - width < 4 &&
+            encodedHeight >= height && encodedHeight - height < 4;
+}
+
+// Read the image width from a PKM header
+
+etc1_uint32 etc1_pkm_get_width(const etc1_byte* pHeader) {
+    return readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET);
+}
+
+// Read the image height from a PKM header
+
+etc1_uint32 etc1_pkm_get_height(const etc1_byte* pHeader){
+    return readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET);
+}
diff --git a/shared/OpenglCodecCommon/etc.h b/shared/OpenglCodecCommon/etc.h
new file mode 100644
index 0000000..7d43c89
--- /dev/null
+++ b/shared/OpenglCodecCommon/etc.h
@@ -0,0 +1,130 @@
+// Copyright 2009 Google Inc.
+//
+// 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.
+
+#pragma once
+
+#define MAX_ETC_SUPPORTED 12
+
+#define ETC1_ENCODED_BLOCK_SIZE 8
+#define ETC1_DECODED_BLOCK_SIZE 48
+#define ETC2_DECODED_RGB8A1_BLOCK_SIZE 64
+#define EAC_ENCODE_ALPHA_BLOCK_SIZE 8
+#define EAC_DECODED_ALPHA_BLOCK_SIZE 16
+#define EAC_ENCODE_R11_BLOCK_SIZE 8
+#define EAC_DECODED_R11_BLOCK_SIZE 64
+#define EAC_DECODED_RG11_BLOCK_SIZE (EAC_DECODED_R11_BLOCK_SIZE*2)
+
+#ifndef ETC1_RGB8_OES
+#define ETC1_RGB8_OES 0x8D64
+#endif
+
+typedef unsigned char etc1_byte;
+typedef int etc1_bool;
+typedef unsigned int etc1_uint32;
+
+enum ETC2ImageFormat {
+    EtcRGB8, EtcRGBA8, EtcR11, EtcSignedR11, EtcRG11, EtcSignedRG11, EtcRGB8A1
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Encode a block of pixels.
+//
+// pIn is a pointer to a ETC_DECODED_BLOCK_SIZE array of bytes that represent a
+// 4 x 4 square of 3-byte pixels in form R, G, B. Byte (3 * (x + 4 * y) is the R
+// value of pixel (x, y).
+//
+// validPixelMask is a 16-bit mask where bit (1 << (x + y * 4)) indicates whether
+// the corresponding (x,y) pixel is valid. Invalid pixel color values are ignored when compressing.
+//
+// pOut is an ETC1 compressed version of the data.
+
+void etc1_encode_block(const etc1_byte* pIn, etc1_uint32 validPixelMask, etc1_byte* pOut);
+
+// Decode a block of rgb pixels.
+//
+// pIn is an ETC2 compressed version of the data.
+//
+// pOut is a pointer to a ETC_DECODED_BLOCK_SIZE array of bytes that represent a
+// 4 x 4 square of 3-byte pixels in form R, G, B. Byte (3 * (x + 4 * y) is the R
+// value of pixel (x, y).
+
+void etc2_decode_rgb_block(const etc1_byte* pIn, bool isPunchthroughAlpha, etc1_byte* pOut);
+
+// Decode a block of single channel pixels
+// This is used when decoding the alpha channel of RGBA8_ETC2_EAC format, or
+// when decoding R11_EAC format
+// decodedElementBytes: number of bits per element after decoding.
+// For RGBA8_ETC2_EAC it must be 1, for R11_EAC it must be 2
+
+void eac_decode_single_channel_block(const etc1_byte* pIn,
+                                     int decodedElementBytes, bool isSigned,
+                                     etc1_byte* pOut);
+
+// Return the size of the encoded image data (does not include size of PKM header).
+
+etc1_uint32 etc1_get_encoded_data_size(etc1_uint32 width, etc1_uint32 height);
+
+etc1_uint32 etc_get_encoded_data_size(ETC2ImageFormat format, etc1_uint32 width,
+                                      etc1_uint32 height);
+etc1_uint32 etc_get_decoded_pixel_size(ETC2ImageFormat format);
+
+// Encode an entire image.
+// pIn - pointer to the image data. Formatted such that
+//       pixel (x,y) is at pIn + pixelSize * x + stride * y;
+// pOut - pointer to encoded data. Must be large enough to store entire encoded image.
+// pixelSize can be 2 or 3. 2 is an GL_UNSIGNED_SHORT_5_6_5 image, 3 is a GL_BYTE RGB image.
+// returns non-zero if there is an error.
+
+int etc1_encode_image(const etc1_byte* pIn, etc1_uint32 width, etc1_uint32 height,
+        etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte* pOut);
+
+// Decode an entire image.
+// pIn - pointer to encoded data.
+// pOut - pointer to the image data. Will be written such that
+//        pixel (x,y) is at pIn + pixelSize * x + stride * y. Must be
+//        large enough to store entire image.
+//        (pixelSize=3 for rgb images, pixelSize=4 for images with alpha channel)
+// returns non-zero if there is an error.
+
+int etc2_decode_image(const etc1_byte* pIn, ETC2ImageFormat format,
+        etc1_byte* pOut,
+        etc1_uint32 width, etc1_uint32 height,
+        etc1_uint32 stride);
+
+// Size of a PKM header, in bytes.
+
+#define ETC_PKM_HEADER_SIZE 16
+
+// Format a PKM header
+
+void etc1_pkm_format_header(etc1_byte* pHeader, etc1_uint32 width, etc1_uint32 height);
+
+// Check if a PKM header is correctly formatted.
+
+etc1_bool etc1_pkm_is_valid(const etc1_byte* pHeader);
+
+// Read the image width from a PKM header
+
+etc1_uint32 etc1_pkm_get_width(const etc1_byte* pHeader);
+
+// Read the image height from a PKM header
+
+etc1_uint32 etc1_pkm_get_height(const etc1_byte* pHeader);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/shared/OpenglCodecCommon/glUtils.cpp b/shared/OpenglCodecCommon/glUtils.cpp
index a0ec240..a6b0b7c 100644
--- a/shared/OpenglCodecCommon/glUtils.cpp
+++ b/shared/OpenglCodecCommon/glUtils.cpp
@@ -20,6 +20,367 @@
 
 #include <GLES3/gl31.h>
 
+bool isSamplerType(GLenum type) {
+    switch (type) {
+        case GL_SAMPLER_2D:
+        case GL_SAMPLER_3D:
+        case GL_SAMPLER_CUBE:
+        case GL_SAMPLER_2D_SHADOW:
+        case GL_SAMPLER_2D_ARRAY:
+        case GL_SAMPLER_2D_ARRAY_SHADOW:
+        case GL_SAMPLER_2D_MULTISAMPLE:
+        case GL_SAMPLER_CUBE_SHADOW:
+        case GL_INT_SAMPLER_2D:
+        case GL_INT_SAMPLER_3D:
+        case GL_INT_SAMPLER_CUBE:
+        case GL_INT_SAMPLER_2D_ARRAY:
+        case GL_INT_SAMPLER_2D_MULTISAMPLE:
+        case GL_UNSIGNED_INT_SAMPLER_2D:
+        case GL_UNSIGNED_INT_SAMPLER_3D:
+        case GL_UNSIGNED_INT_SAMPLER_CUBE:
+        case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
+        case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool isIntegerType(GLenum type) {
+    switch (type) {
+        case GL_UNSIGNED_INT:
+        case GL_INT:
+        case GL_INT_VEC2:
+        case GL_UNSIGNED_INT_VEC2:
+        case GL_INT_VEC3:
+        case GL_UNSIGNED_INT_VEC3:
+        case GL_INT_VEC4:
+        case GL_UNSIGNED_INT_VEC4:
+        case GL_INT_IMAGE_2D:
+        case GL_INT_IMAGE_3D:
+        case GL_INT_IMAGE_CUBE:
+        case GL_INT_IMAGE_2D_ARRAY:
+        case GL_UNSIGNED_INT_IMAGE_2D:
+        case GL_UNSIGNED_INT_IMAGE_3D:
+        case GL_UNSIGNED_INT_IMAGE_CUBE:
+        case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
+        case GL_UNSIGNED_INT_ATOMIC_COUNTER:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool isUnsignedIntType(GLenum type) {
+    switch (type) {
+        case GL_UNSIGNED_INT:
+        case GL_UNSIGNED_INT_VEC2:
+        case GL_UNSIGNED_INT_VEC3:
+        case GL_UNSIGNED_INT_VEC4:
+        case GL_UNSIGNED_INT_IMAGE_2D:
+        case GL_UNSIGNED_INT_IMAGE_3D:
+        case GL_UNSIGNED_INT_IMAGE_CUBE:
+        case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
+        case GL_UNSIGNED_INT_ATOMIC_COUNTER:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool isBoolType(GLenum type) {
+    switch (type) {
+        case GL_BOOL:
+        case GL_BOOL_VEC2:
+        case GL_BOOL_VEC3:
+        case GL_BOOL_VEC4:
+            return true;
+        default:
+            return false;
+    }
+}
+
+uint32_t getColumnsOfType(GLenum type) {
+    switch (type) {
+    case GL_BYTE:
+    case GL_UNSIGNED_BYTE:
+    case GL_SHORT:
+    case GL_UNSIGNED_SHORT:
+    case GL_HALF_FLOAT:
+    case GL_HALF_FLOAT_OES:
+    case GL_IMAGE_2D:
+    case GL_IMAGE_3D:
+    case GL_UNSIGNED_INT:
+    case GL_INT:
+    case GL_FLOAT:
+    case GL_FIXED:
+    case GL_BOOL:
+        return 1;
+#ifdef GL_DOUBLE
+    case GL_DOUBLE:
+        return 1;
+    case GL_DOUBLE_VEC2:
+    case GL_DOUBLE_MAT2:
+    case GL_DOUBLE_MAT2x3:
+    case GL_DOUBLE_MAT2x4:
+        return 2;
+    case GL_DOUBLE_VEC3:
+    case GL_DOUBLE_MAT3:
+    case GL_DOUBLE_MAT3x2:
+    case GL_DOUBLE_MAT3x4:
+        return 3;
+    case GL_DOUBLE_VEC4:
+    case GL_DOUBLE_MAT4:
+    case GL_DOUBLE_MAT4x2:
+    case GL_DOUBLE_MAT4x3:
+        return 4;
+#endif
+    case GL_FLOAT_VEC2:
+    case GL_INT_VEC2:
+    case GL_UNSIGNED_INT_VEC2:
+    case GL_BOOL_VEC2:
+    case GL_FLOAT_MAT2:
+    case GL_FLOAT_MAT2x3:
+    case GL_FLOAT_MAT2x4:
+        return 2;
+    case GL_INT_VEC3:
+    case GL_UNSIGNED_INT_VEC3:
+    case GL_BOOL_VEC3:
+    case GL_FLOAT_VEC3:
+    case GL_FLOAT_MAT3:
+    case GL_FLOAT_MAT3x2:
+    case GL_FLOAT_MAT3x4:
+        return 3;
+    case GL_FLOAT_VEC4:
+    case GL_BOOL_VEC4:
+    case GL_INT_VEC4:
+    case GL_UNSIGNED_INT_VEC4:
+    case GL_FLOAT_MAT4:
+    case GL_FLOAT_MAT4x2:
+    case GL_FLOAT_MAT4x3:
+        return 4;
+    case GL_SAMPLER_2D:
+    case GL_SAMPLER_3D:
+    case GL_SAMPLER_CUBE:
+    case GL_SAMPLER_2D_SHADOW:
+    case GL_SAMPLER_2D_ARRAY:
+    case GL_SAMPLER_2D_ARRAY_SHADOW:
+    case GL_SAMPLER_2D_MULTISAMPLE:
+    case GL_SAMPLER_CUBE_SHADOW:
+    case GL_INT_SAMPLER_2D:
+    case GL_INT_SAMPLER_3D:
+    case GL_INT_SAMPLER_CUBE:
+    case GL_INT_SAMPLER_2D_ARRAY:
+    case GL_INT_SAMPLER_2D_MULTISAMPLE:
+    case GL_UNSIGNED_INT_SAMPLER_2D:
+    case GL_UNSIGNED_INT_SAMPLER_3D:
+    case GL_UNSIGNED_INT_SAMPLER_CUBE:
+    case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
+    case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
+    case GL_IMAGE_CUBE:
+    case GL_IMAGE_2D_ARRAY:
+    case GL_INT_IMAGE_2D:
+    case GL_INT_IMAGE_3D:
+    case GL_INT_IMAGE_CUBE:
+    case GL_INT_IMAGE_2D_ARRAY:
+    case GL_UNSIGNED_INT_IMAGE_2D:
+    case GL_UNSIGNED_INT_IMAGE_3D:
+    case GL_UNSIGNED_INT_IMAGE_CUBE:
+    case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
+    case GL_UNSIGNED_INT_ATOMIC_COUNTER:
+    default:
+        return 1;
+    }
+}
+
+uint32_t getRowsOfType(GLenum type) {
+    switch (type) {
+    case GL_BYTE:
+    case GL_UNSIGNED_BYTE:
+    case GL_SHORT:
+    case GL_UNSIGNED_SHORT:
+    case GL_HALF_FLOAT:
+    case GL_HALF_FLOAT_OES:
+    case GL_IMAGE_2D:
+    case GL_IMAGE_3D:
+    case GL_UNSIGNED_INT:
+    case GL_INT:
+    case GL_FLOAT:
+    case GL_FIXED:
+    case GL_BOOL:
+        return 1;
+#ifdef GL_DOUBLE
+    case GL_DOUBLE:
+    case GL_DOUBLE_VEC2:
+    case GL_DOUBLE_VEC3:
+    case GL_DOUBLE_VEC4:
+        return 1;
+    case GL_DOUBLE_MAT2:
+    case GL_DOUBLE_MAT3x2:
+    case GL_DOUBLE_MAT4x2:
+        return 2;
+    case GL_DOUBLE_MAT3:
+    case GL_DOUBLE_MAT2x3:
+    case GL_DOUBLE_MAT4x3:
+        return 3;
+    case GL_DOUBLE_MAT4:
+    case GL_DOUBLE_MAT3x4:
+    case GL_DOUBLE_MAT2x4:
+        return 4;
+#endif
+    case GL_FLOAT_VEC2:
+    case GL_INT_VEC2:
+    case GL_UNSIGNED_INT_VEC2:
+    case GL_BOOL_VEC2:
+    case GL_INT_VEC3:
+    case GL_UNSIGNED_INT_VEC3:
+    case GL_BOOL_VEC3:
+    case GL_FLOAT_VEC3:
+    case GL_FLOAT_VEC4:
+    case GL_BOOL_VEC4:
+    case GL_INT_VEC4:
+    case GL_UNSIGNED_INT_VEC4:
+        return 1;
+    case GL_FLOAT_MAT2:
+    case GL_FLOAT_MAT3x2:
+    case GL_FLOAT_MAT4x2:
+        return 2;
+    case GL_FLOAT_MAT3:
+    case GL_FLOAT_MAT2x3:
+    case GL_FLOAT_MAT4x3:
+        return 3;
+    case GL_FLOAT_MAT4:
+    case GL_FLOAT_MAT2x4:
+    case GL_FLOAT_MAT3x4:
+        return 4;
+    case GL_SAMPLER_2D:
+    case GL_SAMPLER_3D:
+    case GL_SAMPLER_CUBE:
+    case GL_SAMPLER_2D_SHADOW:
+    case GL_SAMPLER_2D_ARRAY:
+    case GL_SAMPLER_2D_ARRAY_SHADOW:
+    case GL_SAMPLER_2D_MULTISAMPLE:
+    case GL_SAMPLER_CUBE_SHADOW:
+    case GL_INT_SAMPLER_2D:
+    case GL_INT_SAMPLER_3D:
+    case GL_INT_SAMPLER_CUBE:
+    case GL_INT_SAMPLER_2D_ARRAY:
+    case GL_INT_SAMPLER_2D_MULTISAMPLE:
+    case GL_UNSIGNED_INT_SAMPLER_2D:
+    case GL_UNSIGNED_INT_SAMPLER_3D:
+    case GL_UNSIGNED_INT_SAMPLER_CUBE:
+    case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
+    case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
+    case GL_IMAGE_CUBE:
+    case GL_IMAGE_2D_ARRAY:
+    case GL_INT_IMAGE_2D:
+    case GL_INT_IMAGE_3D:
+    case GL_INT_IMAGE_CUBE:
+    case GL_INT_IMAGE_2D_ARRAY:
+    case GL_UNSIGNED_INT_IMAGE_2D:
+    case GL_UNSIGNED_INT_IMAGE_3D:
+    case GL_UNSIGNED_INT_IMAGE_CUBE:
+    case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
+    case GL_UNSIGNED_INT_ATOMIC_COUNTER:
+    default:
+        return 1;
+    }
+}
+
+uint32_t getAttributeCountOfType(GLenum type) {
+    switch (type) {
+    case GL_BYTE:
+    case GL_UNSIGNED_BYTE:
+    case GL_SHORT:
+    case GL_UNSIGNED_SHORT:
+    case GL_HALF_FLOAT:
+    case GL_HALF_FLOAT_OES:
+    case GL_IMAGE_2D:
+    case GL_IMAGE_3D:
+    case GL_UNSIGNED_INT:
+    case GL_INT:
+    case GL_FLOAT:
+    case GL_FIXED:
+    case GL_BOOL:
+        return 1;
+#ifdef GL_DOUBLE
+    case GL_DOUBLE:
+    case GL_DOUBLE_VEC2:
+    case GL_DOUBLE_VEC3:
+    case GL_DOUBLE_VEC4:
+        return 1;
+    case GL_DOUBLE_MAT2:
+    case GL_DOUBLE_MAT2x3:
+    case GL_DOUBLE_MAT2x4:
+        return 4;
+    case GL_DOUBLE_MAT3:
+    case GL_DOUBLE_MAT3x2:
+    case GL_DOUBLE_MAT3x4:
+        return 6;
+    case GL_DOUBLE_MAT4:
+    case GL_DOUBLE_MAT4x2:
+    case GL_DOUBLE_MAT4x3:
+        return 8;
+#endif
+    case GL_FLOAT_VEC2:
+    case GL_INT_VEC2:
+    case GL_UNSIGNED_INT_VEC2:
+    case GL_BOOL_VEC2:
+    case GL_INT_VEC3:
+    case GL_UNSIGNED_INT_VEC3:
+    case GL_BOOL_VEC3:
+    case GL_FLOAT_VEC3:
+    case GL_FLOAT_VEC4:
+    case GL_BOOL_VEC4:
+    case GL_INT_VEC4:
+    case GL_UNSIGNED_INT_VEC4:
+        return 1;
+    case GL_FLOAT_MAT2:
+    case GL_FLOAT_MAT2x3:
+    case GL_FLOAT_MAT2x4:
+        return 2;
+    case GL_FLOAT_MAT3:
+    case GL_FLOAT_MAT3x2:
+    case GL_FLOAT_MAT3x4:
+        return 3;
+    case GL_FLOAT_MAT4:
+    case GL_FLOAT_MAT4x2:
+    case GL_FLOAT_MAT4x3:
+        return 4;
+    case GL_SAMPLER_2D:
+    case GL_SAMPLER_3D:
+    case GL_SAMPLER_CUBE:
+    case GL_SAMPLER_2D_SHADOW:
+    case GL_SAMPLER_2D_ARRAY:
+    case GL_SAMPLER_2D_ARRAY_SHADOW:
+    case GL_SAMPLER_2D_MULTISAMPLE:
+    case GL_SAMPLER_CUBE_SHADOW:
+    case GL_INT_SAMPLER_2D:
+    case GL_INT_SAMPLER_3D:
+    case GL_INT_SAMPLER_CUBE:
+    case GL_INT_SAMPLER_2D_ARRAY:
+    case GL_INT_SAMPLER_2D_MULTISAMPLE:
+    case GL_UNSIGNED_INT_SAMPLER_2D:
+    case GL_UNSIGNED_INT_SAMPLER_3D:
+    case GL_UNSIGNED_INT_SAMPLER_CUBE:
+    case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
+    case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
+    case GL_IMAGE_CUBE:
+    case GL_IMAGE_2D_ARRAY:
+    case GL_INT_IMAGE_2D:
+    case GL_INT_IMAGE_3D:
+    case GL_INT_IMAGE_CUBE:
+    case GL_INT_IMAGE_2D_ARRAY:
+    case GL_UNSIGNED_INT_IMAGE_2D:
+    case GL_UNSIGNED_INT_IMAGE_3D:
+    case GL_UNSIGNED_INT_IMAGE_CUBE:
+    case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
+    case GL_UNSIGNED_INT_ATOMIC_COUNTER:
+    default:
+        return 1;
+    }
+}
+
 size_t glSizeof(GLenum type)
 {
     size_t retval = 0;
@@ -47,6 +408,36 @@
     case GL_DOUBLE:
         retval = 8;
         break;
+    case GL_DOUBLE_VEC2:
+        retval = 16;
+        break;
+    case GL_DOUBLE_VEC3:
+        retval = 24;
+        break;
+    case GL_DOUBLE_VEC4:
+        retval = 32;
+        break;
+    case GL_DOUBLE_MAT2:
+        retval = 8 * 4;
+        break;
+    case GL_DOUBLE_MAT3:
+        retval = 8 * 9;
+        break;
+    case GL_DOUBLE_MAT4:
+        retval = 8 * 16;
+        break;
+    case GL_DOUBLE_MAT2x3:
+    case GL_DOUBLE_MAT3x2:
+        retval = 8 * 6;
+        break;
+    case GL_DOUBLE_MAT2x4:
+    case GL_DOUBLE_MAT4x2:
+        retval = 8 * 8;
+        break;
+    case GL_DOUBLE_MAT3x4:
+    case GL_DOUBLE_MAT4x3:
+        retval = 8 * 12;
+        break;
 #endif
     case GL_FLOAT_VEC2:
     case GL_INT_VEC2:
@@ -88,6 +479,32 @@
     case GL_SAMPLER_2D:
     case GL_SAMPLER_3D:
     case GL_SAMPLER_CUBE:
+    case GL_SAMPLER_2D_SHADOW:
+    case GL_SAMPLER_2D_ARRAY:
+    case GL_SAMPLER_2D_ARRAY_SHADOW:
+    case GL_SAMPLER_2D_MULTISAMPLE:
+    case GL_SAMPLER_CUBE_SHADOW:
+    case GL_INT_SAMPLER_2D:
+    case GL_INT_SAMPLER_3D:
+    case GL_INT_SAMPLER_CUBE:
+    case GL_INT_SAMPLER_2D_ARRAY:
+    case GL_INT_SAMPLER_2D_MULTISAMPLE:
+    case GL_UNSIGNED_INT_SAMPLER_2D:
+    case GL_UNSIGNED_INT_SAMPLER_3D:
+    case GL_UNSIGNED_INT_SAMPLER_CUBE:
+    case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
+    case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
+    case GL_IMAGE_CUBE:
+    case GL_IMAGE_2D_ARRAY:
+    case GL_INT_IMAGE_2D:
+    case GL_INT_IMAGE_3D:
+    case GL_INT_IMAGE_CUBE:
+    case GL_INT_IMAGE_2D_ARRAY:
+    case GL_UNSIGNED_INT_IMAGE_2D:
+    case GL_UNSIGNED_INT_IMAGE_3D:
+    case GL_UNSIGNED_INT_IMAGE_CUBE:
+    case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
+    case GL_UNSIGNED_INT_ATOMIC_COUNTER:
         retval = 4;
         break;
     case GL_UNSIGNED_SHORT_4_4_4_4:
@@ -669,3 +1086,92 @@
     }
     return 4;
 }
+
+bool colorRenderableFormat(GLint internalformat, GLenum texturetype, int majorVersion, int minorVersion, bool hasColorBufferFloatExtension, bool hasColorBufferHalfFloatExtension) {
+    switch (internalformat) {
+        case GL_RGB:
+        case GL_RGBA:
+        case GL_BGRA_EXT:
+            switch (texturetype) {
+                case GL_FLOAT:
+                case GL_HALF_FLOAT_OES:
+                case GL_UNSIGNED_INT_10F_11F_11F_REV:
+                case GL_UNSIGNED_INT_2_10_10_10_REV:
+                    return false;
+                default:
+                    return true;
+            }
+            break;
+        case GL_R8:
+        case GL_RG8:
+        case GL_RGB8:
+        case GL_RGB565:
+        case GL_RGBA4:
+        case GL_RGB5_A1:
+        case GL_RGBA8:
+        case GL_RGB10_A2:
+        case GL_RGB10_A2UI:
+        case GL_SRGB8_ALPHA8:
+        case GL_R8I:
+        case GL_R8UI:
+        case GL_R16I:
+        case GL_R16UI:
+        case GL_R32I:
+        case GL_R32UI:
+        case GL_RG8I:
+        case GL_RG8UI:
+        case GL_RG16I:
+        case GL_RG16UI:
+        case GL_RG32I:
+        case GL_RG32UI:
+        case GL_RGBA8I:
+        case GL_RGBA8UI:
+        case GL_RGBA16I:
+        case GL_RGBA16UI:
+        case GL_RGBA32I:
+        case GL_RGBA32UI:
+        case GL_BGRA8_EXT:
+            return true;
+        case GL_R16F:
+        case GL_RG16F:
+        case GL_RGBA16F:
+        case GL_R32F:
+        case GL_RG32F:
+        case GL_RGBA32F:
+        case GL_R11F_G11F_B10F:
+            return majorVersion >= 3 && hasColorBufferFloatExtension;
+        case GL_RGB16F:
+            return majorVersion >= 3 && hasColorBufferHalfFloatExtension;
+        default:
+            return false;
+    }
+}
+
+bool depthRenderableFormat(GLint internalformat) {
+    switch (internalformat) {
+        case GL_DEPTH_STENCIL:
+        case GL_DEPTH_COMPONENT:
+        case GL_DEPTH_COMPONENT16:
+        case GL_DEPTH_COMPONENT24:
+        case GL_DEPTH_COMPONENT32F:
+        case GL_DEPTH24_STENCIL8:
+        case GL_DEPTH32F_STENCIL8:
+        case 0X81A7: // GL_DEPTH_COMPONENT32
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool stencilRenderableFormat(GLint internalformat) {
+    switch (internalformat) {
+        case GL_STENCIL_INDEX:
+        case GL_DEPTH_STENCIL:
+        case GL_STENCIL_INDEX8:
+        case GL_DEPTH24_STENCIL8:
+        case GL_DEPTH32F_STENCIL8:
+            return true;
+        default:
+            return false;
+    }
+}
diff --git a/shared/OpenglCodecCommon/glUtils.h b/shared/OpenglCodecCommon/glUtils.h
index 2f20b68..09081c2 100644
--- a/shared/OpenglCodecCommon/glUtils.h
+++ b/shared/OpenglCodecCommon/glUtils.h
@@ -57,6 +57,13 @@
     INDIRECT_COMMAND_DRAWELEMENTS = 1,
 } IndirectCommandType;
 
+    bool isSamplerType(GLenum type);
+    bool isIntegerType(GLenum type);
+    bool isUnsignedIntType(GLenum type);
+    bool isBoolType(GLenum type);
+    uint32_t getColumnsOfType(GLenum type);
+    uint32_t getRowsOfType(GLenum type);
+    uint32_t getAttributeCountOfType(GLenum type);
     size_t glSizeof(GLenum type);
     size_t glUtilsParamSize(GLenum param);
     void   glUtilsPackPointerData(unsigned char *dst, unsigned char *str,
@@ -73,6 +80,11 @@
 
     GLuint glUtilsIndirectStructSize(IndirectCommandType cmdType);
 
+    bool colorRenderableFormat(GLint internalformat, GLenum texturetype, int majorVersion, int minorVersion, bool hasColorBufferFloatExtension, bool hasColorBufferHalfFloatExtension);
+
+    bool depthRenderableFormat(GLint internalformat);
+    bool stencilRenderableFormat(GLint internalformat);
+
 #ifdef __cplusplus
 };
 #endif
diff --git a/shared/gralloc_cb/CMakeLists.txt b/shared/gralloc_cb/CMakeLists.txt
index f9e7b71..865d9d7 100644
--- a/shared/gralloc_cb/CMakeLists.txt
+++ b/shared/gralloc_cb/CMakeLists.txt
@@ -5,6 +5,6 @@
 set(gralloc_cb_host_src empty.cpp)
 android_add_library(TARGET gralloc_cb_host LICENSE Apache-2.0 SRC empty.cpp)
 target_include_directories(gralloc_cb_host PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(gralloc_cb_host PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN")
+target_compile_definitions(gralloc_cb_host PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM")
 target_compile_options(gralloc_cb_host PRIVATE "-fvisibility=default" "-Wno-unused-parameter")
 target_link_libraries(gralloc_cb_host PRIVATE android-emu-shared)
\ No newline at end of file
diff --git a/shared/qemupipe/CMakeLists.txt b/shared/qemupipe/CMakeLists.txt
index 2229681..90785d6 100644
--- a/shared/qemupipe/CMakeLists.txt
+++ b/shared/qemupipe/CMakeLists.txt
@@ -5,6 +5,6 @@
 set(qemupipe_host_src qemu_pipe_common.cpp qemu_pipe_host.cpp)
 android_add_library(TARGET qemupipe_host LICENSE Apache-2.0 SRC qemu_pipe_common.cpp qemu_pipe_host.cpp)
 target_include_directories(qemupipe_host PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(qemupipe_host PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN")
+target_compile_definitions(qemupipe_host PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM")
 target_compile_options(qemupipe_host PRIVATE "-fvisibility=default" "-Wno-unused-parameter")
 target_link_libraries(qemupipe_host PRIVATE android-emu-shared)
\ No newline at end of file
diff --git a/system/GLESv1/CMakeLists.txt b/system/GLESv1/CMakeLists.txt
index 5436e5f..8143b9a 100644
--- a/system/GLESv1/CMakeLists.txt
+++ b/system/GLESv1/CMakeLists.txt
@@ -4,7 +4,7 @@
 android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/GLESv1/Android.mk" "e095cb082e3791719749cfc80b90560afd7348eb0d7895449d2509aa129bea75")
 set(GLESv1_CM_emulation_src gl.cpp)
 android_add_library(TARGET GLESv1_CM_emulation SHARED LICENSE Apache-2.0 SRC gl.cpp)
-target_include_directories(GLESv1_CM_emulation PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(GLESv1_CM_emulation PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"GLES_emulation\"")
+target_include_directories(GLESv1_CM_emulation PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(GLESv1_CM_emulation PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"GLES_emulation\"")
 target_compile_options(GLESv1_CM_emulation PRIVATE "-fvisibility=default" "-Wno-unused-parameter")
-target_link_libraries(GLESv1_CM_emulation PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui androidemu cutils utils log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
+target_link_libraries(GLESv1_CM_emulation PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host cutils utils androidemu PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
diff --git a/system/GLESv1_enc/CMakeLists.txt b/system/GLESv1_enc/CMakeLists.txt
index 0a9bc52..2fb5b03 100644
--- a/system/GLESv1_enc/CMakeLists.txt
+++ b/system/GLESv1_enc/CMakeLists.txt
@@ -4,7 +4,7 @@
 android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc/Android.mk" "953e6b7371d10eed63a4be555f8f1fb6f347338484a78102fa8f55dff96f5d3b")
 set(GLESv1_enc_src GLEncoder.cpp GLEncoderUtils.cpp gl_client_context.cpp gl_enc.cpp gl_entry.cpp)
 android_add_library(TARGET GLESv1_enc SHARED LICENSE Apache-2.0 SRC GLEncoder.cpp GLEncoderUtils.cpp gl_client_context.cpp gl_enc.cpp gl_entry.cpp)
-target_include_directories(GLESv1_enc PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(GLESv1_enc PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"emuglGLESv1_enc\"")
+target_include_directories(GLESv1_enc PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(GLESv1_enc PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"emuglGLESv1_enc\"")
 target_compile_options(GLESv1_enc PRIVATE "-fvisibility=default" "-Wno-unused-parameter")
-target_link_libraries(GLESv1_enc PRIVATE OpenglCodecCommon_host cutils utils log android-emu-shared PRIVATE qemupipe_host)
\ No newline at end of file
+target_link_libraries(GLESv1_enc PRIVATE OpenglCodecCommon_host cutils utils log androidemu android-emu-shared PRIVATE qemupipe_host)
\ No newline at end of file
diff --git a/system/GLESv1_enc/GLEncoder.cpp b/system/GLESv1_enc/GLEncoder.cpp
index 20f2c02..1ab13e3 100644
--- a/system/GLESv1_enc/GLEncoder.cpp
+++ b/system/GLESv1_enc/GLEncoder.cpp
@@ -989,7 +989,7 @@
     GLEncoder* ctx = (GLEncoder*)self;
     GLClientState* state = ctx->m_state;
 
-    state->attachTextureObject(target, attachment, texture);
+    state->attachTextureObject(target, attachment, texture, level, 0);
 
     ctx->m_glFramebufferTexture2DOES_enc(self, target, attachment, textarget, texture, level);
 }
@@ -1000,7 +1000,7 @@
     GLEncoder* ctx = (GLEncoder*)self;
     GLClientState* state = ctx->m_state;
 
-    state->attachTextureObject(target, attachment, texture);
+    state->attachTextureObject(target, attachment, texture, level, 0);
 
     ctx->m_glFramebufferTexture2DMultisampleIMG_enc(self, target, attachment, textarget, texture, level, samples);
 }
diff --git a/system/GLESv1_enc/gl_enc.cpp b/system/GLESv1_enc/gl_enc.cpp
index 4e672c6..a536b86 100644
--- a/system/GLESv1_enc/gl_enc.cpp
+++ b/system/GLESv1_enc/gl_enc.cpp
@@ -12,6 +12,7 @@
 
 #include <stdio.h>
 
+#include "android/base/Tracing.h"
 namespace {
 
 void enc_unsupported()
@@ -21,6 +22,7 @@
 
 void glAlphaFunc_enc(void *self , GLenum func, GLclampf ref)
 {
+	AEMU_SCOPED_TRACE("glAlphaFunc encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -47,6 +49,7 @@
 
 void glClearColor_enc(void *self , GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
 {
+	AEMU_SCOPED_TRACE("glClearColor encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -75,6 +78,7 @@
 
 void glClearDepthf_enc(void *self , GLclampf depth)
 {
+	AEMU_SCOPED_TRACE("glClearDepthf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -100,6 +104,7 @@
 
 void glClipPlanef_enc(void *self , GLenum plane, const GLfloat* equation)
 {
+	AEMU_SCOPED_TRACE("glClipPlanef encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -128,6 +133,7 @@
 
 void glColor4f_enc(void *self , GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
 {
+	AEMU_SCOPED_TRACE("glColor4f encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -156,6 +162,7 @@
 
 void glDepthRangef_enc(void *self , GLclampf zNear, GLclampf zFar)
 {
+	AEMU_SCOPED_TRACE("glDepthRangef encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -182,6 +189,7 @@
 
 void glFogf_enc(void *self , GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glFogf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -208,6 +216,7 @@
 
 void glFogfv_enc(void *self , GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glFogfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -236,6 +245,7 @@
 
 void glFrustumf_enc(void *self , GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
 {
+	AEMU_SCOPED_TRACE("glFrustumf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -266,6 +276,7 @@
 
 void glGetClipPlanef_enc(void *self , GLenum pname, GLfloat* eqn)
 {
+	AEMU_SCOPED_TRACE("glGetClipPlanef encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -305,6 +316,7 @@
 
 void glGetFloatv_enc(void *self , GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetFloatv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -344,6 +356,7 @@
 
 void glGetLightfv_enc(void *self , GLenum light, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetLightfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -384,6 +397,7 @@
 
 void glGetMaterialfv_enc(void *self , GLenum face, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetMaterialfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -424,6 +438,7 @@
 
 void glGetTexEnvfv_enc(void *self , GLenum env, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexEnvfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -464,6 +479,7 @@
 
 void glGetTexParameterfv_enc(void *self , GLenum target, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexParameterfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -504,6 +520,7 @@
 
 void glLightModelf_enc(void *self , GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glLightModelf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -530,6 +547,7 @@
 
 void glLightModelfv_enc(void *self , GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glLightModelfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -558,6 +576,7 @@
 
 void glLightf_enc(void *self , GLenum light, GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glLightf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -585,6 +604,7 @@
 
 void glLightfv_enc(void *self , GLenum light, GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glLightfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -614,6 +634,7 @@
 
 void glLineWidth_enc(void *self , GLfloat width)
 {
+	AEMU_SCOPED_TRACE("glLineWidth encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -639,6 +660,7 @@
 
 void glLoadMatrixf_enc(void *self , const GLfloat* m)
 {
+	AEMU_SCOPED_TRACE("glLoadMatrixf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -666,6 +688,7 @@
 
 void glMaterialf_enc(void *self , GLenum face, GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glMaterialf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -693,6 +716,7 @@
 
 void glMaterialfv_enc(void *self , GLenum face, GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glMaterialfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -722,6 +746,7 @@
 
 void glMultMatrixf_enc(void *self , const GLfloat* m)
 {
+	AEMU_SCOPED_TRACE("glMultMatrixf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -749,6 +774,7 @@
 
 void glMultiTexCoord4f_enc(void *self , GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
 {
+	AEMU_SCOPED_TRACE("glMultiTexCoord4f encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -778,6 +804,7 @@
 
 void glNormal3f_enc(void *self , GLfloat nx, GLfloat ny, GLfloat nz)
 {
+	AEMU_SCOPED_TRACE("glNormal3f encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -805,6 +832,7 @@
 
 void glOrthof_enc(void *self , GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
 {
+	AEMU_SCOPED_TRACE("glOrthof encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -835,6 +863,7 @@
 
 void glPointParameterf_enc(void *self , GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glPointParameterf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -861,6 +890,7 @@
 
 void glPointParameterfv_enc(void *self , GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glPointParameterfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -889,6 +919,7 @@
 
 void glPointSize_enc(void *self , GLfloat size)
 {
+	AEMU_SCOPED_TRACE("glPointSize encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -914,6 +945,7 @@
 
 void glPolygonOffset_enc(void *self , GLfloat factor, GLfloat units)
 {
+	AEMU_SCOPED_TRACE("glPolygonOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -940,6 +972,7 @@
 
 void glRotatef_enc(void *self , GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
 {
+	AEMU_SCOPED_TRACE("glRotatef encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -968,6 +1001,7 @@
 
 void glScalef_enc(void *self , GLfloat x, GLfloat y, GLfloat z)
 {
+	AEMU_SCOPED_TRACE("glScalef encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -995,6 +1029,7 @@
 
 void glTexEnvf_enc(void *self , GLenum target, GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glTexEnvf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1022,6 +1057,7 @@
 
 void glTexEnvfv_enc(void *self , GLenum target, GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glTexEnvfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1051,6 +1087,7 @@
 
 void glTexParameterf_enc(void *self , GLenum target, GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glTexParameterf encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1078,6 +1115,7 @@
 
 void glTexParameterfv_enc(void *self , GLenum target, GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glTexParameterfv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1107,6 +1145,7 @@
 
 void glTranslatef_enc(void *self , GLfloat x, GLfloat y, GLfloat z)
 {
+	AEMU_SCOPED_TRACE("glTranslatef encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1134,6 +1173,7 @@
 
 void glActiveTexture_enc(void *self , GLenum texture)
 {
+	AEMU_SCOPED_TRACE("glActiveTexture encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1159,6 +1199,7 @@
 
 void glAlphaFuncx_enc(void *self , GLenum func, GLclampx ref)
 {
+	AEMU_SCOPED_TRACE("glAlphaFuncx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1185,6 +1226,7 @@
 
 void glBindBuffer_enc(void *self , GLenum target, GLuint buffer)
 {
+	AEMU_SCOPED_TRACE("glBindBuffer encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1211,6 +1253,7 @@
 
 void glBindTexture_enc(void *self , GLenum target, GLuint texture)
 {
+	AEMU_SCOPED_TRACE("glBindTexture encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1237,6 +1280,7 @@
 
 void glBlendFunc_enc(void *self , GLenum sfactor, GLenum dfactor)
 {
+	AEMU_SCOPED_TRACE("glBlendFunc encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1263,6 +1307,7 @@
 
 void glBufferData_enc(void *self , GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
 {
+	AEMU_SCOPED_TRACE("glBufferData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1293,6 +1338,7 @@
 
 void glBufferSubData_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glBufferSubData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1323,6 +1369,7 @@
 
 void glClear_enc(void *self , GLbitfield mask)
 {
+	AEMU_SCOPED_TRACE("glClear encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1348,6 +1395,7 @@
 
 void glClearColorx_enc(void *self , GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha)
 {
+	AEMU_SCOPED_TRACE("glClearColorx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1376,6 +1424,7 @@
 
 void glClearDepthx_enc(void *self , GLclampx depth)
 {
+	AEMU_SCOPED_TRACE("glClearDepthx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1401,6 +1450,7 @@
 
 void glClearStencil_enc(void *self , GLint s)
 {
+	AEMU_SCOPED_TRACE("glClearStencil encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1426,6 +1476,7 @@
 
 void glClientActiveTexture_enc(void *self , GLenum texture)
 {
+	AEMU_SCOPED_TRACE("glClientActiveTexture encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1451,6 +1502,7 @@
 
 void glColor4ub_enc(void *self , GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
 {
+	AEMU_SCOPED_TRACE("glColor4ub encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1479,6 +1531,7 @@
 
 void glColor4x_enc(void *self , GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
 {
+	AEMU_SCOPED_TRACE("glColor4x encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1507,6 +1560,7 @@
 
 void glColorMask_enc(void *self , GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
 {
+	AEMU_SCOPED_TRACE("glColorMask encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1535,6 +1589,7 @@
 
 void glCompressedTexImage2D_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexImage2D encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1569,6 +1624,7 @@
 
 void glCompressedTexSubImage2D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexSubImage2D encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1604,6 +1660,7 @@
 
 void glCopyTexImage2D_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
 {
+	AEMU_SCOPED_TRACE("glCopyTexImage2D encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1636,6 +1693,7 @@
 
 void glCopyTexSubImage2D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glCopyTexSubImage2D encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1668,6 +1726,7 @@
 
 void glCullFace_enc(void *self , GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glCullFace encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1693,6 +1752,7 @@
 
 void glDeleteBuffers_enc(void *self , GLsizei n, const GLuint* buffers)
 {
+	AEMU_SCOPED_TRACE("glDeleteBuffers encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1721,6 +1781,7 @@
 
 void glDeleteTextures_enc(void *self , GLsizei n, const GLuint* textures)
 {
+	AEMU_SCOPED_TRACE("glDeleteTextures encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1749,6 +1810,7 @@
 
 void glDepthFunc_enc(void *self , GLenum func)
 {
+	AEMU_SCOPED_TRACE("glDepthFunc encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1774,6 +1836,7 @@
 
 void glDepthMask_enc(void *self , GLboolean flag)
 {
+	AEMU_SCOPED_TRACE("glDepthMask encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1799,6 +1862,7 @@
 
 void glDepthRangex_enc(void *self , GLclampx zNear, GLclampx zFar)
 {
+	AEMU_SCOPED_TRACE("glDepthRangex encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1825,6 +1889,7 @@
 
 void glDisable_enc(void *self , GLenum cap)
 {
+	AEMU_SCOPED_TRACE("glDisable encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1850,6 +1915,7 @@
 
 void glDisableClientState_enc(void *self , GLenum array)
 {
+	AEMU_SCOPED_TRACE("glDisableClientState encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1875,6 +1941,7 @@
 
 void glDrawArrays_enc(void *self , GLenum mode, GLint first, GLsizei count)
 {
+	AEMU_SCOPED_TRACE("glDrawArrays encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1902,6 +1969,7 @@
 
 void glEnable_enc(void *self , GLenum cap)
 {
+	AEMU_SCOPED_TRACE("glEnable encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1927,6 +1995,7 @@
 
 void glEnableClientState_enc(void *self , GLenum array)
 {
+	AEMU_SCOPED_TRACE("glEnableClientState encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1952,6 +2021,7 @@
 
 void glFinish_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glFinish encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1976,6 +2046,7 @@
 
 void glFlush_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glFlush encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2000,6 +2071,7 @@
 
 void glFogx_enc(void *self , GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glFogx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2026,6 +2098,7 @@
 
 void glFogxv_enc(void *self , GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glFogxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2054,6 +2127,7 @@
 
 void glFrontFace_enc(void *self , GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glFrontFace encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2079,6 +2153,7 @@
 
 void glFrustumx_enc(void *self , GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)
 {
+	AEMU_SCOPED_TRACE("glFrustumx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2109,6 +2184,7 @@
 
 void glGetBooleanv_enc(void *self , GLenum pname, GLboolean* params)
 {
+	AEMU_SCOPED_TRACE("glGetBooleanv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2148,6 +2224,7 @@
 
 void glGetBufferParameteriv_enc(void *self , GLenum target, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetBufferParameteriv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2188,6 +2265,7 @@
 
 void glClipPlanex_enc(void *self , GLenum pname, const GLfixed* eqn)
 {
+	AEMU_SCOPED_TRACE("glClipPlanex encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2216,6 +2294,7 @@
 
 void glGenBuffers_enc(void *self , GLsizei n, GLuint* buffers)
 {
+	AEMU_SCOPED_TRACE("glGenBuffers encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2255,6 +2334,7 @@
 
 void glGenTextures_enc(void *self , GLsizei n, GLuint* textures)
 {
+	AEMU_SCOPED_TRACE("glGenTextures encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2294,6 +2374,7 @@
 
 GLenum glGetError_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glGetError encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2333,6 +2414,7 @@
 
 void glGetFixedv_enc(void *self , GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetFixedv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2372,6 +2454,7 @@
 
 void glGetIntegerv_enc(void *self , GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetIntegerv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2411,6 +2494,7 @@
 
 void glGetLightxv_enc(void *self , GLenum light, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetLightxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2451,6 +2535,7 @@
 
 void glGetMaterialxv_enc(void *self , GLenum face, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetMaterialxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2491,6 +2576,7 @@
 
 void glGetTexEnviv_enc(void *self , GLenum env, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexEnviv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2531,6 +2617,7 @@
 
 void glGetTexEnvxv_enc(void *self , GLenum env, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexEnvxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2571,6 +2658,7 @@
 
 void glGetTexParameteriv_enc(void *self , GLenum target, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexParameteriv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2611,6 +2699,7 @@
 
 void glGetTexParameterxv_enc(void *self , GLenum target, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexParameterxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2651,6 +2740,7 @@
 
 void glHint_enc(void *self , GLenum target, GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glHint encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2677,6 +2767,7 @@
 
 GLboolean glIsBuffer_enc(void *self , GLuint buffer)
 {
+	AEMU_SCOPED_TRACE("glIsBuffer encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2717,6 +2808,7 @@
 
 GLboolean glIsEnabled_enc(void *self , GLenum cap)
 {
+	AEMU_SCOPED_TRACE("glIsEnabled encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2757,6 +2849,7 @@
 
 GLboolean glIsTexture_enc(void *self , GLuint texture)
 {
+	AEMU_SCOPED_TRACE("glIsTexture encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2797,6 +2890,7 @@
 
 void glLightModelx_enc(void *self , GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glLightModelx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2823,6 +2917,7 @@
 
 void glLightModelxv_enc(void *self , GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glLightModelxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2851,6 +2946,7 @@
 
 void glLightx_enc(void *self , GLenum light, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glLightx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2878,6 +2974,7 @@
 
 void glLightxv_enc(void *self , GLenum light, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glLightxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2907,6 +3004,7 @@
 
 void glLineWidthx_enc(void *self , GLfixed width)
 {
+	AEMU_SCOPED_TRACE("glLineWidthx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2932,6 +3030,7 @@
 
 void glLoadIdentity_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glLoadIdentity encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2956,6 +3055,7 @@
 
 void glLoadMatrixx_enc(void *self , const GLfixed* m)
 {
+	AEMU_SCOPED_TRACE("glLoadMatrixx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2983,6 +3083,7 @@
 
 void glLogicOp_enc(void *self , GLenum opcode)
 {
+	AEMU_SCOPED_TRACE("glLogicOp encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3008,6 +3109,7 @@
 
 void glMaterialx_enc(void *self , GLenum face, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glMaterialx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3035,6 +3137,7 @@
 
 void glMaterialxv_enc(void *self , GLenum face, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glMaterialxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3064,6 +3167,7 @@
 
 void glMatrixMode_enc(void *self , GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glMatrixMode encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3089,6 +3193,7 @@
 
 void glMultMatrixx_enc(void *self , const GLfixed* m)
 {
+	AEMU_SCOPED_TRACE("glMultMatrixx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3116,6 +3221,7 @@
 
 void glMultiTexCoord4x_enc(void *self , GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
 {
+	AEMU_SCOPED_TRACE("glMultiTexCoord4x encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3145,6 +3251,7 @@
 
 void glNormal3x_enc(void *self , GLfixed nx, GLfixed ny, GLfixed nz)
 {
+	AEMU_SCOPED_TRACE("glNormal3x encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3172,6 +3279,7 @@
 
 void glOrthox_enc(void *self , GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)
 {
+	AEMU_SCOPED_TRACE("glOrthox encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3202,6 +3310,7 @@
 
 void glPixelStorei_enc(void *self , GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glPixelStorei encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3228,6 +3337,7 @@
 
 void glPointParameterx_enc(void *self , GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glPointParameterx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3254,6 +3364,7 @@
 
 void glPointParameterxv_enc(void *self , GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glPointParameterxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3282,6 +3393,7 @@
 
 void glPointSizex_enc(void *self , GLfixed size)
 {
+	AEMU_SCOPED_TRACE("glPointSizex encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3307,6 +3419,7 @@
 
 void glPolygonOffsetx_enc(void *self , GLfixed factor, GLfixed units)
 {
+	AEMU_SCOPED_TRACE("glPolygonOffsetx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3333,6 +3446,7 @@
 
 void glPopMatrix_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glPopMatrix encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3357,6 +3471,7 @@
 
 void glPushMatrix_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glPushMatrix encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3381,6 +3496,7 @@
 
 void glReadPixels_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels)
 {
+	AEMU_SCOPED_TRACE("glReadPixels encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3425,6 +3541,7 @@
 
 void glRotatex_enc(void *self , GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
 {
+	AEMU_SCOPED_TRACE("glRotatex encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3453,6 +3570,7 @@
 
 void glSampleCoverage_enc(void *self , GLclampf value, GLboolean invert)
 {
+	AEMU_SCOPED_TRACE("glSampleCoverage encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3479,6 +3597,7 @@
 
 void glSampleCoveragex_enc(void *self , GLclampx value, GLboolean invert)
 {
+	AEMU_SCOPED_TRACE("glSampleCoveragex encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3505,6 +3624,7 @@
 
 void glScalex_enc(void *self , GLfixed x, GLfixed y, GLfixed z)
 {
+	AEMU_SCOPED_TRACE("glScalex encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3532,6 +3652,7 @@
 
 void glScissor_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glScissor encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3560,6 +3681,7 @@
 
 void glShadeModel_enc(void *self , GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glShadeModel encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3585,6 +3707,7 @@
 
 void glStencilFunc_enc(void *self , GLenum func, GLint ref, GLuint mask)
 {
+	AEMU_SCOPED_TRACE("glStencilFunc encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3612,6 +3735,7 @@
 
 void glStencilMask_enc(void *self , GLuint mask)
 {
+	AEMU_SCOPED_TRACE("glStencilMask encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3637,6 +3761,7 @@
 
 void glStencilOp_enc(void *self , GLenum fail, GLenum zfail, GLenum zpass)
 {
+	AEMU_SCOPED_TRACE("glStencilOp encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3664,6 +3789,7 @@
 
 void glTexEnvi_enc(void *self , GLenum target, GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glTexEnvi encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3691,6 +3817,7 @@
 
 void glTexEnvx_enc(void *self , GLenum target, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glTexEnvx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3718,6 +3845,7 @@
 
 void glTexEnviv_enc(void *self , GLenum target, GLenum pname, const GLint* params)
 {
+	AEMU_SCOPED_TRACE("glTexEnviv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3747,6 +3875,7 @@
 
 void glTexEnvxv_enc(void *self , GLenum target, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glTexEnvxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3776,6 +3905,7 @@
 
 void glTexImage2D_enc(void *self , GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
 {
+	AEMU_SCOPED_TRACE("glTexImage2D encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3817,6 +3947,7 @@
 
 void glTexParameteri_enc(void *self , GLenum target, GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glTexParameteri encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3844,6 +3975,7 @@
 
 void glTexParameterx_enc(void *self , GLenum target, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glTexParameterx encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3871,6 +4003,7 @@
 
 void glTexParameteriv_enc(void *self , GLenum target, GLenum pname, const GLint* params)
 {
+	AEMU_SCOPED_TRACE("glTexParameteriv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3900,6 +4033,7 @@
 
 void glTexParameterxv_enc(void *self , GLenum target, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glTexParameterxv encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3929,6 +4063,7 @@
 
 void glTexSubImage2D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels)
 {
+	AEMU_SCOPED_TRACE("glTexSubImage2D encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3970,6 +4105,7 @@
 
 void glTranslatex_enc(void *self , GLfixed x, GLfixed y, GLfixed z)
 {
+	AEMU_SCOPED_TRACE("glTranslatex encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3997,6 +4133,7 @@
 
 void glViewport_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glViewport encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4025,6 +4162,7 @@
 
 void glVertexPointerOffset_enc(void *self , GLint size, GLenum type, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glVertexPointerOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4053,6 +4191,7 @@
 
 void glColorPointerOffset_enc(void *self , GLint size, GLenum type, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glColorPointerOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4081,6 +4220,7 @@
 
 void glNormalPointerOffset_enc(void *self , GLenum type, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glNormalPointerOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4108,6 +4248,7 @@
 
 void glPointSizePointerOffset_enc(void *self , GLenum type, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glPointSizePointerOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4135,6 +4276,7 @@
 
 void glTexCoordPointerOffset_enc(void *self , GLint size, GLenum type, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glTexCoordPointerOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4163,6 +4305,7 @@
 
 void glWeightPointerOffset_enc(void *self , GLint size, GLenum type, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glWeightPointerOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4191,6 +4334,7 @@
 
 void glMatrixIndexPointerOffset_enc(void *self , GLint size, GLenum type, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glMatrixIndexPointerOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4219,6 +4363,7 @@
 
 void glVertexPointerData_enc(void *self , GLint size, GLenum type, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glVertexPointerData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4250,6 +4395,7 @@
 
 void glColorPointerData_enc(void *self , GLint size, GLenum type, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glColorPointerData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4281,6 +4427,7 @@
 
 void glNormalPointerData_enc(void *self , GLenum type, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glNormalPointerData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4311,6 +4458,7 @@
 
 void glTexCoordPointerData_enc(void *self , GLint unit, GLint size, GLenum type, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glTexCoordPointerData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4343,6 +4491,7 @@
 
 void glPointSizePointerData_enc(void *self , GLenum type, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glPointSizePointerData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4373,6 +4522,7 @@
 
 void glWeightPointerData_enc(void *self , GLint size, GLenum type, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glWeightPointerData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4404,6 +4554,7 @@
 
 void glMatrixIndexPointerData_enc(void *self , GLint size, GLenum type, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glMatrixIndexPointerData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4435,6 +4586,7 @@
 
 void glDrawElementsOffset_enc(void *self , GLenum mode, GLsizei count, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsOffset encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4463,6 +4615,7 @@
 
 void glDrawElementsData_enc(void *self , GLenum mode, GLsizei count, GLenum type, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsData encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4494,6 +4647,7 @@
 
 void glGetCompressedTextureFormats_enc(void *self , int count, GLint* formats)
 {
+	AEMU_SCOPED_TRACE("glGetCompressedTextureFormats encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4533,6 +4687,7 @@
 
 int glFinishRoundTrip_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glFinishRoundTrip encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4572,6 +4727,7 @@
 
 void glBlendEquationSeparateOES_enc(void *self , GLenum modeRGB, GLenum modeAlpha)
 {
+	AEMU_SCOPED_TRACE("glBlendEquationSeparateOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4598,6 +4754,7 @@
 
 void glBlendFuncSeparateOES_enc(void *self , GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
 {
+	AEMU_SCOPED_TRACE("glBlendFuncSeparateOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4626,6 +4783,7 @@
 
 void glBlendEquationOES_enc(void *self , GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glBlendEquationOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4651,6 +4809,7 @@
 
 void glDrawTexsOES_enc(void *self , GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
 {
+	AEMU_SCOPED_TRACE("glDrawTexsOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4680,6 +4839,7 @@
 
 void glDrawTexiOES_enc(void *self , GLint x, GLint y, GLint z, GLint width, GLint height)
 {
+	AEMU_SCOPED_TRACE("glDrawTexiOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4709,6 +4869,7 @@
 
 void glDrawTexxOES_enc(void *self , GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
 {
+	AEMU_SCOPED_TRACE("glDrawTexxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4738,6 +4899,7 @@
 
 void glDrawTexsvOES_enc(void *self , const GLshort* coords)
 {
+	AEMU_SCOPED_TRACE("glDrawTexsvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4765,6 +4927,7 @@
 
 void glDrawTexivOES_enc(void *self , const GLint* coords)
 {
+	AEMU_SCOPED_TRACE("glDrawTexivOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4792,6 +4955,7 @@
 
 void glDrawTexxvOES_enc(void *self , const GLfixed* coords)
 {
+	AEMU_SCOPED_TRACE("glDrawTexxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4819,6 +4983,7 @@
 
 void glDrawTexfOES_enc(void *self , GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
 {
+	AEMU_SCOPED_TRACE("glDrawTexfOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4848,6 +5013,7 @@
 
 void glDrawTexfvOES_enc(void *self , const GLfloat* coords)
 {
+	AEMU_SCOPED_TRACE("glDrawTexfvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4875,6 +5041,7 @@
 
 void glEGLImageTargetTexture2DOES_enc(void *self , GLenum target, GLeglImageOES image)
 {
+	AEMU_SCOPED_TRACE("glEGLImageTargetTexture2DOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4901,6 +5068,7 @@
 
 void glEGLImageTargetRenderbufferStorageOES_enc(void *self , GLenum target, GLeglImageOES image)
 {
+	AEMU_SCOPED_TRACE("glEGLImageTargetRenderbufferStorageOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4927,6 +5095,7 @@
 
 void glAlphaFuncxOES_enc(void *self , GLenum func, GLclampx ref)
 {
+	AEMU_SCOPED_TRACE("glAlphaFuncxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4953,6 +5122,7 @@
 
 void glClearColorxOES_enc(void *self , GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha)
 {
+	AEMU_SCOPED_TRACE("glClearColorxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4981,6 +5151,7 @@
 
 void glClearDepthxOES_enc(void *self , GLclampx depth)
 {
+	AEMU_SCOPED_TRACE("glClearDepthxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5006,6 +5177,7 @@
 
 void glClipPlanexOES_enc(void *self , GLenum plane, const GLfixed* equation)
 {
+	AEMU_SCOPED_TRACE("glClipPlanexOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5034,6 +5206,7 @@
 
 void glClipPlanexIMG_enc(void *self , GLenum plane, const GLfixed* equation)
 {
+	AEMU_SCOPED_TRACE("glClipPlanexIMG encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5062,6 +5235,7 @@
 
 void glColor4xOES_enc(void *self , GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
 {
+	AEMU_SCOPED_TRACE("glColor4xOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5090,6 +5264,7 @@
 
 void glDepthRangexOES_enc(void *self , GLclampx zNear, GLclampx zFar)
 {
+	AEMU_SCOPED_TRACE("glDepthRangexOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5116,6 +5291,7 @@
 
 void glFogxOES_enc(void *self , GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glFogxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5142,6 +5318,7 @@
 
 void glFogxvOES_enc(void *self , GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glFogxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5170,6 +5347,7 @@
 
 void glFrustumxOES_enc(void *self , GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)
 {
+	AEMU_SCOPED_TRACE("glFrustumxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5200,6 +5378,7 @@
 
 void glGetClipPlanexOES_enc(void *self , GLenum pname, GLfixed* eqn)
 {
+	AEMU_SCOPED_TRACE("glGetClipPlanexOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5239,6 +5418,7 @@
 
 void glGetClipPlanex_enc(void *self , GLenum pname, GLfixed* eqn)
 {
+	AEMU_SCOPED_TRACE("glGetClipPlanex encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5278,6 +5458,7 @@
 
 void glGetFixedvOES_enc(void *self , GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetFixedvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5317,6 +5498,7 @@
 
 void glGetLightxvOES_enc(void *self , GLenum light, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetLightxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5357,6 +5539,7 @@
 
 void glGetMaterialxvOES_enc(void *self , GLenum face, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetMaterialxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5397,6 +5580,7 @@
 
 void glGetTexEnvxvOES_enc(void *self , GLenum env, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexEnvxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5437,6 +5621,7 @@
 
 void glGetTexParameterxvOES_enc(void *self , GLenum target, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexParameterxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5477,6 +5662,7 @@
 
 void glLightModelxOES_enc(void *self , GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glLightModelxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5503,6 +5689,7 @@
 
 void glLightModelxvOES_enc(void *self , GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glLightModelxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5531,6 +5718,7 @@
 
 void glLightxOES_enc(void *self , GLenum light, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glLightxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5558,6 +5746,7 @@
 
 void glLightxvOES_enc(void *self , GLenum light, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glLightxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5587,6 +5776,7 @@
 
 void glLineWidthxOES_enc(void *self , GLfixed width)
 {
+	AEMU_SCOPED_TRACE("glLineWidthxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5612,6 +5802,7 @@
 
 void glLoadMatrixxOES_enc(void *self , const GLfixed* m)
 {
+	AEMU_SCOPED_TRACE("glLoadMatrixxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5639,6 +5830,7 @@
 
 void glMaterialxOES_enc(void *self , GLenum face, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glMaterialxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5666,6 +5858,7 @@
 
 void glMaterialxvOES_enc(void *self , GLenum face, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glMaterialxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5695,6 +5888,7 @@
 
 void glMultMatrixxOES_enc(void *self , const GLfixed* m)
 {
+	AEMU_SCOPED_TRACE("glMultMatrixxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5722,6 +5916,7 @@
 
 void glMultiTexCoord4xOES_enc(void *self , GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
 {
+	AEMU_SCOPED_TRACE("glMultiTexCoord4xOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5751,6 +5946,7 @@
 
 void glNormal3xOES_enc(void *self , GLfixed nx, GLfixed ny, GLfixed nz)
 {
+	AEMU_SCOPED_TRACE("glNormal3xOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5778,6 +5974,7 @@
 
 void glOrthoxOES_enc(void *self , GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)
 {
+	AEMU_SCOPED_TRACE("glOrthoxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5808,6 +6005,7 @@
 
 void glPointParameterxOES_enc(void *self , GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glPointParameterxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5834,6 +6032,7 @@
 
 void glPointParameterxvOES_enc(void *self , GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glPointParameterxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5862,6 +6061,7 @@
 
 void glPointSizexOES_enc(void *self , GLfixed size)
 {
+	AEMU_SCOPED_TRACE("glPointSizexOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5887,6 +6087,7 @@
 
 void glPolygonOffsetxOES_enc(void *self , GLfixed factor, GLfixed units)
 {
+	AEMU_SCOPED_TRACE("glPolygonOffsetxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5913,6 +6114,7 @@
 
 void glRotatexOES_enc(void *self , GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
 {
+	AEMU_SCOPED_TRACE("glRotatexOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5941,6 +6143,7 @@
 
 void glSampleCoveragexOES_enc(void *self , GLclampx value, GLboolean invert)
 {
+	AEMU_SCOPED_TRACE("glSampleCoveragexOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5967,6 +6170,7 @@
 
 void glScalexOES_enc(void *self , GLfixed x, GLfixed y, GLfixed z)
 {
+	AEMU_SCOPED_TRACE("glScalexOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5994,6 +6198,7 @@
 
 void glTexEnvxOES_enc(void *self , GLenum target, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glTexEnvxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6021,6 +6226,7 @@
 
 void glTexEnvxvOES_enc(void *self , GLenum target, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glTexEnvxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6050,6 +6256,7 @@
 
 void glTexParameterxOES_enc(void *self , GLenum target, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glTexParameterxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6077,6 +6284,7 @@
 
 void glTexParameterxvOES_enc(void *self , GLenum target, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glTexParameterxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6106,6 +6314,7 @@
 
 void glTranslatexOES_enc(void *self , GLfixed x, GLfixed y, GLfixed z)
 {
+	AEMU_SCOPED_TRACE("glTranslatexOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6133,6 +6342,7 @@
 
 GLboolean glIsRenderbufferOES_enc(void *self , GLuint renderbuffer)
 {
+	AEMU_SCOPED_TRACE("glIsRenderbufferOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6173,6 +6383,7 @@
 
 void glBindRenderbufferOES_enc(void *self , GLenum target, GLuint renderbuffer)
 {
+	AEMU_SCOPED_TRACE("glBindRenderbufferOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6199,6 +6410,7 @@
 
 void glDeleteRenderbuffersOES_enc(void *self , GLsizei n, const GLuint* renderbuffers)
 {
+	AEMU_SCOPED_TRACE("glDeleteRenderbuffersOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6227,6 +6439,7 @@
 
 void glGenRenderbuffersOES_enc(void *self , GLsizei n, GLuint* renderbuffers)
 {
+	AEMU_SCOPED_TRACE("glGenRenderbuffersOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6266,6 +6479,7 @@
 
 void glRenderbufferStorageOES_enc(void *self , GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glRenderbufferStorageOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6294,6 +6508,7 @@
 
 void glGetRenderbufferParameterivOES_enc(void *self , GLenum target, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetRenderbufferParameterivOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6334,6 +6549,7 @@
 
 GLboolean glIsFramebufferOES_enc(void *self , GLuint framebuffer)
 {
+	AEMU_SCOPED_TRACE("glIsFramebufferOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6374,6 +6590,7 @@
 
 void glBindFramebufferOES_enc(void *self , GLenum target, GLuint framebuffer)
 {
+	AEMU_SCOPED_TRACE("glBindFramebufferOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6400,6 +6617,7 @@
 
 void glDeleteFramebuffersOES_enc(void *self , GLsizei n, const GLuint* framebuffers)
 {
+	AEMU_SCOPED_TRACE("glDeleteFramebuffersOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6428,6 +6646,7 @@
 
 void glGenFramebuffersOES_enc(void *self , GLsizei n, GLuint* framebuffers)
 {
+	AEMU_SCOPED_TRACE("glGenFramebuffersOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6467,6 +6686,7 @@
 
 GLenum glCheckFramebufferStatusOES_enc(void *self , GLenum target)
 {
+	AEMU_SCOPED_TRACE("glCheckFramebufferStatusOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6507,6 +6727,7 @@
 
 void glFramebufferRenderbufferOES_enc(void *self , GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
 {
+	AEMU_SCOPED_TRACE("glFramebufferRenderbufferOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6535,6 +6756,7 @@
 
 void glFramebufferTexture2DOES_enc(void *self , GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
 {
+	AEMU_SCOPED_TRACE("glFramebufferTexture2DOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6564,6 +6786,7 @@
 
 void glGetFramebufferAttachmentParameterivOES_enc(void *self , GLenum target, GLenum attachment, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetFramebufferAttachmentParameterivOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6605,6 +6828,7 @@
 
 void glGenerateMipmapOES_enc(void *self , GLenum target)
 {
+	AEMU_SCOPED_TRACE("glGenerateMipmapOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6630,6 +6854,7 @@
 
 GLboolean glUnmapBufferOES_enc(void *self , GLenum target)
 {
+	AEMU_SCOPED_TRACE("glUnmapBufferOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6670,6 +6895,7 @@
 
 void glCurrentPaletteMatrixOES_enc(void *self , GLuint matrixpaletteindex)
 {
+	AEMU_SCOPED_TRACE("glCurrentPaletteMatrixOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6695,6 +6921,7 @@
 
 void glLoadPaletteFromModelViewMatrixOES_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glLoadPaletteFromModelViewMatrixOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6719,6 +6946,7 @@
 
 GLbitfield glQueryMatrixxOES_enc(void *self , GLfixed* mantissa, GLint* exponent)
 {
+	AEMU_SCOPED_TRACE("glQueryMatrixxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6766,6 +6994,7 @@
 
 void glDepthRangefOES_enc(void *self , GLclampf zNear, GLclampf zFar)
 {
+	AEMU_SCOPED_TRACE("glDepthRangefOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6792,6 +7021,7 @@
 
 void glFrustumfOES_enc(void *self , GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
 {
+	AEMU_SCOPED_TRACE("glFrustumfOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6822,6 +7052,7 @@
 
 void glOrthofOES_enc(void *self , GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
 {
+	AEMU_SCOPED_TRACE("glOrthofOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6852,6 +7083,7 @@
 
 void glClipPlanefOES_enc(void *self , GLenum plane, const GLfloat* equation)
 {
+	AEMU_SCOPED_TRACE("glClipPlanefOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6880,6 +7112,7 @@
 
 void glClipPlanefIMG_enc(void *self , GLenum plane, const GLfloat* equation)
 {
+	AEMU_SCOPED_TRACE("glClipPlanefIMG encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6908,6 +7141,7 @@
 
 void glGetClipPlanefOES_enc(void *self , GLenum pname, GLfloat* eqn)
 {
+	AEMU_SCOPED_TRACE("glGetClipPlanefOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6947,6 +7181,7 @@
 
 void glClearDepthfOES_enc(void *self , GLclampf depth)
 {
+	AEMU_SCOPED_TRACE("glClearDepthfOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6972,6 +7207,7 @@
 
 void glTexGenfOES_enc(void *self , GLenum coord, GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glTexGenfOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6999,6 +7235,7 @@
 
 void glTexGenfvOES_enc(void *self , GLenum coord, GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glTexGenfvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7028,6 +7265,7 @@
 
 void glTexGeniOES_enc(void *self , GLenum coord, GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glTexGeniOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7055,6 +7293,7 @@
 
 void glTexGenivOES_enc(void *self , GLenum coord, GLenum pname, const GLint* params)
 {
+	AEMU_SCOPED_TRACE("glTexGenivOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7084,6 +7323,7 @@
 
 void glTexGenxOES_enc(void *self , GLenum coord, GLenum pname, GLfixed param)
 {
+	AEMU_SCOPED_TRACE("glTexGenxOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7111,6 +7351,7 @@
 
 void glTexGenxvOES_enc(void *self , GLenum coord, GLenum pname, const GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glTexGenxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7140,6 +7381,7 @@
 
 void glGetTexGenfvOES_enc(void *self , GLenum coord, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexGenfvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7169,6 +7411,7 @@
 
 void glGetTexGenivOES_enc(void *self , GLenum coord, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexGenivOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7198,6 +7441,7 @@
 
 void glGetTexGenxvOES_enc(void *self , GLenum coord, GLenum pname, GLfixed* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexGenxvOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7227,6 +7471,7 @@
 
 void glBindVertexArrayOES_enc(void *self , GLuint array)
 {
+	AEMU_SCOPED_TRACE("glBindVertexArrayOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7252,6 +7497,7 @@
 
 void glDeleteVertexArraysOES_enc(void *self , GLsizei n, const GLuint* arrays)
 {
+	AEMU_SCOPED_TRACE("glDeleteVertexArraysOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7280,6 +7526,7 @@
 
 void glGenVertexArraysOES_enc(void *self , GLsizei n, GLuint* arrays)
 {
+	AEMU_SCOPED_TRACE("glGenVertexArraysOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7319,6 +7566,7 @@
 
 GLboolean glIsVertexArrayOES_enc(void *self , GLuint array)
 {
+	AEMU_SCOPED_TRACE("glIsVertexArrayOES encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7359,6 +7607,7 @@
 
 void glDiscardFramebufferEXT_enc(void *self , GLenum target, GLsizei numAttachments, const GLenum* attachments)
 {
+	AEMU_SCOPED_TRACE("glDiscardFramebufferEXT encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7388,6 +7637,7 @@
 
 void glRenderbufferStorageMultisampleIMG_enc(void *self , GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glRenderbufferStorageMultisampleIMG encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7417,6 +7667,7 @@
 
 void glFramebufferTexture2DMultisampleIMG_enc(void *self , GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples)
 {
+	AEMU_SCOPED_TRACE("glFramebufferTexture2DMultisampleIMG encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7447,6 +7698,7 @@
 
 void glDeleteFencesNV_enc(void *self , GLsizei n, const GLuint* fences)
 {
+	AEMU_SCOPED_TRACE("glDeleteFencesNV encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7475,6 +7727,7 @@
 
 void glGenFencesNV_enc(void *self , GLsizei n, GLuint* fences)
 {
+	AEMU_SCOPED_TRACE("glGenFencesNV encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7503,6 +7756,7 @@
 
 GLboolean glIsFenceNV_enc(void *self , GLuint fence)
 {
+	AEMU_SCOPED_TRACE("glIsFenceNV encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7543,6 +7797,7 @@
 
 GLboolean glTestFenceNV_enc(void *self , GLuint fence)
 {
+	AEMU_SCOPED_TRACE("glTestFenceNV encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7583,6 +7838,7 @@
 
 void glGetFenceivNV_enc(void *self , GLuint fence, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetFenceivNV encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7623,6 +7879,7 @@
 
 void glFinishFenceNV_enc(void *self , GLuint fence)
 {
+	AEMU_SCOPED_TRACE("glFinishFenceNV encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7648,6 +7905,7 @@
 
 void glSetFenceNV_enc(void *self , GLuint fence, GLenum condition)
 {
+	AEMU_SCOPED_TRACE("glSetFenceNV encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7674,6 +7932,7 @@
 
 void glGetDriverControlsQCOM_enc(void *self , GLint* num, GLsizei size, GLuint* driverControls)
 {
+	AEMU_SCOPED_TRACE("glGetDriverControlsQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7717,6 +7976,7 @@
 
 void glGetDriverControlStringQCOM_enc(void *self , GLuint driverControl, GLsizei bufSize, GLsizei* length, GLchar* driverControlString)
 {
+	AEMU_SCOPED_TRACE("glGetDriverControlStringQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7761,6 +8021,7 @@
 
 void glEnableDriverControlQCOM_enc(void *self , GLuint driverControl)
 {
+	AEMU_SCOPED_TRACE("glEnableDriverControlQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7786,6 +8047,7 @@
 
 void glDisableDriverControlQCOM_enc(void *self , GLuint driverControl)
 {
+	AEMU_SCOPED_TRACE("glDisableDriverControlQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7811,6 +8073,7 @@
 
 void glExtGetTexturesQCOM_enc(void *self , GLuint* textures, GLint maxTextures, GLint* numTextures)
 {
+	AEMU_SCOPED_TRACE("glExtGetTexturesQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7854,6 +8117,7 @@
 
 void glExtGetBuffersQCOM_enc(void *self , GLuint* buffers, GLint maxBuffers, GLint* numBuffers)
 {
+	AEMU_SCOPED_TRACE("glExtGetBuffersQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7897,6 +8161,7 @@
 
 void glExtGetRenderbuffersQCOM_enc(void *self , GLuint* renderbuffers, GLint maxRenderbuffers, GLint* numRenderbuffers)
 {
+	AEMU_SCOPED_TRACE("glExtGetRenderbuffersQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7940,6 +8205,7 @@
 
 void glExtGetFramebuffersQCOM_enc(void *self , GLuint* framebuffers, GLint maxFramebuffers, GLint* numFramebuffers)
 {
+	AEMU_SCOPED_TRACE("glExtGetFramebuffersQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7983,6 +8249,7 @@
 
 void glExtGetTexLevelParameterivQCOM_enc(void *self , GLuint texture, GLenum face, GLint level, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glExtGetTexLevelParameterivQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8025,6 +8292,7 @@
 
 void glExtTexObjectStateOverrideiQCOM_enc(void *self , GLenum target, GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glExtTexObjectStateOverrideiQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8052,6 +8320,7 @@
 
 void glExtGetTexSubImageQCOM_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid* texels)
 {
+	AEMU_SCOPED_TRACE("glExtGetTexSubImageQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8100,6 +8369,7 @@
 
 void glExtGetShadersQCOM_enc(void *self , GLuint* shaders, GLint maxShaders, GLint* numShaders)
 {
+	AEMU_SCOPED_TRACE("glExtGetShadersQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8143,6 +8413,7 @@
 
 void glExtGetProgramsQCOM_enc(void *self , GLuint* programs, GLint maxPrograms, GLint* numPrograms)
 {
+	AEMU_SCOPED_TRACE("glExtGetProgramsQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8186,6 +8457,7 @@
 
 GLboolean glExtIsProgramBinaryQCOM_enc(void *self , GLuint program)
 {
+	AEMU_SCOPED_TRACE("glExtIsProgramBinaryQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8226,6 +8498,7 @@
 
 void glStartTilingQCOM_enc(void *self , GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask)
 {
+	AEMU_SCOPED_TRACE("glStartTilingQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8255,6 +8528,7 @@
 
 void glEndTilingQCOM_enc(void *self , GLbitfield preserveMask)
 {
+	AEMU_SCOPED_TRACE("glEndTilingQCOM encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8280,6 +8554,7 @@
 
 GLenum glGetGraphicsResetStatusEXT_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glGetGraphicsResetStatusEXT encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8319,6 +8594,7 @@
 
 void glReadnPixelsEXT_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glReadnPixelsEXT encode");
 
 	gl_encoder_context_t *ctx = (gl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
diff --git a/system/GLESv2/CMakeLists.txt b/system/GLESv2/CMakeLists.txt
index d90502a..b04a4bb 100644
--- a/system/GLESv2/CMakeLists.txt
+++ b/system/GLESv2/CMakeLists.txt
@@ -4,7 +4,7 @@
 android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/GLESv2/Android.mk" "d8f9dda69ec57ad8b7a65f02c3335b16a4724f612dec1d1a2cd793c28c0a10f9")
 set(GLESv2_emulation_src gl2.cpp)
 android_add_library(TARGET GLESv2_emulation SHARED LICENSE Apache-2.0 SRC gl2.cpp)
-target_include_directories(GLESv2_emulation PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(GLESv2_emulation PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"GLESv2_emulation\"")
+target_include_directories(GLESv2_emulation PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(GLESv2_emulation PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"GLESv2_emulation\"")
 target_compile_options(GLESv2_emulation PRIVATE "-fvisibility=default" "-Wno-unused-parameter")
-target_link_libraries(GLESv2_emulation PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui androidemu cutils utils log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
+target_link_libraries(GLESv2_emulation PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host cutils utils androidemu PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
diff --git a/system/GLESv2/gl2.cpp b/system/GLESv2/gl2.cpp
index a36bdd3..1c5ece7 100644
--- a/system/GLESv2/gl2.cpp
+++ b/system/GLESv2/gl2.cpp
@@ -101,6 +101,7 @@
     DBG("glEGLImageTargetRenderbufferStorageOES v2 image=%p\n", img);
     //TODO: check error - we don't have a way to set gl error
     EGLImage_t *image = (EGLImage_t*)img;
+    GLeglImageOES hostImage = reinterpret_cast<GLeglImageOES>((intptr_t)image->host_egl_image);
 
     if (image->target == EGL_NATIVE_BUFFER_ANDROID) {
         android_native_buffer_t* native_buffer = ((EGLImage_t*)image)->native_buffer;
@@ -114,6 +115,8 @@
         }
 
         DEFINE_AND_VALIDATE_HOST_CONNECTION();
+        GET_CONTEXT;
+        ctx->associateEGLImage(target, hostImage);
         rcEnc->rcBindRenderbuffer(rcEnc,
                 grallocHelper->getHostHandle(native_buffer->handle));
     } else {
diff --git a/system/GLESv2_enc/CMakeLists.txt b/system/GLESv2_enc/CMakeLists.txt
index 39a479f..5d0f049 100644
--- a/system/GLESv2_enc/CMakeLists.txt
+++ b/system/GLESv2_enc/CMakeLists.txt
@@ -4,7 +4,7 @@
 android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc/Android.mk" "df543672d1f36e43fb783b08200aa85dbf3a2e7167f8ecd7e4c01c80e6fd1650")
 set(GLESv2_enc_src GL2EncoderUtils.cpp GL2Encoder.cpp GLESv2Validation.cpp gl2_client_context.cpp gl2_enc.cpp gl2_entry.cpp IOStream2.cpp)
 android_add_library(TARGET GLESv2_enc SHARED LICENSE Apache-2.0 SRC GL2EncoderUtils.cpp GL2Encoder.cpp GLESv2Validation.cpp gl2_client_context.cpp gl2_enc.cpp gl2_entry.cpp IOStream2.cpp)
-target_include_directories(GLESv2_enc PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(GLESv2_enc PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"emuglGLESv2_enc\"")
+target_include_directories(GLESv2_enc PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(GLESv2_enc PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"emuglGLESv2_enc\"")
 target_compile_options(GLESv2_enc PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-unused-private-field")
-target_link_libraries(GLESv2_enc PRIVATE OpenglCodecCommon_host cutils utils log android-emu-shared PRIVATE qemupipe_host)
\ No newline at end of file
+target_link_libraries(GLESv2_enc PRIVATE OpenglCodecCommon_host cutils utils log androidemu android-emu-shared PRIVATE qemupipe_host)
\ No newline at end of file
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index bafd1b6..cca18a9 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -16,6 +16,7 @@
 
 #include "GL2Encoder.h"
 #include "GLESv2Validation.h"
+#include "GLESTextureUtils.h"
 
 #include <string>
 #include <map>
@@ -81,6 +82,7 @@
     m_num_compressedTextureFormats = 0;
     m_max_combinedTextureImageUnits = 0;
     m_max_vertexTextureImageUnits = 0;
+    m_max_array_texture_layers = 0;
     m_max_textureImageUnits = 0;
     m_max_cubeMapTextureSize = 0;
     m_max_renderBufferSize = 0;
@@ -296,6 +298,7 @@
     OVERRIDE(glGenerateMipmap);
 
     OVERRIDE(glBindSampler);
+    OVERRIDE(glDeleteSamplers);
 
     OVERRIDE_CUSTOM(glFenceSync);
     OVERRIDE_CUSTOM(glClientWaitSync);
@@ -375,6 +378,81 @@
 
     OVERRIDE(glInvalidateFramebuffer);
     OVERRIDE(glInvalidateSubFramebuffer);
+
+    OVERRIDE(glDispatchCompute);
+    OVERRIDE(glDispatchComputeIndirect);
+
+    OVERRIDE(glGenTransformFeedbacks);
+    OVERRIDE(glDeleteTransformFeedbacks);
+    OVERRIDE(glGenSamplers);
+    OVERRIDE(glGenQueries);
+    OVERRIDE(glDeleteQueries);
+
+    OVERRIDE(glBindTransformFeedback);
+    OVERRIDE(glBeginQuery);
+    OVERRIDE(glEndQuery);
+
+    OVERRIDE(glClear);
+    OVERRIDE(glClearBufferfi);
+    OVERRIDE(glCopyTexSubImage2D);
+    OVERRIDE(glCopyTexSubImage3D);
+    OVERRIDE(glCompileShader);
+    OVERRIDE(glValidateProgram);
+    OVERRIDE(glProgramBinary);
+
+    OVERRIDE(glGetSamplerParameterfv);
+    OVERRIDE(glGetSamplerParameteriv);
+    OVERRIDE(glSamplerParameterf);
+    OVERRIDE(glSamplerParameteri);
+    OVERRIDE(glSamplerParameterfv);
+    OVERRIDE(glSamplerParameteriv);
+
+    OVERRIDE(glGetAttribLocation);
+
+    OVERRIDE(glBindAttribLocation);
+    OVERRIDE(glUniformBlockBinding);
+    OVERRIDE(glGetTransformFeedbackVarying);
+    OVERRIDE(glScissor);
+    OVERRIDE(glDepthFunc);
+    OVERRIDE(glViewport);
+    OVERRIDE(glStencilFunc);
+    OVERRIDE(glStencilFuncSeparate);
+    OVERRIDE(glStencilOp);
+    OVERRIDE(glStencilOpSeparate);
+    OVERRIDE(glStencilMaskSeparate);
+    OVERRIDE(glBlendEquation);
+    OVERRIDE(glBlendEquationSeparate);
+    OVERRIDE(glBlendFunc);
+    OVERRIDE(glBlendFuncSeparate);
+    OVERRIDE(glCullFace);
+    OVERRIDE(glFrontFace);
+    OVERRIDE(glLineWidth);
+    OVERRIDE(glVertexAttrib1f);
+    OVERRIDE(glVertexAttrib2f);
+    OVERRIDE(glVertexAttrib3f);
+    OVERRIDE(glVertexAttrib4f);
+    OVERRIDE(glVertexAttrib1fv);
+    OVERRIDE(glVertexAttrib2fv);
+    OVERRIDE(glVertexAttrib3fv);
+    OVERRIDE(glVertexAttrib4fv);
+    OVERRIDE(glVertexAttribI4i);
+    OVERRIDE(glVertexAttribI4ui);
+    OVERRIDE(glVertexAttribI4iv);
+    OVERRIDE(glVertexAttribI4uiv);
+
+    OVERRIDE(glGetShaderPrecisionFormat);
+    OVERRIDE(glGetProgramiv);
+    OVERRIDE(glGetActiveUniform);
+    OVERRIDE(glGetActiveUniformsiv);
+    OVERRIDE(glGetActiveUniformBlockName);
+    OVERRIDE(glGetActiveAttrib);
+    OVERRIDE(glGetRenderbufferParameteriv);
+    OVERRIDE(glGetQueryiv);
+    OVERRIDE(glGetQueryObjectuiv);
+    OVERRIDE(glIsEnabled);
+    OVERRIDE(glHint);
+
+    OVERRIDE(glGetFragDataLocation);
 }
 
 GL2Encoder::~GL2Encoder()
@@ -387,7 +465,9 @@
     GL2Encoder *ctx = (GL2Encoder *)self;
     GLenum err = ctx->getError();
     if(err != GL_NO_ERROR) {
-        ctx->m_glGetError_enc(ctx); // also clear host error
+        if (!ctx->m_noHostError) {
+            ctx->m_glGetError_enc(ctx); // also clear host error
+        }
         ctx->setError(GL_NO_ERROR);
         return err;
     }
@@ -405,6 +485,9 @@
         mCtx(ctx),
         guest_error(ctx->getError()),
         host_error(ctx->m_glGetError_enc(ctx)) {
+            if (ctx->m_noHostError) {
+                host_error = GL_NO_ERROR;
+            }
             // Preserve any existing GL error in the guest:
             // OpenGL ES 3.0.5 spec:
             // The command enum GetError( void ); is used to obtain error information.
@@ -577,6 +660,7 @@
     GLuint bufferId = ctx->m_state->getBuffer(target);
     SET_ERROR_IF(bufferId==0, GL_INVALID_OPERATION);
     SET_ERROR_IF(size<0, GL_INVALID_VALUE);
+    SET_ERROR_IF(!GLESv2Validation::bufferUsage(ctx, usage), GL_INVALID_ENUM);
 
     ctx->m_shared->updateBufferData(bufferId, size, data);
     ctx->m_shared->setBufferUsage(bufferId, usage);
@@ -620,18 +704,8 @@
     }
 }
 
-static bool isValidVertexAttribIndex(void *self, GLuint indx)
-{
-    GL2Encoder *ctx = (GL2Encoder *)self;
-    GLint maxIndex;
-    ctx->glGetIntegerv(self, GL_MAX_VERTEX_ATTRIBS, &maxIndex);
-    return indx < maxIndex;
-}
-
 #define VALIDATE_VERTEX_ATTRIB_INDEX(index) \
-    SET_ERROR_WITH_MESSAGE_IF( \
-            !isValidVertexAttribIndex(self, index), GL_INVALID_VALUE, \
-            GLESv2Validation::vertexAttribIndexRangeErrorMsg, (ctx, index)); \
+    SET_ERROR_IF(index >= CODEC_MAX_VERTEX_ATTRIBUTES, GL_INVALID_VALUE); \
 
 void GL2Encoder::s_glVertexAttribPointer(void *self, GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * ptr)
 {
@@ -719,6 +793,14 @@
             ctx->m_max_vertexTextureImageUnits = *ptr;
         }
         break;
+    case GL_MAX_ARRAY_TEXTURE_LAYERS:
+        if (ctx->m_max_array_texture_layers != 0) {
+            *ptr = ctx->m_max_array_texture_layers;
+        } else {
+            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_max_array_texture_layers = *ptr;
+        }
+        break;
     case GL_MAX_TEXTURE_IMAGE_UNITS:
         if (ctx->m_max_textureImageUnits != 0) {
             *ptr = ctx->m_max_textureImageUnits;
@@ -738,10 +820,7 @@
 
     case GL_MAX_VERTEX_ATTRIBS:
         SET_ERROR_IF(!state, GL_INVALID_OPERATION);
-        if (!state->getClientStateParameter<GLint>(param, ptr)) {
-            ctx->safe_glGetIntegerv(param, ptr);
-            state->setMaxVertexAttribs(*ptr);
-        }
+        *ptr = CODEC_MAX_VERTEX_ATTRIBUTES;
         break;
     case GL_MAX_VERTEX_ATTRIB_STRIDE:
         if (ctx->m_max_vertexAttribStride != 0) {
@@ -773,6 +852,13 @@
         } else {
             ctx->safe_glGetIntegerv(param, ptr);
             ctx->m_max_textureSize = *ptr;
+            if (ctx->m_max_textureSize > 0) {
+                uint32_t current = 1;
+                while (current < ctx->m_max_textureSize) {
+                    ++ctx->m_log2MaxTextureSize;
+                    current = current << 1;
+                }
+            }
         }
         break;
     case GL_MAX_3D_TEXTURE_SIZE:
@@ -1046,10 +1132,8 @@
 void GL2Encoder::s_glGetVertexAttribiv(void *self, GLuint index, GLenum pname, GLint *params)
 {
     GL2Encoder *ctx = (GL2Encoder *)self;
-    assert(ctx->m_state);
-    GLint maxIndex;
-    ctx->glGetIntegerv(self, GL_MAX_VERTEX_ATTRIBS, &maxIndex);
-    SET_ERROR_IF(!(index < maxIndex), GL_INVALID_VALUE);
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    SET_ERROR_IF(!GLESv2Validation::allowedGetVertexAttrib(pname), GL_INVALID_ENUM);
 
     if (!ctx->m_state->getVertexAttribParameter<GLint>(index, pname, params)) {
         ctx->m_glGetVertexAttribiv_enc(self, index, pname, params);
@@ -1059,10 +1143,8 @@
 void GL2Encoder::s_glGetVertexAttribfv(void *self, GLuint index, GLenum pname, GLfloat *params)
 {
     GL2Encoder *ctx = (GL2Encoder *)self;
-    assert(ctx->m_state);
-    GLint maxIndex;
-    ctx->glGetIntegerv(self, GL_MAX_VERTEX_ATTRIBS, &maxIndex);
-    SET_ERROR_IF(!(index < maxIndex), GL_INVALID_VALUE);
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    SET_ERROR_IF(!GLESv2Validation::allowedGetVertexAttrib(pname), GL_INVALID_ENUM);
 
     if (!ctx->m_state->getVertexAttribParameter<GLfloat>(index, pname, params)) {
         ctx->m_glGetVertexAttribfv_enc(self, index, pname, params);
@@ -1073,9 +1155,7 @@
 {
     GL2Encoder *ctx = (GL2Encoder *)self;
     if (ctx->m_state == NULL) return;
-    GLint maxIndex;
-    ctx->glGetIntegerv(self, GL_MAX_VERTEX_ATTRIBS, &maxIndex);
-    SET_ERROR_IF(!(index < maxIndex), GL_INVALID_VALUE);
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
     SET_ERROR_IF(pname != GL_VERTEX_ATTRIB_ARRAY_POINTER, GL_INVALID_ENUM);
     (void)pname;
 
@@ -1239,20 +1319,24 @@
                 }
                 if (state.elementSize == 0) {
                     // The vertex attribute array is uninitialized. Abandon it.
-                    ALOGE("a vertex attribute array is uninitialized. Skipping corresponding vertex attribute.");
                     this->m_glDisableVertexAttribArray_enc(this, i);
                     continue;
                 }
                 m_glEnableVertexAttribArray_enc(this, i);
 
                 if (datalen && (!offset || !((unsigned char*)offset + firstIndex))) {
-                    ALOGD("%s: bad offset / len!!!!!", __FUNCTION__);
                     continue;
                 }
+
+                unsigned char* data = (unsigned char*)offset + firstIndex;
+                if (!m_state->isAttribIndexUsedByProgram(i)) {
+                    continue;
+                }
+
                 if (state.isInt) {
-                    this->glVertexAttribIPointerDataAEMU(this, i, state.size, state.type, stride, (unsigned char *)offset + firstIndex, datalen);
+                    this->glVertexAttribIPointerDataAEMU(this, i, state.size, state.type, stride, data, datalen);
                 } else {
-                    this->glVertexAttribPointerData(this, i, state.size, state.type, state.normalized, stride, (unsigned char *)offset + firstIndex, datalen);
+                    this->glVertexAttribPointerData(this, i, state.size, state.type, state.normalized, stride, data, datalen);
                 }
             } else {
                 const BufferData* buf = m_shared->getBufferData(bufferObject);
@@ -1267,20 +1351,24 @@
                 if (buf && firstIndex >= 0 && firstIndex + bufLen <= buf->m_size) {
                     if (hasClientArrays) {
                         m_glEnableVertexAttribArray_enc(this, i);
-                        if (state.isInt) {
-                            this->glVertexAttribIPointerOffsetAEMU(this, i, state.size, state.type, stride, offset + firstIndex);
-                        } else {
-                            this->glVertexAttribPointerOffset(this, i, state.size, state.type, state.normalized, stride, offset + firstIndex);
+                        if (firstIndex) {
+                            if (state.isInt) {
+                                this->glVertexAttribIPointerOffsetAEMU(this, i, state.size, state.type, stride, offset + firstIndex);
+                            } else {
+                                this->glVertexAttribPointerOffset(this, i, state.size, state.type, state.normalized, stride, offset + firstIndex);
+                            }
                         }
                     }
                 } else {
-                    ALOGE("a vertex attribute index out of boundary is detected. Skipping corresponding vertex attribute. buf=%p", buf);
-                    if (buf) {
-                        ALOGE("Out of bounds vertex attribute info: "
-                                "clientArray? %d attribute %d vbo %u allocedBufferSize %u bufferDataSpecified? %d wantedStart %u wantedEnd %u",
-                                hasClientArrays, i, bufferObject, (unsigned int)buf->m_size, buf != NULL, firstIndex, firstIndex + bufLen);
+                    if (m_state->isAttribIndexUsedByProgram(i)) {
+                        ALOGE("a vertex attribute index out of boundary is detected. Skipping corresponding vertex attribute. buf=%p", buf);
+                        if (buf) {
+                            ALOGE("Out of bounds vertex attribute info: "
+                                    "clientArray? %d attribute %d vbo %u allocedBufferSize %u bufferDataSpecified? %d wantedStart %u wantedEnd %u",
+                                    hasClientArrays, i, bufferObject, (unsigned int)buf->m_size, buf != NULL, firstIndex, firstIndex + bufLen);
+                        }
+                        m_glDisableVertexAttribArray_enc(this, i);
                     }
-                    m_glDisableVertexAttribArray_enc(this, i);
                 }
             }
         } else {
@@ -1324,6 +1412,7 @@
     assert(ctx->m_state != NULL);
     SET_ERROR_IF(!isValidDrawMode(mode), GL_INVALID_ENUM);
     SET_ERROR_IF(count < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     bool has_client_vertex_arrays = false;
     bool has_indirect_arrays = false;
@@ -1338,6 +1427,8 @@
     } else {
         ctx->m_glDrawArrays_enc(ctx, mode, first, count);
     }
+
+    ctx->m_state->postDraw();
 }
 
 
@@ -1350,6 +1441,7 @@
     SET_ERROR_IF(count < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(!(type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT), GL_INVALID_ENUM);
     SET_ERROR_IF(ctx->m_state->getTransformFeedbackActiveUnpaused(), GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     bool has_client_vertex_arrays = false;
     bool has_indirect_arrays = false;
@@ -1428,6 +1520,8 @@
             ALOGE("glDrawElements: direct index & direct buffer data - will be implemented in later versions;\n");
         }
     }
+
+    ctx->m_state->postDraw();
 }
 
 void GL2Encoder::s_glDrawArraysNullAEMU(void *self, GLenum mode, GLint first, GLsizei count)
@@ -1436,6 +1530,7 @@
     assert(ctx->m_state != NULL);
     SET_ERROR_IF(!isValidDrawMode(mode), GL_INVALID_ENUM);
     SET_ERROR_IF(count < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     bool has_client_vertex_arrays = false;
     bool has_indirect_arrays = false;
@@ -1451,6 +1546,7 @@
         ctx->m_glDrawArraysNullAEMU_enc(ctx, mode, first, count);
     }
     ctx->flushDrawCall();
+    ctx->m_state->postDraw();
 }
 
 void GL2Encoder::s_glDrawElementsNullAEMU(void *self, GLenum mode, GLsizei count, GLenum type, const void *indices)
@@ -1462,6 +1558,7 @@
     SET_ERROR_IF(count < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(!(type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT), GL_INVALID_ENUM);
     SET_ERROR_IF(ctx->m_state->getTransformFeedbackActiveUnpaused(), GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     bool has_client_vertex_arrays = false;
     bool has_indirect_arrays = false;
@@ -1544,6 +1641,7 @@
             ALOGE("glDrawElementsNullAEMU: direct index & direct buffer data - will be implemented in later versions;\n");
         }
     }
+    ctx->m_state->postDraw();
 }
 
 GLint * GL2Encoder::getCompressedTextureFormats()
@@ -1795,41 +1893,96 @@
     SET_ERROR_IF(!isProgram && !ctx->m_shared->isShader(program), GL_INVALID_VALUE);
     SET_ERROR_IF(!isProgram, GL_INVALID_OPERATION);
 
+    if (program == ctx->m_state->currentProgram() ||
+        (!ctx->m_state->currentProgram() &&
+         (program == ctx->m_state->currentShaderProgram()))) {
+        SET_ERROR_IF(ctx->m_state->getTransformFeedbackActive(), GL_INVALID_OPERATION);
+    }
+
     ctx->m_glLinkProgram_enc(self, program);
 
     GLint linkStatus = 0;
-    ctx->glGetProgramiv(self, program, GL_LINK_STATUS, &linkStatus);
+    ctx->m_glGetProgramiv_enc(self, program, GL_LINK_STATUS, &linkStatus);
+    ctx->m_shared->setProgramLinkStatus(program, linkStatus);
     if (!linkStatus) {
         return;
     }
 
-    //get number of active uniforms in the program
+    // get number of active uniforms and attributes in the program
     GLint numUniforms=0;
-    ctx->glGetProgramiv(self, program, GL_ACTIVE_UNIFORMS, &numUniforms);
-    ctx->m_shared->initProgramData(program,numUniforms);
+    GLint numAttributes=0;
+    ctx->m_glGetProgramiv_enc(self, program, GL_ACTIVE_UNIFORMS, &numUniforms);
+    ctx->m_glGetProgramiv_enc(self, program, GL_ACTIVE_ATTRIBUTES, &numAttributes);
+    ctx->m_shared->initProgramData(program,numUniforms,numAttributes);
 
     //get the length of the longest uniform name
     GLint maxLength=0;
-    ctx->glGetProgramiv(self, program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
+    GLint maxAttribLength=0;
+    ctx->m_glGetProgramiv_enc(self, program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
+    ctx->m_glGetProgramiv_enc(self, program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttribLength);
 
     GLint size;
     GLenum type;
-    GLchar *name = new GLchar[maxLength+1];
+    size_t bufLen = maxLength > maxAttribLength ? maxLength : maxAttribLength;
+    GLchar *name = new GLchar[bufLen + 1];
     GLint location;
     //for each active uniform, get its size and starting location.
     for (GLint i=0 ; i<numUniforms ; ++i)
     {
-        ctx->glGetActiveUniform(self, program, i, maxLength, NULL, &size, &type, name);
+        ctx->m_glGetActiveUniform_enc(self, program, i, maxLength, NULL, &size, &type, name);
         location = ctx->m_glGetUniformLocation_enc(self, program, name);
         ctx->m_shared->setProgramIndexInfo(program, i, location, size, type, name);
     }
 
+    for (GLint i = 0; i < numAttributes; ++i) {
+        ctx->m_glGetActiveAttrib_enc(self, program, i, maxAttribLength,  NULL, &size, &type, name);
+        location = ctx->m_glGetAttribLocation_enc(self, program, name);
+        ctx->m_shared->setProgramAttribInfo(program, i, location, size, type, name);
+    }
+
+    if (ctx->majorVersion() > 2) {
+        GLint numBlocks;
+        ctx->m_glGetProgramiv_enc(ctx, program, GL_ACTIVE_UNIFORM_BLOCKS, &numBlocks);
+        ctx->m_shared->setActiveUniformBlockCountForProgram(program, numBlocks);
+
+        GLint tfVaryingsCount;
+        ctx->m_glGetProgramiv_enc(ctx, program, GL_TRANSFORM_FEEDBACK_VARYINGS, &tfVaryingsCount);
+        ctx->m_shared->setTransformFeedbackVaryingsCountForProgram(program, tfVaryingsCount);
+    }
+
     delete[] name;
 }
 
+#define VALIDATE_PROGRAM_NAME(program) \
+    bool isShaderOrProgramObject = \
+        ctx->m_shared->isShaderOrProgramObject(program); \
+    bool isProgram = \
+        ctx->m_shared->isProgram(program); \
+    SET_ERROR_IF(!isShaderOrProgramObject, GL_INVALID_VALUE); \
+    SET_ERROR_IF(!isProgram, GL_INVALID_OPERATION); \
+
+#define VALIDATE_PROGRAM_NAME_RET(program, ret) \
+    bool isShaderOrProgramObject = \
+        ctx->m_shared->isShaderOrProgramObject(program); \
+    bool isProgram = \
+        ctx->m_shared->isProgram(program); \
+    RET_AND_SET_ERROR_IF(!isShaderOrProgramObject, GL_INVALID_VALUE, ret); \
+    RET_AND_SET_ERROR_IF(!isProgram, GL_INVALID_OPERATION, ret); \
+
+#define VALIDATE_SHADER_NAME(shader) \
+    bool isShaderOrProgramObject = \
+        ctx->m_shared->isShaderOrProgramObject(shader); \
+    bool isShader = \
+        ctx->m_shared->isShader(shader); \
+    SET_ERROR_IF(!isShaderOrProgramObject, GL_INVALID_VALUE); \
+    SET_ERROR_IF(!isShader, GL_INVALID_OPERATION); \
+
 void GL2Encoder::s_glDeleteProgram(void *self, GLuint program)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
+
+    VALIDATE_PROGRAM_NAME(program);
+
     ctx->m_glDeleteProgram_enc(self, program);
 
     ctx->m_shared->deleteProgramData(program);
@@ -1841,9 +1994,9 @@
     SET_ERROR_IF(!ctx->m_shared->isShaderOrProgramObject(program), GL_INVALID_VALUE);
     SET_ERROR_IF(!ctx->m_shared->isProgram(program), GL_INVALID_OPERATION);
     SET_ERROR_IF(!ctx->m_shared->isProgramInitialized(program), GL_INVALID_OPERATION);
-    GLint hostLoc = location;
-    SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,hostLoc)==0, GL_INVALID_OPERATION);
-    ctx->m_glGetUniformiv_enc(self, program, hostLoc, params);
+    SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,location)==0, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!ctx->m_shared->isProgramUniformLocationValid(program,location), GL_INVALID_OPERATION);
+    ctx->m_glGetUniformiv_enc(self, program, location, params);
 }
 void GL2Encoder::s_glGetUniformfv(void *self, GLuint program, GLint location, GLfloat* params)
 {
@@ -1851,9 +2004,9 @@
     SET_ERROR_IF(!ctx->m_shared->isShaderOrProgramObject(program), GL_INVALID_VALUE);
     SET_ERROR_IF(!ctx->m_shared->isProgram(program), GL_INVALID_OPERATION);
     SET_ERROR_IF(!ctx->m_shared->isProgramInitialized(program), GL_INVALID_OPERATION);
-    GLint hostLoc = location;
-    SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,hostLoc)==0, GL_INVALID_OPERATION);
-    ctx->m_glGetUniformfv_enc(self, program, hostLoc, params);
+    SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,location)==0, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!ctx->m_shared->isProgramUniformLocationValid(program,location), GL_INVALID_OPERATION);
+    ctx->m_glGetUniformfv_enc(self, program, location, params);
 }
 
 GLuint GL2Encoder::s_glCreateProgram(void * self)
@@ -1871,7 +2024,7 @@
     RET_AND_SET_ERROR_IF(!GLESv2Validation::shaderType(ctx, shaderType), GL_INVALID_ENUM, 0);
     GLuint shader = ctx->m_glCreateShader_enc(self, shaderType);
     if (shader != 0) {
-        if (!ctx->m_shared->addShaderData(shader)) {
+        if (!ctx->m_shared->addShaderData(shader, shaderType)) {
             ctx->m_glDeleteShader_enc(self, shader);
             return 0;
         }
@@ -1883,6 +2036,7 @@
         GLsizei* count, GLuint* shaders)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
+    VALIDATE_PROGRAM_NAME(program);
     SET_ERROR_IF(maxCount < 0, GL_INVALID_VALUE);
     ctx->m_glGetAttachedShaders_enc(self, program, maxCount, count, shaders);
 }
@@ -1891,6 +2045,7 @@
             GLsizei* length, GLchar* source)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
+    VALIDATE_SHADER_NAME(shader);
     SET_ERROR_IF(bufsize < 0, GL_INVALID_VALUE);
     ctx->m_glGetShaderSource_enc(self, shader, bufsize, length, source);
     ShaderData* shaderData = ctx->m_shared->getShaderData(shader);
@@ -1916,6 +2071,7 @@
         GLsizei* length, GLchar* infolog)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
+    VALIDATE_SHADER_NAME(shader);
     SET_ERROR_IF(bufsize < 0, GL_INVALID_VALUE);
     ctx->m_glGetShaderInfoLog_enc(self, shader, bufsize, length, infolog);
 }
@@ -1924,6 +2080,7 @@
         GLsizei* length, GLchar* infolog)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
+    VALIDATE_PROGRAM_NAME(program);
     SET_ERROR_IF(bufsize < 0, GL_INVALID_VALUE);
     ctx->m_glGetProgramInfoLog_enc(self, program, bufsize, length, infolog);
 }
@@ -1931,6 +2088,15 @@
 void GL2Encoder::s_glDeleteShader(void *self, GLenum shader)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
+
+    bool isShaderOrProgramObject =
+        ctx->m_shared->isShaderOrProgramObject(shader);
+    bool isShader =
+        ctx->m_shared->isShader(shader);
+
+    SET_ERROR_IF(isShaderOrProgramObject && !isShader, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!isShaderOrProgramObject && !isShader, GL_INVALID_VALUE);
+
     ctx->m_glDeleteShader_enc(self,shader);
     ctx->m_shared->unrefShaderData(shader);
 }
@@ -1938,15 +2104,36 @@
 void GL2Encoder::s_glAttachShader(void *self, GLuint program, GLuint shader)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
+    bool programIsShaderOrProgram = ctx->m_shared->isShaderOrProgramObject(program);
+    bool programIsProgram = ctx->m_shared->isProgram(program);
+    bool shaderIsShaderOrProgram = ctx->m_shared->isShaderOrProgramObject(shader);
+    bool shaderIsShader = ctx->m_shared->isShader(shader);
+
+    SET_ERROR_IF(!programIsShaderOrProgram, GL_INVALID_VALUE);
+    SET_ERROR_IF(!shaderIsShaderOrProgram, GL_INVALID_VALUE);
+    SET_ERROR_IF(!programIsProgram, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!shaderIsShader, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!ctx->m_shared->attachShader(program, shader), GL_INVALID_OPERATION);
+
     ctx->m_glAttachShader_enc(self, program, shader);
-    ctx->m_shared->attachShader(program, shader);
 }
 
 void GL2Encoder::s_glDetachShader(void *self, GLuint program, GLuint shader)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
+
+    bool programIsShaderOrProgram = ctx->m_shared->isShaderOrProgramObject(program);
+    bool programIsProgram = ctx->m_shared->isProgram(program);
+    bool shaderIsShaderOrProgram = ctx->m_shared->isShaderOrProgramObject(shader);
+    bool shaderIsShader = ctx->m_shared->isShader(shader);
+
+    SET_ERROR_IF(!programIsShaderOrProgram, GL_INVALID_VALUE);
+    SET_ERROR_IF(!shaderIsShaderOrProgram, GL_INVALID_VALUE);
+    SET_ERROR_IF(!programIsProgram, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!shaderIsShader, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!ctx->m_shared->detachShader(program, shader), GL_INVALID_OPERATION);
+
     ctx->m_glDetachShader_enc(self, program, shader);
-    ctx->m_shared->detachShader(program, shader);
 }
 
 int sArrIndexOfUniformExpr(const char* name, int* err) {
@@ -1966,6 +2153,16 @@
 {
     if (!name) return -1;
     GL2Encoder *ctx = (GL2Encoder*)self;
+
+    bool isShaderOrProgramObject =
+        ctx->m_shared->isShaderOrProgramObject(program);
+    bool isProgram =
+        ctx->m_shared->isProgram(program);
+
+    RET_AND_SET_ERROR_IF(!isShaderOrProgramObject, GL_INVALID_VALUE, -1);
+    RET_AND_SET_ERROR_IF(!isProgram, GL_INVALID_OPERATION, -1);
+    RET_AND_SET_ERROR_IF(!ctx->m_shared->getProgramLinkStatus(program), GL_INVALID_OPERATION, -1);
+
     return ctx->m_glGetUniformLocation_enc(self, program, name);
 }
 
@@ -2026,26 +2223,35 @@
 
     SET_ERROR_IF(program && !shared->isShaderOrProgramObject(program), GL_INVALID_VALUE);
     SET_ERROR_IF(program && !shared->isProgram(program), GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->m_state->getTransformFeedbackActiveUnpaused(), GL_INVALID_OPERATION);
 
     ctx->m_glUseProgram_enc(self, program);
+
+    GLuint currProgram = ctx->m_state->currentProgram();
+    ctx->m_shared->onUseProgram(currProgram, program);
+
     ctx->m_state->setCurrentProgram(program);
     ctx->m_state->setCurrentShaderProgram(program);
-
     ctx->updateHostTexture2DBindingsFromProgramData(program);
+
+    if (program) {
+        ctx->m_state->currentUniformValidationInfo = ctx->m_shared->getUniformValidationInfo(program);
+        ctx->m_state->currentAttribValidationInfo = ctx->m_shared->getAttribValidationInfo(program);
+    }
 }
 
 void GL2Encoder::s_glUniform1f(void *self , GLint location, GLfloat x)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform1f_enc(self, hostLoc, x);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 1 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform1f_enc(self, location, x);
 }
 
 void GL2Encoder::s_glUniform1fv(void *self , GLint location, GLsizei count, const GLfloat* v)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform1fv_enc(self, hostLoc, count, v);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 1 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform1fv_enc(self, location, count, v);
 }
 
 void GL2Encoder::s_glUniform1i(void *self , GLint location, GLint x)
@@ -2054,8 +2260,9 @@
     GLClientState* state = ctx->m_state;
     GLSharedGroupPtr shared = ctx->m_shared;
 
-    GLint hostLoc = location;
-    ctx->m_glUniform1i_enc(self, hostLoc, x);
+    ctx->m_state->validateUniform(false /* is float? */, false /* is unsigned? */, 1 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+
+    ctx->m_glUniform1i_enc(self, location, x);
 
     GLenum target;
     if (shared->setSamplerUniform(state->currentShaderProgram(), location, x, &target)) {
@@ -2070,113 +2277,113 @@
 void GL2Encoder::s_glUniform1iv(void *self , GLint location, GLsizei count, const GLint* v)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform1iv_enc(self, hostLoc, count, v);
+    ctx->m_state->validateUniform(false /* is float? */, false /* is unsigned? */, 1 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform1iv_enc(self, location, count, v);
 }
 
 void GL2Encoder::s_glUniform2f(void *self , GLint location, GLfloat x, GLfloat y)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform2f_enc(self, hostLoc, x, y);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 2 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform2f_enc(self, location, x, y);
 }
 
 void GL2Encoder::s_glUniform2fv(void *self , GLint location, GLsizei count, const GLfloat* v)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform2fv_enc(self, hostLoc, count, v);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 2 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform2fv_enc(self, location, count, v);
 }
 
 void GL2Encoder::s_glUniform2i(void *self , GLint location, GLint x, GLint y)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform2i_enc(self, hostLoc, x, y);
+    ctx->m_state->validateUniform(false /* is float? */, false /* is unsigned? */, 2 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform2i_enc(self, location, x, y);
 }
 
 void GL2Encoder::s_glUniform2iv(void *self , GLint location, GLsizei count, const GLint* v)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform2iv_enc(self, hostLoc, count, v);
+    ctx->m_state->validateUniform(false /* is float? */, false /* is unsigned? */, 2 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform2iv_enc(self, location, count, v);
 }
 
 void GL2Encoder::s_glUniform3f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform3f_enc(self, hostLoc, x, y, z);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 3 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform3f_enc(self, location, x, y, z);
 }
 
 void GL2Encoder::s_glUniform3fv(void *self , GLint location, GLsizei count, const GLfloat* v)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform3fv_enc(self, hostLoc, count, v);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 3 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform3fv_enc(self, location, count, v);
 }
 
 void GL2Encoder::s_glUniform3i(void *self , GLint location, GLint x, GLint y, GLint z)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform3i_enc(self, hostLoc, x, y, z);
+    ctx->m_state->validateUniform(false /* is float? */, false /* is unsigned? */, 3 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform3i_enc(self, location, x, y, z);
 }
 
 void GL2Encoder::s_glUniform3iv(void *self , GLint location, GLsizei count, const GLint* v)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform3iv_enc(self, hostLoc, count, v);
+    ctx->m_state->validateUniform(false /* is float? */, false /* is unsigned? */, 3 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform3iv_enc(self, location, count, v);
 }
 
 void GL2Encoder::s_glUniform4f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform4f_enc(self, hostLoc, x, y, z, w);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 4 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform4f_enc(self, location, x, y, z, w);
 }
 
 void GL2Encoder::s_glUniform4fv(void *self , GLint location, GLsizei count, const GLfloat* v)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform4fv_enc(self, hostLoc, count, v);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 4 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform4fv_enc(self, location, count, v);
 }
 
 void GL2Encoder::s_glUniform4i(void *self , GLint location, GLint x, GLint y, GLint z, GLint w)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform4i_enc(self, hostLoc, x, y, z, w);
+    ctx->m_state->validateUniform(false /* is float? */, false /* is unsigned? */, 4 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform4i_enc(self, location, x, y, z, w);
 }
 
 void GL2Encoder::s_glUniform4iv(void *self , GLint location, GLsizei count, const GLint* v)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform4iv_enc(self, hostLoc, count, v);
+    ctx->m_state->validateUniform(false /* is float? */, false /* is unsigned? */, 4 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform4iv_enc(self, location, count, v);
 }
 
 void GL2Encoder::s_glUniformMatrix2fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix2fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 2 /* columns */, 2 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix2fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glUniformMatrix3fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix3fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 3 /* columns */, 3 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix3fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glUniformMatrix4fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix4fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 4 /* columns */, 4 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix4fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glActiveTexture(void* self, GLenum texture)
@@ -2185,6 +2392,10 @@
     GLClientState* state = ctx->m_state;
     GLenum err;
 
+    GLint maxCombinedUnits;
+    ctx->glGetIntegerv(ctx, GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxCombinedUnits);
+
+    SET_ERROR_IF(texture - GL_TEXTURE0 > maxCombinedUnits - 1, GL_INVALID_ENUM);
     SET_ERROR_IF((err = state->setActiveTextureUnit(texture)) != GL_NO_ERROR, err);
 
     ctx->m_glActiveTexture_enc(ctx, texture);
@@ -2241,6 +2452,10 @@
 {
     GL2Encoder* ctx = (GL2Encoder*)self;
 
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParams(ctx, pname), GL_INVALID_ENUM);
+    if (!params) return;
+
     if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
         ctx->override2DTextureTarget(target);
         ctx->m_glGetTexParameterfv_enc(ctx, GL_TEXTURE_2D, pname, params);
@@ -2255,6 +2470,11 @@
 {
     GL2Encoder* ctx = (GL2Encoder*)self;
 
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParams(ctx, pname), GL_INVALID_ENUM);
+
+    if (!params) return;
+
     switch (pname) {
     case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
         *params = 1;
@@ -2296,6 +2516,9 @@
     SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES &&
             !isValidTextureExternalParam(pname, (GLenum)param)),
             GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParams(ctx, pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParamValue(ctx, pname, (GLint)param, param, (GLenum)param), GL_INVALID_ENUM);
 
     if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
         ctx->override2DTextureTarget(target);
@@ -2314,6 +2537,11 @@
     SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES &&
             !isValidTextureExternalParam(pname, (GLenum)params[0])),
             GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParams(ctx, pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!params, GL_INVALID_VALUE);
+    GLfloat param = *params;
+    SET_ERROR_IF(!GLESv2Validation::textureParamValue(ctx, pname, (GLint)param, param, (GLenum)param), GL_INVALID_ENUM);
 
     if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
         ctx->override2DTextureTarget(target);
@@ -2332,6 +2560,9 @@
     SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES &&
             !isValidTextureExternalParam(pname, (GLenum)param)),
             GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParams(ctx, pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParamValue(ctx, pname, param, (GLfloat)param, (GLenum)param), GL_INVALID_ENUM);
 
     if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
         ctx->override2DTextureTarget(target);
@@ -2359,6 +2590,8 @@
     SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::pixelType(ctx, type), GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::pixelFormat(ctx, format), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::pixelFormat(ctx, internalformat) && !GLESv2Validation::pixelInternalFormat(internalformat), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::pixelSizedFormat(ctx, internalformat, format, type), GL_INVALID_OPERATION);
     // If unpack buffer is nonzero, verify unmapped state.
     SET_ERROR_IF(ctx->isBufferTargetMapped(GL_PIXEL_UNPACK_BUFFER), GL_INVALID_OPERATION);
 
@@ -2375,6 +2608,7 @@
     SET_ERROR_IF(height > max_texture_size, GL_INVALID_VALUE);
     SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(target) && width > max_cube_map_texture_size, GL_INVALID_VALUE);
     SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(target) && height > max_cube_map_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(target) && (width != height), GL_INVALID_VALUE);
     SET_ERROR_IF(border != 0, GL_INVALID_VALUE);
     // If unpack buffer is nonzero, verify buffer data fits and is evenly divisible by the type.
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
@@ -2405,7 +2639,8 @@
     state->setBoundTextureInternalFormat(stateTarget, internalformat);
     state->setBoundTextureFormat(stateTarget, format);
     state->setBoundTextureType(stateTarget, type);
-    state->setBoundTextureDims(stateTarget, level, width, height, 1);
+    state->setBoundTextureDims(stateTarget, target, level, width, height, 1);
+    state->addTextureCubeMapImage(stateTarget, target);
 
     if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
         ctx->override2DTextureTarget(target);
@@ -2466,14 +2701,15 @@
     }
 
     // If unpack buffer is nonzero, verify buffer data fits and is evenly divisible by the type.
+
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
                  ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER) &&
-                 (state->pboNeededDataSize(width, height, 1, format, type, 0) >
+                 (state->pboNeededDataSize(width, height, 1, format, type, 0) + (uintptr_t)pixels >
                   ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER)->m_size),
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
                  ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER) &&
-                 (ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER)->m_size %
+                 ((uintptr_t)pixels %
                   glSizeof(type)),
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(!ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) && !pixels, GL_INVALID_OPERATION);
@@ -2504,6 +2740,35 @@
     GL2Encoder* ctx = (GL2Encoder*)self;
     GLClientState* state = ctx->m_state;
 
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::pixelFormat(ctx, internalformat) && !GLESv2Validation::pixelInternalFormat(internalformat), GL_INVALID_ENUM);
+    GLint max_texture_size;
+    GLint max_cube_map_texture_size;
+    ctx->glGetIntegerv(ctx, GL_MAX_TEXTURE_SIZE, &max_texture_size);
+    ctx->glGetIntegerv(ctx, GL_MAX_CUBE_MAP_TEXTURE_SIZE, &max_cube_map_texture_size);
+    SET_ERROR_IF(level < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(level > ilog2(max_texture_size), GL_INVALID_VALUE);
+    SET_ERROR_IF((target == GL_TEXTURE_CUBE_MAP) &&
+                 (level > ilog2(max_cube_map_texture_size)), GL_INVALID_VALUE);
+    SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(width > max_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(height > max_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(target) && width > max_cube_map_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(target) && height > max_cube_map_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(target) && (width != height), GL_INVALID_VALUE);
+    SET_ERROR_IF(border != 0, GL_INVALID_VALUE);
+
+    GLenum stateTarget = target;
+    if (target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
+        target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
+        target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
+        stateTarget = GL_TEXTURE_CUBE_MAP;
+
+    SET_ERROR_IF(state->isBoundTextureImmutableFormat(target), GL_INVALID_OPERATION);
+
     SET_ERROR_IF(ctx->glCheckFramebufferStatus(ctx, GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE,
                  GL_INVALID_FRAMEBUFFER_OPERATION);
     // This is needed to work around underlying OpenGL drivers
@@ -2514,6 +2779,10 @@
         state->copyTexImageLuminanceCubeMapAMDWorkaround
             (target, level, internalformat);
 
+    state->setBoundTextureInternalFormat(stateTarget, internalformat);
+    state->setBoundTextureDims(stateTarget, target, level, width, height, 1);
+    state->addTextureCubeMapImage(stateTarget, target);
+
     if (extraTarget) {
         ctx->m_glCopyTexImage2D_enc(ctx, extraTarget, level, internalformat,
                                     x, y, width, height, border);
@@ -2521,9 +2790,6 @@
 
     ctx->m_glCopyTexImage2D_enc(ctx, target, level, internalformat,
                                 x, y, width, height, border);
-
-    state->setBoundTextureInternalFormat(target, internalformat);
-    state->setBoundTextureDims(target, level, width, height, 1);
 }
 
 void GL2Encoder::s_glTexParameteriv(void* self,
@@ -2534,6 +2800,11 @@
     SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES &&
             !isValidTextureExternalParam(pname, (GLenum)params[0])),
             GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParams(ctx, pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!params, GL_INVALID_VALUE);
+    GLint param = *params;
+    SET_ERROR_IF(!GLESv2Validation::textureParamValue(ctx, pname, param, (GLfloat)param, (GLenum)param), GL_INVALID_ENUM);
 
     if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
         ctx->override2DTextureTarget(target);
@@ -2634,7 +2905,7 @@
     for (int i = 0; i < n; i++) {
         state->detachRbo(renderbuffers[i]);
     }
-    // state->removeRenderbuffers(n, renderbuffers);
+    state->removeRenderbuffers(n, renderbuffers);
 }
 
 void GL2Encoder::s_glBindRenderbuffer(void* self,
@@ -2660,8 +2931,14 @@
         !GLESv2Validation::rboFormat(ctx, internalformat),
         GL_INVALID_ENUM);
 
+    SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
+    GLint max_rb_size;
+    ctx->glGetIntegerv(ctx, GL_MAX_RENDERBUFFER_SIZE, &max_rb_size);
+    SET_ERROR_IF(width > max_rb_size || height > max_rb_size, GL_INVALID_VALUE);
+
     state->setBoundRenderbufferFormat(internalformat);
     state->setBoundRenderbufferSamples(0);
+    state->setBoundRenderbufferDimensions(width, height);
 
     ctx->m_glRenderbufferStorage_enc(self, target, internalformat,
                                      width, height);
@@ -2675,6 +2952,10 @@
 
     SET_ERROR_IF(!GLESv2Validation::framebufferTarget(ctx, target), GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::framebufferAttachment(ctx, attachment), GL_INVALID_ENUM);
+    SET_ERROR_IF(GL_RENDERBUFFER != renderbuffertarget, GL_INVALID_ENUM);
+    SET_ERROR_IF(!state->getBoundFramebuffer(target), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!state->isRenderbufferThatWasBound(renderbuffer), GL_INVALID_OPERATION);
+
     state->attachRbo(target, attachment, renderbuffer);
 
     ctx->m_glFramebufferRenderbuffer_enc(self, target, attachment, renderbuffertarget, renderbuffer);
@@ -2721,8 +3002,21 @@
     GLClientState* state = ctx->m_state;
 
     SET_ERROR_IF(!GLESv2Validation::framebufferTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, textarget), GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::framebufferAttachment(ctx, attachment), GL_INVALID_ENUM);
-    state->attachTextureObject(target, attachment, texture);
+    SET_ERROR_IF(!state->getBoundFramebuffer(target), GL_INVALID_OPERATION);
+    SET_ERROR_IF(texture && !state->isTexture(texture), GL_INVALID_OPERATION);
+    SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(textarget) && !state->isTextureCubeMap(texture), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!GLESv2Validation::isCubeMapTarget(textarget) && state->isTextureCubeMap(texture), GL_INVALID_OPERATION);
+    SET_ERROR_IF((texture && (level < 0)), GL_INVALID_VALUE);
+
+    if (target == GL_TEXTURE_2D) {
+        SET_ERROR_IF(level > ilog2(ctx->m_state->getMaxTextureSize()), GL_INVALID_VALUE);
+    } else {
+        SET_ERROR_IF(level > ilog2(ctx->m_state->getMaxTextureSizeCubeMap()), GL_INVALID_VALUE);
+    }
+
+    state->attachTextureObject(target, attachment, texture, level, 0);
 
     ctx->m_glFramebufferTexture2D_enc(self, target, attachment, textarget, texture, level);
 }
@@ -2733,7 +3027,7 @@
     GL2Encoder* ctx = (GL2Encoder*)self;
     GLClientState* state = ctx->m_state;
 
-    state->attachTextureObject(target, attachment, texture);
+    state->attachTextureObject(target, attachment, texture, level, zoffset);
 
     ctx->m_glFramebufferTexture3DOES_enc(self, target, attachment, textarget, texture, level, zoffset);
 }
@@ -2743,6 +3037,12 @@
     GL2Encoder* ctx = (GL2Encoder*)self;
     const GLClientState* state = ctx->m_state;
     SET_ERROR_IF(!GLESv2Validation::framebufferTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!state->boundFramebuffer(target) &&
+                 attachment != GL_BACK &&
+                 attachment != GL_FRONT &&
+                 attachment != GL_DEPTH &&
+                 attachment != GL_STENCIL,
+                 GL_INVALID_OPERATION);
     SET_ERROR_IF(pname != GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME &&
                  pname != GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE &&
                  !state->attachmentHasObject(target, attachment),
@@ -2755,6 +3055,11 @@
                   FBO_ATTACHMENT_TEXTURE),
                  !state->attachmentHasObject(target, attachment) ?
                  GL_INVALID_OPERATION : GL_INVALID_ENUM);
+    SET_ERROR_IF(
+        (attachment == GL_FRONT ||
+         attachment == GL_BACK) &&
+        (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME),
+        GL_INVALID_ENUM);
     SET_ERROR_IF(attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
                  pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME &&
                  (state->objectOfAttachment(target, GL_DEPTH_ATTACHMENT) !=
@@ -2762,129 +3067,23 @@
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(state->boundFramebuffer(target) &&
                  (attachment == GL_BACK ||
-                  attachment == GL_FRONT),
+                  attachment == GL_FRONT ||
+                  attachment == GL_DEPTH || 
+                  attachment == GL_STENCIL),
                  GL_INVALID_OPERATION);
     ctx->m_glGetFramebufferAttachmentParameteriv_enc(self, target, attachment, pname, params);
 }
 
-bool GL2Encoder::isCompleteFbo(GLenum target, const GLClientState* state,
-                               GLenum attachment) const {
-    FboFormatInfo fbo_format_info;
-    state->getBoundFramebufferFormat(target, attachment, &fbo_format_info);
-
-    bool res;
-    switch (fbo_format_info.type) {
-    case FBO_ATTACHMENT_RENDERBUFFER:
-        switch (fbo_format_info.rb_format) {
-        case GL_R16F:
-        case GL_RG16F:
-        case GL_RGBA16F:
-        case GL_R32F:
-        case GL_RG32F:
-        case GL_RGBA32F:
-        case GL_R11F_G11F_B10F:
-            res = majorVersion() >= 3 && hasExtension("GL_EXT_color_buffer_float");
-            break;
-        case GL_RGB16F:
-            res = majorVersion() >= 3 && hasExtension("GL_EXT_color_buffer_half_float");
-            break;
-        case GL_STENCIL_INDEX8:
-            if (attachment == GL_STENCIL_ATTACHMENT) {
-                res = true;
-            } else {
-                res = false;
-            }
-            break;
-        default:
-            res = true;
-        }
-        break;
-    case FBO_ATTACHMENT_TEXTURE:
-        switch (fbo_format_info.tex_internalformat) {
-        case GL_R16F:
-        case GL_RG16F:
-        case GL_RGBA16F:
-        case GL_R32F:
-        case GL_RG32F:
-        case GL_RGBA32F:
-        case GL_R11F_G11F_B10F:
-            res = majorVersion() >= 3 && hasExtension("GL_EXT_color_buffer_float");
-            break;
-        case GL_RGB16F:
-            res = majorVersion() >= 3 && hasExtension("GL_EXT_color_buffer_half_float");
-            break;
-        case GL_RED:
-        case GL_RG:
-        case GL_SRGB8:
-        case GL_RGB32UI:
-        case GL_RGB16UI:
-        case GL_RGB8UI:
-        case GL_RGB32I:
-        case GL_RGB16I:
-        case GL_RGB8I:
-        case GL_R8_SNORM:
-        case GL_RG8_SNORM:
-        case GL_RGB8_SNORM:
-        case GL_RGBA8_SNORM:
-            res = false;
-            break;
-        // No float/half-float formats allowed for RGB(A)
-        case GL_RGB:
-        case GL_RGBA:
-            switch (fbo_format_info.tex_type) {
-            case GL_FLOAT:
-            case GL_HALF_FLOAT_OES:
-            case GL_UNSIGNED_INT_10F_11F_11F_REV:
-            case GL_UNSIGNED_INT_2_10_10_10_REV:
-                res = false;
-                break;
-            default:
-                res = true;
-            }
-            break;
-        default:
-            res = true;
-        }
-        break;
-    case FBO_ATTACHMENT_NONE:
-        res = true;
-        break;
-    default:
-        res = true;
-    }
-    return res;
-}
-
-bool GL2Encoder::checkFramebufferCompleteness(GLenum target, const GLClientState* state) const {
-    bool res = true;
-
-    for (int i = 0; i < state->getMaxColorAttachments(); i++) {
-        res = res && isCompleteFbo(target, state, glUtilsColorAttachmentName(i));
-    }
-
-    res = res && isCompleteFbo(target, state, GL_DEPTH_ATTACHMENT);
-    res = res && isCompleteFbo(target, state, GL_STENCIL_ATTACHMENT);
-
-    return res;
-}
-
 GLenum GL2Encoder::s_glCheckFramebufferStatus(void* self, GLenum target) {
     GL2Encoder* ctx = (GL2Encoder*)self;
+
+    RET_AND_SET_ERROR_IF(
+        target != GL_DRAW_FRAMEBUFFER && target != GL_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER,
+        GL_INVALID_ENUM, 0);
+
     GLClientState* state = ctx->m_state;
 
-    bool fboCompleteByCodec =
-        ctx->checkFramebufferCompleteness(target, state);
-
-    if (!fboCompleteByCodec) {
-        state->setCheckFramebufferStatus(target, GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
-        return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
-    } else {
-        // double check with underlying opengl to avoid craziness.
-        GLenum host_checkstatus = ctx->m_glCheckFramebufferStatus_enc(self, target);
-        state->setCheckFramebufferStatus(target, host_checkstatus);
-        if (host_checkstatus == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS) return GL_FRAMEBUFFER_COMPLETE;
-        return host_checkstatus;
-    }
+    return state->checkFramebufferCompleteness(target);
 }
 
 void GL2Encoder::s_glGenVertexArrays(void* self, GLsizei n, GLuint* arrays) {
@@ -2950,11 +3149,17 @@
         ((access & GL_MAP_WRITE_BIT) &&
         (!(access & GL_MAP_INVALIDATE_RANGE_BIT) &&
          !(access & GL_MAP_INVALIDATE_BUFFER_BIT)))) {
+
+        if (ctx->m_state->shouldSkipHostMapBuffer(target))
+            return bits;
+
         ctx->glMapBufferRangeAEMU(
                 ctx, target,
                 offset, length,
                 access,
                 bits);
+
+        ctx->m_state->onHostMappedBuffer(target);
     }
 
     return bits;
@@ -3139,6 +3344,7 @@
     GLClientState* state = ctx->m_state;
 
     SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(target == GL_TEXTURE_CUBE_MAP, GL_INVALID_ENUM);
     // Filter compressed formats support.
     SET_ERROR_IF(!GLESv2Validation::supportedCompressedFormat(ctx, internalformat), GL_INVALID_ENUM);
     // Verify level <= log2(GL_MAX_TEXTURE_SIZE).
@@ -3155,14 +3361,13 @@
     // If unpack buffer is nonzero, verify unmapped state.
     SET_ERROR_IF(ctx->isBufferTargetMapped(GL_PIXEL_UNPACK_BUFFER), GL_INVALID_OPERATION);
     SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
+
     // If unpack buffer is nonzero, verify buffer data fits.
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
                  ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER) &&
                  (imageSize > ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER)->m_size),
                  GL_INVALID_OPERATION);
-    // TODO: Fix:
-    // If |imageSize| is inconsistent with compressed dimensions.
-    // SET_ERROR_IF(GLESv2Validation::compressedTexImageSize(internalformat, width, height, 1) != imageSize, GL_INVALID_VALUE);
+    SET_ERROR_IF(!ctx->m_state->compressedTexImageSizeCompatible(internalformat, width, height, 1, imageSize), GL_INVALID_VALUE);
 
     GLenum stateTarget = target;
     if (target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
@@ -3173,7 +3378,7 @@
         target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
         stateTarget = GL_TEXTURE_CUBE_MAP;
     state->setBoundTextureInternalFormat(stateTarget, (GLint)internalformat);
-    state->setBoundTextureDims(stateTarget, level, width, height, 1);
+    state->setBoundTextureDims(stateTarget, target, level, width, height, 1);
 
     if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
         ctx->override2DTextureTarget(target);
@@ -3200,13 +3405,28 @@
     GL2Encoder* ctx = (GL2Encoder*)self;
 
     SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(target == GL_TEXTURE_CUBE_MAP, GL_INVALID_ENUM);
     // If unpack buffer is nonzero, verify unmapped state.
     SET_ERROR_IF(ctx->isBufferTargetMapped(GL_PIXEL_UNPACK_BUFFER), GL_INVALID_OPERATION);
+
+    GLenum stateTarget = target;
+    if (target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
+        target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
+        target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
+        stateTarget = GL_TEXTURE_CUBE_MAP;
+    GLuint tex = ctx->m_state->getBoundTexture(stateTarget);
+
+    GLint internalFormat = ctx->m_state->queryTexInternalFormat(tex);
+    SET_ERROR_IF(internalFormat != format, GL_INVALID_OPERATION);
+    SET_ERROR_IF(level < 0, GL_INVALID_VALUE);
+
     GLint max_texture_size;
     GLint max_cube_map_texture_size;
     ctx->glGetIntegerv(ctx, GL_MAX_TEXTURE_SIZE, &max_texture_size);
     ctx->glGetIntegerv(ctx, GL_MAX_CUBE_MAP_TEXTURE_SIZE, &max_cube_map_texture_size);
-    SET_ERROR_IF(level < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(level > ilog2(max_texture_size), GL_INVALID_VALUE);
     SET_ERROR_IF(level > ilog2(max_cube_map_texture_size), GL_INVALID_VALUE);
     SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
@@ -3217,6 +3437,20 @@
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(xoffset < 0 || yoffset < 0, GL_INVALID_VALUE);
 
+    GLint totalWidth = ctx->m_state->queryTexWidth(level, tex);
+    GLint totalHeight = ctx->m_state->queryTexHeight(level, tex);
+
+    if (GLESTextureUtils::isEtc2Format(internalFormat)) {
+        SET_ERROR_IF((width % 4) && (totalWidth != xoffset + width), GL_INVALID_OPERATION);
+        SET_ERROR_IF((height % 4) && (totalHeight != yoffset + height), GL_INVALID_OPERATION);
+        SET_ERROR_IF((xoffset % 4) || (yoffset % 4), GL_INVALID_OPERATION);
+    }
+
+    SET_ERROR_IF(totalWidth < xoffset + width, GL_INVALID_VALUE);
+    SET_ERROR_IF(totalHeight < yoffset + height, GL_INVALID_VALUE);
+
+    SET_ERROR_IF(!ctx->m_state->compressedTexImageSizeCompatible(internalFormat, width, height, 1, imageSize), GL_INVALID_VALUE);
+
     if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
         ctx->override2DTextureTarget(target);
     }
@@ -3345,22 +3579,33 @@
                   writetarget == GL_DISPATCH_INDIRECT_BUFFER ||
                   writetarget == GL_DRAW_INDIRECT_BUFFER ||
                   writetarget == GL_SHADER_STORAGE_BUFFER), GL_INVALID_ENUM);
-    SET_ERROR_IF(!ctx->boundBuffer(readtarget), GL_INVALID_OPERATION);
-    SET_ERROR_IF(!ctx->boundBuffer(writetarget), GL_INVALID_OPERATION);
+
+    GLuint readBufferId = ctx->boundBuffer(readtarget);
+    GLuint writeBufferId = ctx->boundBuffer(writetarget);
+
+    SET_ERROR_IF(!readBufferId || !writeBufferId, GL_INVALID_OPERATION);
+
     SET_ERROR_IF(ctx->isBufferTargetMapped(readtarget), GL_INVALID_OPERATION);
     SET_ERROR_IF(ctx->isBufferTargetMapped(writetarget), GL_INVALID_OPERATION);
+
     SET_ERROR_IF(readoffset < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(writeoffset < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(size < 0, GL_INVALID_VALUE);
+
+    BufferData* readBufferData = ctx->getBufferData(readtarget);
+    BufferData* writeBufferData = ctx->getBufferData(writetarget);
+
     SET_ERROR_IF(
-        ctx->getBufferData(readtarget) &&
-        (readoffset + size > ctx->getBufferData(readtarget)->m_size),
+        readBufferData &&
+        (readoffset + size > readBufferData->m_size),
         GL_INVALID_VALUE);
+
     SET_ERROR_IF(
-        ctx->getBufferData(writetarget) &&
-        (writeoffset + size > ctx->getBufferData(writetarget)->m_size),
+        writeBufferData &&
+        (writeoffset + size > writeBufferData->m_size),
         GL_INVALID_VALUE);
-    SET_ERROR_IF(readtarget == writetarget &&
+
+    SET_ERROR_IF(readBufferId == writeBufferId &&
                  !((writeoffset >= readoffset + size) ||
                    (readoffset >= writeoffset + size)),
                  GL_INVALID_VALUE);
@@ -3522,6 +3767,8 @@
 void GL2Encoder::s_glGetUniformIndices(void* self, GLuint program, GLsizei uniformCount, const GLchar ** uniformNames, GLuint* uniformIndices) {
     GL2Encoder* ctx = (GL2Encoder*)self;
 
+    VALIDATE_PROGRAM_NAME(program);
+
     if (!uniformCount) return;
 
     GLint err = GL_NO_ERROR;
@@ -3546,8 +3793,8 @@
     GLClientState* state = ctx->m_state;
     GLSharedGroupPtr shared = ctx->m_shared;
 
-    GLint hostLoc = location;
-    ctx->m_glUniform1ui_enc(self, hostLoc, v0);
+    ctx->m_state->validateUniform(false /* is float? */, true /* is unsigned? */, 1 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform1ui_enc(self, location, v0);
 
     GLenum target;
     if (shared->setSamplerUniform(state->currentShaderProgram(), location, v0, &target)) {
@@ -3561,80 +3808,80 @@
 
 void GL2Encoder::s_glUniform2ui(void* self, GLint location, GLuint v0, GLuint v1) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform2ui_enc(self, hostLoc, v0, v1);
+    ctx->m_state->validateUniform(false /* is float? */, true /* is unsigned? */, 2 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform2ui_enc(self, location, v0, v1);
 }
 
 void GL2Encoder::s_glUniform3ui(void* self, GLint location, GLuint v0, GLuint v1, GLuint v2) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform3ui_enc(self, hostLoc, v0, v1, v2);
+    ctx->m_state->validateUniform(false /* is float? */, true /* is unsigned? */, 3 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform3ui_enc(self, location, v0, v1, v2);
 }
 
 void GL2Encoder::s_glUniform4ui(void* self, GLint location, GLint v0, GLuint v1, GLuint v2, GLuint v3) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform4ui_enc(self, hostLoc, v0, v1, v2, v3);
+    ctx->m_state->validateUniform(false /* is float? */, true /* is unsigned? */, 4 /* columns */, 1 /* rows */, location, 1 /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform4ui_enc(self, location, v0, v1, v2, v3);
 }
 
 void GL2Encoder::s_glUniform1uiv(void* self, GLint location, GLsizei count, const GLuint *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform1uiv_enc(self, hostLoc, count, value);
+    ctx->m_state->validateUniform(false /* is float? */, true /* is unsigned? */, 1 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform1uiv_enc(self, location, count, value);
 }
 
 void GL2Encoder::s_glUniform2uiv(void* self, GLint location, GLsizei count, const GLuint *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform2uiv_enc(self, hostLoc, count, value);
+    ctx->m_state->validateUniform(false /* is float? */, true /* is unsigned? */, 2 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform2uiv_enc(self, location, count, value);
 }
 
 void GL2Encoder::s_glUniform3uiv(void* self, GLint location, GLsizei count, const GLuint *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform3uiv_enc(self, hostLoc, count, value);
+    ctx->m_state->validateUniform(false /* is float? */, true /* is unsigned? */, 3 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform3uiv_enc(self, location, count, value);
 }
 
 void GL2Encoder::s_glUniform4uiv(void* self, GLint location, GLsizei count, const GLuint *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniform4uiv_enc(self, hostLoc, count, value);
+    ctx->m_state->validateUniform(false /* is float? */, true /* is unsigned? */, 4 /* columns */, 1 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniform4uiv_enc(self, location, count, value);
 }
 
 void GL2Encoder::s_glUniformMatrix2x3fv(void* self, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix2x3fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 2 /* columns */, 3 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix2x3fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glUniformMatrix3x2fv(void* self, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix3x2fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 3 /* columns */, 2 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix3x2fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glUniformMatrix2x4fv(void* self, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix2x4fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 2 /* columns */, 4 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix2x4fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glUniformMatrix4x2fv(void* self, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix4x2fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 4 /* columns */, 2 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix4x2fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glUniformMatrix3x4fv(void* self, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix3x4fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 3 /* columns */, 4 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix3x4fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glUniformMatrix4x3fv(void* self, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glUniformMatrix4x3fv_enc(self, hostLoc, count, transpose, value);
+    ctx->m_state->validateUniform(true /* is float? */, false /* is unsigned? */, 4 /* columns */, 3 /* rows */, location, count /* count */, ctx->getErrorPtr());
+    ctx->m_glUniformMatrix4x3fv_enc(self, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glGetUniformuiv(void* self, GLuint program, GLint location, GLuint* params) {
@@ -3642,14 +3889,18 @@
     SET_ERROR_IF(!ctx->m_shared->isShaderOrProgramObject(program), GL_INVALID_VALUE);
     SET_ERROR_IF(!ctx->m_shared->isProgram(program), GL_INVALID_OPERATION);
     SET_ERROR_IF(!ctx->m_shared->isProgramInitialized(program), GL_INVALID_OPERATION);
-    GLint hostLoc = location;
-    SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,hostLoc)==0, GL_INVALID_OPERATION);
-    ctx->m_glGetUniformuiv_enc(self, program, hostLoc, params);
+    SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,location)==0, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!ctx->m_shared->isProgramUniformLocationValid(program,location), GL_INVALID_OPERATION);
+    ctx->m_glGetUniformuiv_enc(self, program, location, params);
 }
 
 void GL2Encoder::s_glGetActiveUniformBlockiv(void* self, GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params) {
     GL2Encoder* ctx = (GL2Encoder*)self;
 
+    VALIDATE_PROGRAM_NAME(program);
+    SET_ERROR_IF(!GLESv2Validation::allowedGetActiveUniformBlock(pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(uniformBlockIndex >= ctx->m_shared->getActiveUniformBlockCount(program), GL_INVALID_VALUE);
+
     // refresh client state's # active uniforms in this block
     if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) {
         // TODO if worth it: cache uniform count and other params,
@@ -3670,10 +3921,8 @@
 
 void GL2Encoder::s_glGetVertexAttribIiv(void* self, GLuint index, GLenum pname, GLint* params) {
     GL2Encoder *ctx = (GL2Encoder *)self;
-    assert(ctx->m_state);
-    GLint maxIndex;
-    ctx->glGetIntegerv(self, GL_MAX_VERTEX_ATTRIBS, &maxIndex);
-    SET_ERROR_IF(!(index < maxIndex), GL_INVALID_VALUE);
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    SET_ERROR_IF(!GLESv2Validation::allowedGetVertexAttrib(pname), GL_INVALID_ENUM);
 
     if (!ctx->m_state->getVertexAttribParameter<GLint>(index, pname, params)) {
         ctx->m_glGetVertexAttribIiv_enc(self, index, pname, params);
@@ -3682,10 +3931,8 @@
 
 void GL2Encoder::s_glGetVertexAttribIuiv(void* self, GLuint index, GLenum pname, GLuint* params) {
     GL2Encoder *ctx = (GL2Encoder *)self;
-    assert(ctx->m_state);
-    GLint maxIndex;
-    ctx->glGetIntegerv(self, GL_MAX_VERTEX_ATTRIBS, &maxIndex);
-    SET_ERROR_IF(!(index < maxIndex), GL_INVALID_VALUE);
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    SET_ERROR_IF(!GLESv2Validation::allowedGetVertexAttrib(pname), GL_INVALID_ENUM);
 
     if (!ctx->m_state->getVertexAttribParameter<GLuint>(index, pname, params)) {
         ctx->m_glGetVertexAttribIuiv_enc(self, index, pname, params);
@@ -3741,12 +3988,18 @@
     SET_ERROR_IF(target != GL_RENDERBUFFER, GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::rboFormat(ctx, internalformat), GL_INVALID_ENUM);
 
+    SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
+    GLint max_rb_size;
+    ctx->glGetIntegerv(ctx, GL_MAX_RENDERBUFFER_SIZE, &max_rb_size);
+    SET_ERROR_IF(width > max_rb_size || height > max_rb_size, GL_INVALID_VALUE);
+
     GLint max_samples;
     ctx->s_glGetInternalformativ(ctx, target, internalformat, GL_SAMPLES, 1, &max_samples);
     SET_ERROR_IF(samples > max_samples, GL_INVALID_OPERATION);
 
     state->setBoundRenderbufferFormat(internalformat);
     state->setBoundRenderbufferSamples(samples);
+    state->setBoundRenderbufferDimensions(width, height);
     ctx->m_glRenderbufferStorageMultisample_enc(
             self, target, samples, internalformat, width, height);
 }
@@ -3818,11 +4071,16 @@
 
     SET_ERROR_IF(!GLESv2Validation::framebufferTarget(ctx, target), GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::framebufferAttachment(ctx, attachment), GL_INVALID_ENUM);
+    SET_ERROR_IF(texture != 0 && layer < 0, GL_INVALID_VALUE);
+    GLint maxArrayTextureLayers;
+    ctx->glGetIntegerv(ctx, GL_MAX_ARRAY_TEXTURE_LAYERS, &maxArrayTextureLayers);
+    SET_ERROR_IF(texture != 0 && layer > maxArrayTextureLayers - 1, GL_INVALID_VALUE);
+    SET_ERROR_IF(!ctx->m_state->boundFramebuffer(target), GL_INVALID_OPERATION);
     GLenum lastBoundTarget = state->queryTexLastBoundTarget(texture);
     SET_ERROR_IF(lastBoundTarget != GL_TEXTURE_2D_ARRAY &&
                  lastBoundTarget != GL_TEXTURE_3D,
                  GL_INVALID_OPERATION);
-    state->attachTextureObject(target, attachment, texture);
+    state->attachTextureObject(target, attachment, texture, level, layer);
 
     GLint max3DTextureSize;
     ctx->glGetIntegerv(ctx, GL_MAX_3D_TEXTURE_SIZE, &max3DTextureSize);
@@ -3849,7 +4107,7 @@
     SET_ERROR_IF(state->isBoundTextureImmutableFormat(target), GL_INVALID_OPERATION);
 
     state->setBoundTextureInternalFormat(target, internalformat);
-    state->setBoundTextureDims(target, -1, width, height, 1);
+    state->setBoundTextureDims(target, -1 /* set all cube dimensions */, -1, width, height, 1);
     state->setBoundTextureImmutableFormat(target);
 
     if (target == GL_TEXTURE_2D) {
@@ -3880,6 +4138,11 @@
         bufferMode != GL_SEPARATE_ATTRIBS,
         GL_INVALID_ENUM);
 
+    // NOTE: This only has an effect on the program that is being linked.
+    // The dEQP test in dEQP-GLES3.functional.negative_api doesn't know
+    // about this.
+    ctx->m_state->setTransformFeedbackVaryingsCountForLinking(count);
+
     if (!count) return;
 
     GLint err = GL_NO_ERROR;
@@ -3892,29 +4155,51 @@
 void GL2Encoder::s_glBeginTransformFeedback(void* self, GLenum primitiveMode) {
     GL2Encoder* ctx = (GL2Encoder*)self;
     GLClientState* state = ctx->m_state;
+    SET_ERROR_IF(
+        primitiveMode != GL_POINTS &&
+        primitiveMode != GL_LINES &&
+        primitiveMode != GL_TRIANGLES,
+        GL_INVALID_ENUM);
+    SET_ERROR_IF(
+        ctx->m_state->getTransformFeedbackActive(),
+        GL_INVALID_OPERATION);
+    // TODO:
+    // dEQP-GLES3.functional.lifetime.attach.deleted_output.buffer_transform_feedback
+    // SET_ERROR_IF(
+    //     !ctx->boundBuffer(GL_TRANSFORM_FEEDBACK_BUFFER),
+    //     GL_INVALID_OPERATION);
+    SET_ERROR_IF(
+        !ctx->m_state->currentProgram(), GL_INVALID_OPERATION);
     ctx->m_glBeginTransformFeedback_enc(ctx, primitiveMode);
-    state->setTransformFeedbackActiveUnpaused(true);
+    state->setTransformFeedbackActive(true);
+    state->setTransformFeedbackUnpaused(true);
 }
 
 void GL2Encoder::s_glEndTransformFeedback(void* self) {
     GL2Encoder* ctx = (GL2Encoder*)self;
     GLClientState* state = ctx->m_state;
+    SET_ERROR_IF(!state->getTransformFeedbackActive(), GL_INVALID_OPERATION);
     ctx->m_glEndTransformFeedback_enc(ctx);
-    state->setTransformFeedbackActiveUnpaused(false);
+    state->setTransformFeedbackActive(false);
+    state->setTransformFeedbackUnpaused(false);
 }
 
 void GL2Encoder::s_glPauseTransformFeedback(void* self) {
     GL2Encoder* ctx = (GL2Encoder*)self;
     GLClientState* state = ctx->m_state;
+    SET_ERROR_IF(!state->getTransformFeedbackActive(), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!state->getTransformFeedbackUnpaused(), GL_INVALID_OPERATION);
     ctx->m_glPauseTransformFeedback_enc(ctx);
-    state->setTransformFeedbackActiveUnpaused(false);
+    state->setTransformFeedbackUnpaused(false);
 }
 
 void GL2Encoder::s_glResumeTransformFeedback(void* self) {
     GL2Encoder* ctx = (GL2Encoder*)self;
     GLClientState* state = ctx->m_state;
+    SET_ERROR_IF(!state->getTransformFeedbackActive(), GL_INVALID_OPERATION);
+    SET_ERROR_IF(state->getTransformFeedbackUnpaused(), GL_INVALID_OPERATION);
     ctx->m_glResumeTransformFeedback_enc(ctx);
-    state->setTransformFeedbackActiveUnpaused(true);
+    state->setTransformFeedbackUnpaused(true);
 }
 
 void GL2Encoder::s_glTexImage3D(void* self, GLenum target, GLint level, GLint internalFormat,
@@ -3928,6 +4213,10 @@
                  GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::pixelType(ctx, type), GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::pixelFormat(ctx, format), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::pixelSizedFormat(ctx, internalFormat, format, type), GL_INVALID_OPERATION);
+    SET_ERROR_IF(target == GL_TEXTURE_3D &&
+        ((format == GL_DEPTH_COMPONENT) ||
+         (format == GL_DEPTH_STENCIL)), GL_INVALID_OPERATION);
 
     // If unpack buffer is nonzero, verify unmapped state.
     SET_ERROR_IF(ctx->isBufferTargetMapped(GL_PIXEL_UNPACK_BUFFER), GL_INVALID_OPERATION);
@@ -3943,7 +4232,13 @@
     SET_ERROR_IF(width < 0 || height < 0 || depth < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(width > max_texture_size, GL_INVALID_VALUE);
     SET_ERROR_IF(height > max_texture_size, GL_INVALID_VALUE);
-    SET_ERROR_IF(depth > max_texture_size, GL_INVALID_VALUE);
+    if (target == GL_TEXTURE_3D) {
+        SET_ERROR_IF(depth > max_texture_size, GL_INVALID_VALUE);
+    } else {
+        GLint maxArrayTextureLayers;
+        ctx->glGetIntegerv(ctx, GL_MAX_ARRAY_TEXTURE_LAYERS, &maxArrayTextureLayers);
+        SET_ERROR_IF(depth > maxArrayTextureLayers, GL_INVALID_VALUE);
+    }
     SET_ERROR_IF(width > max_3d_texture_size, GL_INVALID_VALUE);
     SET_ERROR_IF(height > max_3d_texture_size, GL_INVALID_VALUE);
     SET_ERROR_IF(depth > max_3d_texture_size, GL_INVALID_VALUE);
@@ -3951,12 +4246,12 @@
     // If unpack buffer is nonzero, verify buffer data fits and is evenly divisible by the type.
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
                  ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER) &&
-                 (ctx->m_state->pboNeededDataSize(width, height, depth, format, type, 0) >
+                 ((uintptr_t)data + ctx->m_state->pboNeededDataSize(width, height, depth, format, type, 0) >
                   ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER)->m_size),
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
                  ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER) &&
-                 (ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER)->m_size %
+                 ((uintptr_t)data %
                   glSizeof(type)),
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(state->isBoundTextureImmutableFormat(target), GL_INVALID_OPERATION);
@@ -3964,7 +4259,7 @@
     state->setBoundTextureInternalFormat(target, internalFormat);
     state->setBoundTextureFormat(target, format);
     state->setBoundTextureType(target, type);
-    state->setBoundTextureDims(target, level, width, height, depth);
+    state->setBoundTextureDims(target, target, level, width, height, depth);
 
     if (ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER)) {
         ctx->glTexImage3DOffsetAEMU(
@@ -4012,13 +4307,12 @@
     // If unpack buffer is nonzero, verify buffer data fits and is evenly divisible by the type.
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
                  ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER) &&
-                 (ctx->m_state->pboNeededDataSize(width, height, depth, format, type, 0) >
+                 ((uintptr_t)data + ctx->m_state->pboNeededDataSize(width, height, depth, format, type, 0) >
                   ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER)->m_size),
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
                  ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER) &&
-                 (ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER)->m_size %
-                  glSizeof(type)),
+                 ((uintptr_t)data % glSizeof(type)),
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(!ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) && !data, GL_INVALID_OPERATION);
     SET_ERROR_IF(xoffset < 0 || yoffset < 0 || zoffset < 0, GL_INVALID_VALUE);
@@ -4042,22 +4336,48 @@
     GL2Encoder* ctx = (GL2Encoder*)self;
     GLClientState* state = ctx->m_state;
 
+    SET_ERROR_IF(target != GL_TEXTURE_3D &&
+                 target != GL_TEXTURE_2D_ARRAY,
+                 GL_INVALID_ENUM);
     // Filter compressed formats support.
     SET_ERROR_IF(!GLESv2Validation::supportedCompressedFormat(ctx, internalformat), GL_INVALID_ENUM);
+    SET_ERROR_IF(target == GL_TEXTURE_CUBE_MAP, GL_INVALID_ENUM);
     // If unpack buffer is nonzero, verify unmapped state.
     SET_ERROR_IF(ctx->isBufferTargetMapped(GL_PIXEL_UNPACK_BUFFER), GL_INVALID_OPERATION);
     SET_ERROR_IF(width < 0 || height < 0 || depth < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(border, GL_INVALID_VALUE);
+
+    GLint max_texture_size;
+    GLint max_3d_texture_size;
+    ctx->glGetIntegerv(ctx, GL_MAX_TEXTURE_SIZE, &max_texture_size);
+    ctx->glGetIntegerv(ctx, GL_MAX_3D_TEXTURE_SIZE, &max_3d_texture_size);
+    SET_ERROR_IF(level < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(level > ilog2(max_texture_size), GL_INVALID_VALUE);
+    SET_ERROR_IF(level > ilog2(max_3d_texture_size), GL_INVALID_VALUE);
+
+    SET_ERROR_IF(width < 0 || height < 0 || depth < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(width > max_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(height > max_texture_size, GL_INVALID_VALUE);
+    if (target == GL_TEXTURE_3D) {
+        SET_ERROR_IF(depth > max_texture_size, GL_INVALID_VALUE);
+    } else {
+        GLint maxArrayTextureLayers;
+        ctx->glGetIntegerv(ctx, GL_MAX_ARRAY_TEXTURE_LAYERS, &maxArrayTextureLayers);
+        SET_ERROR_IF(depth > maxArrayTextureLayers, GL_INVALID_VALUE);
+    }
+    SET_ERROR_IF(width > max_3d_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(height > max_3d_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(depth > max_3d_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(GLESTextureUtils::isAstcFormat(internalformat) && GL_TEXTURE_3D == target, GL_INVALID_OPERATION);
+
     // If unpack buffer is nonzero, verify buffer data fits.
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER) &&
                  ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER) &&
                  (imageSize > ctx->getBufferData(GL_PIXEL_UNPACK_BUFFER)->m_size),
                  GL_INVALID_OPERATION);
-    // TODO: Fix:
-    // If |imageSize| is too small for compressed dimensions.
-    // SET_ERROR_IF(GLESv2Validation::compressedTexImageSize(internalformat, width, height, depth) > imageSize, GL_INVALID_VALUE);
+    SET_ERROR_IF(!ctx->m_state->compressedTexImageSizeCompatible(internalformat, width, height, depth, imageSize), GL_INVALID_VALUE);
     state->setBoundTextureInternalFormat(target, (GLint)internalformat);
-    state->setBoundTextureDims(target, level, width, height, depth);
+    state->setBoundTextureDims(target, target, level, width, height, depth);
 
     if (ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER)) {
         ctx->glCompressedTexImage3DOffsetAEMU(
@@ -4076,6 +4396,7 @@
     GL2Encoder* ctx = (GL2Encoder*)self;
 
     SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(target == GL_TEXTURE_CUBE_MAP, GL_INVALID_ENUM);
     // If unpack buffer is nonzero, verify unmapped state.
     SET_ERROR_IF(ctx->isBufferTargetMapped(GL_PIXEL_UNPACK_BUFFER), GL_INVALID_OPERATION);
     SET_ERROR_IF(width < 0 || height < 0 || depth < 0, GL_INVALID_VALUE);
@@ -4086,6 +4407,52 @@
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(xoffset < 0 || yoffset < 0 || zoffset < 0, GL_INVALID_VALUE);
 
+    GLint max_texture_size;
+    GLint max_3d_texture_size;
+    ctx->glGetIntegerv(ctx, GL_MAX_TEXTURE_SIZE, &max_texture_size);
+    ctx->glGetIntegerv(ctx, GL_MAX_3D_TEXTURE_SIZE, &max_3d_texture_size);
+    SET_ERROR_IF(level < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(level > ilog2(max_texture_size), GL_INVALID_VALUE);
+    SET_ERROR_IF(level > ilog2(max_3d_texture_size), GL_INVALID_VALUE);
+    SET_ERROR_IF(width < 0 || height < 0 || depth < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(xoffset < 0 || yoffset < 0 || zoffset < 0, GL_INVALID_VALUE);
+    GLenum stateTarget = target;
+    if (target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
+        target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
+        target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
+        stateTarget = GL_TEXTURE_CUBE_MAP;
+
+    GLuint tex = ctx->m_state->getBoundTexture(stateTarget);
+    GLsizei neededWidth = xoffset + width;
+    GLsizei neededHeight = yoffset + height;
+    GLsizei neededDepth = zoffset + depth;
+
+    SET_ERROR_IF(tex &&
+                 (neededWidth > ctx->m_state->queryTexWidth(level, tex) ||
+                  neededHeight > ctx->m_state->queryTexHeight(level, tex) ||
+                  neededDepth > ctx->m_state->queryTexDepth(level, tex)),
+                 GL_INVALID_VALUE);
+
+    GLint internalFormat = ctx->m_state->queryTexInternalFormat(tex);
+    SET_ERROR_IF(internalFormat != format, GL_INVALID_OPERATION);
+
+    GLint totalWidth = ctx->m_state->queryTexWidth(level, tex);
+    GLint totalHeight = ctx->m_state->queryTexHeight(level, tex);
+
+    if (GLESTextureUtils::isEtc2Format(internalFormat)) {
+        SET_ERROR_IF((width % 4) && (totalWidth != xoffset + width), GL_INVALID_OPERATION);
+        SET_ERROR_IF((height % 4) && (totalHeight != yoffset + height), GL_INVALID_OPERATION);
+        SET_ERROR_IF((xoffset % 4) || (yoffset % 4), GL_INVALID_OPERATION);
+    }
+
+    SET_ERROR_IF(totalWidth < xoffset + width, GL_INVALID_VALUE);
+    SET_ERROR_IF(totalHeight < yoffset + height, GL_INVALID_VALUE);
+
+    SET_ERROR_IF(!ctx->m_state->compressedTexImageSizeCompatible(internalFormat, width, height, depth, imageSize), GL_INVALID_VALUE);
+
     if (ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER)) {
         ctx->glCompressedTexSubImage3DOffsetAEMU(
                 ctx, target, level,
@@ -4110,7 +4477,27 @@
                  GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::pixelInternalFormat(internalformat), GL_INVALID_ENUM);
     SET_ERROR_IF(!state->getBoundTexture(target), GL_INVALID_OPERATION);
-    SET_ERROR_IF(levels < 1 || width < 1 || height < 1, GL_INVALID_VALUE);
+    SET_ERROR_IF(levels < 1 || width < 1 || height < 1 || depth < 1, GL_INVALID_VALUE);
+    GLint max_texture_size;
+    GLint max_3d_texture_size;
+    ctx->glGetIntegerv(ctx, GL_MAX_TEXTURE_SIZE, &max_texture_size);
+    ctx->glGetIntegerv(ctx, GL_MAX_3D_TEXTURE_SIZE, &max_3d_texture_size);
+    SET_ERROR_IF(width > max_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(height > max_texture_size, GL_INVALID_VALUE);
+    if (target == GL_TEXTURE_3D) {
+        SET_ERROR_IF(depth > max_texture_size, GL_INVALID_VALUE);
+    } else {
+        GLint maxArrayTextureLayers;
+        ctx->glGetIntegerv(ctx, GL_MAX_ARRAY_TEXTURE_LAYERS, &maxArrayTextureLayers);
+        SET_ERROR_IF(depth > maxArrayTextureLayers, GL_INVALID_VALUE);
+    }
+
+    SET_ERROR_IF(width > max_3d_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(height > max_3d_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(depth > max_3d_texture_size, GL_INVALID_VALUE);
+
+    SET_ERROR_IF(GLESTextureUtils::isAstcFormat(internalformat) && GL_TEXTURE_3D == target, GL_INVALID_OPERATION);
+
     SET_ERROR_IF(target == GL_TEXTURE_3D && (levels > ilog2((uint32_t)std::max(width, std::max(height, depth))) + 1),
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(target == GL_TEXTURE_2D_ARRAY && (levels > ilog2((uint32_t)std::max(width, height)) + 1),
@@ -4118,7 +4505,7 @@
     SET_ERROR_IF(state->isBoundTextureImmutableFormat(target), GL_INVALID_OPERATION);
 
     state->setBoundTextureInternalFormat(target, internalformat);
-    state->setBoundTextureDims(target, -1, width, height, depth);
+    state->setBoundTextureDims(target, target, -1, width, height, depth);
     state->setBoundTextureImmutableFormat(target);
     ctx->m_glTexStorage3D_enc(ctx, target, levels, internalformat, width, height, depth);
     state->setBoundTextureImmutableFormat(target);
@@ -4130,6 +4517,7 @@
     SET_ERROR_IF(!isValidDrawMode(mode), GL_INVALID_ENUM);
     SET_ERROR_IF(count < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(primcount < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     bool has_client_vertex_arrays = false;
     bool has_indirect_arrays = false;
@@ -4146,6 +4534,7 @@
         ctx->m_glDrawArraysInstanced_enc(ctx, mode, first, count, primcount);
     }
     ctx->m_stream->flush();
+    ctx->m_state->postDraw();
 }
 
 void GL2Encoder::s_glDrawElementsInstanced(void* self, GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei primcount)
@@ -4158,6 +4547,7 @@
     SET_ERROR_IF(primcount < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(!(type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT), GL_INVALID_ENUM);
     SET_ERROR_IF(ctx->m_state->getTransformFeedbackActiveUnpaused(), GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     bool has_client_vertex_arrays = false;
     bool has_indirect_arrays = false;
@@ -4237,6 +4627,7 @@
             ALOGE("glDrawElements: direct index & direct buffer data - will be implemented in later versions;\n");
         }
     }
+    ctx->m_state->postDraw();
 }
 
 void GL2Encoder::s_glDrawRangeElements(void* self, GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
@@ -4249,6 +4640,7 @@
     SET_ERROR_IF(count < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(!(type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT), GL_INVALID_ENUM);
     SET_ERROR_IF(ctx->m_state->getTransformFeedbackActiveUnpaused(), GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     bool has_client_vertex_arrays = false;
     bool has_indirect_arrays = false;
@@ -4334,6 +4726,7 @@
             ALOGE("glDrawElements: direct index & direct buffer data - will be implemented in later versions;\n");
         }
     }
+    ctx->m_state->postDraw();
 }
 
 const GLubyte* GL2Encoder::s_glGetStringi(void* self, GLenum name, GLuint index) {
@@ -4383,12 +4776,12 @@
 void GL2Encoder::s_glGetProgramBinary(void* self, GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, void* binary) {
     GL2Encoder *ctx = (GL2Encoder *)self;
 
-    SET_ERROR_IF(!ctx->m_shared->isProgram(program), GL_INVALID_OPERATION);
+    VALIDATE_PROGRAM_NAME(program);
 
     GLint linkStatus = 0;
-    ctx->glGetProgramiv(self, program, GL_LINK_STATUS, &linkStatus);
+    ctx->m_glGetProgramiv_enc(self, program, GL_LINK_STATUS, &linkStatus);
     GLint properLength = 0;
-    ctx->glGetProgramiv(self, program, GL_PROGRAM_BINARY_LENGTH, &properLength);
+    ctx->m_glGetProgramiv_enc(self, program, GL_PROGRAM_BINARY_LENGTH, &properLength);
 
     SET_ERROR_IF(!linkStatus, GL_INVALID_OPERATION);
     SET_ERROR_IF(bufSize < properLength, GL_INVALID_OPERATION);
@@ -4401,6 +4794,7 @@
 
     SET_ERROR_IF(!GLESv2Validation::readPixelsFormat(format), GL_INVALID_ENUM);
     SET_ERROR_IF(!GLESv2Validation::readPixelsType(type), GL_INVALID_ENUM);
+    SET_ERROR_IF(!(GLESv2Validation::pixelOp(format,type)),GL_INVALID_OPERATION);
     SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(ctx->isBufferTargetMapped(GL_PIXEL_PACK_BUFFER), GL_INVALID_OPERATION);
     SET_ERROR_IF(ctx->boundBuffer(GL_PIXEL_PACK_BUFFER) &&
@@ -4408,6 +4802,24 @@
                  (ctx->m_state->pboNeededDataSize(width, height, 1, format, type, 1) >
                   ctx->getBufferData(GL_PIXEL_PACK_BUFFER)->m_size),
                  GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->s_glCheckFramebufferStatus(ctx, GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
+
+    // now is complete
+    // GL_INVALID_OPERATION is generated if GL_READ_FRAMEBUFFER_BINDING is nonzero, the read fbo is complete, and the value of
+    // GL_SAMPLE_BUFFERS for the read framebuffer is greater than zero
+    if (ctx->m_state->boundFramebuffer(GL_READ_FRAMEBUFFER) &&
+        ctx->s_glCheckFramebufferStatus(ctx, GL_READ_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) {
+        FboFormatInfo resInfo;
+        ctx->m_state->getBoundFramebufferFormat(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, &resInfo);
+        if (resInfo.type == FBO_ATTACHMENT_RENDERBUFFER) {
+            SET_ERROR_IF(resInfo.rb_multisamples > 0, GL_INVALID_OPERATION);
+        }
+        if (resInfo.type == FBO_ATTACHMENT_TEXTURE) {
+            SET_ERROR_IF(resInfo.tex_multisamples > 0, GL_INVALID_OPERATION);
+        }
+    }
+
+
     /*
 GL_INVALID_OPERATION is generated if the readbuffer of the currently bound framebuffer is a fixed point normalized surface and format and type are neither GL_RGBA and GL_UNSIGNED_BYTE, respectively, nor the format/type pair returned by querying GL_IMPLEMENTATION_COLOR_READ_FORMAT and GL_IMPLEMENTATION_COLOR_READ_TYPE.
 
@@ -4436,6 +4848,7 @@
                 ctx, x, y, width, height,
                 format, type, pixels);
     }
+    ctx->m_state->postReadPixels();
 }
 
 // Track enabled state for some things like:
@@ -4443,6 +4856,8 @@
 void GL2Encoder::s_glEnable(void* self, GLenum what) {
     GL2Encoder *ctx = (GL2Encoder *)self;
 
+	SET_ERROR_IF(!GLESv2Validation::allowedEnable(ctx->majorVersion(), ctx->minorVersion(), what), GL_INVALID_ENUM);
+
     switch (what) {
     case GL_PRIMITIVE_RESTART_FIXED_INDEX:
         ctx->m_primitiveRestartEnabled = true;
@@ -4455,6 +4870,8 @@
 void GL2Encoder::s_glDisable(void* self, GLenum what) {
     GL2Encoder *ctx = (GL2Encoder *)self;
 
+	SET_ERROR_IF(!GLESv2Validation::allowedEnable(ctx->majorVersion(), ctx->minorVersion(), what), GL_INVALID_ENUM);
+
     switch (what) {
     case GL_PRIMITIVE_RESTART_FIXED_INDEX:
         ctx->m_primitiveRestartEnabled = false;
@@ -4467,7 +4884,18 @@
 void GL2Encoder::s_glClearBufferiv(void* self, GLenum buffer, GLint drawBuffer, const GLint * value) {
     GL2Encoder *ctx = (GL2Encoder *)self;
 
-    SET_ERROR_IF(buffer == GL_DEPTH || buffer == GL_DEPTH_STENCIL, GL_INVALID_ENUM);
+    SET_ERROR_IF(buffer != GL_COLOR && buffer != GL_STENCIL, GL_INVALID_ENUM);
+
+    GLint maxDrawBuffers;
+    ctx->glGetIntegerv(ctx, GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
+
+    SET_ERROR_IF(!value, GL_INVALID_VALUE);
+
+    if (buffer == GL_COLOR) {
+        SET_ERROR_IF(drawBuffer < 0 || drawBuffer>= maxDrawBuffers, GL_INVALID_VALUE);
+    } else {
+        SET_ERROR_IF(drawBuffer != 0, GL_INVALID_VALUE);
+    }
 
     ctx->m_glClearBufferiv_enc(ctx, buffer, drawBuffer, value);
 }
@@ -4475,7 +4903,12 @@
 void GL2Encoder::s_glClearBufferuiv(void* self, GLenum buffer, GLint drawBuffer, const GLuint * value) {
     GL2Encoder *ctx = (GL2Encoder *)self;
 
-    SET_ERROR_IF(buffer == GL_DEPTH || buffer == GL_STENCIL || buffer == GL_DEPTH_STENCIL, GL_INVALID_ENUM);
+    SET_ERROR_IF(buffer != GL_COLOR, GL_INVALID_ENUM);
+    SET_ERROR_IF(!value, GL_INVALID_VALUE);
+
+    GLint maxDrawBuffers;
+    ctx->glGetIntegerv(ctx, GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
+    SET_ERROR_IF(drawBuffer < 0 || drawBuffer>= maxDrawBuffers, GL_INVALID_VALUE);
 
     ctx->m_glClearBufferuiv_enc(ctx, buffer, drawBuffer, value);
 }
@@ -4483,11 +4916,31 @@
 void GL2Encoder::s_glClearBufferfv(void* self, GLenum buffer, GLint drawBuffer, const GLfloat * value) {
     GL2Encoder *ctx = (GL2Encoder *)self;
 
-    SET_ERROR_IF(buffer == GL_STENCIL || buffer == GL_DEPTH_STENCIL, GL_INVALID_ENUM);
+    SET_ERROR_IF(buffer != GL_COLOR && buffer != GL_DEPTH, GL_INVALID_ENUM);
+
+    SET_ERROR_IF(!value, GL_INVALID_VALUE);
+
+    GLint maxDrawBuffers;
+    ctx->glGetIntegerv(ctx, GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
+
+    if (buffer == GL_COLOR) {
+        SET_ERROR_IF(drawBuffer < 0 || drawBuffer>= maxDrawBuffers, GL_INVALID_VALUE);
+    } else {
+        SET_ERROR_IF(drawBuffer != 0, GL_INVALID_VALUE);
+    }
 
     ctx->m_glClearBufferfv_enc(ctx, buffer, drawBuffer, value);
 }
 
+void GL2Encoder::s_glClearBufferfi(void* self, GLenum buffer, GLint drawBuffer, float depth, int stencil) {
+    GL2Encoder *ctx = (GL2Encoder *)self;
+
+    SET_ERROR_IF(buffer != GL_DEPTH_STENCIL, GL_INVALID_ENUM);
+    SET_ERROR_IF(drawBuffer != 0, GL_INVALID_VALUE);
+
+    ctx->m_glClearBufferfi_enc(ctx, buffer, drawBuffer, depth, stencil);
+}
+
 void GL2Encoder::s_glBlitFramebuffer(void* self, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) {
     GL2Encoder *ctx = (GL2Encoder *)self;
     GLClientState* state = ctx->m_state;
@@ -4495,6 +4948,7 @@
     bool validateColor = mask & GL_COLOR_BUFFER_BIT;
     bool validateDepth = mask & GL_DEPTH_BUFFER_BIT;
     bool validateStencil = mask & GL_STENCIL_BUFFER_BIT;
+    bool validateDepthOrStencil = validateDepth || validateStencil;
 
     FboFormatInfo read_fbo_format_info;
     FboFormatInfo draw_fbo_format_info;
@@ -4502,6 +4956,13 @@
         state->getBoundFramebufferFormat(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, &read_fbo_format_info);
         state->getBoundFramebufferFormat(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, &draw_fbo_format_info);
 
+        if (read_fbo_format_info.type == FBO_ATTACHMENT_TEXTURE) {
+            SET_ERROR_IF(
+                GL_LINEAR == filter &&
+                GLESv2Validation::isIntegerFormat(read_fbo_format_info.tex_format),
+                    GL_INVALID_OPERATION);
+        }
+
         if (read_fbo_format_info.type == FBO_ATTACHMENT_TEXTURE &&
             draw_fbo_format_info.type == FBO_ATTACHMENT_TEXTURE) {
             SET_ERROR_IF(
@@ -4546,6 +5007,10 @@
         }
     }
 
+    if (validateDepthOrStencil) {
+        SET_ERROR_IF(filter != GL_NEAREST, GL_INVALID_OPERATION);
+    }
+
     state->getBoundFramebufferFormat(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, &draw_fbo_format_info);
     SET_ERROR_IF(
             draw_fbo_format_info.type == FBO_ATTACHMENT_RENDERBUFFER &&
@@ -4633,6 +5098,17 @@
                    GLESv2Validation::filterableTexFormat(ctx, internalformat)),
                  GL_INVALID_OPERATION);
 
+    GLenum stateTarget = target;
+    if (target == GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
+        target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y ||
+        target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ||
+        target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
+        stateTarget = GL_TEXTURE_CUBE_MAP;
+
+    SET_ERROR_IF(!ctx->m_state->isBoundTextureComplete(stateTarget), GL_INVALID_OPERATION);
+
     if (target == GL_TEXTURE_2D) {
         ctx->override2DTextureTarget(target);
     }
@@ -4649,35 +5125,42 @@
     GLint maxCombinedUnits;
     ctx->glGetIntegerv(ctx, GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxCombinedUnits);
     SET_ERROR_IF(unit >= maxCombinedUnits, GL_INVALID_VALUE);
-
-    ctx->doSamplerBindEncodeCached(unit, sampler);
-}
-
-void GL2Encoder::doSamplerBindEncodeCached(GLuint unit, GLuint sampler) {
-    if (m_state->isSamplerBindNoOp(unit, sampler)) return;
-    m_glBindSampler_enc(this, unit, sampler);
-    m_state->bindSampler(unit, sampler);
+    SET_ERROR_IF(!ctx->m_state->samplerExists(sampler), GL_INVALID_OPERATION);
+    if (ctx->m_state->isSamplerBindNoOp(unit, sampler)) return;
+    ctx->m_glBindSampler_enc(ctx, unit, sampler);
+    ctx->m_state->bindSampler(unit, sampler);
 }
 
 void GL2Encoder::s_glDeleteSamplers(void* self, GLsizei n, const GLuint* samplers) {
     GL2Encoder *ctx = (GL2Encoder *)self;
     ctx->m_state->onDeleteSamplers(n, samplers);
+    ctx->m_state->setExistence(GLClientState::ObjectType::Sampler, false, n, samplers);
     ctx->m_glDeleteSamplers_enc(ctx, n, samplers);
 }
 
 GLsync GL2Encoder::s_glFenceSync(void* self, GLenum condition, GLbitfield flags) {
     GL2Encoder *ctx = (GL2Encoder *)self;
+    RET_AND_SET_ERROR_IF(condition != GL_SYNC_GPU_COMMANDS_COMPLETE, GL_INVALID_ENUM, 0);
+    RET_AND_SET_ERROR_IF(flags != 0, GL_INVALID_VALUE, 0);
     uint64_t syncHandle = ctx->glFenceSyncAEMU(ctx, condition, flags);
-    return (GLsync)(uintptr_t)syncHandle;
+
+    GLsync res = (GLsync)(uintptr_t)syncHandle;
+    GLClientState::onFenceCreated(res);
+    return res;
 }
 
 GLenum GL2Encoder::s_glClientWaitSync(void* self, GLsync wait_on, GLbitfield flags, GLuint64 timeout) {
     GL2Encoder *ctx = (GL2Encoder *)self;
+    RET_AND_SET_ERROR_IF(!GLClientState::fenceExists(wait_on), GL_INVALID_VALUE, GL_WAIT_FAILED);
+    RET_AND_SET_ERROR_IF(flags && !(flags & GL_SYNC_FLUSH_COMMANDS_BIT), GL_INVALID_VALUE, GL_WAIT_FAILED);
     return ctx->glClientWaitSyncAEMU(ctx, (uint64_t)(uintptr_t)wait_on, flags, timeout);
 }
 
 void GL2Encoder::s_glWaitSync(void* self, GLsync wait_on, GLbitfield flags, GLuint64 timeout) {
     GL2Encoder *ctx = (GL2Encoder *)self;
+    SET_ERROR_IF(flags != 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(timeout != GL_TIMEOUT_IGNORED, GL_INVALID_VALUE);
+    SET_ERROR_IF(!GLClientState::fenceExists(wait_on), GL_INVALID_VALUE);
     ctx->glWaitSyncAEMU(ctx, (uint64_t)(uintptr_t)wait_on, flags, timeout);
 }
 
@@ -4686,6 +5169,8 @@
 
     if (!sync) return;
 
+    SET_ERROR_IF(!GLClientState::fenceExists(sync), GL_INVALID_VALUE);
+    GLClientState::onFenceDestroyed(sync);
     ctx->glDeleteSyncAEMU(ctx, (uint64_t)(uintptr_t)sync);
 }
 
@@ -4697,7 +5182,9 @@
 void GL2Encoder::s_glGetSynciv(void* self, GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values) {
     GL2Encoder *ctx = (GL2Encoder *)self;
 
+    SET_ERROR_IF(!GLESv2Validation::allowedGetSyncParam(pname), GL_INVALID_ENUM);
     SET_ERROR_IF(bufSize < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(!GLClientState::fenceExists(sync), GL_INVALID_VALUE);
 
     return ctx->glGetSyncivAEMU(ctx, (uint64_t)(uintptr_t)sync, pname, bufSize, length, values);
 }
@@ -4819,6 +5306,10 @@
 void GL2Encoder::s_glGetShaderiv(void* self, GLuint shader, GLenum pname, GLint* params) {
     GL2Encoder *ctx = (GL2Encoder *)self;
     ctx->m_glGetShaderiv_enc(self, shader, pname, params);
+
+    SET_ERROR_IF(!GLESv2Validation::allowedGetShader(pname), GL_INVALID_ENUM);
+    VALIDATE_SHADER_NAME(shader);
+	
     if (pname == GL_SHADER_SOURCE_LENGTH) {
         ShaderData* shaderData = ctx->m_shared->getShaderData(shader);
         if (shaderData) {
@@ -4848,7 +5339,7 @@
     }
 }
 
-GLuint GL2Encoder::s_glCreateShaderProgramv(void* self, GLenum type, GLsizei count, const char** strings) {
+GLuint GL2Encoder::s_glCreateShaderProgramv(void* self, GLenum shaderType, GLsizei count, const char** strings) {
 
     GLint* length = NULL;
     GL2Encoder* ctx = (GL2Encoder*)self;
@@ -4869,12 +5360,13 @@
         return -1;
     }
 
-    GLuint res = ctx->glCreateShaderProgramvAEMU(ctx, type, count, str, len + 1);
+    GLuint res = ctx->glCreateShaderProgramvAEMU(ctx, shaderType, count, str, len + 1);
     delete [] str;
 
     // Phase 2: do glLinkProgram-related initialization for locationWorkARound
     GLint linkStatus = 0;
-    ctx->glGetProgramiv(self, res, GL_LINK_STATUS ,&linkStatus);
+    ctx->m_glGetProgramiv_enc(self, res, GL_LINK_STATUS ,&linkStatus);
+    ctx->m_shared->setProgramLinkStatus(res, linkStatus);
     if (!linkStatus) {
         ctx->m_shared->deleteShaderProgramDataById(spDataId);
         return -1;
@@ -4883,20 +5375,39 @@
     ctx->m_shared->associateGLShaderProgram(res, spDataId);
 
     GLint numUniforms = 0;
-    ctx->glGetProgramiv(self, res, GL_ACTIVE_UNIFORMS, &numUniforms);
-    ctx->m_shared->initShaderProgramData(res, numUniforms);
+    GLint numAttributes = 0;
+    ctx->m_glGetProgramiv_enc(self, res, GL_ACTIVE_UNIFORMS, &numUniforms);
+    ctx->m_glGetProgramiv_enc(self, res, GL_ACTIVE_ATTRIBUTES, &numAttributes);
+    ctx->m_shared->initShaderProgramData(res, numUniforms, numAttributes);
 
     GLint maxLength=0;
-    ctx->glGetProgramiv(self, res, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
+    GLint maxAttribLength=0;
+    ctx->m_glGetProgramiv_enc(self, res, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
+    ctx->m_glGetProgramiv_enc(self, res, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttribLength);
 
-    GLint size; GLenum uniformType; GLchar* name = new GLchar[maxLength + 1];
+    size_t bufLen = maxLength > maxAttribLength ? maxLength : maxAttribLength;
+    GLint size; GLenum type; GLchar *name = new GLchar[bufLen + 1];
 
     for (GLint i = 0; i < numUniforms; ++i) {
-        ctx->glGetActiveUniform(self, res, i, maxLength, NULL, &size, &uniformType, name);
+        ctx->m_glGetActiveUniform_enc(self, res, i, maxLength, NULL, &size, &type, name);
         GLint location = ctx->m_glGetUniformLocation_enc(self, res, name);
-        ctx->m_shared->setShaderProgramIndexInfo(res, i, location, size, uniformType, name);
+        ctx->m_shared->setShaderProgramIndexInfo(res, i, location, size, type, name);
     }
 
+    for (GLint i = 0; i < numAttributes; ++i) {
+        ctx->m_glGetActiveAttrib_enc(self, res, i, maxAttribLength,  NULL, &size, &type, name);
+        GLint location = ctx->m_glGetAttribLocation_enc(self, res, name);
+        ctx->m_shared->setProgramAttribInfo(res, i, location, size, type, name);
+    }
+
+    GLint numBlocks;
+    ctx->m_glGetProgramiv_enc(ctx, res, GL_ACTIVE_UNIFORM_BLOCKS, &numBlocks);
+    ctx->m_shared->setActiveUniformBlockCountForProgram(res, numBlocks);
+
+    GLint tfVaryingsCount;
+    ctx->m_glGetProgramiv_enc(ctx, res, GL_TRANSFORM_FEEDBACK_VARYINGS, &tfVaryingsCount);
+    ctx->m_shared->setTransformFeedbackVaryingsCountForProgram(res, tfVaryingsCount);
+
     delete [] name;
 
     return res;
@@ -4905,22 +5416,19 @@
 void GL2Encoder::s_glProgramUniform1f(void* self, GLuint program, GLint location, GLfloat v0)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform1f_enc(self, program, hostLoc, v0);
+    ctx->m_glProgramUniform1f_enc(self, program, location, v0);
 }
 
 void GL2Encoder::s_glProgramUniform1fv(void* self, GLuint program, GLint location, GLsizei count, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform1fv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform1fv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform1i(void* self, GLuint program, GLint location, GLint v0)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform1i_enc(self, program, hostLoc, v0);
+    ctx->m_glProgramUniform1i_enc(self, program, location, v0);
 
     GLClientState* state = ctx->m_state;
     GLSharedGroupPtr shared = ctx->m_shared;
@@ -4938,15 +5446,13 @@
 void GL2Encoder::s_glProgramUniform1iv(void* self, GLuint program, GLint location, GLsizei count, const GLint *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform1iv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform1iv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform1ui(void* self, GLuint program, GLint location, GLuint v0)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform1ui_enc(self, program, hostLoc, v0);
+    ctx->m_glProgramUniform1ui_enc(self, program, location, v0);
 
     GLClientState* state = ctx->m_state;
     GLSharedGroupPtr shared = ctx->m_shared;
@@ -4964,201 +5470,176 @@
 void GL2Encoder::s_glProgramUniform1uiv(void* self, GLuint program, GLint location, GLsizei count, const GLuint *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform1uiv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform1uiv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform2f(void* self, GLuint program, GLint location, GLfloat v0, GLfloat v1)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform2f_enc(self, program, hostLoc, v0, v1);
+    ctx->m_glProgramUniform2f_enc(self, program, location, v0, v1);
 }
 
 void GL2Encoder::s_glProgramUniform2fv(void* self, GLuint program, GLint location, GLsizei count, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform2fv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform2fv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform2i(void* self, GLuint program, GLint location, GLint v0, GLint v1)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform2i_enc(self, program, hostLoc, v0, v1);
+    ctx->m_glProgramUniform2i_enc(self, program, location, v0, v1);
 }
 
 void GL2Encoder::s_glProgramUniform2iv(void* self, GLuint program, GLint location, GLsizei count, const GLint *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform2iv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform2iv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform2ui(void* self, GLuint program, GLint location, GLint v0, GLuint v1)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform2ui_enc(self, program, hostLoc, v0, v1);
+    ctx->m_glProgramUniform2ui_enc(self, program, location, v0, v1);
 }
 
 void GL2Encoder::s_glProgramUniform2uiv(void* self, GLuint program, GLint location, GLsizei count, const GLuint *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform2uiv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform2uiv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform3f(void* self, GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform3f_enc(self, program, hostLoc, v0, v1, v2);
+    ctx->m_glProgramUniform3f_enc(self, program, location, v0, v1, v2);
 }
 
 void GL2Encoder::s_glProgramUniform3fv(void* self, GLuint program, GLint location, GLsizei count, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform3fv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform3fv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform3i(void* self, GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform3i_enc(self, program, hostLoc, v0, v1, v2);
+    ctx->m_glProgramUniform3i_enc(self, program, location, v0, v1, v2);
 }
 
 void GL2Encoder::s_glProgramUniform3iv(void* self, GLuint program, GLint location, GLsizei count, const GLint *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform3iv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform3iv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform3ui(void* self, GLuint program, GLint location, GLint v0, GLint v1, GLuint v2)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform3ui_enc(self, program, hostLoc, v0, v1, v2);
+    ctx->m_glProgramUniform3ui_enc(self, program, location, v0, v1, v2);
 }
 
 void GL2Encoder::s_glProgramUniform3uiv(void* self, GLuint program, GLint location, GLsizei count, const GLuint *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform3uiv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform3uiv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform4f(void* self, GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform4f_enc(self, program, hostLoc, v0, v1, v2, v3);
+    ctx->m_glProgramUniform4f_enc(self, program, location, v0, v1, v2, v3);
 }
 
 void GL2Encoder::s_glProgramUniform4fv(void* self, GLuint program, GLint location, GLsizei count, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform4fv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform4fv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform4i(void* self, GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform4i_enc(self, program, hostLoc, v0, v1, v2, v3);
+    ctx->m_glProgramUniform4i_enc(self, program, location, v0, v1, v2, v3);
 }
 
 void GL2Encoder::s_glProgramUniform4iv(void* self, GLuint program, GLint location, GLsizei count, const GLint *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform4iv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform4iv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniform4ui(void* self, GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLuint v3)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform4ui_enc(self, program, hostLoc, v0, v1, v2, v3);
+    ctx->m_glProgramUniform4ui_enc(self, program, location, v0, v1, v2, v3);
 }
 
 void GL2Encoder::s_glProgramUniform4uiv(void* self, GLuint program, GLint location, GLsizei count, const GLuint *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniform4uiv_enc(self, program, hostLoc, count, value);
+    ctx->m_glProgramUniform4uiv_enc(self, program, location, count, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix2fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix2fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix2fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix2x3fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix2x3fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix2x3fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix2x4fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix2x4fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix2x4fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix3fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix3fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix3fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix3x2fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix3x2fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix3x2fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix3x4fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix3x4fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix3x4fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix4fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix4fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix4fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix4x2fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix4x2fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix4x2fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramUniformMatrix4x3fv(void* self, GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
 {
     GL2Encoder *ctx = (GL2Encoder*)self;
-    GLint hostLoc = location;
-    ctx->m_glProgramUniformMatrix4x3fv_enc(self, program, hostLoc, count, transpose, value);
+    ctx->m_glProgramUniformMatrix4x3fv_enc(self, program, location, count, transpose, value);
 }
 
 void GL2Encoder::s_glProgramParameteri(void* self, GLuint program, GLenum pname, GLint value) {
     GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_PROGRAM_NAME(program);
+    SET_ERROR_IF(pname != GL_PROGRAM_BINARY_RETRIEVABLE_HINT && pname != GL_PROGRAM_SEPARABLE, GL_INVALID_ENUM);
+    SET_ERROR_IF(value != GL_FALSE && value != GL_TRUE, GL_INVALID_VALUE);
     ctx->m_glProgramParameteri_enc(self, program, pname, value);
 }
 
@@ -5182,6 +5663,11 @@
 
     // Otherwise, update host texture 2D bindings.
     ctx->updateHostTexture2DBindingsFromProgramData(program);
+
+    if (program) {
+        ctx->m_state->currentUniformValidationInfo = ctx->m_shared->getUniformValidationInfo(program);
+        ctx->m_state->currentAttribValidationInfo = ctx->m_shared->getAttribValidationInfo(program);
+    }
 }
 
 void GL2Encoder::s_glBindProgramPipeline(void* self, GLuint pipeline)
@@ -5349,6 +5835,7 @@
     SET_ERROR_IF(hasClientArrays, GL_INVALID_OPERATION);
     SET_ERROR_IF(!state->currentVertexArrayObject(), GL_INVALID_OPERATION);
     SET_ERROR_IF(!ctx->boundBuffer(GL_DRAW_INDIRECT_BUFFER), GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     GLuint indirectStructSize = glUtilsIndirectStructSize(INDIRECT_COMMAND_DRAWARRAYS);
     if (ctx->boundBuffer(GL_DRAW_INDIRECT_BUFFER)) {
@@ -5362,6 +5849,7 @@
         // This is purely for debug/dev purposes.
         ctx->glDrawArraysIndirectDataAEMU(ctx, mode, indirect, indirectStructSize);
     }
+    ctx->m_state->postDraw();
 }
 
 void GL2Encoder::s_glDrawElementsIndirect(void* self, GLenum mode, GLenum type, const void* indirect) {
@@ -5378,6 +5866,7 @@
     SET_ERROR_IF(!ctx->boundBuffer(GL_DRAW_INDIRECT_BUFFER), GL_INVALID_OPERATION);
 
     SET_ERROR_IF(ctx->m_state->getTransformFeedbackActiveUnpaused(), GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->m_state->checkFramebufferCompleteness(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, GL_INVALID_FRAMEBUFFER_OPERATION);
 
     GLuint indirectStructSize = glUtilsIndirectStructSize(INDIRECT_COMMAND_DRAWELEMENTS);
     if (ctx->boundBuffer(GL_DRAW_INDIRECT_BUFFER)) {
@@ -5391,7 +5880,7 @@
         // This is purely for debug/dev purposes.
         ctx->glDrawElementsIndirectDataAEMU(ctx, mode, type, indirect, indirectStructSize);
     }
-
+    ctx->m_state->postDraw();
 }
 
 void GL2Encoder::s_glTexStorage2DMultisample(void* self, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations) {
@@ -5408,7 +5897,7 @@
     SET_ERROR_IF(samples > max_samples, GL_INVALID_OPERATION);
 
     state->setBoundTextureInternalFormat(target, internalformat);
-    state->setBoundTextureDims(target, 0, width, height, 1);
+    state->setBoundTextureDims(target, target, 0, width, height, 1);
     state->setBoundTextureImmutableFormat(target);
     state->setBoundTextureSamples(target, samples);
 
@@ -5427,6 +5916,7 @@
     SET_ERROR_IF(bufSize < glesv2_enc::pixelDataSize(self, width, height, format,
         type, 1), GL_INVALID_OPERATION);
     s_glReadPixels(self, x, y, width, height, format, type, pixels);
+    ctx->m_state->postReadPixels();
 }
 
 void GL2Encoder::s_glGetnUniformfvEXT(void *self, GLuint program, GLint location,
@@ -5447,14 +5937,627 @@
 
 void GL2Encoder::s_glInvalidateFramebuffer(void* self, GLenum target, GLsizei numAttachments, const GLenum *attachments) {
     GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF((target != GL_FRAMEBUFFER) &&
+                 (target != GL_READ_FRAMEBUFFER) &&
+                 (target != GL_DRAW_FRAMEBUFFER), GL_INVALID_ENUM);
     SET_ERROR_IF(numAttachments < 0, GL_INVALID_VALUE);
+
+    GLint maxColorAttachments;
+    ctx->glGetIntegerv(ctx, GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
+    for (GLsizei i = 0; i < numAttachments; ++i) {
+        if (attachments[i] != GL_DEPTH_ATTACHMENT && attachments[i] != GL_STENCIL_ATTACHMENT && attachments[i] != GL_DEPTH_STENCIL_ATTACHMENT) {
+            SET_ERROR_IF(attachments[i] >= GL_COLOR_ATTACHMENT0 + maxColorAttachments, GL_INVALID_OPERATION);
+        }
+    }
+
     ctx->m_glInvalidateFramebuffer_enc(ctx, target, numAttachments, attachments);
 }
 
 void GL2Encoder::s_glInvalidateSubFramebuffer(void* self, GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height) {
     GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(target != GL_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER, GL_INVALID_ENUM);
     SET_ERROR_IF(numAttachments < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(width < 0, GL_INVALID_VALUE);
     SET_ERROR_IF(height < 0, GL_INVALID_VALUE);
+    GLint maxColorAttachments;
+    ctx->glGetIntegerv(ctx, GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
+    for (GLsizei i = 0; i < numAttachments; ++i) {
+        if (attachments[i] != GL_DEPTH_ATTACHMENT && attachments[i] != GL_STENCIL_ATTACHMENT && attachments[i] != GL_DEPTH_STENCIL_ATTACHMENT) {
+            SET_ERROR_IF(attachments[i] >= GL_COLOR_ATTACHMENT0 + maxColorAttachments, GL_INVALID_OPERATION);
+        }
+    }
     ctx->m_glInvalidateSubFramebuffer_enc(ctx, target, numAttachments, attachments, x, y, width, height);
 }
+
+void GL2Encoder::s_glDispatchCompute(void* self, GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    ctx->m_glDispatchCompute_enc(ctx, num_groups_x, num_groups_y, num_groups_z);
+    ctx->m_state->postDispatchCompute();
+}
+
+void GL2Encoder::s_glDispatchComputeIndirect(void* self, GLintptr indirect) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    ctx->m_glDispatchComputeIndirect_enc(ctx, indirect);
+    ctx->m_state->postDispatchCompute();
+}
+
+void GL2Encoder::s_glGenTransformFeedbacks(void* self, GLsizei n, GLuint* ids) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    ctx->m_glGenTransformFeedbacks_enc(ctx, n, ids);
+    ctx->m_state->setExistence(GLClientState::ObjectType::TransformFeedback, true, n, ids);
+}
+
+void GL2Encoder::s_glDeleteTransformFeedbacks(void* self, GLsizei n, const GLuint* ids) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(ctx->m_state->getTransformFeedbackActive(), GL_INVALID_OPERATION);
+
+    ctx->m_state->setExistence(GLClientState::ObjectType::TransformFeedback, false, n, ids);
+    ctx->m_glDeleteTransformFeedbacks_enc(ctx, n, ids);
+}
+
+void GL2Encoder::s_glGenSamplers(void* self, GLsizei n, GLuint* ids) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    ctx->m_glGenSamplers_enc(ctx, n, ids);
+    ctx->m_state->setExistence(GLClientState::ObjectType::Sampler, true, n, ids);
+}
+
+void GL2Encoder::s_glGenQueries(void* self, GLsizei n, GLuint* ids) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    ctx->m_glGenQueries_enc(ctx, n, ids);
+    ctx->m_state->setExistence(GLClientState::ObjectType::Query, true, n, ids);
+}
+
+void GL2Encoder::s_glDeleteQueries(void* self, GLsizei n, const GLuint* ids) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    ctx->m_state->setExistence(GLClientState::ObjectType::Query, false, n, ids);
+    ctx->m_glDeleteQueries_enc(ctx, n, ids);
+}
+
+void GL2Encoder::s_glBindTransformFeedback(void* self, GLenum target, GLuint id) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(GL_TRANSFORM_FEEDBACK != target, GL_INVALID_ENUM);
+    SET_ERROR_IF(ctx->m_state->getTransformFeedbackActiveUnpaused(), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!ctx->m_state->tryBind(target, id), GL_INVALID_OPERATION);
+    ctx->m_glBindTransformFeedback_enc(ctx, target, id);
+}
+
+void GL2Encoder::s_glBeginQuery(void* self, GLenum target, GLuint query) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::allowedQueryTarget(target), GL_INVALID_ENUM);
+
+    if (target != GL_ANY_SAMPLES_PASSED_CONSERVATIVE &&
+        target != GL_ANY_SAMPLES_PASSED) {
+        SET_ERROR_IF(ctx->m_state->isQueryBound(target), GL_INVALID_OPERATION);
+    } else {
+        SET_ERROR_IF(ctx->m_state->isQueryBound(GL_ANY_SAMPLES_PASSED_CONSERVATIVE), GL_INVALID_OPERATION);
+        SET_ERROR_IF(ctx->m_state->isQueryBound(GL_ANY_SAMPLES_PASSED), GL_INVALID_OPERATION);
+    }
+
+    GLenum lastTarget = ctx->m_state->getLastQueryTarget(query);
+
+    if (lastTarget) {
+        SET_ERROR_IF(target != lastTarget, GL_INVALID_OPERATION);
+    }
+
+    SET_ERROR_IF(!query, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!ctx->m_state->tryBind(target, query), GL_INVALID_OPERATION);
+    ctx->m_state->setLastQueryTarget(target, query);
+    ctx->m_glBeginQuery_enc(ctx, target, query);
+}
+
+void GL2Encoder::s_glEndQuery(void* self, GLenum target) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::allowedQueryTarget(target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!ctx->m_state->isBoundTargetValid(target), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!ctx->m_state->tryBind(target, 0), GL_INVALID_OPERATION);
+    ctx->m_glEndQuery_enc(ctx, target);
+}
+
+void GL2Encoder::s_glClear(void* self, GLbitfield mask) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+
+    GLbitfield allowed_bits = GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
+    GLbitfield has_disallowed_bits = (mask & ~allowed_bits);
+    SET_ERROR_IF(has_disallowed_bits, GL_INVALID_VALUE);
+
+    ctx->m_glClear_enc(ctx, mask);
+}
+
+void GL2Encoder::s_glCopyTexSubImage2D(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::textureTarget(ctx, target), GL_INVALID_ENUM);
+    SET_ERROR_IF(level < 0, GL_INVALID_VALUE);
+    GLint max_texture_size;
+    GLint max_cube_map_texture_size;
+    ctx->glGetIntegerv(ctx, GL_MAX_TEXTURE_SIZE, &max_texture_size);
+    ctx->glGetIntegerv(ctx, GL_MAX_CUBE_MAP_TEXTURE_SIZE, &max_cube_map_texture_size);
+    SET_ERROR_IF(level > ilog2(max_texture_size), GL_INVALID_VALUE);
+    SET_ERROR_IF((target == GL_TEXTURE_CUBE_MAP) &&
+                 (level > ilog2(max_cube_map_texture_size)), GL_INVALID_VALUE);
+    SET_ERROR_IF(xoffset < 0 || yoffset < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(width > max_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(height > max_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(target) && width > max_cube_map_texture_size, GL_INVALID_VALUE);
+    SET_ERROR_IF(GLESv2Validation::isCubeMapTarget(target) && height > max_cube_map_texture_size, GL_INVALID_VALUE);
+    GLuint tex = ctx->m_state->getBoundTexture(target);
+    GLsizei neededWidth = xoffset + width;
+    GLsizei neededHeight = yoffset + height;
+    SET_ERROR_IF(tex &&
+                 (neededWidth > ctx->m_state->queryTexWidth(level, tex) ||
+                  neededHeight > ctx->m_state->queryTexHeight(level, tex)),
+                 GL_INVALID_VALUE);
+    SET_ERROR_IF(ctx->glCheckFramebufferStatus(ctx, GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE,
+                 GL_INVALID_FRAMEBUFFER_OPERATION);
+
+    ctx->m_glCopyTexSubImage2D_enc(ctx, target, level, xoffset, yoffset, x, y, width, height);
+}
+
+void GL2Encoder::s_glCopyTexSubImage3D(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(target != GL_TEXTURE_3D &&
+                 target != GL_TEXTURE_2D_ARRAY,
+                 GL_INVALID_ENUM);
+    GLint max_texture_size;
+    GLint max_3d_texture_size;
+    ctx->glGetIntegerv(ctx, GL_MAX_TEXTURE_SIZE, &max_texture_size);
+    ctx->glGetIntegerv(ctx, GL_MAX_3D_TEXTURE_SIZE, &max_3d_texture_size);
+    SET_ERROR_IF(level < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(level > ilog2(max_texture_size), GL_INVALID_VALUE);
+    SET_ERROR_IF(level > ilog2(max_3d_texture_size), GL_INVALID_VALUE);
+    SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(xoffset < 0 || yoffset < 0 || zoffset < 0, GL_INVALID_VALUE);
+    GLuint tex = ctx->m_state->getBoundTexture(target);
+    GLsizei neededWidth = xoffset + width;
+    GLsizei neededHeight = yoffset + height;
+    GLsizei neededDepth = zoffset + 1;
+    SET_ERROR_IF(tex &&
+                 (neededWidth > ctx->m_state->queryTexWidth(level, tex) ||
+                  neededHeight > ctx->m_state->queryTexHeight(level, tex) ||
+                  neededDepth > ctx->m_state->queryTexDepth(level, tex)),
+                 GL_INVALID_VALUE);
+    SET_ERROR_IF(ctx->glCheckFramebufferStatus(ctx, GL_READ_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE,
+                 GL_INVALID_FRAMEBUFFER_OPERATION);
+
+    ctx->m_glCopyTexSubImage3D_enc(ctx, target, level, xoffset, yoffset, zoffset, x, y, width, height);
+}
+
+void GL2Encoder::s_glCompileShader(void* self, GLuint shader) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    bool isShaderOrProgramObject =
+        ctx->m_shared->isShaderOrProgramObject(shader);
+    bool isShader =
+        ctx->m_shared->isShader(shader);
+
+    SET_ERROR_IF(isShaderOrProgramObject && !isShader, GL_INVALID_OPERATION);
+    SET_ERROR_IF(!isShaderOrProgramObject && !isShader, GL_INVALID_VALUE);
+
+    ctx->m_glCompileShader_enc(ctx, shader);
+}
+
+void GL2Encoder::s_glValidateProgram(void* self, GLuint program ) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+
+    VALIDATE_PROGRAM_NAME(program);
+
+    ctx->m_glValidateProgram_enc(self, program);
+}
+
+void GL2Encoder::s_glProgramBinary(void *self , GLuint program, GLenum binaryFormat, const void* binary, GLsizei length) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+
+    VALIDATE_PROGRAM_NAME(program);
+
+    SET_ERROR_IF(~0 == binaryFormat, GL_INVALID_ENUM);
+
+    ctx->m_glProgramBinary_enc(self, program, binaryFormat, binary, length);
+}
+
+void GL2Encoder::s_glGetSamplerParameterfv(void *self, GLuint sampler, GLenum pname, GLfloat* params) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+
+    SET_ERROR_IF(!ctx->m_state->samplerExists(sampler), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!GLESv2Validation::samplerParams(ctx, pname), GL_INVALID_ENUM);
+
+    if (!params) return;
+
+    ctx->m_glGetSamplerParameterfv_enc(ctx, sampler, pname, params);
+}
+
+void GL2Encoder::s_glGetSamplerParameteriv(void *self, GLuint sampler, GLenum pname, GLint* params) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!ctx->m_state->samplerExists(sampler), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!GLESv2Validation::samplerParams(ctx, pname), GL_INVALID_ENUM);
+
+    if (!params) return;
+
+    ctx->m_glGetSamplerParameteriv_enc(ctx, sampler, pname, params);
+}
+
+void GL2Encoder::s_glSamplerParameterf(void *self , GLuint sampler, GLenum pname, GLfloat param) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!ctx->m_state->samplerExists(sampler), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!GLESv2Validation::samplerParams(ctx, pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParamValue(ctx, pname, (GLint)param, param, (GLenum)param), GL_INVALID_ENUM);
+
+    ctx->m_glSamplerParameterf_enc(ctx, sampler, pname, param);
+}
+
+void GL2Encoder::s_glSamplerParameteri(void *self , GLuint sampler, GLenum pname, GLint param) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!ctx->m_state->samplerExists(sampler), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!GLESv2Validation::samplerParams(ctx, pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::textureParamValue(ctx, pname, param, (GLfloat)param, (GLenum)param), GL_INVALID_ENUM);
+
+    ctx->m_glSamplerParameteri_enc(ctx, sampler, pname, param);
+}
+
+void GL2Encoder::s_glSamplerParameterfv(void *self , GLuint sampler, GLenum pname, const GLfloat* params) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!ctx->m_state->samplerExists(sampler), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!GLESv2Validation::samplerParams(ctx, pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!params, GL_INVALID_VALUE);
+    GLfloat param = *params;
+    SET_ERROR_IF(!GLESv2Validation::textureParamValue(ctx, pname, (GLint)param, param, (GLenum)param), GL_INVALID_ENUM);
+
+    ctx->m_glSamplerParameterfv_enc(ctx, sampler, pname, params);
+}
+
+void GL2Encoder::s_glSamplerParameteriv(void *self , GLuint sampler, GLenum pname, const GLint* params) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!ctx->m_state->samplerExists(sampler), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!GLESv2Validation::samplerParams(ctx, pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!params, GL_INVALID_VALUE);
+    GLint param = *params;
+    SET_ERROR_IF(!GLESv2Validation::textureParamValue(ctx, pname, (GLint)param, param, (GLenum)param), GL_INVALID_ENUM);
+
+    ctx->m_glSamplerParameteriv_enc(ctx, sampler, pname, params);
+}
+
+int GL2Encoder::s_glGetAttribLocation(void *self , GLuint program, const GLchar* name) {
+    GL2Encoder *ctx = (GL2Encoder*)self;
+
+    bool isShaderOrProgramObject =
+        ctx->m_shared->isShaderOrProgramObject(program);
+    bool isProgram =
+        ctx->m_shared->isProgram(program);
+
+    RET_AND_SET_ERROR_IF(!isShaderOrProgramObject, GL_INVALID_VALUE, -1);
+    RET_AND_SET_ERROR_IF(!isProgram, GL_INVALID_OPERATION, -1);
+    RET_AND_SET_ERROR_IF(!ctx->m_shared->getProgramLinkStatus(program), GL_INVALID_OPERATION, -1);
+
+    return ctx->m_glGetAttribLocation_enc(ctx, program, name);
+}
+
+void GL2Encoder::s_glBindAttribLocation(void *self , GLuint program, GLuint index, const GLchar* name) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+
+    VALIDATE_PROGRAM_NAME(program);
+
+    GLint maxVertexAttribs;
+    ctx->glGetIntegerv(self, GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
+    SET_ERROR_IF(!(index < maxVertexAttribs), GL_INVALID_VALUE);
+    SET_ERROR_IF(index > maxVertexAttribs, GL_INVALID_VALUE);
+    SET_ERROR_IF(name && !strncmp("gl_", name, 3), GL_INVALID_OPERATION);
+
+    fprintf(stderr, "%s: bind attrib %u name %s\n", __func__, index, name);
+    ctx->m_glBindAttribLocation_enc(ctx, program, index, name);
+}
+
+// TODO-SLOW
+void GL2Encoder::s_glUniformBlockBinding(void *self , GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+
+    VALIDATE_PROGRAM_NAME(program);
+    SET_ERROR_IF(uniformBlockIndex >= ctx->m_shared->getActiveUniformBlockCount(program), GL_INVALID_VALUE);
+
+    GLint maxUniformBufferBindings;
+    ctx->glGetIntegerv(ctx, GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferBindings);
+    SET_ERROR_IF(uniformBlockBinding >= maxUniformBufferBindings, GL_INVALID_VALUE);
+
+    ctx->m_glUniformBlockBinding_enc(ctx, program, uniformBlockIndex, uniformBlockBinding);
+}
+
+void GL2Encoder::s_glGetTransformFeedbackVarying(void *self , GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, char* name) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+
+    VALIDATE_PROGRAM_NAME(program);
+    SET_ERROR_IF(!ctx->m_shared->getProgramLinkStatus(program), GL_INVALID_OPERATION);
+    SET_ERROR_IF(index >= ctx->m_shared->getTransformFeedbackVaryingsCountForProgram(program), GL_INVALID_VALUE);
+
+    ctx->m_glGetTransformFeedbackVarying_enc(ctx, program, index, bufSize, length, size, type, name);
+}
+
+void GL2Encoder::s_glScissor(void *self , GLint x, GLint y, GLsizei width, GLsizei height) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
+    ctx->m_glScissor_enc(ctx, x, y, width, height);
+}
+
+void GL2Encoder::s_glDepthFunc(void *self , GLenum func) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        (func != GL_NEVER) &&
+        (func != GL_ALWAYS) &&
+        (func != GL_LESS) &&
+        (func != GL_LEQUAL) &&
+        (func != GL_EQUAL) &&
+        (func != GL_GREATER) &&
+        (func != GL_GEQUAL) &&
+        (func != GL_NOTEQUAL),
+        GL_INVALID_ENUM);
+    ctx->m_glDepthFunc_enc(ctx, func);
+}
+
+void GL2Encoder::s_glViewport(void *self , GLint x, GLint y, GLsizei width, GLsizei height) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(width < 0 || height < 0, GL_INVALID_VALUE);
+    ctx->m_glViewport_enc(ctx, x, y, width, height);
+}
+
+void GL2Encoder::s_glStencilFunc(void *self , GLenum func, GLint ref, GLuint mask) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::allowedFunc(func), GL_INVALID_ENUM);
+    ctx->m_glStencilFunc_enc(ctx, func, ref, mask);
+}
+
+void GL2Encoder::s_glStencilFuncSeparate(void *self , GLenum face, GLenum func, GLint ref, GLuint mask) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::allowedFace(face) || !GLESv2Validation::allowedFunc(func), GL_INVALID_ENUM);
+    ctx->m_glStencilFuncSeparate_enc(ctx, face, func, ref, mask);
+}
+
+void GL2Encoder::s_glStencilOp(void *self , GLenum fail, GLenum zfail, GLenum zpass) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedStencilOp(fail) ||
+        !GLESv2Validation::allowedStencilOp(zfail) ||
+        !GLESv2Validation::allowedStencilOp(zpass),
+        GL_INVALID_ENUM);
+    ctx->m_glStencilOp_enc(ctx, fail, zfail, zpass);
+}
+
+void GL2Encoder::s_glStencilOpSeparate(void *self , GLenum face, GLenum fail, GLenum zfail, GLenum zpass) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedFace(face) ||
+        !GLESv2Validation::allowedStencilOp(fail) ||
+        !GLESv2Validation::allowedStencilOp(zfail) ||
+        !GLESv2Validation::allowedStencilOp(zpass),
+        GL_INVALID_ENUM);
+    ctx->m_glStencilOpSeparate_enc(ctx, face, fail, zfail, zpass);
+}
+
+void GL2Encoder::s_glStencilMaskSeparate(void *self , GLenum face, GLuint mask) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedFace(face),
+        GL_INVALID_ENUM);
+    ctx->m_glStencilMaskSeparate_enc(ctx, face, mask);
+}
+
+void GL2Encoder::s_glBlendEquation(void *self , GLenum mode) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedBlendEquation(mode),
+        GL_INVALID_ENUM);
+    ctx->m_glBlendEquation_enc(ctx, mode);
+}
+
+void GL2Encoder::s_glBlendEquationSeparate(void *self , GLenum modeRGB, GLenum modeAlpha) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedBlendEquation(modeRGB) ||
+        !GLESv2Validation::allowedBlendEquation(modeAlpha),
+        GL_INVALID_ENUM);
+    ctx->m_glBlendEquationSeparate_enc(ctx, modeRGB, modeAlpha);
+}
+
+void GL2Encoder::s_glBlendFunc(void *self , GLenum sfactor, GLenum dfactor) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedBlendFunc(sfactor) ||
+        !GLESv2Validation::allowedBlendFunc(dfactor),
+        GL_INVALID_ENUM);
+    ctx->m_glBlendFunc_enc(ctx, sfactor, dfactor);
+}
+
+void GL2Encoder::s_glBlendFuncSeparate(void *self , GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedBlendFunc(srcRGB) ||
+        !GLESv2Validation::allowedBlendFunc(dstRGB) ||
+        !GLESv2Validation::allowedBlendFunc(srcAlpha) ||
+        !GLESv2Validation::allowedBlendFunc(dstAlpha),
+        GL_INVALID_ENUM);
+    ctx->m_glBlendFuncSeparate_enc(ctx, srcRGB, dstRGB, srcAlpha, dstAlpha);
+}
+
+void GL2Encoder::s_glCullFace(void *self , GLenum mode) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedCullFace(mode),
+        GL_INVALID_ENUM);
+    ctx->m_glCullFace_enc(ctx, mode);
+}
+
+void GL2Encoder::s_glFrontFace(void *self , GLenum mode) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(
+        !GLESv2Validation::allowedFrontFace(mode),
+        GL_INVALID_ENUM);
+    ctx->m_glFrontFace_enc(ctx, mode);
+}
+
+void GL2Encoder::s_glLineWidth(void *self , GLfloat width) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(width <= 0.0f, GL_INVALID_VALUE);
+    ctx->m_glLineWidth_enc(ctx, width);
+}
+
+void GL2Encoder::s_glVertexAttrib1f(void *self , GLuint indx, GLfloat x) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(indx);
+    ctx->m_glVertexAttrib1f_enc(ctx, indx, x);
+}
+
+void GL2Encoder::s_glVertexAttrib2f(void *self , GLuint indx, GLfloat x, GLfloat y) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(indx);
+    ctx->m_glVertexAttrib2f_enc(ctx, indx, x, y);
+}
+
+void GL2Encoder::s_glVertexAttrib3f(void *self , GLuint indx, GLfloat x, GLfloat y, GLfloat z) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(indx);
+    ctx->m_glVertexAttrib3f_enc(ctx, indx, x, y, z);
+}
+
+void GL2Encoder::s_glVertexAttrib4f(void *self , GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(indx);
+    ctx->m_glVertexAttrib4f_enc(ctx, indx, x, y, z, w);
+}
+
+void GL2Encoder::s_glVertexAttrib1fv(void *self , GLuint indx, const GLfloat* values) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(indx);
+    ctx->m_glVertexAttrib1fv_enc(ctx, indx, values);
+}
+
+void GL2Encoder::s_glVertexAttrib2fv(void *self , GLuint indx, const GLfloat* values) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(indx);
+    ctx->m_glVertexAttrib2fv_enc(ctx, indx, values);
+}
+
+void GL2Encoder::s_glVertexAttrib3fv(void *self , GLuint indx, const GLfloat* values) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(indx);
+    ctx->m_glVertexAttrib3fv_enc(ctx, indx, values);
+}
+
+void GL2Encoder::s_glVertexAttrib4fv(void *self , GLuint indx, const GLfloat* values) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(indx);
+    ctx->m_glVertexAttrib4fv_enc(ctx, indx, values);
+}
+
+void GL2Encoder::s_glVertexAttribI4i(void *self , GLuint index, GLint v0, GLint v1, GLint v2, GLint v3) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    ctx->m_glVertexAttribI4i_enc(ctx, index, v0, v1, v2, v3);
+}
+
+void GL2Encoder::s_glVertexAttribI4ui(void *self , GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    ctx->m_glVertexAttribI4ui_enc(ctx, index, v0, v1, v2, v3);
+}
+
+void GL2Encoder::s_glVertexAttribI4iv(void *self , GLuint index, const GLint* v) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    ctx->m_glVertexAttribI4iv_enc(ctx, index, v);
+}
+
+void GL2Encoder::s_glVertexAttribI4uiv(void *self , GLuint index, const GLuint* v) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    ctx->m_glVertexAttribI4uiv_enc(ctx, index, v);
+}
+
+void GL2Encoder::s_glGetShaderPrecisionFormat(void *self , GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::allowedShaderType(shadertype), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::allowedPrecisionType(precisiontype), GL_INVALID_ENUM);
+    ctx->m_glGetShaderPrecisionFormat_enc(ctx, shadertype, precisiontype, range, precision);
+}
+
+void GL2Encoder::s_glGetProgramiv(void *self , GLuint program, GLenum pname, GLint* params) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::allowedGetProgram(ctx->majorVersion(), ctx->minorVersion(), pname), GL_INVALID_ENUM);
+    VALIDATE_PROGRAM_NAME(program);
+    ctx->m_glGetProgramiv_enc(ctx, program, pname, params);
+}
+
+void GL2Encoder::s_glGetActiveUniform(void *self , GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_PROGRAM_NAME(program);
+    SET_ERROR_IF(index >= ctx->m_shared->getActiveUniformsCountForProgram(program), GL_INVALID_VALUE);
+    ctx->m_glGetActiveUniform_enc(ctx, program, index, bufsize, length, size, type, name);
+}
+
+void GL2Encoder::s_glGetActiveUniformsiv(void *self , GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_PROGRAM_NAME(program);
+    SET_ERROR_IF(uniformCount < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(!GLESv2Validation::allowedGetActiveUniforms(pname), GL_INVALID_ENUM);
+    int activeUniformsCount = ctx->m_shared->getActiveUniformsCountForProgram(program);
+    for (GLsizei i = 0; i < uniformCount; ++i) {
+        SET_ERROR_IF(uniformIndices[i] >= activeUniformsCount, GL_INVALID_VALUE);
+    }
+    ctx->m_glGetActiveUniformsiv_enc(ctx, program, uniformCount, uniformIndices, pname, params);
+}
+
+void GL2Encoder::s_glGetActiveUniformBlockName(void *self , GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_PROGRAM_NAME(program);
+    SET_ERROR_IF(bufSize < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(uniformBlockIndex >= ctx->m_shared->getActiveUniformBlockCount(program), GL_INVALID_VALUE);
+    ctx->m_glGetActiveUniformBlockName_enc(ctx, program, uniformBlockIndex, bufSize, length, uniformBlockName);
+}
+
+void GL2Encoder::s_glGetActiveAttrib(void *self , GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_PROGRAM_NAME(program);
+    VALIDATE_VERTEX_ATTRIB_INDEX(index);
+    SET_ERROR_IF(bufsize < 0, GL_INVALID_VALUE);
+    SET_ERROR_IF(index >= ctx->m_shared->getActiveAttributesCountForProgram(program), GL_INVALID_VALUE);
+    ctx->m_glGetActiveAttrib_enc(ctx, program, index, bufsize, length, size, type, name);
+}
+
+void GL2Encoder::s_glGetRenderbufferParameteriv(void *self , GLenum target, GLenum pname, GLint* params) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(target != GL_RENDERBUFFER, GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::allowedGetRenderbufferParameter(pname), GL_INVALID_ENUM);
+    ctx->m_glGetRenderbufferParameteriv_enc(ctx, target, pname, params);
+}
+
+void GL2Encoder::s_glGetQueryiv(void *self , GLenum target, GLenum pname, GLint* params) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::allowedQueryTarget(target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::allowedQueryParam(pname), GL_INVALID_ENUM);
+    ctx->m_glGetQueryiv_enc(ctx, target, pname, params);
+}
+
+void GL2Encoder::s_glGetQueryObjectuiv(void *self , GLuint query, GLenum pname, GLuint* params) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    GLClientState* state = ctx->m_state;
+    SET_ERROR_IF(!GLESv2Validation::allowedQueryObjectParam(pname), GL_INVALID_ENUM);
+    SET_ERROR_IF(!state->queryExistence(GLClientState::ObjectType::Query, query), GL_INVALID_OPERATION);
+    SET_ERROR_IF(!state->getLastQueryTarget(query), GL_INVALID_OPERATION);
+    SET_ERROR_IF(ctx->m_state->isQueryObjectActive(query), GL_INVALID_OPERATION);
+
+    ctx->m_glGetQueryObjectuiv_enc(ctx, query, pname, params);
+}
+
+GLboolean GL2Encoder::s_glIsEnabled(void *self , GLenum cap) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+	RET_AND_SET_ERROR_IF(!GLESv2Validation::allowedEnable(ctx->majorVersion(), ctx->minorVersion(), cap), GL_INVALID_ENUM, 0);
+    return ctx->m_glIsEnabled_enc(ctx, cap);
+}
+
+void GL2Encoder::s_glHint(void *self , GLenum target, GLenum mode) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    SET_ERROR_IF(!GLESv2Validation::allowedHintTarget(target), GL_INVALID_ENUM);
+    SET_ERROR_IF(!GLESv2Validation::allowedHintMode(mode), GL_INVALID_ENUM);
+    ctx->m_glHint_enc(ctx, target, mode);
+}
+
+GLint GL2Encoder::s_glGetFragDataLocation (void *self , GLuint program, const char* name) {
+    GL2Encoder* ctx = (GL2Encoder*)self;
+    VALIDATE_PROGRAM_NAME_RET(program, -1);
+    RET_AND_SET_ERROR_IF(!ctx->m_shared->getProgramLinkStatus(program), GL_INVALID_OPERATION, -1);
+    return ctx->m_glGetFragDataLocation_enc(ctx, program, name);
+}
diff --git a/system/GLESv2_enc/GL2Encoder.h b/system/GLESv2_enc/GL2Encoder.h
index 0ceb9de..61aed34 100644
--- a/system/GLESv2_enc/GL2Encoder.h
+++ b/system/GLESv2_enc/GL2Encoder.h
@@ -62,8 +62,11 @@
     }
     void setSharedGroup(GLSharedGroupPtr shared) {
         m_shared = shared;
-        if (m_state && m_shared.Ptr())
+        if (m_state && m_shared.Ptr()) {
             m_state->setTextureData(m_shared->getTextureData());
+            m_state->setRenderbufferInfo(m_shared->getRenderbufferInfo());
+            m_state->setSamplerInfo(m_shared->getSamplerInfo());
+        }
     }
     int majorVersion() const { return m_currMajorVersion; }
     int minorVersion() const { return m_currMinorVersion; }
@@ -71,6 +74,7 @@
                        const std::vector<std::string>& extArray) {
         m_currExtensions = std::string(exts);
         m_currExtensionsArray = extArray;
+        m_state->setExtensions(m_currExtensions);
     }
     bool hasExtension(const char* ext) const {
         return m_currExtensions.find(ext) != std::string::npos;
@@ -85,6 +89,9 @@
     virtual void setError(GLenum error){ m_error = error; };
     virtual GLenum getError() { return m_error; };
 
+    __attribute__((always_inline)) GLenum* getErrorPtr() { return &m_error; }
+    __attribute__((always_inline)) bool hasError() const { return m_error != GL_NO_ERROR; }
+
     void override2DTextureTarget(GLenum target);
     void restore2DTextureTarget(GLenum target);
     void associateEGLImage(GLenum target, GLeglImageOES eglImage);
@@ -118,6 +125,7 @@
 
     GLint m_max_combinedTextureImageUnits;
     GLint m_max_vertexTextureImageUnits;
+    GLint m_max_array_texture_layers;;
     GLint m_max_textureImageUnits;
     GLint m_max_cubeMapTextureSize;
     GLint m_max_renderBufferSize;
@@ -137,6 +145,8 @@
     GLuint m_ssbo_offset_align;
     GLuint m_ubo_offset_align;
 
+    GLint m_log2MaxTextureSize;
+
     std::vector<char> m_fixedBuffer;
 
     uint32_t m_drawCallFlushInterval;
@@ -161,8 +171,6 @@
     bool updateHostTexture2DBinding(GLenum texUnit, GLenum newTarget);
     void updateHostTexture2DBindingsFromProgramData(GLuint program);
     bool texture2DNeedsOverride(GLenum target) const;
-    bool isCompleteFbo(GLenum target, const GLClientState* state, GLenum attachment) const;
-    bool checkFramebufferCompleteness(GLenum target, const GLClientState* state) const;
 
     // Utility classes for safe queries that
     // need access to private class members
@@ -614,7 +622,6 @@
 
     glBindSampler_client_proc_t m_glBindSampler_enc;
     static void s_glBindSampler(void* self, GLuint unit, GLuint sampler);
-    void doSamplerBindEncodeCached(GLuint unit, GLuint sampler);
 
     glDeleteSamplers_client_proc_t m_glDeleteSamplers_enc;
     static void s_glDeleteSamplers(void* self, GLsizei n, const GLuint* samplers);
@@ -769,6 +776,167 @@
     glInvalidateFramebuffer_client_proc_t m_glInvalidateFramebuffer_enc;
     glInvalidateSubFramebuffer_client_proc_t m_glInvalidateSubFramebuffer_enc;;
 
+    // Dispatch compute
+    static void s_glDispatchCompute(void* self, GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);
+    static void s_glDispatchComputeIndirect(void* self, GLintptr indirect);
+
+    glDispatchCompute_client_proc_t m_glDispatchCompute_enc;
+    glDispatchComputeIndirect_client_proc_t m_glDispatchComputeIndirect_enc;
+
+    // State tracking for transform feedbacks, samplers, and query objects
+    static void s_glGenTransformFeedbacks(void* self, GLsizei n, GLuint* ids);
+    static void s_glDeleteTransformFeedbacks(void* self, GLsizei n, const GLuint* ids);
+    static void s_glGenSamplers(void* self, GLsizei n, GLuint* ids);
+    static void s_glGenQueries(void* self, GLsizei n, GLuint* ids);
+    static void s_glDeleteQueries(void* self, GLsizei n, const GLuint* ids);
+
+    glGenTransformFeedbacks_client_proc_t m_glGenTransformFeedbacks_enc;
+    glDeleteTransformFeedbacks_client_proc_t m_glDeleteTransformFeedbacks_enc;
+    glGenSamplers_client_proc_t m_glGenSamplers_enc;
+    glGenQueries_client_proc_t m_glGenQueries_enc;
+    glDeleteQueries_client_proc_t m_glDeleteQueries_enc;
+
+    static void s_glBindTransformFeedback(void* self, GLenum target, GLuint id);
+    static void s_glBeginQuery(void* self, GLenum target, GLuint query);
+    static void s_glEndQuery(void* self, GLenum target);
+
+    glBindTransformFeedback_client_proc_t m_glBindTransformFeedback_enc;
+    glBeginQuery_client_proc_t m_glBeginQuery_enc;
+    glEndQuery_client_proc_t m_glEndQuery_enc;
+
+    static void s_glClear(void* self, GLbitfield mask);
+    glClear_client_proc_t m_glClear_enc;
+
+    static void s_glClearBufferfi(void* self, GLenum buffer, GLint drawBuffer, float depth, int stencil);
+    glClearBufferfi_client_proc_t m_glClearBufferfi_enc;
+
+    static void s_glCopyTexSubImage2D(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+    glCopyTexSubImage2D_client_proc_t m_glCopyTexSubImage2D_enc;
+
+    static void s_glCopyTexSubImage3D(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+    glCopyTexSubImage3D_client_proc_t m_glCopyTexSubImage3D_enc;
+
+    static void s_glCompileShader(void* self, GLuint shader);
+    glCompileShader_client_proc_t m_glCompileShader_enc;
+
+    static void s_glValidateProgram(void* self, GLuint program);
+    glValidateProgram_client_proc_t m_glValidateProgram_enc;
+
+    static void s_glProgramBinary(void *self , GLuint program, GLenum binaryFormat, const void* binary, GLsizei length);
+    glProgramBinary_client_proc_t m_glProgramBinary_enc;
+
+    static void s_glGetSamplerParameterfv(void *self, GLuint sampler, GLenum pname, GLfloat* params);
+    static void s_glGetSamplerParameteriv(void *self, GLuint sampler, GLenum pname, GLint* params);
+    glGetSamplerParameterfv_client_proc_t m_glGetSamplerParameterfv_enc;
+    glGetSamplerParameteriv_client_proc_t m_glGetSamplerParameteriv_enc;
+
+    static void s_glSamplerParameterf(void *self , GLuint sampler, GLenum pname, GLfloat param);
+    static void s_glSamplerParameteri(void *self , GLuint sampler, GLenum pname, GLint param);
+    static void s_glSamplerParameterfv(void *self , GLuint sampler, GLenum pname, const GLfloat* params);
+    static void s_glSamplerParameteriv(void *self , GLuint sampler, GLenum pname, const GLint* params);
+
+    glSamplerParameterf_client_proc_t m_glSamplerParameterf_enc;
+    glSamplerParameteri_client_proc_t m_glSamplerParameteri_enc;
+    glSamplerParameterfv_client_proc_t m_glSamplerParameterfv_enc;
+    glSamplerParameteriv_client_proc_t m_glSamplerParameteriv_enc;
+
+    static int s_glGetAttribLocation(void *self , GLuint program, const GLchar* name);
+    glGetAttribLocation_client_proc_t m_glGetAttribLocation_enc;
+
+    static void s_glBindAttribLocation(void *self , GLuint program, GLuint index, const GLchar* name);
+    static void s_glUniformBlockBinding(void *self , GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
+    static void s_glGetTransformFeedbackVarying(void *self , GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, char* name);
+    static void s_glScissor(void *self , GLint x, GLint y, GLsizei width, GLsizei height);
+    static void s_glDepthFunc(void *self , GLenum func);
+    static void s_glViewport(void *self , GLint x, GLint y, GLsizei width, GLsizei height);
+    static void s_glStencilFunc(void *self , GLenum func, GLint ref, GLuint mask);
+    static void s_glStencilFuncSeparate(void *self , GLenum face, GLenum func, GLint ref, GLuint mask);
+    static void s_glStencilOp(void *self , GLenum fail, GLenum zfail, GLenum zpass);
+    static void s_glStencilOpSeparate(void *self , GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
+    static void s_glStencilMaskSeparate(void *self , GLenum face, GLuint mask);
+    static void s_glBlendEquation(void *self , GLenum mode);
+    static void s_glBlendEquationSeparate(void *self , GLenum modeRGB, GLenum modeAlpha);
+    static void s_glBlendFunc(void *self , GLenum sfactor, GLenum dfactor);
+    static void s_glBlendFuncSeparate(void *self , GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+    static void s_glCullFace(void *self , GLenum mode);
+    static void s_glFrontFace(void *self , GLenum mode);
+    static void s_glLineWidth(void *self , GLfloat width);
+    static void s_glVertexAttrib1f(void *self , GLuint indx, GLfloat x);
+    static void s_glVertexAttrib2f(void *self , GLuint indx, GLfloat x, GLfloat y);
+    static void s_glVertexAttrib3f(void *self , GLuint indx, GLfloat x, GLfloat y, GLfloat z);
+    static void s_glVertexAttrib4f(void *self , GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+    static void s_glVertexAttrib1fv(void *self , GLuint indx, const GLfloat* values);
+    static void s_glVertexAttrib2fv(void *self , GLuint indx, const GLfloat* values);
+    static void s_glVertexAttrib3fv(void *self , GLuint indx, const GLfloat* values);
+    static void s_glVertexAttrib4fv(void *self , GLuint indx, const GLfloat* values);
+    static void s_glVertexAttribI4i(void *self , GLuint index, GLint v0, GLint v1, GLint v2, GLint v3);
+    static void s_glVertexAttribI4ui(void *self , GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+    static void s_glVertexAttribI4iv(void *self , GLuint index, const GLint* v);
+    static void s_glVertexAttribI4uiv(void *self , GLuint index, const GLuint* v);
+
+    static void s_glGetShaderPrecisionFormat(void *self , GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
+    static void s_glGetProgramiv(void *self , GLuint program, GLenum pname, GLint* params);
+    static void s_glGetActiveUniform(void *self , GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+    static void s_glGetActiveUniformsiv(void *self , GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params);
+    static void s_glGetActiveUniformBlockName(void *self , GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName);
+    static void s_glGetActiveAttrib(void *self , GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+    static void s_glGetRenderbufferParameteriv(void *self , GLenum target, GLenum pname, GLint* params);
+    static void s_glGetQueryiv(void *self , GLenum target, GLenum pname, GLint* params);
+    static void s_glGetQueryObjectuiv(void *self , GLuint query, GLenum pname, GLuint* params);
+    static GLboolean s_glIsEnabled(void *self , GLenum cap);
+    static void s_glHint(void *self , GLenum target, GLenum mode);
+    static GLint s_glGetFragDataLocation (void *self , GLuint program, const char* name);
+
+#define LIST_REMAINING_FUNCTIONS_FOR_VALIDATION(f) \
+    f(glBindAttribLocation) \
+    f(glUniformBlockBinding) \
+    f(glGetTransformFeedbackVarying) \
+    f(glScissor) \
+    f(glDepthFunc) \
+    f(glViewport) \
+    f(glStencilFunc) \
+    f(glStencilFuncSeparate) \
+    f(glStencilOp) \
+    f(glStencilOpSeparate) \
+    f(glStencilMaskSeparate) \
+    f(glBlendEquation) \
+    f(glBlendEquationSeparate) \
+    f(glBlendFunc) \
+    f(glBlendFuncSeparate) \
+    f(glCullFace) \
+    f(glFrontFace) \
+    f(glLineWidth) \
+    f(glVertexAttrib1f) \
+    f(glVertexAttrib2f) \
+    f(glVertexAttrib3f) \
+    f(glVertexAttrib4f) \
+    f(glVertexAttrib1fv) \
+    f(glVertexAttrib2fv) \
+    f(glVertexAttrib3fv) \
+    f(glVertexAttrib4fv) \
+    f(glVertexAttribI4i) \
+    f(glVertexAttribI4ui) \
+    f(glVertexAttribI4iv) \
+    f(glVertexAttribI4uiv) \
+    f(glGetShaderPrecisionFormat) \
+    f(glGetProgramiv) \
+    f(glGetActiveUniform) \
+    f(glGetActiveUniformsiv) \
+    f(glGetActiveUniformBlockName) \
+    f(glGetActiveAttrib) \
+    f(glGetRenderbufferParameteriv) \
+    f(glGetQueryiv) \
+    f(glGetQueryObjectuiv) \
+    f(glIsEnabled) \
+    f(glHint) \
+    f(glGetFragDataLocation) \
+
+#define DECLARE_CLIENT_ENCODER_PROC(n) \
+    n##_client_proc_t m_##n##_enc;
+
+    LIST_REMAINING_FUNCTIONS_FOR_VALIDATION(DECLARE_CLIENT_ENCODER_PROC)
+
+
 public:
     glEGLImageTargetTexture2DOES_client_proc_t m_glEGLImageTargetTexture2DOES_enc;
 
diff --git a/system/GLESv2_enc/GLESv2Validation.cpp b/system/GLESv2_enc/GLESv2Validation.cpp
index aff7902..b3b4637 100644
--- a/system/GLESv2_enc/GLESv2Validation.cpp
+++ b/system/GLESv2_enc/GLESv2Validation.cpp
@@ -18,6 +18,241 @@
 
 #include <sstream>
 
+#define LIST_VALID_TEX_INTERNALFORMATS(f) \
+    f(GL_BGRA8_EXT) \
+    f(GL_R8) \
+    f(GL_R8_SNORM) \
+    f(GL_R16F) \
+    f(GL_R32F) \
+    f(GL_R8UI) \
+    f(GL_R8I) \
+    f(GL_R16UI) \
+    f(GL_R16I) \
+    f(GL_R32UI) \
+    f(GL_R32I) \
+    f(GL_RG8) \
+    f(GL_RG8_SNORM) \
+    f(GL_RG16F) \
+    f(GL_RG32F) \
+    f(GL_RG8UI) \
+    f(GL_RG8I) \
+    f(GL_RG16UI) \
+    f(GL_RG16I) \
+    f(GL_RG32UI) \
+    f(GL_RG32I) \
+    f(GL_RGB8) \
+    f(GL_SRGB8) \
+    f(GL_RGB565) \
+    f(GL_RGB8_SNORM) \
+    f(GL_R11F_G11F_B10F) \
+    f(GL_RGB9_E5) \
+    f(GL_RGB16F) \
+    f(GL_RGB32F) \
+    f(GL_RGB8UI) \
+    f(GL_RGB8I) \
+    f(GL_RGB16UI) \
+    f(GL_RGB16I) \
+    f(GL_RGB32UI) \
+    f(GL_RGB32I) \
+    f(GL_RGBA8) \
+    f(GL_SRGB8_ALPHA8) \
+    f(GL_RGBA8_SNORM) \
+    f(GL_RGB5_A1) \
+    f(GL_RGBA4) \
+    f(GL_RGB10_A2) \
+    f(GL_RGBA16F) \
+    f(GL_RGBA32F) \
+    f(GL_RGBA8UI) \
+    f(GL_RGBA8I) \
+    f(GL_RGB10_A2UI) \
+    f(GL_RGBA16UI) \
+    f(GL_RGBA16I) \
+    f(GL_RGBA32I) \
+    f(GL_RGBA32UI) \
+    f(GL_DEPTH_COMPONENT16) \
+    f(GL_DEPTH_COMPONENT24) \
+    f(GL_DEPTH_COMPONENT32F) \
+    f(GL_DEPTH24_STENCIL8) \
+    f(GL_DEPTH32F_STENCIL8) \
+    f(GL_ETC1_RGB8_OES) \
+    f(GL_COMPRESSED_R11_EAC) \
+    f(GL_COMPRESSED_SIGNED_R11_EAC) \
+    f(GL_COMPRESSED_RG11_EAC) \
+    f(GL_COMPRESSED_SIGNED_RG11_EAC) \
+    f(GL_COMPRESSED_RGB8_ETC2) \
+    f(GL_COMPRESSED_SRGB8_ETC2) \
+    f(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2) \
+    f(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2) \
+    f(GL_COMPRESSED_RGBA8_ETC2_EAC) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC) \
+    f(GL_COMPRESSED_RGBA_ASTC_4x4_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_5x4_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_5x5_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_6x5_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_6x6_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_8x5_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_8x6_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_8x8_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_10x5_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_10x6_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_10x8_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_10x10_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_12x10_KHR) \
+    f(GL_COMPRESSED_RGBA_ASTC_12x12_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR) \
+
+#define LIST_INTEGER_TEX_FORMATS(f) \
+    f(GL_RED_INTEGER) \
+    f(GL_RG_INTEGER) \
+    f(GL_RGB_INTEGER) \
+    f(GL_RGBA_INTEGER) \
+    f(GL_R8UI) \
+    f(GL_R8I) \
+    f(GL_R16UI) \
+    f(GL_R16I) \
+    f(GL_R32UI) \
+    f(GL_R32I) \
+    f(GL_RG8UI) \
+    f(GL_RG8I) \
+    f(GL_RG16UI) \
+    f(GL_RG16I) \
+    f(GL_RG32UI) \
+    f(GL_RG32I) \
+    f(GL_RGB8UI) \
+    f(GL_RGB8I) \
+    f(GL_RGB16UI) \
+    f(GL_RGB16I) \
+    f(GL_RGB32UI) \
+    f(GL_RGB32I) \
+    f(GL_RGBA8UI) \
+    f(GL_RGBA8I) \
+    f(GL_RGB10_A2UI) \
+    f(GL_RGBA16UI) \
+    f(GL_RGBA16I) \
+    f(GL_RGBA32I) \
+    f(GL_RGBA32UI) \
+
+#define LIST_VALID_TEXFORMAT_COMBINATIONS(f) \
+    f(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE) \
+    f(GL_R8, GL_RED, GL_UNSIGNED_BYTE) \
+    f(GL_R8_SNORM, GL_RED, GL_BYTE) \
+    f(GL_R16F, GL_RED, GL_FLOAT) \
+    f(GL_R16F, GL_RED, GL_HALF_FLOAT) \
+    f(GL_R32F, GL_RED, GL_FLOAT) \
+    f(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE) \
+    f(GL_R8I, GL_RED_INTEGER, GL_BYTE) \
+    f(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT) \
+    f(GL_R16I, GL_RED_INTEGER, GL_SHORT) \
+    f(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT) \
+    f(GL_R32I, GL_RED_INTEGER, GL_INT) \
+    f(GL_RG8, GL_RG, GL_UNSIGNED_BYTE) \
+    f(GL_RG8_SNORM, GL_RG, GL_BYTE) \
+    f(GL_RG16F, GL_RG, GL_HALF_FLOAT) \
+    f(GL_RG16F, GL_RG, GL_FLOAT) \
+    f(GL_RG32F, GL_RG, GL_FLOAT) \
+    f(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE) \
+    f(GL_RG8I, GL_RG_INTEGER, GL_BYTE) \
+    f(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT) \
+    f(GL_RG16I, GL_RG_INTEGER, GL_SHORT) \
+    f(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT) \
+    f(GL_RG32I, GL_RG_INTEGER, GL_INT) \
+    f(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE) \
+    f(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE) \
+    f(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE) \
+    f(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5) \
+    f(GL_RGB8_SNORM, GL_RGB, GL_BYTE) \
+    f(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV) \
+    f(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT) \
+    f(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT) \
+    f(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV) \
+    f(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT) \
+    f(GL_RGB9_E5, GL_RGB, GL_FLOAT) \
+    f(GL_RGB16F, GL_RGB, GL_HALF_FLOAT) \
+    f(GL_RGB16F, GL_RGB, GL_FLOAT) \
+    f(GL_RGB32F, GL_RGB, GL_FLOAT) \
+    f(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE) \
+    f(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE) \
+    f(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT) \
+    f(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT) \
+    f(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT) \
+    f(GL_RGB32I, GL_RGB_INTEGER, GL_INT) \
+    f(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE) \
+    f(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1) \
+    f(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV) \
+    f(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4) \
+    f(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV) \
+    f(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT) \
+    f(GL_RGBA16F, GL_RGBA, GL_FLOAT) \
+    f(GL_RGBA32F, GL_RGBA, GL_FLOAT) \
+    f(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE) \
+    f(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE) \
+    f(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV) \
+    f(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT) \
+    f(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT) \
+    f(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT) \
+    f(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT) \
+    f(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT) \
+    f(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT) \
+    f(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT) \
+    f(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT) \
+    f(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8) \
+    f(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV) \
+    f(GL_COMPRESSED_R11_EAC, GL_RED, GL_FLOAT) \
+    f(GL_COMPRESSED_SIGNED_R11_EAC, GL_RED, GL_FLOAT) \
+    f(GL_COMPRESSED_RG11_EAC, GL_RG, GL_FLOAT) \
+    f(GL_COMPRESSED_SIGNED_RG11_EAC, GL_RG, GL_FLOAT) \
+    f(GL_COMPRESSED_RGB8_ETC2, GL_RGB, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ETC2, GL_RGB, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, GL_RGBA, GL_UNSIGNED_BYTE) \
+
 namespace GLESv2Validation {
 
 GLbitfield allBufferMapAccessFlags =
@@ -69,6 +304,24 @@
     }
 }
 
+bool bufferUsage(GL2Encoder* ctx, GLenum usage) {
+    int glesMajorVersion = ctx->majorVersion();
+    switch(usage) {
+        case GL_STREAM_DRAW:
+        case GL_STATIC_DRAW:
+        case GL_DYNAMIC_DRAW:
+            return true;
+        case GL_STREAM_READ:
+        case GL_STATIC_READ:
+        case GL_DYNAMIC_READ:
+        case GL_STREAM_COPY:
+        case GL_STATIC_COPY:
+        case GL_DYNAMIC_COPY:
+            return glesMajorVersion >= 3;
+    }
+    return false;
+
+}
 bool pixelStoreParam(GL2Encoder* ctx, GLenum param) {
     int glesMajorVersion = ctx->majorVersion();
     switch(param) {
@@ -260,6 +513,17 @@
     return false;
 }
 
+bool pixelOp(GLenum format,GLenum type) {
+     switch(type) {
+     case GL_UNSIGNED_SHORT_4_4_4_4:
+     case GL_UNSIGNED_SHORT_5_5_5_1:
+         return format == GL_RGBA;
+     case GL_UNSIGNED_SHORT_5_6_5:
+         return format == GL_RGB;
+     }
+     return true;
+}
+
 bool vertexAttribType(GL2Encoder* ctx, GLenum type)
 {
     int glesMajorVersion = ctx->majorVersion();
@@ -347,32 +611,133 @@
     return false;
 }
 
-static GLsizei ceildiv(GLsizei x, GLsizei y) {
-    return (x + y - 1) / y;
+bool textureParams(GL2Encoder* ctx, GLenum param) {
+    int glesMajorVersion = ctx->majorVersion();
+    int glesMinorVersion = ctx->minorVersion();
+    switch(param) {
+    case GL_TEXTURE_MIN_FILTER:
+    case GL_TEXTURE_MAG_FILTER:
+    case GL_TEXTURE_WRAP_S:
+    case GL_TEXTURE_WRAP_T:
+    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+        return true;
+    case GL_TEXTURE_SWIZZLE_R:
+    case GL_TEXTURE_SWIZZLE_G:
+    case GL_TEXTURE_SWIZZLE_B:
+    case GL_TEXTURE_SWIZZLE_A:
+    case GL_TEXTURE_MIN_LOD:
+    case GL_TEXTURE_MAX_LOD:
+    case GL_TEXTURE_BASE_LEVEL:
+    case GL_TEXTURE_MAX_LEVEL:
+    case GL_TEXTURE_COMPARE_MODE:
+    case GL_TEXTURE_COMPARE_FUNC:
+    case GL_TEXTURE_WRAP_R:
+    case GL_TEXTURE_IMMUTABLE_FORMAT:
+    case GL_TEXTURE_IMMUTABLE_LEVELS:
+        return glesMajorVersion >= 3;
+    case GL_DEPTH_STENCIL_TEXTURE_MODE:
+        return glesMajorVersion >= 3 && glesMinorVersion >= 1;
+    default:
+        return false;
+    }
 }
 
-GLsizei compressedTexImageSize(GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) {
-    GLsizei base_size = ceildiv(width, 4) * ceildiv(height, 4) * depth;
-#define COMPRESSED_TEX_IMAGE_SIZE_CASE(internal, multiplier) \
-    case internal: \
-        return base_size * multiplier; \
-
-    switch (internalformat) {
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_R11_EAC, 8)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_SIGNED_R11_EAC, 8)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_RG11_EAC, 16)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_SIGNED_RG11_EAC, 16)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_RGB8_ETC2, 8)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_SRGB8_ETC2, 8)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 8)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 8)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_RGBA8_ETC2_EAC, 16)
-    COMPRESSED_TEX_IMAGE_SIZE_CASE(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 16)
-    default:
-        break;
+bool samplerParams(GL2Encoder* ctx, GLenum param) {
+    (void)ctx;
+    switch(param) {
+        case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+        case GL_TEXTURE_MIN_FILTER:
+        case GL_TEXTURE_MAG_FILTER:
+        case GL_TEXTURE_WRAP_S:
+        case GL_TEXTURE_WRAP_T:
+        case GL_TEXTURE_WRAP_R:
+        case GL_TEXTURE_MIN_LOD:
+        case GL_TEXTURE_MAX_LOD:
+        case GL_TEXTURE_COMPARE_MODE:
+        case GL_TEXTURE_COMPARE_FUNC:
+            return true;
+        default:
+            return false;
     }
+}
 
-    return 0;
+bool textureParamValue(GL2Encoder* ctx, GLenum pname, GLint intval, GLfloat floatval, GLenum enumval) {
+    (void)ctx;
+    (void)floatval;
+    switch (pname) {
+    case GL_TEXTURE_BASE_LEVEL:
+        return intval >= 0;
+    case GL_TEXTURE_COMPARE_MODE:
+        return
+            (enumval == GL_NONE) ||
+            (enumval == GL_COMPARE_REF_TO_TEXTURE);
+    case GL_TEXTURE_COMPARE_FUNC:
+        return
+            (enumval == GL_LEQUAL) ||
+            (enumval == GL_GEQUAL) ||
+            (enumval == GL_LESS) ||
+            (enumval == GL_GREATER) ||
+            (enumval == GL_EQUAL) ||
+            (enumval == GL_NOTEQUAL) ||
+            (enumval == GL_ALWAYS) ||
+            (enumval == GL_NEVER);
+    case GL_TEXTURE_MAG_FILTER:
+        return
+            (enumval == GL_NEAREST) ||
+            (enumval == GL_LINEAR);
+    case GL_TEXTURE_MAX_LEVEL:
+        return intval >= 0;
+    case GL_TEXTURE_MAX_LOD:
+        return true;
+    case GL_TEXTURE_MIN_FILTER:
+        return
+            (enumval == GL_NEAREST) ||
+            (enumval == GL_LINEAR) ||
+            (enumval == GL_NEAREST_MIPMAP_NEAREST) ||
+            (enumval == GL_NEAREST_MIPMAP_LINEAR) ||
+            (enumval == GL_LINEAR_MIPMAP_NEAREST) ||
+            (enumval == GL_LINEAR_MIPMAP_LINEAR);
+    case GL_TEXTURE_MIN_LOD:
+        return true;
+    case GL_TEXTURE_SWIZZLE_R:
+    case GL_TEXTURE_SWIZZLE_G:
+    case GL_TEXTURE_SWIZZLE_B:
+    case GL_TEXTURE_SWIZZLE_A:
+        return
+            (enumval == GL_RED) ||
+            (enumval == GL_GREEN) ||
+            (enumval == GL_BLUE) ||
+            (enumval == GL_ALPHA) ||
+            (enumval == GL_ZERO) ||
+            (enumval == GL_ONE);
+    case GL_TEXTURE_WRAP_S:
+    case GL_TEXTURE_WRAP_T:
+    case GL_TEXTURE_WRAP_R:
+        return
+            (enumval == GL_CLAMP_TO_EDGE) ||
+            (enumval == GL_REPEAT) ||
+            (enumval == GL_MIRRORED_REPEAT);
+    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
+        return true;
+    case GL_TEXTURE_IMMUTABLE_FORMAT:
+    case GL_TEXTURE_IMMUTABLE_LEVELS:
+    case GL_DEPTH_STENCIL_TEXTURE_MODE:
+        return true;
+    default:
+        return true;
+    }
+}
+
+bool isIntegerFormat(GLenum format) {
+
+#define CHECK_EQUAL(x) case x: return true;
+
+    switch (format) {
+        LIST_INTEGER_TEX_FORMATS(CHECK_EQUAL)
+
+    default:
+        return false;
+    }
 }
 
 bool isCompressedFormat(GLenum internalformat) {
@@ -445,6 +810,7 @@
         return false ; \
 
     switch (internalformat) {
+    COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_ETC1_RGB8_OES, 2, 0)
     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_R11_EAC, 2, 0)
     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_SIGNED_R11_EAC, 2, 0)
     COMPRESSED_TEX_IMAGE_SUPPORT_CASE(GL_COMPRESSED_RG11_EAC, 2, 0)
@@ -486,7 +852,7 @@
     default:
         break;
     }
-    return true;
+    return false;
 }
 
 bool unsizedFormat(GLenum format) {
@@ -730,103 +1096,6 @@
     }
     return false;
 }
-#define LIST_VALID_TEX_INTERNALFORMATS(f) \
-    f(GL_BGRA8_EXT) \
-    f(GL_R8) \
-    f(GL_R8_SNORM) \
-    f(GL_R16F) \
-    f(GL_R32F) \
-    f(GL_R8UI) \
-    f(GL_R8I) \
-    f(GL_R16UI) \
-    f(GL_R16I) \
-    f(GL_R32UI) \
-    f(GL_R32I) \
-    f(GL_RG8) \
-    f(GL_RG8_SNORM) \
-    f(GL_RG16F) \
-    f(GL_RG32F) \
-    f(GL_RG8UI) \
-    f(GL_RG8I) \
-    f(GL_RG16UI) \
-    f(GL_RG16I) \
-    f(GL_RG32UI) \
-    f(GL_RG32I) \
-    f(GL_RGB8) \
-    f(GL_SRGB8) \
-    f(GL_RGB565) \
-    f(GL_RGB8_SNORM) \
-    f(GL_R11F_G11F_B10F) \
-    f(GL_RGB9_E5) \
-    f(GL_RGB16F) \
-    f(GL_RGB32F) \
-    f(GL_RGB8UI) \
-    f(GL_RGB8I) \
-    f(GL_RGB16UI) \
-    f(GL_RGB16I) \
-    f(GL_RGB32UI) \
-    f(GL_RGB32I) \
-    f(GL_RGBA8) \
-    f(GL_SRGB8_ALPHA8) \
-    f(GL_RGBA8_SNORM) \
-    f(GL_RGB5_A1) \
-    f(GL_RGBA4) \
-    f(GL_RGB10_A2) \
-    f(GL_RGBA16F) \
-    f(GL_RGBA32F) \
-    f(GL_RGBA8UI) \
-    f(GL_RGBA8I) \
-    f(GL_RGB10_A2UI) \
-    f(GL_RGBA16UI) \
-    f(GL_RGBA16I) \
-    f(GL_RGBA32I) \
-    f(GL_RGBA32UI) \
-    f(GL_DEPTH_COMPONENT16) \
-    f(GL_DEPTH_COMPONENT24) \
-    f(GL_DEPTH_COMPONENT32F) \
-    f(GL_DEPTH24_STENCIL8) \
-    f(GL_DEPTH32F_STENCIL8) \
-    f(GL_ETC1_RGB8_OES) \
-    f(GL_COMPRESSED_R11_EAC) \
-    f(GL_COMPRESSED_SIGNED_R11_EAC) \
-    f(GL_COMPRESSED_RG11_EAC) \
-    f(GL_COMPRESSED_SIGNED_RG11_EAC) \
-    f(GL_COMPRESSED_RGB8_ETC2) \
-    f(GL_COMPRESSED_SRGB8_ETC2) \
-    f(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2) \
-    f(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2) \
-    f(GL_COMPRESSED_RGBA8_ETC2_EAC) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC) \
-    f(GL_COMPRESSED_RGBA_ASTC_4x4_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_5x4_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_5x5_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_6x5_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_6x6_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_8x5_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_8x6_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_8x8_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_10x5_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_10x6_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_10x8_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_10x10_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_12x10_KHR) \
-    f(GL_COMPRESSED_RGBA_ASTC_12x12_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR) \
-    f(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR) \
-
-
 bool pixelInternalFormat(GLenum internalformat) {
 #define VALID_INTERNAL_FORMAT(format) \
     case format: \
@@ -840,6 +1109,83 @@
     return false;
 }
 
+bool pixelSizedFormat(GL2Encoder* ctx, GLenum internalformat, GLenum format, GLenum type) {
+    int glesMajorVersion = ctx->majorVersion();
+    if (internalformat == format) {
+        return true;
+    }
+
+    if (glesMajorVersion < 3) {
+        switch (format) {
+            case GL_RED:
+                switch (type) {
+                    case GL_UNSIGNED_BYTE:
+                        return internalformat == GL_R8;
+                    case GL_HALF_FLOAT:
+                    case GL_FLOAT:
+                        return internalformat == GL_R16F;
+                    case GL_BYTE:
+                        return internalformat == GL_R8_SNORM;
+                    default:
+                        return false;
+                }
+                break;
+            case GL_RG:
+                switch (type) {
+                    case GL_UNSIGNED_BYTE:
+                        return internalformat == GL_RG8;
+                    case GL_HALF_FLOAT:
+                    case GL_FLOAT:
+                        return internalformat == GL_RG16F;
+                    default:
+                        return false;
+                }
+                break;
+            case GL_RGB:
+                switch (type) {
+                    case GL_HALF_FLOAT:
+                    case GL_FLOAT:
+                        return internalformat == GL_RGB16F
+                            || internalformat == GL_R11F_G11F_B10F;
+                    case GL_UNSIGNED_INT_10F_11F_11F_REV:
+                        return internalformat == GL_R11F_G11F_B10F;
+                    default:
+                        return internalformat == GL_RGB8 ||
+                               internalformat == GL_RGB;
+                }
+                break;
+            case GL_RGBA:
+                switch (type) {
+                    case GL_HALF_FLOAT:
+                    case GL_FLOAT:
+                        return internalformat == GL_RGBA16F;
+                    default:
+                        return internalformat == GL_RGBA8 ||
+                               internalformat == GL_RGBA;
+                }
+                break;
+        }
+    }
+
+#define VALIDATE_FORMAT_COMBINATION(x, y, z) \
+    if (internalformat == x && format == y && type == z) return true; \
+
+    LIST_VALID_TEXFORMAT_COMBINATIONS(VALIDATE_FORMAT_COMBINATION)
+
+    return false;
+}
+
+void getCompatibleFormatTypeForInternalFormat(GLenum internalformat, GLenum* format_out, GLenum* type_out) {
+#define RETURN_COMPATIBLE_FORMAT(x, y, z) \
+    if (internalformat == x) { \
+        *format_out = y; \
+        *type_out = z; \
+        return; \
+    } \
+
+    LIST_VALID_TEXFORMAT_COMBINATIONS(RETURN_COMPATIBLE_FORMAT)
+}
+
 bool shaderType(GL2Encoder* ctx, GLenum type) {
     int glesMajorVersion = ctx->majorVersion();
     int glesMinorVersion = ctx->minorVersion();
@@ -873,4 +1219,323 @@
     return ss.str();
 }
 
+bool allowedFace(GLenum face) {
+    switch (face) {
+        case GL_FRONT:
+        case GL_BACK:
+        case GL_FRONT_AND_BACK:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedFunc(GLenum func) {
+    switch (func) {
+        case GL_NEVER:
+        case GL_ALWAYS:
+        case GL_LESS:
+        case GL_LEQUAL:
+        case GL_EQUAL:
+        case GL_GREATER:
+        case GL_GEQUAL:
+        case GL_NOTEQUAL:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedStencilOp(GLenum op) {
+    switch (op) {
+        case GL_KEEP:
+        case GL_ZERO:
+        case GL_REPLACE:
+        case GL_INCR:
+        case GL_DECR:
+        case GL_INVERT:
+        case GL_INCR_WRAP:
+        case GL_DECR_WRAP:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedBlendEquation(GLenum eq) {
+    switch (eq) {
+        case GL_FUNC_ADD:
+        case GL_FUNC_SUBTRACT:
+        case GL_FUNC_REVERSE_SUBTRACT:
+        case GL_MIN:
+        case GL_MAX:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedBlendFunc(GLenum func) {
+    switch (func) {
+        case GL_ZERO:
+        case GL_ONE:
+        case GL_SRC_COLOR:
+        case GL_ONE_MINUS_SRC_COLOR:
+        case GL_DST_COLOR:
+        case GL_ONE_MINUS_DST_COLOR:
+        case GL_SRC_ALPHA:
+        case GL_ONE_MINUS_SRC_ALPHA:
+        case GL_DST_ALPHA:
+        case GL_ONE_MINUS_DST_ALPHA:
+        case GL_CONSTANT_COLOR:
+        case GL_ONE_MINUS_CONSTANT_COLOR:
+        case GL_CONSTANT_ALPHA:
+        case GL_ONE_MINUS_CONSTANT_ALPHA:
+        case GL_SRC_ALPHA_SATURATE:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedCullFace(GLenum mode) {
+    switch (mode) {
+        case GL_FRONT:
+        case GL_BACK:
+        case GL_FRONT_AND_BACK:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedFrontFace(GLenum mode) {
+    switch (mode) {
+        case GL_CCW:
+        case GL_CW:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedEnable(int majorVersion, int minorVersion, GLenum cap) {
+    switch (cap) {
+        case GL_CULL_FACE:
+        case GL_POLYGON_OFFSET_FILL:
+        case GL_SAMPLE_ALPHA_TO_COVERAGE:
+        case GL_SAMPLE_COVERAGE:
+        case GL_SCISSOR_TEST:
+        case GL_STENCIL_TEST:
+        case GL_DEPTH_TEST:
+        case GL_BLEND:
+        case GL_DITHER:
+            return true;
+        case GL_PRIMITIVE_RESTART_FIXED_INDEX:
+        case GL_RASTERIZER_DISCARD:
+            return majorVersion >= 3;
+        case GL_SAMPLE_MASK:
+            return majorVersion >= 3 && minorVersion >= 1;
+		default:
+			return false;
+    }
+}
+
+bool allowedGetShader(GLenum pname) {
+	switch (pname) {
+		case GL_SHADER_TYPE:
+		case GL_DELETE_STATUS:
+		case GL_COMPILE_STATUS:
+		case GL_INFO_LOG_LENGTH:
+		case GL_SHADER_SOURCE_LENGTH:
+			return true;
+		default:
+			return false;
+	}
+}
+
+bool allowedShaderType(GLenum shadertype) {
+	switch (shadertype) {
+		case GL_VERTEX_SHADER:
+		case GL_FRAGMENT_SHADER:
+            return true;
+		default:
+			return false;
+	}
+}
+
+bool allowedPrecisionType(GLenum precisiontype) {
+	switch (precisiontype) {
+		case GL_LOW_FLOAT:
+		case GL_MEDIUM_FLOAT:
+		case GL_HIGH_FLOAT:
+		case GL_LOW_INT:
+		case GL_MEDIUM_INT:
+		case GL_HIGH_INT:
+            return true;
+		default:
+			return false;
+	}
+}
+
+bool allowedGetProgram(int majorVersion, int minorVersion, GLenum pname) {
+    switch (pname) {
+        case GL_DELETE_STATUS:
+        case GL_LINK_STATUS:
+        case GL_VALIDATE_STATUS:
+        case GL_INFO_LOG_LENGTH:
+        case GL_ATTACHED_SHADERS:
+        case GL_ACTIVE_ATTRIBUTES:
+        case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
+        case GL_ACTIVE_UNIFORMS:
+        case GL_ACTIVE_UNIFORM_MAX_LENGTH:
+            return true;
+        case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
+        case GL_PROGRAM_BINARY_RETRIEVABLE_HINT:
+        case GL_PROGRAM_BINARY_LENGTH:
+        case GL_TRANSFORM_FEEDBACK_VARYINGS:
+        case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
+        case GL_ACTIVE_UNIFORM_BLOCKS:
+        case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
+            return majorVersion > 2;
+        case GL_COMPUTE_WORK_GROUP_SIZE:
+        case GL_PROGRAM_SEPARABLE:
+        case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS:
+            return majorVersion > 2 && minorVersion > 0;
+        default:
+            return false;
+    }
+}
+
+bool allowedGetActiveUniforms(GLenum pname) {
+    switch (pname) {
+        case GL_UNIFORM_TYPE:
+        case GL_UNIFORM_SIZE:
+        case GL_UNIFORM_NAME_LENGTH:
+        case GL_UNIFORM_BLOCK_INDEX:
+        case GL_UNIFORM_OFFSET:
+        case GL_UNIFORM_ARRAY_STRIDE:
+        case GL_UNIFORM_MATRIX_STRIDE:
+        case GL_UNIFORM_IS_ROW_MAJOR:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedGetActiveUniformBlock(GLenum pname) {
+    switch (pname) {
+        case GL_UNIFORM_BLOCK_BINDING:
+        case GL_UNIFORM_BLOCK_DATA_SIZE:
+        case GL_UNIFORM_BLOCK_NAME_LENGTH:
+        case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
+        case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
+        case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
+        case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedGetVertexAttrib(GLenum pname) {
+    switch (pname) {
+        case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
+        case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
+        case GL_VERTEX_ATTRIB_ARRAY_SIZE:
+        case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
+        case GL_VERTEX_ATTRIB_ARRAY_TYPE:
+        case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
+        case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
+        case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
+        case GL_VERTEX_ATTRIB_BINDING:
+        case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
+        case GL_CURRENT_VERTEX_ATTRIB:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedGetRenderbufferParameter(GLenum pname) {
+    switch (pname) {
+        case GL_RENDERBUFFER_WIDTH:
+        case GL_RENDERBUFFER_HEIGHT:
+        case GL_RENDERBUFFER_INTERNAL_FORMAT:
+        case GL_RENDERBUFFER_RED_SIZE:
+        case GL_RENDERBUFFER_GREEN_SIZE:
+        case GL_RENDERBUFFER_BLUE_SIZE:
+        case GL_RENDERBUFFER_ALPHA_SIZE:
+        case GL_RENDERBUFFER_DEPTH_SIZE:
+        case GL_RENDERBUFFER_STENCIL_SIZE:
+        case GL_RENDERBUFFER_SAMPLES:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedQueryTarget(GLenum target) {
+    switch (target) {
+        case GL_ANY_SAMPLES_PASSED:
+        case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
+        case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedQueryParam(GLenum pname) {
+    switch (pname) {
+        case GL_CURRENT_QUERY:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedQueryObjectParam(GLenum pname) {
+    switch (pname) {
+        case GL_QUERY_RESULT:
+        case GL_QUERY_RESULT_AVAILABLE:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedGetSyncParam(GLenum pname) {
+    switch (pname) {
+        case GL_OBJECT_TYPE:
+        case GL_SYNC_STATUS:
+        case GL_SYNC_CONDITION:
+        case GL_SYNC_FLAGS:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedHintTarget(GLenum target) {
+    switch (target) {
+        case GL_GENERATE_MIPMAP_HINT:
+        case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
+            return true;
+        default:
+            return false;
+    }
+}
+
+bool allowedHintMode(GLenum mode) {
+    switch (mode) {
+        case GL_DONT_CARE:
+        case GL_NICEST:
+        case GL_FASTEST:
+            return true;
+        default:
+            return false;
+    }
+}
+
 } // namespace GLESv2Validation
diff --git a/system/GLESv2_enc/GLESv2Validation.h b/system/GLESv2_enc/GLESv2Validation.h
index a37bd58..4ac5787 100644
--- a/system/GLESv2_enc/GLESv2Validation.h
+++ b/system/GLESv2_enc/GLESv2Validation.h
@@ -33,6 +33,7 @@
 extern GLbitfield allBufferMapAccessFlags;
 bool bufferTarget(GL2Encoder* ctx, GLenum target);
 bool bufferParam(GL2Encoder* ctx, GLenum param);
+bool bufferUsage(GL2Encoder* ctx, GLenum usage);
 
 bool pixelStoreParam(GL2Encoder* ctx, GLenum param);
 bool pixelStoreValue(GLenum param, GLint value);
@@ -44,6 +45,7 @@
 
 bool readPixelsFormat(GLenum format);
 bool readPixelsType(GLenum type);
+bool pixelOp(GLenum format, GLenum type);
 
 bool vertexAttribType(GL2Encoder* ctx, GLenum type);
 
@@ -51,9 +53,11 @@
 bool blitFramebufferFormat(GLenum readFormat, GLenum drawFormat);
 
 bool textureTarget(GL2Encoder* ctx, GLenum target);
+bool textureParams(GL2Encoder* ctx, GLenum pname);
+bool samplerParams(GL2Encoder* ctx, GLenum pname);
+bool textureParamValue(GL2Encoder* ctx, GLenum pname, GLint intval, GLfloat floatval, GLenum enumval);
 
-GLsizei compressedTexImageSize(GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
-
+bool isIntegerFormat(GLenum format);
 bool isCompressedFormat(GLenum internalformat);
 bool supportedCompressedFormat(GL2Encoder* ctx, GLenum internalformat);
 
@@ -70,6 +74,8 @@
 bool pixelFormat(GL2Encoder* ctx, GLenum format);
 
 bool pixelInternalFormat(GLenum internalformat);
+bool pixelSizedFormat(GL2Encoder* ctx, GLenum internalformat, GLenum format, GLenum type);
+void getCompatibleFormatTypeForInternalFormat(GLenum internalformat, GLenum* format_out, GLenum* type_out);
 
 bool shaderType(GL2Encoder* ctx, GLenum type);
 
@@ -77,6 +83,40 @@
 
 std::string vertexAttribIndexRangeErrorMsg(GL2Encoder* ctx, GLuint index);
 
+bool allowedFace(GLenum face);
+bool allowedFunc(GLenum func);
+bool allowedStencilOp(GLenum op);
+bool allowedBlendEquation(GLenum eq);
+bool allowedBlendFunc(GLenum func);
+
+bool allowedCullFace(GLenum mode);
+bool allowedFrontFace(GLenum mode);
+
+bool allowedEnable(int majorVersion, int minorVersion, GLenum mode);
+
+bool allowedGetShader(GLenum pname);
+
+bool allowedShaderType(GLenum shadertype);
+bool allowedPrecisionType(GLenum precisiontype);
+
+bool allowedGetProgram(int majorVersion, int minorVersion, GLenum pname);
+
+bool allowedGetActiveUniforms(GLenum pname) ;
+bool allowedGetActiveUniformBlock(GLenum pname) ;
+
+bool allowedGetVertexAttrib(GLenum pname) ;
+
+bool allowedGetRenderbufferParameter(GLenum pname);
+
+bool allowedQueryTarget(GLenum target);
+bool allowedQueryParam(GLenum pname);
+bool allowedQueryObjectParam(GLenum pname);
+
+bool allowedGetSyncParam(GLenum pname);
+
+bool allowedHintTarget(GLenum target);
+bool allowedHintMode(GLenum pname);
+
 } // namespace GLESv2Validation
 
 #endif
diff --git a/system/GLESv2_enc/gl2_enc.cpp b/system/GLESv2_enc/gl2_enc.cpp
index 814021b..d59dbeb 100644
--- a/system/GLESv2_enc/gl2_enc.cpp
+++ b/system/GLESv2_enc/gl2_enc.cpp
@@ -12,6 +12,7 @@
 
 #include <stdio.h>
 
+#include "android/base/Tracing.h"
 namespace {
 
 void enc_unsupported()
@@ -21,6 +22,7 @@
 
 void glActiveTexture_enc(void *self , GLenum texture)
 {
+	AEMU_SCOPED_TRACE("glActiveTexture encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -46,6 +48,7 @@
 
 void glAttachShader_enc(void *self , GLuint program, GLuint shader)
 {
+	AEMU_SCOPED_TRACE("glAttachShader encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -72,6 +75,7 @@
 
 void glBindAttribLocation_enc(void *self , GLuint program, GLuint index, const GLchar* name)
 {
+	AEMU_SCOPED_TRACE("glBindAttribLocation encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -101,6 +105,7 @@
 
 void glBindBuffer_enc(void *self , GLenum target, GLuint buffer)
 {
+	AEMU_SCOPED_TRACE("glBindBuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -127,6 +132,7 @@
 
 void glBindFramebuffer_enc(void *self , GLenum target, GLuint framebuffer)
 {
+	AEMU_SCOPED_TRACE("glBindFramebuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -153,6 +159,7 @@
 
 void glBindRenderbuffer_enc(void *self , GLenum target, GLuint renderbuffer)
 {
+	AEMU_SCOPED_TRACE("glBindRenderbuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -179,6 +186,7 @@
 
 void glBindTexture_enc(void *self , GLenum target, GLuint texture)
 {
+	AEMU_SCOPED_TRACE("glBindTexture encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -205,6 +213,7 @@
 
 void glBlendColor_enc(void *self , GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
 {
+	AEMU_SCOPED_TRACE("glBlendColor encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -233,6 +242,7 @@
 
 void glBlendEquation_enc(void *self , GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glBlendEquation encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -258,6 +268,7 @@
 
 void glBlendEquationSeparate_enc(void *self , GLenum modeRGB, GLenum modeAlpha)
 {
+	AEMU_SCOPED_TRACE("glBlendEquationSeparate encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -284,6 +295,7 @@
 
 void glBlendFunc_enc(void *self , GLenum sfactor, GLenum dfactor)
 {
+	AEMU_SCOPED_TRACE("glBlendFunc encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -310,6 +322,7 @@
 
 void glBlendFuncSeparate_enc(void *self , GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
 {
+	AEMU_SCOPED_TRACE("glBlendFuncSeparate encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -338,6 +351,7 @@
 
 void glBufferData_enc(void *self , GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
 {
+	AEMU_SCOPED_TRACE("glBufferData encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -378,6 +392,7 @@
 
 void glBufferSubData_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glBufferSubData encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -414,6 +429,7 @@
 
 GLenum glCheckFramebufferStatus_enc(void *self , GLenum target)
 {
+	AEMU_SCOPED_TRACE("glCheckFramebufferStatus encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -454,6 +470,7 @@
 
 void glClear_enc(void *self , GLbitfield mask)
 {
+	AEMU_SCOPED_TRACE("glClear encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -479,6 +496,7 @@
 
 void glClearColor_enc(void *self , GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
 {
+	AEMU_SCOPED_TRACE("glClearColor encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -507,6 +525,7 @@
 
 void glClearDepthf_enc(void *self , GLclampf depth)
 {
+	AEMU_SCOPED_TRACE("glClearDepthf encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -532,6 +551,7 @@
 
 void glClearStencil_enc(void *self , GLint s)
 {
+	AEMU_SCOPED_TRACE("glClearStencil encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -557,6 +577,7 @@
 
 void glColorMask_enc(void *self , GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
 {
+	AEMU_SCOPED_TRACE("glColorMask encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -585,6 +606,7 @@
 
 void glCompileShader_enc(void *self , GLuint shader)
 {
+	AEMU_SCOPED_TRACE("glCompileShader encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -610,6 +632,7 @@
 
 void glCompressedTexImage2D_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexImage2D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -650,6 +673,7 @@
 
 void glCompressedTexSubImage2D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexSubImage2D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -691,6 +715,7 @@
 
 void glCopyTexImage2D_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
 {
+	AEMU_SCOPED_TRACE("glCopyTexImage2D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -723,6 +748,7 @@
 
 void glCopyTexSubImage2D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glCopyTexSubImage2D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -755,6 +781,7 @@
 
 GLuint glCreateProgram_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glCreateProgram encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -794,6 +821,7 @@
 
 GLuint glCreateShader_enc(void *self , GLenum type)
 {
+	AEMU_SCOPED_TRACE("glCreateShader encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -834,6 +862,7 @@
 
 void glCullFace_enc(void *self , GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glCullFace encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -859,6 +888,7 @@
 
 void glDeleteBuffers_enc(void *self , GLsizei n, const GLuint* buffers)
 {
+	AEMU_SCOPED_TRACE("glDeleteBuffers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -887,6 +917,7 @@
 
 void glDeleteFramebuffers_enc(void *self , GLsizei n, const GLuint* framebuffers)
 {
+	AEMU_SCOPED_TRACE("glDeleteFramebuffers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -915,6 +946,7 @@
 
 void glDeleteProgram_enc(void *self , GLuint program)
 {
+	AEMU_SCOPED_TRACE("glDeleteProgram encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -940,6 +972,7 @@
 
 void glDeleteRenderbuffers_enc(void *self , GLsizei n, const GLuint* renderbuffers)
 {
+	AEMU_SCOPED_TRACE("glDeleteRenderbuffers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -968,6 +1001,7 @@
 
 void glDeleteShader_enc(void *self , GLuint shader)
 {
+	AEMU_SCOPED_TRACE("glDeleteShader encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -993,6 +1027,7 @@
 
 void glDeleteTextures_enc(void *self , GLsizei n, const GLuint* textures)
 {
+	AEMU_SCOPED_TRACE("glDeleteTextures encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1021,6 +1056,7 @@
 
 void glDepthFunc_enc(void *self , GLenum func)
 {
+	AEMU_SCOPED_TRACE("glDepthFunc encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1046,6 +1082,7 @@
 
 void glDepthMask_enc(void *self , GLboolean flag)
 {
+	AEMU_SCOPED_TRACE("glDepthMask encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1071,6 +1108,7 @@
 
 void glDepthRangef_enc(void *self , GLclampf zNear, GLclampf zFar)
 {
+	AEMU_SCOPED_TRACE("glDepthRangef encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1097,6 +1135,7 @@
 
 void glDetachShader_enc(void *self , GLuint program, GLuint shader)
 {
+	AEMU_SCOPED_TRACE("glDetachShader encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1123,6 +1162,7 @@
 
 void glDisable_enc(void *self , GLenum cap)
 {
+	AEMU_SCOPED_TRACE("glDisable encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1148,6 +1188,7 @@
 
 void glDisableVertexAttribArray_enc(void *self , GLuint index)
 {
+	AEMU_SCOPED_TRACE("glDisableVertexAttribArray encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1173,6 +1214,7 @@
 
 void glDrawArrays_enc(void *self , GLenum mode, GLint first, GLsizei count)
 {
+	AEMU_SCOPED_TRACE("glDrawArrays encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1200,6 +1242,7 @@
 
 void glEnable_enc(void *self , GLenum cap)
 {
+	AEMU_SCOPED_TRACE("glEnable encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1225,6 +1268,7 @@
 
 void glEnableVertexAttribArray_enc(void *self , GLuint index)
 {
+	AEMU_SCOPED_TRACE("glEnableVertexAttribArray encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1250,6 +1294,7 @@
 
 void glFinish_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glFinish encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1274,6 +1319,7 @@
 
 void glFlush_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glFlush encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1298,6 +1344,7 @@
 
 void glFramebufferRenderbuffer_enc(void *self , GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
 {
+	AEMU_SCOPED_TRACE("glFramebufferRenderbuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1326,6 +1373,7 @@
 
 void glFramebufferTexture2D_enc(void *self , GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
 {
+	AEMU_SCOPED_TRACE("glFramebufferTexture2D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1355,6 +1403,7 @@
 
 void glFrontFace_enc(void *self , GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glFrontFace encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1380,6 +1429,7 @@
 
 void glGenBuffers_enc(void *self , GLsizei n, GLuint* buffers)
 {
+	AEMU_SCOPED_TRACE("glGenBuffers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1419,6 +1469,7 @@
 
 void glGenerateMipmap_enc(void *self , GLenum target)
 {
+	AEMU_SCOPED_TRACE("glGenerateMipmap encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1444,6 +1495,7 @@
 
 void glGenFramebuffers_enc(void *self , GLsizei n, GLuint* framebuffers)
 {
+	AEMU_SCOPED_TRACE("glGenFramebuffers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1483,6 +1535,7 @@
 
 void glGenRenderbuffers_enc(void *self , GLsizei n, GLuint* renderbuffers)
 {
+	AEMU_SCOPED_TRACE("glGenRenderbuffers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1522,6 +1575,7 @@
 
 void glGenTextures_enc(void *self , GLsizei n, GLuint* textures)
 {
+	AEMU_SCOPED_TRACE("glGenTextures encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1561,6 +1615,7 @@
 
 void glGetActiveAttrib_enc(void *self , GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
 {
+	AEMU_SCOPED_TRACE("glGetActiveAttrib encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1622,6 +1677,7 @@
 
 void glGetActiveUniform_enc(void *self , GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
 {
+	AEMU_SCOPED_TRACE("glGetActiveUniform encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1683,6 +1739,7 @@
 
 void glGetAttachedShaders_enc(void *self , GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
 {
+	AEMU_SCOPED_TRACE("glGetAttachedShaders encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1729,6 +1786,7 @@
 
 int glGetAttribLocation_enc(void *self , GLuint program, const GLchar* name)
 {
+	AEMU_SCOPED_TRACE("glGetAttribLocation encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1772,6 +1830,7 @@
 
 void glGetBooleanv_enc(void *self , GLenum pname, GLboolean* params)
 {
+	AEMU_SCOPED_TRACE("glGetBooleanv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1811,6 +1870,7 @@
 
 void glGetBufferParameteriv_enc(void *self , GLenum target, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetBufferParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1851,6 +1911,7 @@
 
 GLenum glGetError_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glGetError encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1890,6 +1951,7 @@
 
 void glGetFloatv_enc(void *self , GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetFloatv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1929,6 +1991,7 @@
 
 void glGetFramebufferAttachmentParameteriv_enc(void *self , GLenum target, GLenum attachment, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetFramebufferAttachmentParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1970,6 +2033,7 @@
 
 void glGetIntegerv_enc(void *self , GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetIntegerv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2009,6 +2073,7 @@
 
 void glGetProgramiv_enc(void *self , GLuint program, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetProgramiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2049,6 +2114,7 @@
 
 void glGetProgramInfoLog_enc(void *self , GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
 {
+	AEMU_SCOPED_TRACE("glGetProgramInfoLog encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2095,6 +2161,7 @@
 
 void glGetRenderbufferParameteriv_enc(void *self , GLenum target, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetRenderbufferParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2135,6 +2202,7 @@
 
 void glGetShaderiv_enc(void *self , GLuint shader, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetShaderiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2175,6 +2243,7 @@
 
 void glGetShaderInfoLog_enc(void *self , GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
 {
+	AEMU_SCOPED_TRACE("glGetShaderInfoLog encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2221,6 +2290,7 @@
 
 void glGetShaderPrecisionFormat_enc(void *self , GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
 {
+	AEMU_SCOPED_TRACE("glGetShaderPrecisionFormat encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2265,6 +2335,7 @@
 
 void glGetShaderSource_enc(void *self , GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
 {
+	AEMU_SCOPED_TRACE("glGetShaderSource encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2311,6 +2382,7 @@
 
 void glGetTexParameterfv_enc(void *self , GLenum target, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexParameterfv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2351,6 +2423,7 @@
 
 void glGetTexParameteriv_enc(void *self , GLenum target, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2391,6 +2464,7 @@
 
 void glGetUniformfv_enc(void *self , GLuint program, GLint location, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetUniformfv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2431,6 +2505,7 @@
 
 void glGetUniformiv_enc(void *self , GLuint program, GLint location, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetUniformiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2471,6 +2546,7 @@
 
 int glGetUniformLocation_enc(void *self , GLuint program, const GLchar* name)
 {
+	AEMU_SCOPED_TRACE("glGetUniformLocation encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2514,6 +2590,7 @@
 
 void glGetVertexAttribfv_enc(void *self , GLuint index, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetVertexAttribfv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2554,6 +2631,7 @@
 
 void glGetVertexAttribiv_enc(void *self , GLuint index, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetVertexAttribiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2594,6 +2672,7 @@
 
 void glHint_enc(void *self , GLenum target, GLenum mode)
 {
+	AEMU_SCOPED_TRACE("glHint encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2620,6 +2699,7 @@
 
 GLboolean glIsBuffer_enc(void *self , GLuint buffer)
 {
+	AEMU_SCOPED_TRACE("glIsBuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2660,6 +2740,7 @@
 
 GLboolean glIsEnabled_enc(void *self , GLenum cap)
 {
+	AEMU_SCOPED_TRACE("glIsEnabled encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2700,6 +2781,7 @@
 
 GLboolean glIsFramebuffer_enc(void *self , GLuint framebuffer)
 {
+	AEMU_SCOPED_TRACE("glIsFramebuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2740,6 +2822,7 @@
 
 GLboolean glIsProgram_enc(void *self , GLuint program)
 {
+	AEMU_SCOPED_TRACE("glIsProgram encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2780,6 +2863,7 @@
 
 GLboolean glIsRenderbuffer_enc(void *self , GLuint renderbuffer)
 {
+	AEMU_SCOPED_TRACE("glIsRenderbuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2820,6 +2904,7 @@
 
 GLboolean glIsShader_enc(void *self , GLuint shader)
 {
+	AEMU_SCOPED_TRACE("glIsShader encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2860,6 +2945,7 @@
 
 GLboolean glIsTexture_enc(void *self , GLuint texture)
 {
+	AEMU_SCOPED_TRACE("glIsTexture encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2900,6 +2986,7 @@
 
 void glLineWidth_enc(void *self , GLfloat width)
 {
+	AEMU_SCOPED_TRACE("glLineWidth encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2925,6 +3012,7 @@
 
 void glLinkProgram_enc(void *self , GLuint program)
 {
+	AEMU_SCOPED_TRACE("glLinkProgram encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2950,6 +3038,7 @@
 
 void glPixelStorei_enc(void *self , GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glPixelStorei encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -2976,6 +3065,7 @@
 
 void glPolygonOffset_enc(void *self , GLfloat factor, GLfloat units)
 {
+	AEMU_SCOPED_TRACE("glPolygonOffset encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3002,6 +3092,7 @@
 
 void glReadPixels_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels)
 {
+	AEMU_SCOPED_TRACE("glReadPixels encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3046,6 +3137,7 @@
 
 void glReleaseShaderCompiler_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glReleaseShaderCompiler encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3070,6 +3162,7 @@
 
 void glRenderbufferStorage_enc(void *self , GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glRenderbufferStorage encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3098,6 +3191,7 @@
 
 void glSampleCoverage_enc(void *self , GLclampf value, GLboolean invert)
 {
+	AEMU_SCOPED_TRACE("glSampleCoverage encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3124,6 +3218,7 @@
 
 void glScissor_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glScissor encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3152,6 +3247,7 @@
 
 void glStencilFunc_enc(void *self , GLenum func, GLint ref, GLuint mask)
 {
+	AEMU_SCOPED_TRACE("glStencilFunc encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3179,6 +3275,7 @@
 
 void glStencilFuncSeparate_enc(void *self , GLenum face, GLenum func, GLint ref, GLuint mask)
 {
+	AEMU_SCOPED_TRACE("glStencilFuncSeparate encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3207,6 +3304,7 @@
 
 void glStencilMask_enc(void *self , GLuint mask)
 {
+	AEMU_SCOPED_TRACE("glStencilMask encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3232,6 +3330,7 @@
 
 void glStencilMaskSeparate_enc(void *self , GLenum face, GLuint mask)
 {
+	AEMU_SCOPED_TRACE("glStencilMaskSeparate encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3258,6 +3357,7 @@
 
 void glStencilOp_enc(void *self , GLenum fail, GLenum zfail, GLenum zpass)
 {
+	AEMU_SCOPED_TRACE("glStencilOp encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3285,6 +3385,7 @@
 
 void glStencilOpSeparate_enc(void *self , GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
 {
+	AEMU_SCOPED_TRACE("glStencilOpSeparate encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3313,6 +3414,7 @@
 
 void glTexImage2D_enc(void *self , GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
 {
+	AEMU_SCOPED_TRACE("glTexImage2D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3354,6 +3456,7 @@
 
 void glTexParameterf_enc(void *self , GLenum target, GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glTexParameterf encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3381,6 +3484,7 @@
 
 void glTexParameterfv_enc(void *self , GLenum target, GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glTexParameterfv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3410,6 +3514,7 @@
 
 void glTexParameteri_enc(void *self , GLenum target, GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glTexParameteri encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3437,6 +3542,7 @@
 
 void glTexParameteriv_enc(void *self , GLenum target, GLenum pname, const GLint* params)
 {
+	AEMU_SCOPED_TRACE("glTexParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3466,6 +3572,7 @@
 
 void glTexSubImage2D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels)
 {
+	AEMU_SCOPED_TRACE("glTexSubImage2D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3507,6 +3614,7 @@
 
 void glUniform1f_enc(void *self , GLint location, GLfloat x)
 {
+	AEMU_SCOPED_TRACE("glUniform1f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3533,6 +3641,7 @@
 
 void glUniform1fv_enc(void *self , GLint location, GLsizei count, const GLfloat* v)
 {
+	AEMU_SCOPED_TRACE("glUniform1fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3562,6 +3671,7 @@
 
 void glUniform1i_enc(void *self , GLint location, GLint x)
 {
+	AEMU_SCOPED_TRACE("glUniform1i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3588,6 +3698,7 @@
 
 void glUniform1iv_enc(void *self , GLint location, GLsizei count, const GLint* v)
 {
+	AEMU_SCOPED_TRACE("glUniform1iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3617,6 +3728,7 @@
 
 void glUniform2f_enc(void *self , GLint location, GLfloat x, GLfloat y)
 {
+	AEMU_SCOPED_TRACE("glUniform2f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3644,6 +3756,7 @@
 
 void glUniform2fv_enc(void *self , GLint location, GLsizei count, const GLfloat* v)
 {
+	AEMU_SCOPED_TRACE("glUniform2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3673,6 +3786,7 @@
 
 void glUniform2i_enc(void *self , GLint location, GLint x, GLint y)
 {
+	AEMU_SCOPED_TRACE("glUniform2i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3700,6 +3814,7 @@
 
 void glUniform2iv_enc(void *self , GLint location, GLsizei count, const GLint* v)
 {
+	AEMU_SCOPED_TRACE("glUniform2iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3729,6 +3844,7 @@
 
 void glUniform3f_enc(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z)
 {
+	AEMU_SCOPED_TRACE("glUniform3f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3757,6 +3873,7 @@
 
 void glUniform3fv_enc(void *self , GLint location, GLsizei count, const GLfloat* v)
 {
+	AEMU_SCOPED_TRACE("glUniform3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3786,6 +3903,7 @@
 
 void glUniform3i_enc(void *self , GLint location, GLint x, GLint y, GLint z)
 {
+	AEMU_SCOPED_TRACE("glUniform3i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3814,6 +3932,7 @@
 
 void glUniform3iv_enc(void *self , GLint location, GLsizei count, const GLint* v)
 {
+	AEMU_SCOPED_TRACE("glUniform3iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3843,6 +3962,7 @@
 
 void glUniform4f_enc(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
 {
+	AEMU_SCOPED_TRACE("glUniform4f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3872,6 +3992,7 @@
 
 void glUniform4fv_enc(void *self , GLint location, GLsizei count, const GLfloat* v)
 {
+	AEMU_SCOPED_TRACE("glUniform4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3901,6 +4022,7 @@
 
 void glUniform4i_enc(void *self , GLint location, GLint x, GLint y, GLint z, GLint w)
 {
+	AEMU_SCOPED_TRACE("glUniform4i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3930,6 +4052,7 @@
 
 void glUniform4iv_enc(void *self , GLint location, GLsizei count, const GLint* v)
 {
+	AEMU_SCOPED_TRACE("glUniform4iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3959,6 +4082,7 @@
 
 void glUniformMatrix2fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -3989,6 +4113,7 @@
 
 void glUniformMatrix3fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4019,6 +4144,7 @@
 
 void glUniformMatrix4fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4049,6 +4175,7 @@
 
 void glUseProgram_enc(void *self , GLuint program)
 {
+	AEMU_SCOPED_TRACE("glUseProgram encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4074,6 +4201,7 @@
 
 void glValidateProgram_enc(void *self , GLuint program)
 {
+	AEMU_SCOPED_TRACE("glValidateProgram encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4099,6 +4227,7 @@
 
 void glVertexAttrib1f_enc(void *self , GLuint indx, GLfloat x)
 {
+	AEMU_SCOPED_TRACE("glVertexAttrib1f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4125,6 +4254,7 @@
 
 void glVertexAttrib1fv_enc(void *self , GLuint indx, const GLfloat* values)
 {
+	AEMU_SCOPED_TRACE("glVertexAttrib1fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4153,6 +4283,7 @@
 
 void glVertexAttrib2f_enc(void *self , GLuint indx, GLfloat x, GLfloat y)
 {
+	AEMU_SCOPED_TRACE("glVertexAttrib2f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4180,6 +4311,7 @@
 
 void glVertexAttrib2fv_enc(void *self , GLuint indx, const GLfloat* values)
 {
+	AEMU_SCOPED_TRACE("glVertexAttrib2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4208,6 +4340,7 @@
 
 void glVertexAttrib3f_enc(void *self , GLuint indx, GLfloat x, GLfloat y, GLfloat z)
 {
+	AEMU_SCOPED_TRACE("glVertexAttrib3f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4236,6 +4369,7 @@
 
 void glVertexAttrib3fv_enc(void *self , GLuint indx, const GLfloat* values)
 {
+	AEMU_SCOPED_TRACE("glVertexAttrib3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4264,6 +4398,7 @@
 
 void glVertexAttrib4f_enc(void *self , GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
 {
+	AEMU_SCOPED_TRACE("glVertexAttrib4f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4293,6 +4428,7 @@
 
 void glVertexAttrib4fv_enc(void *self , GLuint indx, const GLfloat* values)
 {
+	AEMU_SCOPED_TRACE("glVertexAttrib4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4321,6 +4457,7 @@
 
 void glViewport_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glViewport encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4349,6 +4486,7 @@
 
 void glEGLImageTargetTexture2DOES_enc(void *self , GLenum target, GLeglImageOES image)
 {
+	AEMU_SCOPED_TRACE("glEGLImageTargetTexture2DOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4375,6 +4513,7 @@
 
 void glEGLImageTargetRenderbufferStorageOES_enc(void *self , GLenum target, GLeglImageOES image)
 {
+	AEMU_SCOPED_TRACE("glEGLImageTargetRenderbufferStorageOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4401,6 +4540,7 @@
 
 GLboolean glUnmapBufferOES_enc(void *self , GLenum target)
 {
+	AEMU_SCOPED_TRACE("glUnmapBufferOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4441,6 +4581,7 @@
 
 void glTexImage3DOES_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
 {
+	AEMU_SCOPED_TRACE("glTexImage3DOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4483,6 +4624,7 @@
 
 void glTexSubImage3DOES_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels)
 {
+	AEMU_SCOPED_TRACE("glTexSubImage3DOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4526,6 +4668,7 @@
 
 void glCopyTexSubImage3DOES_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glCopyTexSubImage3DOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4559,6 +4702,7 @@
 
 void glCompressedTexImage3DOES_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexImage3DOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4600,6 +4744,7 @@
 
 void glCompressedTexSubImage3DOES_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexSubImage3DOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4643,6 +4788,7 @@
 
 void glFramebufferTexture3DOES_enc(void *self , GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset)
 {
+	AEMU_SCOPED_TRACE("glFramebufferTexture3DOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4673,6 +4819,7 @@
 
 void glBindVertexArrayOES_enc(void *self , GLuint array)
 {
+	AEMU_SCOPED_TRACE("glBindVertexArrayOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4698,6 +4845,7 @@
 
 void glDeleteVertexArraysOES_enc(void *self , GLsizei n, const GLuint* arrays)
 {
+	AEMU_SCOPED_TRACE("glDeleteVertexArraysOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4726,6 +4874,7 @@
 
 void glGenVertexArraysOES_enc(void *self , GLsizei n, GLuint* arrays)
 {
+	AEMU_SCOPED_TRACE("glGenVertexArraysOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4765,6 +4914,7 @@
 
 GLboolean glIsVertexArrayOES_enc(void *self , GLuint array)
 {
+	AEMU_SCOPED_TRACE("glIsVertexArrayOES encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4805,6 +4955,7 @@
 
 void glDiscardFramebufferEXT_enc(void *self , GLenum target, GLsizei numAttachments, const GLenum* attachments)
 {
+	AEMU_SCOPED_TRACE("glDiscardFramebufferEXT encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4834,6 +4985,7 @@
 
 void glVertexAttribPointerData_enc(void *self , GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribPointerData encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4867,6 +5019,7 @@
 
 void glVertexAttribPointerOffset_enc(void *self , GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribPointerOffset encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4897,6 +5050,7 @@
 
 void glDrawElementsOffset_enc(void *self , GLenum mode, GLsizei count, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsOffset encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4925,6 +5079,7 @@
 
 void glDrawElementsData_enc(void *self , GLenum mode, GLsizei count, GLenum type, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsData encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4956,6 +5111,7 @@
 
 void glGetCompressedTextureFormats_enc(void *self , int count, GLint* formats)
 {
+	AEMU_SCOPED_TRACE("glGetCompressedTextureFormats encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -4995,6 +5151,7 @@
 
 void glShaderString_enc(void *self , GLuint shader, const GLchar* string, GLsizei len)
 {
+	AEMU_SCOPED_TRACE("glShaderString encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5024,6 +5181,7 @@
 
 int glFinishRoundTrip_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glFinishRoundTrip encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5063,6 +5221,7 @@
 
 void glGenVertexArrays_enc(void *self , GLsizei n, GLuint* arrays)
 {
+	AEMU_SCOPED_TRACE("glGenVertexArrays encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5102,6 +5261,7 @@
 
 void glBindVertexArray_enc(void *self , GLuint array)
 {
+	AEMU_SCOPED_TRACE("glBindVertexArray encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5127,6 +5287,7 @@
 
 void glDeleteVertexArrays_enc(void *self , GLsizei n, const GLuint* arrays)
 {
+	AEMU_SCOPED_TRACE("glDeleteVertexArrays encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5155,6 +5316,7 @@
 
 GLboolean glIsVertexArray_enc(void *self , GLuint array)
 {
+	AEMU_SCOPED_TRACE("glIsVertexArray encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5195,6 +5357,7 @@
 
 void glMapBufferRangeAEMU_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, void* mapped)
 {
+	AEMU_SCOPED_TRACE("glMapBufferRangeAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5239,6 +5402,7 @@
 
 void glUnmapBufferAEMU_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, void* guest_buffer, GLboolean* out_res)
 {
+	AEMU_SCOPED_TRACE("glUnmapBufferAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5284,6 +5448,7 @@
 
 void glFlushMappedBufferRangeAEMU_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, void* guest_buffer)
 {
+	AEMU_SCOPED_TRACE("glFlushMappedBufferRangeAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5315,6 +5480,7 @@
 
 void glReadPixelsOffsetAEMU_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glReadPixelsOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5346,6 +5512,7 @@
 
 void glCompressedTexImage2DOffsetAEMU_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexImage2DOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5378,6 +5545,7 @@
 
 void glCompressedTexSubImage2DOffsetAEMU_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexSubImage2DOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5411,6 +5579,7 @@
 
 void glTexImage2DOffsetAEMU_enc(void *self , GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glTexImage2DOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5444,6 +5613,7 @@
 
 void glTexSubImage2DOffsetAEMU_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glTexSubImage2DOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5477,6 +5647,7 @@
 
 void glBindBufferRange_enc(void *self , GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
 {
+	AEMU_SCOPED_TRACE("glBindBufferRange encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5506,6 +5677,7 @@
 
 void glBindBufferBase_enc(void *self , GLenum target, GLuint index, GLuint buffer)
 {
+	AEMU_SCOPED_TRACE("glBindBufferBase encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5533,6 +5705,7 @@
 
 void glCopyBufferSubData_enc(void *self , GLenum readtarget, GLenum writetarget, GLintptr readoffset, GLintptr writeoffset, GLsizeiptr size)
 {
+	AEMU_SCOPED_TRACE("glCopyBufferSubData encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5563,6 +5736,7 @@
 
 void glClearBufferiv_enc(void *self , GLenum buffer, GLint drawBuffer, const GLint* value)
 {
+	AEMU_SCOPED_TRACE("glClearBufferiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5592,6 +5766,7 @@
 
 void glClearBufferuiv_enc(void *self , GLenum buffer, GLint drawBuffer, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glClearBufferuiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5621,6 +5796,7 @@
 
 void glClearBufferfv_enc(void *self , GLenum buffer, GLint drawBuffer, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glClearBufferfv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5650,6 +5826,7 @@
 
 void glClearBufferfi_enc(void *self , GLenum buffer, GLint drawBuffer, GLfloat depth, GLint stencil)
 {
+	AEMU_SCOPED_TRACE("glClearBufferfi encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5678,6 +5855,7 @@
 
 void glUniformBlockBinding_enc(void *self , GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
 {
+	AEMU_SCOPED_TRACE("glUniformBlockBinding encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5705,6 +5883,7 @@
 
 GLuint glGetUniformBlockIndex_enc(void *self , GLuint program, const GLchar* uniformBlockName)
 {
+	AEMU_SCOPED_TRACE("glGetUniformBlockIndex encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5748,6 +5927,7 @@
 
 void glGetUniformIndicesAEMU_enc(void *self , GLuint program, GLsizei uniformCount, const GLchar* packedUniformNames, GLsizei packedLen, GLuint* uniformIndices)
 {
+	AEMU_SCOPED_TRACE("glGetUniformIndicesAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5792,6 +5972,7 @@
 
 void glGetActiveUniformBlockiv_enc(void *self , GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetActiveUniformBlockiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5833,6 +6014,7 @@
 
 void glGetActiveUniformBlockName_enc(void *self , GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
 {
+	AEMU_SCOPED_TRACE("glGetActiveUniformBlockName encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5882,6 +6064,7 @@
 
 void glUniform1ui_enc(void *self , GLint location, GLuint v0)
 {
+	AEMU_SCOPED_TRACE("glUniform1ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5908,6 +6091,7 @@
 
 void glUniform2ui_enc(void *self , GLint location, GLuint v0, GLuint v1)
 {
+	AEMU_SCOPED_TRACE("glUniform2ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5935,6 +6119,7 @@
 
 void glUniform3ui_enc(void *self , GLint location, GLuint v0, GLuint v1, GLuint v2)
 {
+	AEMU_SCOPED_TRACE("glUniform3ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5963,6 +6148,7 @@
 
 void glUniform4ui_enc(void *self , GLint location, GLint v0, GLuint v1, GLuint v2, GLuint v3)
 {
+	AEMU_SCOPED_TRACE("glUniform4ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -5992,6 +6178,7 @@
 
 void glUniform1uiv_enc(void *self , GLint location, GLsizei count, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glUniform1uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6021,6 +6208,7 @@
 
 void glUniform2uiv_enc(void *self , GLint location, GLsizei count, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glUniform2uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6050,6 +6238,7 @@
 
 void glUniform3uiv_enc(void *self , GLint location, GLsizei count, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glUniform3uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6079,6 +6268,7 @@
 
 void glUniform4uiv_enc(void *self , GLint location, GLsizei count, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glUniform4uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6108,6 +6298,7 @@
 
 void glUniformMatrix2x3fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix2x3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6138,6 +6329,7 @@
 
 void glUniformMatrix3x2fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix3x2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6168,6 +6360,7 @@
 
 void glUniformMatrix2x4fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix2x4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6198,6 +6391,7 @@
 
 void glUniformMatrix4x2fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix4x2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6228,6 +6422,7 @@
 
 void glUniformMatrix3x4fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix3x4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6258,6 +6453,7 @@
 
 void glUniformMatrix4x3fv_enc(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glUniformMatrix4x3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6288,6 +6484,7 @@
 
 void glGetUniformuiv_enc(void *self , GLuint program, GLint location, GLuint* params)
 {
+	AEMU_SCOPED_TRACE("glGetUniformuiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6328,6 +6525,7 @@
 
 void glGetActiveUniformsiv_enc(void *self , GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetActiveUniformsiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6372,6 +6570,7 @@
 
 void glVertexAttribI4i_enc(void *self , GLuint index, GLint v0, GLint v1, GLint v2, GLint v3)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribI4i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6401,6 +6600,7 @@
 
 void glVertexAttribI4ui_enc(void *self , GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribI4ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6430,6 +6630,7 @@
 
 void glVertexAttribI4iv_enc(void *self , GLuint index, const GLint* v)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribI4iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6458,6 +6659,7 @@
 
 void glVertexAttribI4uiv_enc(void *self , GLuint index, const GLuint* v)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribI4uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6486,6 +6688,7 @@
 
 void glVertexAttribIPointerOffsetAEMU_enc(void *self , GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribIPointerOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6515,6 +6718,7 @@
 
 void glVertexAttribIPointerDataAEMU_enc(void *self , GLuint index, GLint size, GLenum type, GLsizei stride, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribIPointerDataAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6547,6 +6751,7 @@
 
 void glGetVertexAttribIiv_enc(void *self , GLuint index, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetVertexAttribIiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6587,6 +6792,7 @@
 
 void glGetVertexAttribIuiv_enc(void *self , GLuint index, GLenum pname, GLuint* params)
 {
+	AEMU_SCOPED_TRACE("glGetVertexAttribIuiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6627,6 +6833,7 @@
 
 void glVertexAttribDivisor_enc(void *self , GLuint index, GLuint divisor)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribDivisor encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6653,6 +6860,7 @@
 
 void glDrawArraysInstanced_enc(void *self , GLenum mode, GLint first, GLsizei count, GLsizei primcount)
 {
+	AEMU_SCOPED_TRACE("glDrawArraysInstanced encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6681,6 +6889,7 @@
 
 void glDrawElementsInstancedDataAEMU_enc(void *self , GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei primcount, GLsizei datalen)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsInstancedDataAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6713,6 +6922,7 @@
 
 void glDrawElementsInstancedOffsetAEMU_enc(void *self , GLenum mode, GLsizei count, GLenum type, GLuint offset, GLsizei primcount)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsInstancedOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6742,6 +6952,7 @@
 
 void glDrawRangeElementsDataAEMU_enc(void *self , GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices, GLsizei datalen)
 {
+	AEMU_SCOPED_TRACE("glDrawRangeElementsDataAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6775,6 +6986,7 @@
 
 void glDrawRangeElementsOffsetAEMU_enc(void *self , GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glDrawRangeElementsOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6805,6 +7017,7 @@
 
 uint64_t glFenceSyncAEMU_enc(void *self , GLenum condition, GLbitfield flags)
 {
+	AEMU_SCOPED_TRACE("glFenceSyncAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6846,6 +7059,7 @@
 
 GLenum glClientWaitSyncAEMU_enc(void *self , uint64_t wait_on, GLbitfield flags, GLuint64 timeout)
 {
+	AEMU_SCOPED_TRACE("glClientWaitSyncAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6888,6 +7102,7 @@
 
 void glWaitSyncAEMU_enc(void *self , uint64_t wait_on, GLbitfield flags, GLuint64 timeout)
 {
+	AEMU_SCOPED_TRACE("glWaitSyncAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6915,6 +7130,7 @@
 
 void glDeleteSyncAEMU_enc(void *self , uint64_t to_delete)
 {
+	AEMU_SCOPED_TRACE("glDeleteSyncAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6940,6 +7156,7 @@
 
 GLboolean glIsSyncAEMU_enc(void *self , uint64_t sync)
 {
+	AEMU_SCOPED_TRACE("glIsSyncAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -6980,6 +7197,7 @@
 
 void glGetSyncivAEMU_enc(void *self , uint64_t sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
 {
+	AEMU_SCOPED_TRACE("glGetSyncivAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7027,6 +7245,7 @@
 
 void glDrawBuffers_enc(void *self , GLsizei n, const GLenum* bufs)
 {
+	AEMU_SCOPED_TRACE("glDrawBuffers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7055,6 +7274,7 @@
 
 void glReadBuffer_enc(void *self , GLenum src)
 {
+	AEMU_SCOPED_TRACE("glReadBuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7080,6 +7300,7 @@
 
 void glBlitFramebuffer_enc(void *self , GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
 {
+	AEMU_SCOPED_TRACE("glBlitFramebuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7114,6 +7335,7 @@
 
 void glInvalidateFramebuffer_enc(void *self , GLenum target, GLsizei numAttachments, const GLenum* attachments)
 {
+	AEMU_SCOPED_TRACE("glInvalidateFramebuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7143,6 +7365,7 @@
 
 void glInvalidateSubFramebuffer_enc(void *self , GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glInvalidateSubFramebuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7176,6 +7399,7 @@
 
 void glFramebufferTextureLayer_enc(void *self , GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
 {
+	AEMU_SCOPED_TRACE("glFramebufferTextureLayer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7205,6 +7429,7 @@
 
 void glRenderbufferStorageMultisample_enc(void *self , GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glRenderbufferStorageMultisample encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7234,6 +7459,7 @@
 
 void glTexStorage2D_enc(void *self , GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glTexStorage2D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7263,6 +7489,7 @@
 
 void glGetInternalformativ_enc(void *self , GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetInternalformativ encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7305,6 +7532,7 @@
 
 void glBeginTransformFeedback_enc(void *self , GLenum primitiveMode)
 {
+	AEMU_SCOPED_TRACE("glBeginTransformFeedback encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7330,6 +7558,7 @@
 
 void glEndTransformFeedback_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glEndTransformFeedback encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7354,6 +7583,7 @@
 
 void glGenTransformFeedbacks_enc(void *self , GLsizei n, GLuint* ids)
 {
+	AEMU_SCOPED_TRACE("glGenTransformFeedbacks encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7393,6 +7623,7 @@
 
 void glDeleteTransformFeedbacks_enc(void *self , GLsizei n, const GLuint* ids)
 {
+	AEMU_SCOPED_TRACE("glDeleteTransformFeedbacks encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7421,6 +7652,7 @@
 
 void glBindTransformFeedback_enc(void *self , GLenum target, GLuint id)
 {
+	AEMU_SCOPED_TRACE("glBindTransformFeedback encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7447,6 +7679,7 @@
 
 void glPauseTransformFeedback_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glPauseTransformFeedback encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7471,6 +7704,7 @@
 
 void glResumeTransformFeedback_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glResumeTransformFeedback encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7495,6 +7729,7 @@
 
 GLboolean glIsTransformFeedback_enc(void *self , GLuint id)
 {
+	AEMU_SCOPED_TRACE("glIsTransformFeedback encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7535,6 +7770,7 @@
 
 void glTransformFeedbackVaryingsAEMU_enc(void *self , GLuint program, GLsizei count, const char* packedVaryings, GLuint packedVaryingsLen, GLenum bufferMode)
 {
+	AEMU_SCOPED_TRACE("glTransformFeedbackVaryingsAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7566,6 +7802,7 @@
 
 void glGetTransformFeedbackVarying_enc(void *self , GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, char* name)
 {
+	AEMU_SCOPED_TRACE("glGetTransformFeedbackVarying encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7625,6 +7862,7 @@
 
 void glGenSamplers_enc(void *self , GLsizei n, GLuint* samplers)
 {
+	AEMU_SCOPED_TRACE("glGenSamplers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7664,6 +7902,7 @@
 
 void glDeleteSamplers_enc(void *self , GLsizei n, const GLuint* samplers)
 {
+	AEMU_SCOPED_TRACE("glDeleteSamplers encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7692,6 +7931,7 @@
 
 void glBindSampler_enc(void *self , GLuint unit, GLuint sampler)
 {
+	AEMU_SCOPED_TRACE("glBindSampler encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7718,6 +7958,7 @@
 
 void glSamplerParameterf_enc(void *self , GLuint sampler, GLenum pname, GLfloat param)
 {
+	AEMU_SCOPED_TRACE("glSamplerParameterf encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7745,6 +7986,7 @@
 
 void glSamplerParameteri_enc(void *self , GLuint sampler, GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glSamplerParameteri encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7772,6 +8014,7 @@
 
 void glSamplerParameterfv_enc(void *self , GLuint sampler, GLenum pname, const GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glSamplerParameterfv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7801,6 +8044,7 @@
 
 void glSamplerParameteriv_enc(void *self , GLuint sampler, GLenum pname, const GLint* params)
 {
+	AEMU_SCOPED_TRACE("glSamplerParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7830,6 +8074,7 @@
 
 void glGetSamplerParameterfv_enc(void *self , GLuint sampler, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetSamplerParameterfv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7870,6 +8115,7 @@
 
 void glGetSamplerParameteriv_enc(void *self , GLuint sampler, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetSamplerParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7910,6 +8156,7 @@
 
 GLboolean glIsSampler_enc(void *self , GLuint sampler)
 {
+	AEMU_SCOPED_TRACE("glIsSampler encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7950,6 +8197,7 @@
 
 void glGenQueries_enc(void *self , GLsizei n, GLuint* queries)
 {
+	AEMU_SCOPED_TRACE("glGenQueries encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -7989,6 +8237,7 @@
 
 void glDeleteQueries_enc(void *self , GLsizei n, const GLuint* queries)
 {
+	AEMU_SCOPED_TRACE("glDeleteQueries encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8017,6 +8266,7 @@
 
 void glBeginQuery_enc(void *self , GLenum target, GLuint query)
 {
+	AEMU_SCOPED_TRACE("glBeginQuery encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8043,6 +8293,7 @@
 
 void glEndQuery_enc(void *self , GLenum target)
 {
+	AEMU_SCOPED_TRACE("glEndQuery encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8068,6 +8319,7 @@
 
 void glGetQueryiv_enc(void *self , GLenum target, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetQueryiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8108,6 +8360,7 @@
 
 void glGetQueryObjectuiv_enc(void *self , GLuint query, GLenum pname, GLuint* params)
 {
+	AEMU_SCOPED_TRACE("glGetQueryObjectuiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8148,6 +8401,7 @@
 
 GLboolean glIsQuery_enc(void *self , GLuint query)
 {
+	AEMU_SCOPED_TRACE("glIsQuery encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8188,6 +8442,7 @@
 
 void glProgramParameteri_enc(void *self , GLuint program, GLenum pname, GLint value)
 {
+	AEMU_SCOPED_TRACE("glProgramParameteri encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8215,6 +8470,7 @@
 
 void glProgramBinary_enc(void *self , GLuint program, GLenum binaryFormat, const void* binary, GLsizei length)
 {
+	AEMU_SCOPED_TRACE("glProgramBinary encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8245,6 +8501,7 @@
 
 void glGetProgramBinary_enc(void *self , GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, void* binary)
 {
+	AEMU_SCOPED_TRACE("glGetProgramBinary encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8295,6 +8552,7 @@
 
 GLint glGetFragDataLocation_enc(void *self , GLuint program, const char* name)
 {
+	AEMU_SCOPED_TRACE("glGetFragDataLocation encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8338,6 +8596,7 @@
 
 void glGetInteger64v_enc(void *self , GLenum pname, GLint64* data)
 {
+	AEMU_SCOPED_TRACE("glGetInteger64v encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8377,6 +8636,7 @@
 
 void glGetIntegeri_v_enc(void *self , GLenum target, GLuint index, GLint* data)
 {
+	AEMU_SCOPED_TRACE("glGetIntegeri_v encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8417,6 +8677,7 @@
 
 void glGetInteger64i_v_enc(void *self , GLenum target, GLuint index, GLint64* data)
 {
+	AEMU_SCOPED_TRACE("glGetInteger64i_v encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8457,6 +8718,7 @@
 
 void glTexImage3D_enc(void *self , GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glTexImage3D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8499,6 +8761,7 @@
 
 void glTexImage3DOffsetAEMU_enc(void *self , GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glTexImage3DOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8533,6 +8796,7 @@
 
 void glTexStorage3D_enc(void *self , GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
 {
+	AEMU_SCOPED_TRACE("glTexStorage3D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8563,6 +8827,7 @@
 
 void glTexSubImage3D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glTexSubImage3D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8606,6 +8871,7 @@
 
 void glTexSubImage3DOffsetAEMU_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glTexSubImage3DOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8641,6 +8907,7 @@
 
 void glCompressedTexImage3D_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexImage3D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8682,6 +8949,7 @@
 
 void glCompressedTexImage3DOffsetAEMU_enc(void *self , GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexImage3DOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8715,6 +8983,7 @@
 
 void glCompressedTexSubImage3D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexSubImage3D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8758,6 +9027,7 @@
 
 void glCompressedTexSubImage3DOffsetAEMU_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, GLuint data)
 {
+	AEMU_SCOPED_TRACE("glCompressedTexSubImage3DOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8793,6 +9063,7 @@
 
 void glCopyTexSubImage3D_enc(void *self , GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
 {
+	AEMU_SCOPED_TRACE("glCopyTexSubImage3D encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8826,6 +9097,7 @@
 
 void glGetBooleani_v_enc(void *self , GLenum target, GLuint index, GLboolean* data)
 {
+	AEMU_SCOPED_TRACE("glGetBooleani_v encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8866,6 +9138,7 @@
 
 void glMemoryBarrier_enc(void *self , GLbitfield barriers)
 {
+	AEMU_SCOPED_TRACE("glMemoryBarrier encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8891,6 +9164,7 @@
 
 void glMemoryBarrierByRegion_enc(void *self , GLbitfield barriers)
 {
+	AEMU_SCOPED_TRACE("glMemoryBarrierByRegion encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8916,6 +9190,7 @@
 
 void glGenProgramPipelines_enc(void *self , GLsizei n, GLuint* pipelines)
 {
+	AEMU_SCOPED_TRACE("glGenProgramPipelines encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8955,6 +9230,7 @@
 
 void glDeleteProgramPipelines_enc(void *self , GLsizei n, const GLuint* pipelines)
 {
+	AEMU_SCOPED_TRACE("glDeleteProgramPipelines encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -8983,6 +9259,7 @@
 
 void glBindProgramPipeline_enc(void *self , GLuint pipeline)
 {
+	AEMU_SCOPED_TRACE("glBindProgramPipeline encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9008,6 +9285,7 @@
 
 void glGetProgramPipelineiv_enc(void *self , GLuint pipeline, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetProgramPipelineiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9048,6 +9326,7 @@
 
 void glGetProgramPipelineInfoLog_enc(void *self , GLuint pipeline, GLsizei bufSize, GLsizei* length, GLchar* infoLog)
 {
+	AEMU_SCOPED_TRACE("glGetProgramPipelineInfoLog encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9094,6 +9373,7 @@
 
 void glValidateProgramPipeline_enc(void *self , GLuint pipeline)
 {
+	AEMU_SCOPED_TRACE("glValidateProgramPipeline encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9119,6 +9399,7 @@
 
 GLboolean glIsProgramPipeline_enc(void *self , GLuint pipeline)
 {
+	AEMU_SCOPED_TRACE("glIsProgramPipeline encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9159,6 +9440,7 @@
 
 void glUseProgramStages_enc(void *self , GLuint pipeline, GLbitfield stages, GLuint program)
 {
+	AEMU_SCOPED_TRACE("glUseProgramStages encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9186,6 +9468,7 @@
 
 void glActiveShaderProgram_enc(void *self , GLuint pipeline, GLuint program)
 {
+	AEMU_SCOPED_TRACE("glActiveShaderProgram encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9212,6 +9495,7 @@
 
 GLuint glCreateShaderProgramvAEMU_enc(void *self , GLenum type, GLsizei count, const char* packedStrings, GLuint packedLen)
 {
+	AEMU_SCOPED_TRACE("glCreateShaderProgramvAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9257,6 +9541,7 @@
 
 void glProgramUniform1f_enc(void *self , GLuint program, GLint location, GLfloat v0)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform1f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9284,6 +9569,7 @@
 
 void glProgramUniform2f_enc(void *self , GLuint program, GLint location, GLfloat v0, GLfloat v1)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform2f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9312,6 +9598,7 @@
 
 void glProgramUniform3f_enc(void *self , GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform3f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9341,6 +9628,7 @@
 
 void glProgramUniform4f_enc(void *self , GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform4f encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9371,6 +9659,7 @@
 
 void glProgramUniform1i_enc(void *self , GLuint program, GLint location, GLint v0)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform1i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9398,6 +9687,7 @@
 
 void glProgramUniform2i_enc(void *self , GLuint program, GLint location, GLint v0, GLint v1)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform2i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9426,6 +9716,7 @@
 
 void glProgramUniform3i_enc(void *self , GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform3i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9455,6 +9746,7 @@
 
 void glProgramUniform4i_enc(void *self , GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform4i encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9485,6 +9777,7 @@
 
 void glProgramUniform1ui_enc(void *self , GLuint program, GLint location, GLuint v0)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform1ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9512,6 +9805,7 @@
 
 void glProgramUniform2ui_enc(void *self , GLuint program, GLint location, GLint v0, GLuint v1)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform2ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9540,6 +9834,7 @@
 
 void glProgramUniform3ui_enc(void *self , GLuint program, GLint location, GLint v0, GLint v1, GLuint v2)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform3ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9569,6 +9864,7 @@
 
 void glProgramUniform4ui_enc(void *self , GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLuint v3)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform4ui encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9599,6 +9895,7 @@
 
 void glProgramUniform1fv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform1fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9629,6 +9926,7 @@
 
 void glProgramUniform2fv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9659,6 +9957,7 @@
 
 void glProgramUniform3fv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9689,6 +9988,7 @@
 
 void glProgramUniform4fv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9719,6 +10019,7 @@
 
 void glProgramUniform1iv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLint* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform1iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9749,6 +10050,7 @@
 
 void glProgramUniform2iv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLint* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform2iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9779,6 +10081,7 @@
 
 void glProgramUniform3iv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLint* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform3iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9809,6 +10112,7 @@
 
 void glProgramUniform4iv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLint* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform4iv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9839,6 +10143,7 @@
 
 void glProgramUniform1uiv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform1uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9869,6 +10174,7 @@
 
 void glProgramUniform2uiv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform2uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9899,6 +10205,7 @@
 
 void glProgramUniform3uiv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform3uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9929,6 +10236,7 @@
 
 void glProgramUniform4uiv_enc(void *self , GLuint program, GLint location, GLsizei count, const GLuint* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniform4uiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9959,6 +10267,7 @@
 
 void glProgramUniformMatrix2fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -9990,6 +10299,7 @@
 
 void glProgramUniformMatrix3fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10021,6 +10331,7 @@
 
 void glProgramUniformMatrix4fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10052,6 +10363,7 @@
 
 void glProgramUniformMatrix2x3fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix2x3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10083,6 +10395,7 @@
 
 void glProgramUniformMatrix3x2fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix3x2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10114,6 +10427,7 @@
 
 void glProgramUniformMatrix2x4fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix2x4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10145,6 +10459,7 @@
 
 void glProgramUniformMatrix4x2fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix4x2fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10176,6 +10491,7 @@
 
 void glProgramUniformMatrix3x4fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix3x4fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10207,6 +10523,7 @@
 
 void glProgramUniformMatrix4x3fv_enc(void *self , GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
 {
+	AEMU_SCOPED_TRACE("glProgramUniformMatrix4x3fv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10238,6 +10555,7 @@
 
 void glGetProgramInterfaceiv_enc(void *self , GLuint program, GLenum programInterface, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetProgramInterfaceiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10279,6 +10597,7 @@
 
 void glGetProgramResourceiv_enc(void *self , GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum* props, GLsizei bufSize, GLsizei* length, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetProgramResourceiv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10331,6 +10650,7 @@
 
 GLuint glGetProgramResourceIndex_enc(void *self , GLuint program, GLenum programInterface, const char* name)
 {
+	AEMU_SCOPED_TRACE("glGetProgramResourceIndex encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10375,6 +10695,7 @@
 
 GLint glGetProgramResourceLocation_enc(void *self , GLuint program, GLenum programInterface, const char* name)
 {
+	AEMU_SCOPED_TRACE("glGetProgramResourceLocation encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10419,6 +10740,7 @@
 
 void glGetProgramResourceName_enc(void *self , GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei* length, char* name)
 {
+	AEMU_SCOPED_TRACE("glGetProgramResourceName encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10467,6 +10789,7 @@
 
 void glBindImageTexture_enc(void *self , GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format)
 {
+	AEMU_SCOPED_TRACE("glBindImageTexture encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10498,6 +10821,7 @@
 
 void glDispatchCompute_enc(void *self , GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z)
 {
+	AEMU_SCOPED_TRACE("glDispatchCompute encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10525,6 +10849,7 @@
 
 void glDispatchComputeIndirect_enc(void *self , GLintptr indirect)
 {
+	AEMU_SCOPED_TRACE("glDispatchComputeIndirect encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10550,6 +10875,7 @@
 
 void glBindVertexBuffer_enc(void *self , GLuint bindingindex, GLuint buffer, GLintptr offset, GLintptr stride)
 {
+	AEMU_SCOPED_TRACE("glBindVertexBuffer encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10578,6 +10904,7 @@
 
 void glVertexAttribBinding_enc(void *self , GLuint attribindex, GLuint bindingindex)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribBinding encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10604,6 +10931,7 @@
 
 void glVertexAttribFormat_enc(void *self , GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribFormat encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10633,6 +10961,7 @@
 
 void glVertexAttribIFormat_enc(void *self , GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset)
 {
+	AEMU_SCOPED_TRACE("glVertexAttribIFormat encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10661,6 +10990,7 @@
 
 void glVertexBindingDivisor_enc(void *self , GLuint bindingindex, GLuint divisor)
 {
+	AEMU_SCOPED_TRACE("glVertexBindingDivisor encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10687,6 +11017,7 @@
 
 void glDrawArraysIndirectDataAEMU_enc(void *self , GLenum mode, const void* indirect, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glDrawArraysIndirectDataAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10716,6 +11047,7 @@
 
 void glDrawArraysIndirectOffsetAEMU_enc(void *self , GLenum mode, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glDrawArraysIndirectOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10742,6 +11074,7 @@
 
 void glDrawElementsIndirectDataAEMU_enc(void *self , GLenum mode, GLenum type, const void* indirect, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsIndirectDataAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10772,6 +11105,7 @@
 
 void glDrawElementsIndirectOffsetAEMU_enc(void *self , GLenum mode, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsIndirectOffsetAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10799,6 +11133,7 @@
 
 void glTexStorage2DMultisample_enc(void *self , GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations)
 {
+	AEMU_SCOPED_TRACE("glTexStorage2DMultisample encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10829,6 +11164,7 @@
 
 void glSampleMaski_enc(void *self , GLuint maskNumber, GLbitfield mask)
 {
+	AEMU_SCOPED_TRACE("glSampleMaski encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10855,6 +11191,7 @@
 
 void glGetMultisamplefv_enc(void *self , GLenum pname, GLuint index, GLfloat* val)
 {
+	AEMU_SCOPED_TRACE("glGetMultisamplefv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10895,6 +11232,7 @@
 
 void glFramebufferParameteri_enc(void *self , GLenum target, GLenum pname, GLint param)
 {
+	AEMU_SCOPED_TRACE("glFramebufferParameteri encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10922,6 +11260,7 @@
 
 void glGetFramebufferParameteriv_enc(void *self , GLenum target, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetFramebufferParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -10962,6 +11301,7 @@
 
 void glGetTexLevelParameterfv_enc(void *self , GLenum target, GLint level, GLenum pname, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexLevelParameterfv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11003,6 +11343,7 @@
 
 void glGetTexLevelParameteriv_enc(void *self , GLenum target, GLint level, GLenum pname, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetTexLevelParameteriv encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11044,6 +11385,7 @@
 
 void glMapBufferRangeDMA_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, uint64_t paddr)
 {
+	AEMU_SCOPED_TRACE("glMapBufferRangeDMA encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11073,6 +11415,7 @@
 
 void glUnmapBufferDMA_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, uint64_t paddr, GLboolean* out_res)
 {
+	AEMU_SCOPED_TRACE("glUnmapBufferDMA encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11116,6 +11459,7 @@
 
 uint64_t glMapBufferRangeDirect_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, uint64_t paddr)
 {
+	AEMU_SCOPED_TRACE("glMapBufferRangeDirect encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11160,6 +11504,7 @@
 
 void glUnmapBufferDirect_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, uint64_t paddr, uint64_t guest_ptr, GLboolean* out_res)
 {
+	AEMU_SCOPED_TRACE("glUnmapBufferDirect encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11204,6 +11549,7 @@
 
 void glFlushMappedBufferRangeDirect_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
 {
+	AEMU_SCOPED_TRACE("glFlushMappedBufferRangeDirect encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11232,6 +11578,7 @@
 
 GLenum glGetGraphicsResetStatusEXT_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("glGetGraphicsResetStatusEXT encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11271,6 +11618,7 @@
 
 void glReadnPixelsEXT_enc(void *self , GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid* data)
 {
+	AEMU_SCOPED_TRACE("glReadnPixelsEXT encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11316,6 +11664,7 @@
 
 void glGetnUniformfvEXT_enc(void *self , GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
 {
+	AEMU_SCOPED_TRACE("glGetnUniformfvEXT encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11357,6 +11706,7 @@
 
 void glGetnUniformivEXT_enc(void *self , GLuint program, GLint location, GLsizei bufSize, GLint* params)
 {
+	AEMU_SCOPED_TRACE("glGetnUniformivEXT encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11398,6 +11748,7 @@
 
 void glDrawArraysNullAEMU_enc(void *self , GLenum mode, GLint first, GLsizei count)
 {
+	AEMU_SCOPED_TRACE("glDrawArraysNullAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11425,6 +11776,7 @@
 
 void glDrawElementsOffsetNullAEMU_enc(void *self , GLenum mode, GLsizei count, GLenum type, GLuint offset)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsOffsetNullAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11453,6 +11805,7 @@
 
 void glDrawElementsDataNullAEMU_enc(void *self , GLenum mode, GLsizei count, GLenum type, void* data, GLuint datalen)
 {
+	AEMU_SCOPED_TRACE("glDrawElementsDataNullAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11484,6 +11837,7 @@
 
 void glUnmapBufferAsyncAEMU_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, void* guest_buffer, GLboolean* out_res)
 {
+	AEMU_SCOPED_TRACE("glUnmapBufferAsyncAEMU encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -11528,6 +11882,7 @@
 
 void glFlushMappedBufferRangeAEMU2_enc(void *self , GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, void* guest_buffer)
 {
+	AEMU_SCOPED_TRACE("glFlushMappedBufferRangeAEMU2 encode");
 
 	gl2_encoder_context_t *ctx = (gl2_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
diff --git a/system/OpenglSystemCommon/AddressSpaceStream.cpp b/system/OpenglSystemCommon/AddressSpaceStream.cpp
index 4f26da9..ba9f289 100644
--- a/system/OpenglSystemCommon/AddressSpaceStream.cpp
+++ b/system/OpenglSystemCommon/AddressSpaceStream.cpp
@@ -142,7 +142,7 @@
     return res;
 }
 
-#ifdef HOST_BUILD
+#if defined(HOST_BUILD) || defined(__Fuchsia__)
 AddressSpaceStream* createVirtioGpuAddressSpaceStream(size_t ignored_bufSize) {
     // Ignore incoming ignored_bufSize
     (void)ignored_bufSize;
@@ -259,7 +259,7 @@
 
     return res;
 }
-#endif
+#endif // HOST_BUILD || __Fuchsia__
 
 
 AddressSpaceStream::AddressSpaceStream(
diff --git a/system/OpenglSystemCommon/Android.mk b/system/OpenglSystemCommon/Android.mk
index fa24719..189e16b 100644
--- a/system/OpenglSystemCommon/Android.mk
+++ b/system/OpenglSystemCommon/Android.mk
@@ -18,7 +18,7 @@
     QemuPipeStream.cpp \
     ProcessPipe.cpp    \
 
-ifeq (true,$(BUILD_EMULATOR_VULKAN))
+ifeq (true,$(GFXSTREAM))
 $(call emugl-import,libvulkan_enc)
 
 LOCAL_SRC_FILES += AddressSpaceStream.cpp
@@ -34,7 +34,7 @@
 
 else
 
-ifeq (true,$(BUILD_EMULATOR_VULKAN))
+ifeq (true,$(GFXSTREAM))
 
 LOCAL_HEADER_LIBRARIES += vulkan_headers
 
diff --git a/system/OpenglSystemCommon/CMakeLists.txt b/system/OpenglSystemCommon/CMakeLists.txt
index ff4947a..0149f8b 100644
--- a/system/OpenglSystemCommon/CMakeLists.txt
+++ b/system/OpenglSystemCommon/CMakeLists.txt
@@ -1,10 +1,10 @@
 # This is an autogenerated file! Do not edit!
 # instead run make from .../device/generic/goldfish-opengl
 # which will re-generate this file.
-android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/Android.mk" "1a769e79e22604f569e4345e4f432bb4bd41ca810d479b69887007b5d9bec528")
+android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/Android.mk" "014a10fd6e8b1977ab8f66a6e7211136ea921d3c1692653988c894c7e87fee7a")
 set(OpenglSystemCommon_src FormatConversions.cpp HostConnection.cpp QemuPipeStream.cpp ProcessPipe.cpp AddressSpaceStream.cpp ThreadInfo_host.cpp)
 android_add_library(TARGET OpenglSystemCommon SHARED LICENSE Apache-2.0 SRC FormatConversions.cpp HostConnection.cpp QemuPipeStream.cpp ProcessPipe.cpp AddressSpaceStream.cpp ThreadInfo_host.cpp)
-target_include_directories(OpenglSystemCommon PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(OpenglSystemCommon PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN")
+target_include_directories(OpenglSystemCommon PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(OpenglSystemCommon PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM")
 target_compile_options(OpenglSystemCommon PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-unused-variable")
-target_link_libraries(OpenglSystemCommon PRIVATE android-emu-shared vulkan_enc gui androidemu cutils utils log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
+target_link_libraries(OpenglSystemCommon PRIVATE android-emu-shared vulkan_enc gui log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host cutils utils androidemu PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
diff --git a/system/OpenglSystemCommon/EmulatorFeatureInfo.h b/system/OpenglSystemCommon/EmulatorFeatureInfo.h
index d0ae853..304ab36 100644
--- a/system/OpenglSystemCommon/EmulatorFeatureInfo.h
+++ b/system/OpenglSystemCommon/EmulatorFeatureInfo.h
@@ -114,6 +114,9 @@
 // Vulkan async queue submit
 static const char kVulkanAsyncQueueSubmit[] = "ANDROID_EMU_vulkan_async_queue_submit";
 
+// A flag to _not_ ignore host opengl errors (now host opengl errors are ignored by default)
+static const char kGLESUseHostError[] = "ANDROID_EMU_gles_use_host_error";
+
 // Struct describing available emulator features
 struct EmulatorFeatureInfo {
 
diff --git a/system/OpenglSystemCommon/FormatConversions.cpp b/system/OpenglSystemCommon/FormatConversions.cpp
index cc976ed..aae6bb9 100644
--- a/system/OpenglSystemCommon/FormatConversions.cpp
+++ b/system/OpenglSystemCommon/FormatConversions.cpp
@@ -35,11 +35,14 @@
     return row * width * rgbStride;
 }
 
+#define OMX_COLOR_FormatYUV420Planar 0x13
+
 bool gralloc_is_yuv_format(const int format) {
     switch (format) {
     case HAL_PIXEL_FORMAT_YV12:
     case HAL_PIXEL_FORMAT_YCbCr_420_888:
     case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+    case OMX_COLOR_FormatYUV420Planar:
         return true;
 
     default:
diff --git a/system/OpenglSystemCommon/HostConnection.cpp b/system/OpenglSystemCommon/HostConnection.cpp
index c371742..7d309fb 100644
--- a/system/OpenglSystemCommon/HostConnection.cpp
+++ b/system/OpenglSystemCommon/HostConnection.cpp
@@ -42,13 +42,14 @@
 #include "GL2Encoder.h"
 #endif
 
-#ifdef GOLDFISH_VULKAN
+#ifdef GFXSTREAM
 #include "VkEncoder.h"
 #include "AddressSpaceStream.h"
 #else
 namespace goldfish_vk {
 struct VkEncoder {
     VkEncoder(IOStream*) { }
+    void decRef() { }
     int placeholder;
 };
 } // namespace goldfish_vk
@@ -346,6 +347,7 @@
     {
         return ::processPipeInit(connType, rcEnc);
     }
+    
 };
 
 static GoldfishGralloc m_goldfishGralloc;
@@ -355,7 +357,7 @@
     m_checksumHelper(),
     m_glExtensions(),
     m_grallocOnly(true),
-    m_noHostError(false),
+    m_noHostError(true),
     m_rendernodeFd(-1),
     m_rendernodeFdOwned(false) { }
 
@@ -373,6 +375,14 @@
     if (m_rendernodeFdOwned) {
         close(m_rendernodeFd);
     }
+
+    if (m_vkEnc) {
+        m_vkEnc->decRef();
+    }
+
+    if (m_stream) {
+        m_stream->decRef();
+    }
 }
 
 // static
@@ -384,21 +394,20 @@
     auto con = std::unique_ptr<HostConnection>(new HostConnection);
     switch (connType) {
         case HOST_CONNECTION_ADDRESS_SPACE: {
-            auto stream = std::unique_ptr<AddressSpaceStream>(
-                createAddressSpaceStream(STREAM_BUFFER_SIZE));
+            auto stream = createAddressSpaceStream(STREAM_BUFFER_SIZE);
             if (!stream) {
                 ALOGE("Failed to create AddressSpaceStream for host connection!!!\n");
                 return nullptr;
             }
             con->m_connectionType = HOST_CONNECTION_ADDRESS_SPACE;
             con->m_grallocType = GRALLOC_TYPE_RANCHU;
-            con->m_stream = std::move(stream);
+            con->m_stream = stream;
             con->m_grallocHelper = &m_goldfishGralloc;
             con->m_processPipe = &m_goldfishProcessPipe;
             break;
         }
         case HOST_CONNECTION_QEMU_PIPE: {
-            auto stream = std::make_unique<QemuPipeStream>(STREAM_BUFFER_SIZE);
+            auto stream = new QemuPipeStream(STREAM_BUFFER_SIZE);
             if (!stream) {
                 ALOGE("Failed to create QemuPipeStream for host connection!!!\n");
                 return nullptr;
@@ -409,7 +418,7 @@
             }
             con->m_connectionType = HOST_CONNECTION_QEMU_PIPE;
             con->m_grallocType = GRALLOC_TYPE_RANCHU;
-            con->m_stream = std::move(stream);
+            con->m_stream = stream;
             con->m_grallocHelper = &m_goldfishGralloc;
             con->m_processPipe = &m_goldfishProcessPipe;
             break;
@@ -420,7 +429,7 @@
             return nullptr;
             break;
 #else
-            auto stream = std::make_unique<TcpStream>(STREAM_BUFFER_SIZE);
+            auto stream = new TcpStream(STREAM_BUFFER_SIZE);
             if (!stream) {
                 ALOGE("Failed to create TcpStream for host connection!!!\n");
                 return nullptr;
@@ -432,7 +441,7 @@
             }
             con->m_connectionType = HOST_CONNECTION_TCP;
             con->m_grallocType = GRALLOC_TYPE_RANCHU;
-            con->m_stream = std::move(stream);
+            con->m_stream = stream;
             con->m_grallocHelper = &m_goldfishGralloc;
             con->m_processPipe = &m_goldfishProcessPipe;
             break;
@@ -440,7 +449,7 @@
         }
 #ifdef VIRTIO_GPU
         case HOST_CONNECTION_VIRTIO_GPU: {
-            auto stream = std::make_unique<VirtioGpuStream>(STREAM_BUFFER_SIZE);
+            auto stream = new VirtioGpuStream(STREAM_BUFFER_SIZE);
             if (!stream) {
                 ALOGE("Failed to create VirtioGpu for host connection!!!\n");
                 return nullptr;
@@ -453,7 +462,7 @@
             con->m_grallocType = GRALLOC_TYPE_MINIGBM;
             auto rendernodeFd = stream->getRendernodeFd();
             con->m_processPipe = stream->getProcessPipe();
-            con->m_stream = std::move(stream);
+            con->m_stream = stream;
             con->m_rendernodeFdOwned = false;
             con->m_rendernodeFdOwned = rendernodeFd;
             MinigbmGralloc* m = new MinigbmGralloc;
@@ -462,8 +471,7 @@
             break;
         }
         case HOST_CONNECTION_VIRTIO_GPU_PIPE: {
-            auto stream =
-                std::make_unique<VirtioGpuPipeStream>(STREAM_BUFFER_SIZE);
+            auto stream = new VirtioGpuPipeStream(STREAM_BUFFER_SIZE);
             if (!stream) {
                 ALOGE("Failed to create VirtioGpu for host connection!!!\n");
                 return nullptr;
@@ -476,7 +484,7 @@
             con->m_grallocType = getGrallocTypeFromProperty();
             con->m_rendernodeFdOwned = false;
             auto rendernodeFd = stream->getRendernodeFd();
-            con->m_stream = std::move(stream);
+            con->m_stream = stream;
             con->m_rendernodeFd = rendernodeFd;
             switch (con->m_grallocType) {
                 case GRALLOC_TYPE_RANCHU:
@@ -495,10 +503,9 @@
             con->m_processPipe = &m_goldfishProcessPipe;
             break;
         }
-#ifndef HOST_BUILD
+#if !defined(HOST_BUILD) && !defined(__Fuchsia__)
         case HOST_CONNECTION_VIRTIO_GPU_ADDRESS_SPACE: {
-            auto stream = std::unique_ptr<AddressSpaceStream>(
-                createVirtioGpuAddressSpaceStream(STREAM_BUFFER_SIZE));
+            auto stream = createVirtioGpuAddressSpaceStream(STREAM_BUFFER_SIZE);
             if (!stream) {
                 ALOGE("Failed to create virtgpu AddressSpaceStream for host connection!!!\n");
                 return nullptr;
@@ -507,7 +514,7 @@
             con->m_grallocType = getGrallocTypeFromProperty();
             con->m_rendernodeFdOwned = false;
             auto rendernodeFd = stream->getRendernodeFd();
-            con->m_stream = std::move(stream);
+            con->m_stream = stream;
             con->m_rendernodeFd = rendernodeFd;
             switch (con->m_grallocType) {
                 case GRALLOC_TYPE_RANCHU:
@@ -526,7 +533,7 @@
             con->m_processPipe = &m_goldfishProcessPipe;
             break;
         }
-#endif // !HOST_BUILD
+#endif // !HOST_BUILD && !__Fuchsia__
 #else
         default:
             break;
@@ -581,7 +588,7 @@
 GLEncoder *HostConnection::glEncoder()
 {
     if (!m_glEnc) {
-        m_glEnc = std::make_unique<GLEncoder>(m_stream.get(), checksumHelper());
+        m_glEnc = std::make_unique<GLEncoder>(m_stream, checksumHelper());
         DBG("HostConnection::glEncoder new encoder %p, tid %d",
             m_glEnc, getCurrentThreadId());
         m_glEnc->setContextAccessor(s_getGLContext);
@@ -593,7 +600,7 @@
 {
     if (!m_gl2Enc) {
         m_gl2Enc =
-            std::make_unique<GL2Encoder>(m_stream.get(), checksumHelper());
+            std::make_unique<GL2Encoder>(m_stream, checksumHelper());
         DBG("HostConnection::gl2Encoder new encoder %p, tid %d",
             m_gl2Enc, getCurrentThreadId());
         m_gl2Enc->setContextAccessor(s_getGL2Context);
@@ -608,15 +615,15 @@
 VkEncoder *HostConnection::vkEncoder()
 {
     if (!m_vkEnc) {
-        m_vkEnc = std::make_unique<VkEncoder>(m_stream.get());
+        m_vkEnc = new VkEncoder(m_stream);
     }
-    return m_vkEnc.get();
+    return m_vkEnc;
 }
 
 ExtendedRCEncoderContext *HostConnection::rcEncoder()
 {
     if (!m_rcEnc) {
-        m_rcEnc = std::make_unique<ExtendedRCEncoderContext>(m_stream.get(),
+        m_rcEnc = std::make_unique<ExtendedRCEncoderContext>(m_stream,
                                                              checksumHelper());
 
         ExtendedRCEncoderContext* rcEnc = m_rcEnc.get();
@@ -800,8 +807,8 @@
 
 void HostConnection::queryAndSetNoErrorState(ExtendedRCEncoderContext* rcEnc) {
     std::string glExtensions = queryGLExtensions(rcEnc);
-    if (glExtensions.find(kGLESNoHostError) != std::string::npos) {
-        m_noHostError = true;
+    if (glExtensions.find(kGLESUseHostError) != std::string::npos) {
+        m_noHostError = false;
     }
 }
 
diff --git a/system/OpenglSystemCommon/HostConnection.h b/system/OpenglSystemCommon/HostConnection.h
index 69d8a16..32a1521 100644
--- a/system/OpenglSystemCommon/HostConnection.h
+++ b/system/OpenglSystemCommon/HostConnection.h
@@ -24,7 +24,7 @@
 
 #include <cutils/native_handle.h>
 
-#ifdef GOLDFISH_VULKAN
+#ifdef GFXSTREAM
 #include <mutex>
 #else
 #include <utils/threads.h>
@@ -222,10 +222,14 @@
     HostConnectionType m_connectionType;
     GrallocType m_grallocType;
 
-    std::unique_ptr<IOStream> m_stream;
+    // intrusively refcounted
+    IOStream* m_stream = nullptr;
+
     std::unique_ptr<GLEncoder> m_glEnc;
     std::unique_ptr<GL2Encoder> m_gl2Enc;
-    std::unique_ptr<goldfish_vk::VkEncoder> m_vkEnc;
+
+    // intrusively refcounted
+    goldfish_vk::VkEncoder* m_vkEnc = nullptr;
     std::unique_ptr<ExtendedRCEncoderContext> m_rcEnc;
 
     ChecksumCalculator m_checksumHelper;
@@ -234,7 +238,7 @@
     std::string m_glExtensions;
     bool m_grallocOnly;
     bool m_noHostError;
-#ifdef GOLDFISH_VULKAN
+#ifdef GFXSTREAM
     mutable std::mutex m_lock;
 #else
     mutable android::Mutex m_lock;
diff --git a/system/OpenglSystemCommon/ProcessPipe.cpp b/system/OpenglSystemCommon/ProcessPipe.cpp
index 0d74789..c79bf17 100644
--- a/system/OpenglSystemCommon/ProcessPipe.cpp
+++ b/system/OpenglSystemCommon/ProcessPipe.cpp
@@ -28,11 +28,14 @@
 #include <errno.h>
 
 #ifdef __Fuchsia__
-#include <fuchsia/hardware/goldfish/cpp/fidl.h>
+#include <fuchsia/hardware/goldfish/llcpp/fidl.h>
 #include <lib/zx/vmo.h>
 
 #include "services/service_connector.h"
 
+#define GET_STATUS_SAFE(result, member) \
+    ((result).ok() ? ((result).Unwrap()->member) : ZX_OK)
+
 static QEMU_PIPE_HANDLE   sProcDevice = 0;
 #else // __Fuchsia__
 
@@ -64,32 +67,45 @@
         return;
     }
 
-    fuchsia::hardware::goldfish::PipeDeviceSyncPtr device;
-    device.Bind(std::move(channel));
+    llcpp::fuchsia::hardware::goldfish::PipeDevice::SyncClient device(
+        std::move(channel));
 
-    fuchsia::hardware::goldfish::PipeSyncPtr pipe;
-    device->OpenPipe(pipe.NewRequest());
-
-    zx_status_t status, status2 = ZX_OK;
-    zx::vmo vmo;
-    status = pipe->GetBuffer(&status2, &vmo);
-    if (status != ZX_OK || status2 != ZX_OK) {
-        ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__, status, status2);
+    zx::channel pipe_server, pipe_client;
+    zx_status_t status = zx::channel::create(0, &pipe_server, &pipe_client);
+    if (status != ZX_OK) {
+        ALOGE("%s: zx_channel_create failed: %d", __FUNCTION__, status);
         return;
     }
 
+    llcpp::fuchsia::hardware::goldfish::Pipe::SyncClient pipe(
+        std::move(pipe_client));
+    device.OpenPipe(std::move(pipe_server));
+
+    zx::vmo vmo;
+    {
+        auto result = pipe.GetBuffer();
+        if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+            ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__,
+                  result.status(), GET_STATUS_SAFE(result, res));
+            return;
+        }
+        vmo = std::move(result.Unwrap()->vmo);
+    }
+
     size_t len = strlen("pipe:GLProcessPipe");
     status = vmo.write("pipe:GLProcessPipe", 0, len + 1);
     if (status != ZX_OK) {
         ALOGE("%s: failed write pipe name", __FUNCTION__);
         return;
     }
-    uint64_t actual;
-    status = pipe->Write(len + 1, 0, &status2, &actual);
-    if (status != ZX_OK || status2 != ZX_OK) {
-        ALOGD("%s: connecting to pipe service failed: %d:%d", __FUNCTION__,
-              status, status2);
-        return;
+
+    {
+        auto result = pipe.Write(len + 1, 0);
+        if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+            ALOGD("%s: connecting to pipe service failed: %d:%d", __FUNCTION__,
+                  result.status(), GET_STATUS_SAFE(result, res));
+            return;
+        }
     }
 
     // Send a confirmation int to the host and get per-process unique ID back
@@ -99,19 +115,23 @@
         ALOGE("%s: failed write confirm int", __FUNCTION__);
         return;
     }
-    status = pipe->DoCall(sizeof(confirmInt), 0, sizeof(sProcUID), 0, &status2, &actual);
-    if (status != ZX_OK || status2 != ZX_OK) {
-        ALOGD("%s: failed to get per-process ID: %d:%d", __FUNCTION__,
-              status, status2);
-        return;
+
+    {
+        auto result = pipe.DoCall(sizeof(confirmInt), 0, sizeof(sProcUID), 0);
+        if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+            ALOGD("%s: failed to get per-process ID: %d:%d", __FUNCTION__,
+                  result.status(), GET_STATUS_SAFE(result, res));
+            return;
+        }
     }
+
     status = vmo.read(&sProcUID, 0, sizeof(sProcUID));
     if (status != ZX_OK) {
         ALOGE("%s: failed read per-process ID: %d", __FUNCTION__, status);
         return;
     }
-    sProcDevice = device.Unbind().TakeChannel().release();
-    sProcPipe = pipe.Unbind().TakeChannel().release();
+    sProcDevice = device.mutable_channel()->release();
+    sProcPipe = pipe.mutable_channel()->release();
 }
 #else // __Fuchsia__
 
@@ -155,7 +175,7 @@
 }
 
 static void processPipeInitOnce() {
-#if defined(HOST_BUILD) || !defined(GOLDFISH_VULKAN)
+#if defined(HOST_BUILD) || !defined(GFXSTREAM)
     sQemuPipeInit();
 #else // HOST_BUILD
     switch (sConnType) {
diff --git a/system/OpenglSystemCommon/QemuPipeStream.h b/system/OpenglSystemCommon/QemuPipeStream.h
index 4e779eb..312eaf9 100644
--- a/system/OpenglSystemCommon/QemuPipeStream.h
+++ b/system/OpenglSystemCommon/QemuPipeStream.h
@@ -21,12 +21,13 @@
  * <hardware/qemu_pipe.h> for more details.
  */
 #include <stdlib.h>
+#include <memory>
 #include "IOStream.h"
 
 #include <qemu_pipe_bp.h>
 
 #ifdef __Fuchsia__
-#include <fuchsia/hardware/goldfish/cpp/fidl.h>
+#include <fuchsia/hardware/goldfish/llcpp/fidl.h>
 #include <lib/zx/event.h>
 #include <lib/zx/vmo.h>
 #endif
@@ -58,8 +59,10 @@
     size_t m_read;
     size_t m_readLeft;
 #ifdef __Fuchsia__
-    fuchsia::hardware::goldfish::PipeDeviceSyncPtr m_device;
-    fuchsia::hardware::goldfish::PipeSyncPtr m_pipe;
+    std::unique_ptr<llcpp::fuchsia::hardware::goldfish::PipeDevice::SyncClient>
+        m_device;
+    std::unique_ptr<llcpp::fuchsia::hardware::goldfish::Pipe::SyncClient>
+        m_pipe;
     zx::event m_event;
     zx::vmo m_vmo;
 #endif
diff --git a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
index 5472f30..6a236f1 100644
--- a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
+++ b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
@@ -28,6 +28,9 @@
 
 #include "services/service_connector.h"
 
+#define GET_STATUS_SAFE(result, member) \
+    ((result).ok() ? ((result).Unwrap()->member) : ZX_OK)
+
 constexpr size_t kReadSize = 512 * 1024;
 constexpr size_t kWriteOffset = kReadSize;
 
@@ -53,7 +56,7 @@
 
 QemuPipeStream::~QemuPipeStream()
 {
-    if (m_device.is_bound()) {
+    if (m_device) {
         flush();
     }
     if (m_buf) {
@@ -76,11 +79,23 @@
         return -1;
     }
 
-    m_device.Bind(std::move(channel));
-    m_device->OpenPipe(m_pipe.NewRequest());
+    m_device = std::make_unique<
+        llcpp::fuchsia::hardware::goldfish::PipeDevice::SyncClient>(
+        std::move(channel));
+
+    zx::channel pipe_client, pipe_server;
+    zx_status_t status = zx::channel::create(0, &pipe_server, &pipe_client);
+    if (status != ZX_OK) {
+        ALOGE("zx::channel::create failed: %d", status);
+        return ZX_HANDLE_INVALID;
+    }
+    m_device->OpenPipe(std::move(pipe_server));
+    m_pipe =
+        std::make_unique<llcpp::fuchsia::hardware::goldfish::Pipe::SyncClient>(
+            std::move(pipe_client));
 
     zx::event event;
-    zx_status_t status = zx::event::create(0, &event);
+    status = zx::event::create(0, &event);
     if (status != ZX_OK) {
         ALOGE("%s: failed to create event: %d", __FUNCTION__, status);
         return -1;
@@ -92,10 +107,13 @@
         return -1;
     }
 
-    status = m_pipe->SetEvent(std::move(event_copy));
-    if (status != ZX_OK) {
-        ALOGE("%s: failed to set event: %d:%d", __FUNCTION__, status);
-        return -1;
+    {
+        auto result = m_pipe->SetEvent(std::move(event_copy));
+        if (!result.ok()) {
+            ALOGE("%s: failed to set event: %d:%d", __FUNCTION__,
+                  result.status());
+            return -1;
+        }
     }
 
     if (!allocBuffer(m_bufsize)) {
@@ -110,13 +128,13 @@
         return -1;
     }
 
-    uint64_t actual;
-    zx_status_t status2 = ZX_OK;
-    status = m_pipe->Write(len + 1, 0, &status2, &actual);
-    if (status != ZX_OK || status2 != ZX_OK) {
-        ALOGD("%s: connecting to pipe service failed: %d:%d", __FUNCTION__,
-              status, status2);
-        return -1;
+    {
+        auto result = m_pipe->Write(len + 1, 0);
+        if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+            ALOGD("%s: connecting to pipe service failed: %d:%d", __FUNCTION__,
+                  result.status(), GET_STATUS_SAFE(result, res));
+            return -1;
+        }
     }
 
     m_event = std::move(event);
@@ -145,26 +163,32 @@
 
     size_t allocSize = m_bufsize < minSize ? minSize : m_bufsize;
 
-    zx_status_t status2 = ZX_OK;
-    status = m_pipe->SetBufferSize(allocSize, &status2);
-    if (status != ZX_OK || status2 != ZX_OK) {
-        ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__, status, status2);
-        return nullptr;
+    {
+        auto result = m_pipe->SetBufferSize(allocSize);
+        if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+            ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__,
+                  result.status(), GET_STATUS_SAFE(result, res));
+            return nullptr;
+        }
     }
 
     zx::vmo vmo;
-    status = m_pipe->GetBuffer(&status2, &vmo);
-    if (status != ZX_OK || status2 != ZX_OK) {
-        ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__, status, status2);
-        return nullptr;
+    {
+        auto result = m_pipe->GetBuffer();
+        if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+            ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__,
+                  result.status(), GET_STATUS_SAFE(result, res));
+            return nullptr;
+        }
+        vmo = std::move(result.Unwrap()->vmo);
     }
 
     zx_vaddr_t mapped_addr;
-    status = zx_vmar_map(zx_vmar_root_self(),
-                         ZX_VM_PERM_READ | ZX_VM_PERM_WRITE,
-                         0, vmo.get(), 0, allocSize, &mapped_addr);
+    status =
+        zx_vmar_map(zx_vmar_root_self(), ZX_VM_PERM_READ | ZX_VM_PERM_WRITE, 0,
+                    vmo.get(), 0, allocSize, &mapped_addr);
     if (status != ZX_OK) {
-        ALOGE("%s: failed to map buffer: %d:%d", __FUNCTION__, status);
+        ALOGE("%s: failed to map buffer: %d", __FUNCTION__, status);
         return nullptr;
     }
 
@@ -178,11 +202,10 @@
 {
     if (size == 0) return 0;
 
-    uint64_t actual = 0;
-    zx_status_t status2 = ZX_OK;
-    zx_status_t status = m_pipe->DoCall(size, kWriteOffset, 0, 0, &status2, &actual);
-    if (status != ZX_OK || status2 != ZX_OK) {
-        ALOGD("%s: Pipe call failed: %d:%d", __FUNCTION__, status, status2);
+    auto result = m_pipe->DoCall(size, kWriteOffset, 0, 0);
+    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+        ALOGD("%s: Pipe call failed: %d:%d", __FUNCTION__, result.status(),
+              GET_STATUS_SAFE(result, res));
         return -1;
     }
 
@@ -207,7 +230,8 @@
 
 const unsigned char *QemuPipeStream::commitBufferAndReadFully(size_t size, void *buf, size_t len)
 {
-    if (!m_device.is_bound()) return nullptr;
+    if (!m_device)
+        return nullptr;
 
     if (!buf) {
         if (len > 0) {
@@ -236,17 +260,16 @@
 
     // Read up to kReadSize bytes if all buffered read has been consumed.
     size_t maxRead = (m_readLeft || !remaining) ? 0 : kReadSize;
-    uint64_t actual = 0;
-    zx_status_t status2 = ZX_OK;
-    zx_status_t status = m_pipe->DoCall(size, kWriteOffset, maxRead, 0, &status2, &actual);
-    if (status != ZX_OK) {
-        ALOGD("%s: Pipe call failed: %d", __FUNCTION__, status);
+
+    auto result = m_pipe->DoCall(size, kWriteOffset, maxRead, 0);
+    if (!result.ok()) {
+        ALOGD("%s: Pipe call failed: %d", __FUNCTION__, result.status());
         return nullptr;
     }
 
     // Updated buffered read size.
-    if (actual) {
-        m_read = m_readLeft = actual;
+    if (result.Unwrap()->actual) {
+        m_read = m_readLeft = result.Unwrap()->actual;
     }
 
     // Consume buffered read and read more if neccessary.
@@ -261,31 +284,33 @@
             continue;
         }
 
-        status2 = ZX_OK;
-        actual = 0;
-        status = m_pipe->Read(kReadSize, 0, &status2, &actual);
-        if (status != ZX_OK) {
-            ALOGD("%s: Failed reading from pipe: %d", __FUNCTION__, status);
+        auto result = m_pipe->Read(kReadSize, 0);
+        if (!result.ok()) {
+            ALOGD("%s: Failed reading from pipe: %d:%d", __FUNCTION__,
+                  result.status());
             return nullptr;
         }
-        if (actual) {
-            m_read = m_readLeft = actual;
+
+        if (result.Unwrap()->actual) {
+            m_read = m_readLeft = result.Unwrap()->actual;
             continue;
         }
-        if (status2 != ZX_ERR_SHOULD_WAIT) {
-            ALOGD("%s: Error reading from pipe: %d", __FUNCTION__, status2);
+        if (result.Unwrap()->res != ZX_ERR_SHOULD_WAIT) {
+            ALOGD("%s: Error reading from pipe: %d", __FUNCTION__,
+                  result.Unwrap()->res);
             return nullptr;
         }
+
         zx_signals_t observed = ZX_SIGNAL_NONE;
-        status = m_event.wait_one(
-            fuchsia::hardware::goldfish::SIGNAL_READABLE |
-            fuchsia::hardware::goldfish::SIGNAL_HANGUP,
+        zx_status_t status = m_event.wait_one(
+            llcpp::fuchsia::hardware::goldfish::SIGNAL_READABLE |
+                llcpp::fuchsia::hardware::goldfish::SIGNAL_HANGUP,
             zx::time::infinite(), &observed);
         if (status != ZX_OK) {
             ALOGD("%s: wait_one failed: %d", __FUNCTION__, status);
             return nullptr;
         }
-        if (observed & fuchsia::hardware::goldfish::SIGNAL_HANGUP) {
+        if (observed & llcpp::fuchsia::hardware::goldfish::SIGNAL_HANGUP) {
             ALOGD("%s: Remote end hungup", __FUNCTION__);
             return nullptr;
         }
diff --git a/system/OpenglSystemCommon/ThreadInfo.cpp b/system/OpenglSystemCommon/ThreadInfo.cpp
index 99b0b9b..70837b2 100644
--- a/system/OpenglSystemCommon/ThreadInfo.cpp
+++ b/system/OpenglSystemCommon/ThreadInfo.cpp
@@ -13,9 +13,33 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
+
 #include "ThreadInfo.h"
 #include "cutils/threads.h"
 
+#ifdef GFXSTREAM
+
+thread_local EGLThreadInfo sEglThreadInfoThreadLocal;
+
+EGLThreadInfo *goldfish_get_egl_tls()
+{
+    return &sEglThreadInfoThreadLocal;
+}
+
+EGLThreadInfo* getEGLThreadInfo() {
+    return goldfish_get_egl_tls();
+}
+
+int32_t getCurrentThreadId() {
+    return (int32_t)gettid();
+}
+
+void setTlsDestructor(tlsDtorCallback func) {
+    getEGLThreadInfo()->dtor = func;
+}
+
+#else // GFXSTREAM
+
 #ifdef __BIONIC__
 #include <bionic/tls.h>
 #endif
@@ -58,14 +82,14 @@
 
 EGLThreadInfo *goldfish_get_egl_tls()
 {
-    EGLThreadInfo* ti = (EGLThreadInfo*)thread_store_get(&s_tls);
+   EGLThreadInfo* ti = (EGLThreadInfo*)thread_store_get(&s_tls);
 
-    if (ti) return ti;
+   if (ti) return ti;
 
-    ti = new EGLThreadInfo();
-    thread_store_set(&s_tls, ti, tlsDestruct);
+   ti = new EGLThreadInfo();
+   thread_store_set(&s_tls, ti, tlsDestruct);
 
-    return ti;
+   return ti;
 }
 
 EGLThreadInfo* getEGLThreadInfo() {
@@ -85,3 +109,5 @@
 int32_t getCurrentThreadId() {
     return (int32_t)gettid();
 }
+
+#endif // !GFXSTREAM
diff --git a/system/OpenglSystemCommon/ThreadInfo.h b/system/OpenglSystemCommon/ThreadInfo.h
index fa6b44b..7f49273 100644
--- a/system/OpenglSystemCommon/ThreadInfo.h
+++ b/system/OpenglSystemCommon/ThreadInfo.h
@@ -22,16 +22,19 @@
 
 struct EGLContext_t;
 
+typedef bool (*tlsDtorCallback)(void*);
+
 struct EGLThreadInfo
 {
-    EGLThreadInfo() : currentContext(NULL), eglError(EGL_SUCCESS) {}
+    EGLThreadInfo() : currentContext(NULL), eglError(EGL_SUCCESS), dtor(0) {}
+    ~EGLThreadInfo() { if (dtor) dtor(this); }
 
     EGLContext_t *currentContext;
     std::unique_ptr<HostConnection> hostConn;
     int           eglError;
+    tlsDtorCallback dtor;
 };
 
-typedef bool (*tlsDtorCallback)(void*);
 void setTlsDestructor(tlsDtorCallback);
 
 extern "C" __attribute__((visibility("default"))) EGLThreadInfo *goldfish_get_egl_tls();
diff --git a/system/OpenglSystemCommon/VirtioGpuPipeStream.cpp b/system/OpenglSystemCommon/VirtioGpuPipeStream.cpp
index 238d555..6143bd5 100644
--- a/system/OpenglSystemCommon/VirtioGpuPipeStream.cpp
+++ b/system/OpenglSystemCommon/VirtioGpuPipeStream.cpp
@@ -120,9 +120,9 @@
     }
 
     if (!m_virtio_mapped) {
-        drm_virtgpu_map map = {
-            .handle = m_virtio_bo,
-        };
+        drm_virtgpu_map map;
+        memset(&map, 0, sizeof(map));
+        map.handle = m_virtio_bo;
 
         int ret = drmIoctl(m_fd, DRM_IOCTL_VIRTGPU_MAP, &map);
         if (ret) {
diff --git a/system/OpenglSystemCommon/VirtioGpuStream.cpp b/system/OpenglSystemCommon/VirtioGpuStream.cpp
index 1b49244..bbf9dd2 100644
--- a/system/OpenglSystemCommon/VirtioGpuStream.cpp
+++ b/system/OpenglSystemCommon/VirtioGpuStream.cpp
@@ -149,9 +149,10 @@
     }
 
     if (!m_cmdResp) {
-        drm_virtgpu_map map = {
-            .handle = m_cmdResp_bo,
-        };
+        drm_virtgpu_map map;
+        memset(&map, 0, sizeof(map));
+        map.handle = m_cmdResp_bo;
+
         int ret = drmIoctl(m_fd, DRM_IOCTL_VIRTGPU_MAP, &map);
         if (ret) {
             ERR("%s: failed with %d mapping command response buffer (%s)",
diff --git a/system/OpenglSystemCommon/address_space_graphics_types.h b/system/OpenglSystemCommon/address_space_graphics_types.h
index 5f0e9b6..753644b 100644
--- a/system/OpenglSystemCommon/address_space_graphics_types.h
+++ b/system/OpenglSystemCommon/address_space_graphics_types.h
@@ -124,7 +124,7 @@
 // Helper function that will be common between guest and host:
 // Given ring storage and a write buffer, returns asg_context that
 // is the correct view into it.
-static struct asg_context asg_context_create(
+static inline struct asg_context asg_context_create(
     char* ring_storage,
     char* buffer,
     uint32_t buffer_size) {
diff --git a/system/codecs/omx/common/Android.mk b/system/codecs/omx/common/Android.mk
index 4daf0b7..1ebdff9 100644
--- a/system/codecs/omx/common/Android.mk
+++ b/system/codecs/omx/common/Android.mk
@@ -34,7 +34,7 @@
 else
 $(call emugl-export,STATIC_LIBRARIES,libGoldfishAddressSpace)
 
-ifeq (true,$(BUILD_EMULATOR_VULKAN))
+ifeq (true,$(GFXSTREAM))
 
 LOCAL_CFLAGS += -DVIRTIO_GPU
 LOCAL_C_INCLUDES += external/libdrm external/minigbm/cros_gralloc
diff --git a/system/egl/Android.mk b/system/egl/Android.mk
index a5e1c1f..f312efb 100644
--- a/system/egl/Android.mk
+++ b/system/egl/Android.mk
@@ -23,11 +23,11 @@
 ifneq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
 
 LOCAL_SHARED_LIBRARIES += libdl
-ifeq (true,$(BUILD_EMULATOR_VULKAN))
+ifeq (true,$(GFXSTREAM))
 LOCAL_CFLAGS += -DVIRTIO_GPU
 LOCAL_C_INCLUDES += external/libdrm
 LOCAL_SHARED_LIBRARIES += libdrm
-endif # BUILD_EMULATOR_VULKAN
+endif # GFXSTREAM
 endif # GOLDFISH_OPENGL_BUILD_FOR_HOST
 
 ifneq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
diff --git a/system/egl/CMakeLists.txt b/system/egl/CMakeLists.txt
index 301ef62..cf649a2 100644
--- a/system/egl/CMakeLists.txt
+++ b/system/egl/CMakeLists.txt
@@ -1,10 +1,10 @@
 # This is an autogenerated file! Do not edit!
 # instead run make from .../device/generic/goldfish-opengl
 # which will re-generate this file.
-android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/egl/Android.mk" "729a65bbc7934fa79a239b55b801e4ebaa44d02c2deeab7ab43e42196376c7c7")
+android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/egl/Android.mk" "0d72068bb429ec9da33f7086a879a08b540b887538f21d0a9f468cead76c45df")
 set(EGL_emulation_src eglDisplay.cpp egl.cpp ClientAPIExts.cpp)
 android_add_library(TARGET EGL_emulation SHARED LICENSE Apache-2.0 SRC eglDisplay.cpp egl.cpp ClientAPIExts.cpp)
-target_include_directories(EGL_emulation PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(EGL_emulation PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"EGL_emulation\"" "-DEGL_EGLEXT_PROTOTYPES")
+target_include_directories(EGL_emulation PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(EGL_emulation PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"EGL_emulation\"" "-DEGL_EGLEXT_PROTOTYPES")
 target_compile_options(EGL_emulation PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-gnu-designator")
-target_link_libraries(EGL_emulation PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui androidemu cutils utils log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
+target_link_libraries(EGL_emulation PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host cutils utils androidemu PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
diff --git a/system/egl/egl.cpp b/system/egl/egl.cpp
index fbd2405..601ad9d 100644
--- a/system/egl/egl.cpp
+++ b/system/egl/egl.cpp
@@ -1210,6 +1210,7 @@
             case EGL_VG_COLORSPACE:
                 break;
             default:
+                ALOGE("%s:%d unknown attribute: 0x%x\n", __func__, __LINE__, attrib_list[0]);
                 setErrorReturn(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
         };
         attrib_list+=2;
@@ -1703,6 +1704,8 @@
         }
         break;
     default:
+        ALOGE("%s:%d EGL_BAD_CONFIG: invalid major GLES version: %d\n",
+              __func__, __LINE__, majorVersion);
         setErrorReturn(EGL_BAD_CONFIG, EGL_NO_CONTEXT);
     }
 
@@ -1856,41 +1859,25 @@
                 context->minorVersion,
                 context->deviceMajorVersion,
                 context->deviceMinorVersion);
-            // Get caps for indexed buffers from host.
-            // Some need a current context.
-            int max_transform_feedback_separate_attribs = 0;
-            int max_uniform_buffer_bindings = 0;
-            int max_atomic_counter_buffer_bindings = 0;
-            int max_shader_storage_buffer_bindings = 0;
-            int max_vertex_attrib_bindings = 0;
-            int max_color_attachments = 1;
-            int max_draw_buffers = 1;
-            if (context->majorVersion > 2) {
-                s_display.gles2_iface()->getIntegerv(
-                        GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &max_transform_feedback_separate_attribs);
-                s_display.gles2_iface()->getIntegerv(
-                        GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_uniform_buffer_bindings);
-                if (context->minorVersion > 0) {
-                    s_display.gles2_iface()->getIntegerv(
-                            GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &max_atomic_counter_buffer_bindings);
-                    s_display.gles2_iface()->getIntegerv(
-                            GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &max_shader_storage_buffer_bindings);
-                    s_display.gles2_iface()->getIntegerv(
-                            GL_MAX_VERTEX_ATTRIB_BINDINGS, &max_vertex_attrib_bindings);
-                }
-                s_display.gles2_iface()->getIntegerv(
-                        GL_MAX_COLOR_ATTACHMENTS, &max_color_attachments);
-                s_display.gles2_iface()->getIntegerv(
-                        GL_MAX_DRAW_BUFFERS, &max_draw_buffers);
+            hostCon->gl2Encoder()->setClientState(contextState);
+            if (context->majorVersion > 1) {
+                HostDriverCaps caps = s_display.getHostDriverCaps(
+                    context->majorVersion,
+                    context->minorVersion);
+                contextState->initFromCaps(caps);
+            } else {
+                // Just put some stuff here to make gles1 happy
+                HostDriverCaps gles1Caps = {
+                    .max_vertex_attribs = 16,
+                    .max_combined_texture_image_units = 8,
+                    .max_color_attachments = 8,
+
+                    .max_texture_size = 4096,
+                    .max_texture_size_cube_map = 2048,
+                    .max_renderbuffer_size = 4096,
+                };
+                contextState->initFromCaps(gles1Caps);
             }
-            contextState->initFromCaps(
-                    max_transform_feedback_separate_attribs,
-                    max_uniform_buffer_bindings,
-                    max_atomic_counter_buffer_bindings,
-                    max_shader_storage_buffer_bindings,
-                    max_vertex_attrib_bindings,
-                    max_color_attachments,
-                    max_draw_buffers);
         }
 
         // update the client state, share group, and version
@@ -1977,6 +1964,7 @@
         case EGL_DRAW:
             return context->draw;
         default:
+            ALOGE("%s:%d unknown parameter: 0x%x\n", __func__, __LINE__, readdraw);
             setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
     }
 }
@@ -2127,7 +2115,11 @@
             case HAL_PIXEL_FORMAT_YCBCR_420_888:
 #endif
                 break;
+            case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
+                ALOGW("%s:%d using HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED\n", __func__, __LINE__);
+                break;
             default:
+                ALOGE("%s:%d unknown parameter: 0x%x\n", __func__, __LINE__, format);
                 setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
         }
 
diff --git a/system/egl/eglDisplay.cpp b/system/egl/eglDisplay.cpp
index 2508f48..7f4800c 100644
--- a/system/egl/eglDisplay.cpp
+++ b/system/egl/eglDisplay.cpp
@@ -26,6 +26,8 @@
 
 #include <dlfcn.h>
 
+#include <GLES3/gl31.h>
+
 static const int systemEGLVersionMajor = 1;
 static const int systemEGLVersionMinor = 4;
 static const char systemEGLVendor[] = "Google Android emulator";
@@ -73,7 +75,9 @@
     m_gles2_iface(NULL),
     m_versionString(NULL),
     m_vendorString(NULL),
-    m_extensionString(NULL)
+    m_extensionString(NULL),
+    m_hostDriverCaps_knownMajorVersion(0),
+    m_hostDriverCaps_knownMinorVersion(0)
 {
     pthread_mutex_init(&m_lock, NULL);
     pthread_mutex_init(&m_ctxLock, NULL);
@@ -171,7 +175,6 @@
 
         uint32_t nInts = m_numConfigAttribs * (m_numConfigs + 1);
         EGLint tmp_buf[nInts];
-        uint32_t configCount = nInts - m_numConfigAttribs;
 
         m_configs = new EGLint[nInts-m_numConfigAttribs];
 
@@ -654,3 +657,55 @@
     pthread_mutex_unlock(&m_surfaceLock);
     return res;
 }
+
+HostDriverCaps eglDisplay::getHostDriverCaps(int majorVersion, int minorVersion) {
+    pthread_mutex_lock(&m_lock);
+    if (majorVersion <= m_hostDriverCaps_knownMajorVersion &&
+        minorVersion <= m_hostDriverCaps_knownMinorVersion) {
+        pthread_mutex_unlock(&m_lock);
+        return m_hostDriverCaps;
+    }
+
+    memset(&m_hostDriverCaps, 0x0, sizeof(m_hostDriverCaps));
+
+    m_hostDriverCaps.max_color_attachments = 8;
+
+    // Can we query gles2?
+    if (majorVersion >= 1) {
+        m_gles2_iface->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &m_hostDriverCaps.max_vertex_attribs);
+        m_gles2_iface->getIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_hostDriverCaps.max_combined_texture_image_units);
+
+        m_gles2_iface->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_hostDriverCaps.max_texture_size);
+        m_gles2_iface->getIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &m_hostDriverCaps.max_texture_size_cube_map);
+        m_gles2_iface->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_hostDriverCaps.max_renderbuffer_size);
+        m_hostDriverCaps_knownMajorVersion = 2;
+    }
+
+    // Can we query gles3.0?
+    if (majorVersion >= 3) {
+        m_gles2_iface->getIntegerv(GL_MAX_COLOR_ATTACHMENTS, &m_hostDriverCaps.max_color_attachments);
+        m_gles2_iface->getIntegerv(GL_MAX_DRAW_BUFFERS, &m_hostDriverCaps.max_draw_buffers);
+        m_gles2_iface->getIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &m_hostDriverCaps.ubo_offset_alignment);
+        m_gles2_iface->getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &m_hostDriverCaps.max_uniform_buffer_bindings);
+        m_gles2_iface->getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &m_hostDriverCaps.max_transform_feedback_separate_attribs);
+        m_gles2_iface->getIntegerv(GL_MAX_3D_TEXTURE_SIZE, &m_hostDriverCaps.max_texture_size_3d);
+        m_gles2_iface->getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &m_hostDriverCaps.max_array_texture_layers);
+
+        m_hostDriverCaps_knownMajorVersion = 3;
+
+        // Can we query gles3.1?
+        if (minorVersion >= 1) {
+            m_gles2_iface->getIntegerv(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &m_hostDriverCaps.max_atomic_counter_buffer_bindings);
+            m_gles2_iface->getIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &m_hostDriverCaps.max_shader_storage_buffer_bindings);
+            m_gles2_iface->getIntegerv(GL_MAX_VERTEX_ATTRIB_BINDINGS, &m_hostDriverCaps.max_vertex_attrib_bindings);
+            m_gles2_iface->getIntegerv(GL_MAX_VERTEX_ATTRIB_STRIDE, &m_hostDriverCaps.max_vertex_attrib_stride);
+            m_gles2_iface->getIntegerv(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, &m_hostDriverCaps.ssbo_offset_alignment);
+            m_hostDriverCaps_knownMinorVersion = 1;
+        }
+    }
+
+    pthread_mutex_unlock(&m_lock);
+
+    return m_hostDriverCaps;
+}
+
diff --git a/system/egl/eglDisplay.h b/system/egl/eglDisplay.h
index 951075d..25494e1 100644
--- a/system/egl/eglDisplay.h
+++ b/system/egl/eglDisplay.h
@@ -22,6 +22,7 @@
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
 #include "EGLClientIface.h"
+#include "GLClientState.h"
 
 #if __cplusplus >= 201103L
 #include <unordered_set>
@@ -76,6 +77,10 @@
 
     bool isContext(EGLContext ctx);
     bool isSurface(EGLSurface ctx);
+
+    // Needs a current context (put this near eglMakeCurrent)
+    HostDriverCaps getHostDriverCaps(int majorVersion, int minorVersion);
+
 private:
     EGLClient_glesInterface *loadGLESClientAPI(const char *libName,
                                                EGLClient_eglInterface *eglIface,
@@ -118,6 +123,10 @@
     EGLSurfaceSet m_surfaces;
     pthread_mutex_t m_ctxLock;
     pthread_mutex_t m_surfaceLock;
+
+    int m_hostDriverCaps_knownMajorVersion;
+    int m_hostDriverCaps_knownMinorVersion;
+    HostDriverCaps m_hostDriverCaps;
 };
 
 #endif
diff --git a/system/gralloc/Android.mk b/system/gralloc/Android.mk
index 38ae394..5d5667e 100644
--- a/system/gralloc/Android.mk
+++ b/system/gralloc/Android.mk
@@ -20,7 +20,7 @@
 ifneq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
 LOCAL_SHARED_LIBRARIES += libdl
 
-ifeq (true,$(BUILD_EMULATOR_VULKAN))
+ifeq (true,$(GFXSTREAM))
 LOCAL_CFLAGS += -DVIRTIO_GPU
 LOCAL_C_INCLUDES += external/libdrm external/minigbm/cros_gralloc
 LOCAL_SHARED_LIBRARIES += libdrm
diff --git a/system/gralloc/CMakeLists.txt b/system/gralloc/CMakeLists.txt
index 21bcde2..c090eb3 100644
--- a/system/gralloc/CMakeLists.txt
+++ b/system/gralloc/CMakeLists.txt
@@ -1,20 +1,20 @@
 # This is an autogenerated file! Do not edit!
 # instead run make from .../device/generic/goldfish-opengl
 # which will re-generate this file.
-android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/gralloc/Android.mk" "c6313719aae414d05f6f4e8c6eb9039dd5cb120ae0a63818e25bfbe0cebcc702")
+android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/gralloc/Android.mk" "4c44a906197808b25fde953a476e026aac725e5286e0f91d5f8a3083f40f49da")
 set(gralloc.goldfish_src gralloc_old.cpp)
 android_add_library(TARGET gralloc.goldfish SHARED LICENSE Apache-2.0 SRC gralloc_old.cpp)
-target_include_directories(gralloc.goldfish PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(gralloc.goldfish PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"gralloc_goldfish\"")
+target_include_directories(gralloc.goldfish PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(gralloc.goldfish PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"gralloc_goldfish\"")
 target_compile_options(gralloc.goldfish PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-Wno-gnu-designator")
-target_link_libraries(gralloc.goldfish PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui androidemu cutils utils log GLESv2_enc _renderControl_enc GLESv1_enc OpenglCodecCommon_host PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
+target_link_libraries(gralloc.goldfish PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui log GLESv2_enc _renderControl_enc GLESv1_enc OpenglCodecCommon_host cutils utils androidemu PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
 # This is an autogenerated file! Do not edit!
 # instead run make from .../device/generic/goldfish-opengl
 # which will re-generate this file.
-android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/gralloc/Android.mk" "c6313719aae414d05f6f4e8c6eb9039dd5cb120ae0a63818e25bfbe0cebcc702")
+android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/gralloc/Android.mk" "4c44a906197808b25fde953a476e026aac725e5286e0f91d5f8a3083f40f49da")
 set(gralloc.ranchu_src gralloc_old.cpp)
 android_add_library(TARGET gralloc.ranchu SHARED LICENSE Apache-2.0 SRC gralloc_old.cpp)
-target_include_directories(gralloc.ranchu PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(gralloc.ranchu PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"gralloc_ranchu\"")
+target_include_directories(gralloc.ranchu PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(gralloc.ranchu PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"gralloc_ranchu\"")
 target_compile_options(gralloc.ranchu PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-Wno-gnu-designator")
-target_link_libraries(gralloc.ranchu PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui androidemu cutils utils log GLESv2_enc _renderControl_enc GLESv1_enc OpenglCodecCommon_host PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
+target_link_libraries(gralloc.ranchu PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui log GLESv2_enc _renderControl_enc GLESv1_enc OpenglCodecCommon_host cutils utils androidemu PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
diff --git a/system/renderControl_enc/CMakeLists.txt b/system/renderControl_enc/CMakeLists.txt
index 8a42acb..a2b4221 100644
--- a/system/renderControl_enc/CMakeLists.txt
+++ b/system/renderControl_enc/CMakeLists.txt
@@ -4,7 +4,7 @@
 android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc/Android.mk" "780a007ac7a3d2255372ddf40e03aeb10e4c759343d2532f6ddf769f4df73810")
 set(_renderControl_enc_src renderControl_client_context.cpp renderControl_enc.cpp renderControl_entry.cpp)
 android_add_library(TARGET _renderControl_enc SHARED LICENSE Apache-2.0 SRC renderControl_client_context.cpp renderControl_enc.cpp renderControl_entry.cpp)
-target_include_directories(_renderControl_enc PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
-target_compile_definitions(_renderControl_enc PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN")
+target_include_directories(_renderControl_enc PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_compile_definitions(_renderControl_enc PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM")
 target_compile_options(_renderControl_enc PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-unused-function")
-target_link_libraries(_renderControl_enc PRIVATE OpenglCodecCommon_host cutils utils log android-emu-shared PRIVATE qemupipe_host)
\ No newline at end of file
+target_link_libraries(_renderControl_enc PRIVATE OpenglCodecCommon_host cutils utils log androidemu android-emu-shared PRIVATE qemupipe_host)
\ No newline at end of file
diff --git a/system/renderControl_enc/renderControl_client_context.cpp b/system/renderControl_enc/renderControl_client_context.cpp
index ca38884..5b1f14e 100644
--- a/system/renderControl_enc/renderControl_client_context.cpp
+++ b/system/renderControl_enc/renderControl_client_context.cpp
@@ -61,6 +61,10 @@
 	rcCreateColorBufferWithHandle = (rcCreateColorBufferWithHandle_client_proc_t) getProc("rcCreateColorBufferWithHandle", userData);
 	rcCreateBuffer = (rcCreateBuffer_client_proc_t) getProc("rcCreateBuffer", userData);
 	rcCloseBuffer = (rcCloseBuffer_client_proc_t) getProc("rcCloseBuffer", userData);
+	rcSetColorBufferVulkanMode2 = (rcSetColorBufferVulkanMode2_client_proc_t) getProc("rcSetColorBufferVulkanMode2", userData);
+	rcMapGpaToBufferHandle = (rcMapGpaToBufferHandle_client_proc_t) getProc("rcMapGpaToBufferHandle", userData);
+	rcCreateBuffer2 = (rcCreateBuffer2_client_proc_t) getProc("rcCreateBuffer2", userData);
+	rcMapGpaToBufferHandle2 = (rcMapGpaToBufferHandle2_client_proc_t) getProc("rcMapGpaToBufferHandle2", userData);
 	return 0;
 }
 
diff --git a/system/renderControl_enc/renderControl_client_context.h b/system/renderControl_enc/renderControl_client_context.h
index c9dc410..2032a32 100644
--- a/system/renderControl_enc/renderControl_client_context.h
+++ b/system/renderControl_enc/renderControl_client_context.h
@@ -61,6 +61,10 @@
 	rcCreateColorBufferWithHandle_client_proc_t rcCreateColorBufferWithHandle;
 	rcCreateBuffer_client_proc_t rcCreateBuffer;
 	rcCloseBuffer_client_proc_t rcCloseBuffer;
+	rcSetColorBufferVulkanMode2_client_proc_t rcSetColorBufferVulkanMode2;
+	rcMapGpaToBufferHandle_client_proc_t rcMapGpaToBufferHandle;
+	rcCreateBuffer2_client_proc_t rcCreateBuffer2;
+	rcMapGpaToBufferHandle2_client_proc_t rcMapGpaToBufferHandle2;
 	virtual ~renderControl_client_context_t() {}
 
 	typedef renderControl_client_context_t *CONTEXT_ACCESSOR_TYPE(void);
diff --git a/system/renderControl_enc/renderControl_client_proc.h b/system/renderControl_enc/renderControl_client_proc.h
index 4192b0e..c0b9a7f 100644
--- a/system/renderControl_enc/renderControl_client_proc.h
+++ b/system/renderControl_enc/renderControl_client_proc.h
@@ -63,6 +63,10 @@
 typedef void (renderControl_APIENTRY *rcCreateColorBufferWithHandle_client_proc_t) (void * ctx, uint32_t, uint32_t, GLenum, uint32_t);
 typedef uint32_t (renderControl_APIENTRY *rcCreateBuffer_client_proc_t) (void * ctx, uint32_t);
 typedef void (renderControl_APIENTRY *rcCloseBuffer_client_proc_t) (void * ctx, uint32_t);
+typedef GLint (renderControl_APIENTRY *rcSetColorBufferVulkanMode2_client_proc_t) (void * ctx, uint32_t, uint32_t, uint32_t);
+typedef int (renderControl_APIENTRY *rcMapGpaToBufferHandle_client_proc_t) (void * ctx, uint32_t, uint64_t);
+typedef uint32_t (renderControl_APIENTRY *rcCreateBuffer2_client_proc_t) (void * ctx, uint64_t, uint32_t);
+typedef int (renderControl_APIENTRY *rcMapGpaToBufferHandle2_client_proc_t) (void * ctx, uint32_t, uint64_t, uint64_t);
 
 
 #endif
diff --git a/system/renderControl_enc/renderControl_enc.cpp b/system/renderControl_enc/renderControl_enc.cpp
index b841bf1..6b2680c 100644
--- a/system/renderControl_enc/renderControl_enc.cpp
+++ b/system/renderControl_enc/renderControl_enc.cpp
@@ -12,6 +12,7 @@
 
 #include <stdio.h>
 
+#include "android/base/Tracing.h"
 namespace {
 
 void enc_unsupported()
@@ -21,6 +22,7 @@
 
 GLint rcGetRendererVersion_enc(void *self )
 {
+	AEMU_SCOPED_TRACE("rcGetRendererVersion encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -60,6 +62,7 @@
 
 EGLint rcGetEGLVersion_enc(void *self , EGLint* major, EGLint* minor)
 {
+	AEMU_SCOPED_TRACE("rcGetEGLVersion encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -107,6 +110,7 @@
 
 EGLint rcQueryEGLString_enc(void *self , EGLenum name, void* buffer, EGLint bufferSize)
 {
+	AEMU_SCOPED_TRACE("rcQueryEGLString encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -152,6 +156,7 @@
 
 EGLint rcGetGLString_enc(void *self , EGLenum name, void* buffer, EGLint bufferSize)
 {
+	AEMU_SCOPED_TRACE("rcGetGLString encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -197,6 +202,7 @@
 
 EGLint rcGetNumConfigs_enc(void *self , uint32_t* numAttribs)
 {
+	AEMU_SCOPED_TRACE("rcGetNumConfigs encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -240,6 +246,7 @@
 
 EGLint rcGetConfigs_enc(void *self , uint32_t bufSize, GLuint* buffer)
 {
+	AEMU_SCOPED_TRACE("rcGetConfigs encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -284,6 +291,7 @@
 
 EGLint rcChooseConfig_enc(void *self , EGLint* attribs, uint32_t attribs_size, uint32_t* configs, uint32_t configs_size)
 {
+	AEMU_SCOPED_TRACE("rcChooseConfig encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -334,6 +342,7 @@
 
 EGLint rcGetFBParam_enc(void *self , EGLint param)
 {
+	AEMU_SCOPED_TRACE("rcGetFBParam encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -374,6 +383,7 @@
 
 uint32_t rcCreateContext_enc(void *self , uint32_t config, uint32_t share, uint32_t glVersion)
 {
+	AEMU_SCOPED_TRACE("rcCreateContext encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -416,6 +426,7 @@
 
 void rcDestroyContext_enc(void *self , uint32_t context)
 {
+	AEMU_SCOPED_TRACE("rcDestroyContext encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -441,6 +452,7 @@
 
 uint32_t rcCreateWindowSurface_enc(void *self , uint32_t config, uint32_t width, uint32_t height)
 {
+	AEMU_SCOPED_TRACE("rcCreateWindowSurface encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -483,6 +495,7 @@
 
 void rcDestroyWindowSurface_enc(void *self , uint32_t windowSurface)
 {
+	AEMU_SCOPED_TRACE("rcDestroyWindowSurface encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -508,6 +521,7 @@
 
 uint32_t rcCreateColorBuffer_enc(void *self , uint32_t width, uint32_t height, GLenum internalFormat)
 {
+	AEMU_SCOPED_TRACE("rcCreateColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -550,6 +564,7 @@
 
 void rcOpenColorBuffer_enc(void *self , uint32_t colorbuffer)
 {
+	AEMU_SCOPED_TRACE("rcOpenColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -575,6 +590,7 @@
 
 void rcCloseColorBuffer_enc(void *self , uint32_t colorbuffer)
 {
+	AEMU_SCOPED_TRACE("rcCloseColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -601,6 +617,7 @@
 
 void rcSetWindowColorBuffer_enc(void *self , uint32_t windowSurface, uint32_t colorBuffer)
 {
+	AEMU_SCOPED_TRACE("rcSetWindowColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -627,6 +644,7 @@
 
 int rcFlushWindowColorBuffer_enc(void *self , uint32_t windowSurface)
 {
+	AEMU_SCOPED_TRACE("rcFlushWindowColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -667,6 +685,7 @@
 
 EGLint rcMakeCurrent_enc(void *self , uint32_t context, uint32_t drawSurf, uint32_t readSurf)
 {
+	AEMU_SCOPED_TRACE("rcMakeCurrent encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -709,6 +728,7 @@
 
 void rcFBPost_enc(void *self , uint32_t colorBuffer)
 {
+	AEMU_SCOPED_TRACE("rcFBPost encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -734,6 +754,7 @@
 
 void rcFBSetSwapInterval_enc(void *self , EGLint interval)
 {
+	AEMU_SCOPED_TRACE("rcFBSetSwapInterval encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -759,6 +780,7 @@
 
 void rcBindTexture_enc(void *self , uint32_t colorBuffer)
 {
+	AEMU_SCOPED_TRACE("rcBindTexture encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -784,6 +806,7 @@
 
 void rcBindRenderbuffer_enc(void *self , uint32_t colorBuffer)
 {
+	AEMU_SCOPED_TRACE("rcBindRenderbuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -809,6 +832,7 @@
 
 EGLint rcColorBufferCacheFlush_enc(void *self , uint32_t colorbuffer, EGLint postCount, int forRead)
 {
+	AEMU_SCOPED_TRACE("rcColorBufferCacheFlush encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -851,6 +875,7 @@
 
 void rcReadColorBuffer_enc(void *self , uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void* pixels)
 {
+	AEMU_SCOPED_TRACE("rcReadColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -896,6 +921,7 @@
 
 int rcUpdateColorBuffer_enc(void *self , uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void* pixels)
 {
+	AEMU_SCOPED_TRACE("rcUpdateColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -949,6 +975,7 @@
 
 int rcOpenColorBuffer2_enc(void *self , uint32_t colorbuffer)
 {
+	AEMU_SCOPED_TRACE("rcOpenColorBuffer2 encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -989,6 +1016,7 @@
 
 uint32_t rcCreateClientImage_enc(void *self , uint32_t context, EGLenum target, GLuint buffer)
 {
+	AEMU_SCOPED_TRACE("rcCreateClientImage encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1031,6 +1059,7 @@
 
 int rcDestroyClientImage_enc(void *self , uint32_t image)
 {
+	AEMU_SCOPED_TRACE("rcDestroyClientImage encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1071,6 +1100,7 @@
 
 void rcSelectChecksumHelper_enc(void *self , uint32_t newProtocol, uint32_t reserved)
 {
+	AEMU_SCOPED_TRACE("rcSelectChecksumHelper encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1097,6 +1127,7 @@
 
 void rcCreateSyncKHR_enc(void *self , EGLenum type, EGLint* attribs, uint32_t num_attribs, int destroy_when_signaled, uint64_t* glsync_out, uint64_t* syncthread_out)
 {
+	AEMU_SCOPED_TRACE("rcCreateSyncKHR encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1145,6 +1176,7 @@
 
 EGLint rcClientWaitSyncKHR_enc(void *self , uint64_t sync, EGLint flags, uint64_t timeout)
 {
+	AEMU_SCOPED_TRACE("rcClientWaitSyncKHR encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1187,6 +1219,7 @@
 
 void rcFlushWindowColorBufferAsync_enc(void *self , uint32_t windowSurface)
 {
+	AEMU_SCOPED_TRACE("rcFlushWindowColorBufferAsync encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1212,6 +1245,7 @@
 
 int rcDestroySyncKHR_enc(void *self , uint64_t sync)
 {
+	AEMU_SCOPED_TRACE("rcDestroySyncKHR encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1252,6 +1286,7 @@
 
 void rcSetPuid_enc(void *self , uint64_t puid)
 {
+	AEMU_SCOPED_TRACE("rcSetPuid encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1277,6 +1312,7 @@
 
 int rcUpdateColorBufferDMA_enc(void *self , uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void* pixels, uint32_t pixels_size)
 {
+	AEMU_SCOPED_TRACE("rcUpdateColorBufferDMA encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1326,6 +1362,7 @@
 
 uint32_t rcCreateColorBufferDMA_enc(void *self , uint32_t width, uint32_t height, GLenum internalFormat, int frameworkFormat)
 {
+	AEMU_SCOPED_TRACE("rcCreateColorBufferDMA encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1369,6 +1406,7 @@
 
 void rcWaitSyncKHR_enc(void *self , uint64_t sync, EGLint flags)
 {
+	AEMU_SCOPED_TRACE("rcWaitSyncKHR encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1395,6 +1433,7 @@
 
 GLint rcCompose_enc(void *self , uint32_t bufferSize, void* buffer)
 {
+	AEMU_SCOPED_TRACE("rcCompose encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1438,6 +1477,7 @@
 
 int rcCreateDisplay_enc(void *self , uint32_t* displayId)
 {
+	AEMU_SCOPED_TRACE("rcCreateDisplay encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1481,6 +1521,7 @@
 
 int rcDestroyDisplay_enc(void *self , uint32_t displayId)
 {
+	AEMU_SCOPED_TRACE("rcDestroyDisplay encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1521,6 +1562,7 @@
 
 int rcSetDisplayColorBuffer_enc(void *self , uint32_t displayId, uint32_t colorBuffer)
 {
+	AEMU_SCOPED_TRACE("rcSetDisplayColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1562,6 +1604,7 @@
 
 int rcGetDisplayColorBuffer_enc(void *self , uint32_t displayId, uint32_t* colorBuffer)
 {
+	AEMU_SCOPED_TRACE("rcGetDisplayColorBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1606,6 +1649,7 @@
 
 int rcGetColorBufferDisplay_enc(void *self , uint32_t colorBuffer, uint32_t* displayId)
 {
+	AEMU_SCOPED_TRACE("rcGetColorBufferDisplay encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1650,6 +1694,7 @@
 
 int rcGetDisplayPose_enc(void *self , uint32_t displayId, GLint* x, GLint* y, uint32_t* w, uint32_t* h)
 {
+	AEMU_SCOPED_TRACE("rcGetDisplayPose encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1706,6 +1751,7 @@
 
 int rcSetDisplayPose_enc(void *self , uint32_t displayId, GLint x, GLint y, uint32_t w, uint32_t h)
 {
+	AEMU_SCOPED_TRACE("rcSetDisplayPose encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1750,6 +1796,7 @@
 
 GLint rcSetColorBufferVulkanMode_enc(void *self , uint32_t colorBuffer, uint32_t mode)
 {
+	AEMU_SCOPED_TRACE("rcSetColorBufferVulkanMode encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1791,6 +1838,7 @@
 
 void rcReadColorBufferYUV_enc(void *self , uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, void* pixels, uint32_t pixels_size)
 {
+	AEMU_SCOPED_TRACE("rcReadColorBufferYUV encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1835,6 +1883,7 @@
 
 int rcIsSyncSignaled_enc(void *self , uint64_t sync)
 {
+	AEMU_SCOPED_TRACE("rcIsSyncSignaled encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1875,6 +1924,7 @@
 
 void rcCreateColorBufferWithHandle_enc(void *self , uint32_t width, uint32_t height, GLenum internalFormat, uint32_t handle)
 {
+	AEMU_SCOPED_TRACE("rcCreateColorBufferWithHandle encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1903,6 +1953,7 @@
 
 uint32_t rcCreateBuffer_enc(void *self , uint32_t size)
 {
+	AEMU_SCOPED_TRACE("rcCreateBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1943,6 +1994,7 @@
 
 void rcCloseBuffer_enc(void *self , uint32_t buffer)
 {
+	AEMU_SCOPED_TRACE("rcCloseBuffer encode");
 
 	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
 	IOStream *stream = ctx->m_stream;
@@ -1966,6 +2018,176 @@
 
 }
 
+GLint rcSetColorBufferVulkanMode2_enc(void *self , uint32_t colorBuffer, uint32_t mode, uint32_t memoryProperty)
+{
+	AEMU_SCOPED_TRACE("rcSetColorBufferVulkanMode2 encode");
+
+	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
+	IOStream *stream = ctx->m_stream;
+	ChecksumCalculator *checksumCalculator = ctx->m_checksumCalculator;
+	bool useChecksum = checksumCalculator->getVersion() > 0;
+
+	 unsigned char *ptr;
+	 unsigned char *buf;
+	 const size_t sizeWithoutChecksum = 8 + 4 + 4 + 4;
+	 const size_t checksumSize = checksumCalculator->checksumByteSize();
+	 const size_t totalSize = sizeWithoutChecksum + checksumSize;
+	buf = stream->alloc(totalSize);
+	ptr = buf;
+	int tmp = OP_rcSetColorBufferVulkanMode2;memcpy(ptr, &tmp, 4); ptr += 4;
+	memcpy(ptr, &totalSize, 4);  ptr += 4;
+
+		memcpy(ptr, &colorBuffer, 4); ptr += 4;
+		memcpy(ptr, &mode, 4); ptr += 4;
+		memcpy(ptr, &memoryProperty, 4); ptr += 4;
+
+	if (useChecksum) checksumCalculator->addBuffer(buf, ptr-buf);
+	if (useChecksum) checksumCalculator->writeChecksum(ptr, checksumSize); ptr += checksumSize;
+
+
+	GLint retval;
+	stream->readback(&retval, 4);
+	if (useChecksum) checksumCalculator->addBuffer(&retval, 4);
+	if (useChecksum) {
+		unsigned char *checksumBufPtr = NULL;
+		unsigned char checksumBuf[ChecksumCalculator::kMaxChecksumSize];
+		if (checksumSize > 0) checksumBufPtr = &checksumBuf[0];
+		stream->readback(checksumBufPtr, checksumSize);
+		if (!checksumCalculator->validate(checksumBufPtr, checksumSize)) {
+			ALOGE("rcSetColorBufferVulkanMode2: GL communication error, please report this issue to b.android.com.\n");
+			abort();
+		}
+	}
+	return retval;
+}
+
+int rcMapGpaToBufferHandle_enc(void *self , uint32_t bufferHandle, uint64_t gpa)
+{
+	AEMU_SCOPED_TRACE("rcMapGpaToBufferHandle encode");
+
+	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
+	IOStream *stream = ctx->m_stream;
+	ChecksumCalculator *checksumCalculator = ctx->m_checksumCalculator;
+	bool useChecksum = checksumCalculator->getVersion() > 0;
+
+	 unsigned char *ptr;
+	 unsigned char *buf;
+	 const size_t sizeWithoutChecksum = 8 + 4 + 8;
+	 const size_t checksumSize = checksumCalculator->checksumByteSize();
+	 const size_t totalSize = sizeWithoutChecksum + checksumSize;
+	buf = stream->alloc(totalSize);
+	ptr = buf;
+	int tmp = OP_rcMapGpaToBufferHandle;memcpy(ptr, &tmp, 4); ptr += 4;
+	memcpy(ptr, &totalSize, 4);  ptr += 4;
+
+		memcpy(ptr, &bufferHandle, 4); ptr += 4;
+		memcpy(ptr, &gpa, 8); ptr += 8;
+
+	if (useChecksum) checksumCalculator->addBuffer(buf, ptr-buf);
+	if (useChecksum) checksumCalculator->writeChecksum(ptr, checksumSize); ptr += checksumSize;
+
+
+	int retval;
+	stream->readback(&retval, 4);
+	if (useChecksum) checksumCalculator->addBuffer(&retval, 4);
+	if (useChecksum) {
+		unsigned char *checksumBufPtr = NULL;
+		unsigned char checksumBuf[ChecksumCalculator::kMaxChecksumSize];
+		if (checksumSize > 0) checksumBufPtr = &checksumBuf[0];
+		stream->readback(checksumBufPtr, checksumSize);
+		if (!checksumCalculator->validate(checksumBufPtr, checksumSize)) {
+			ALOGE("rcMapGpaToBufferHandle: GL communication error, please report this issue to b.android.com.\n");
+			abort();
+		}
+	}
+	return retval;
+}
+
+uint32_t rcCreateBuffer2_enc(void *self , uint64_t size, uint32_t memoryProperty)
+{
+	AEMU_SCOPED_TRACE("rcCreateBuffer2 encode");
+
+	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
+	IOStream *stream = ctx->m_stream;
+	ChecksumCalculator *checksumCalculator = ctx->m_checksumCalculator;
+	bool useChecksum = checksumCalculator->getVersion() > 0;
+
+	 unsigned char *ptr;
+	 unsigned char *buf;
+	 const size_t sizeWithoutChecksum = 8 + 8 + 4;
+	 const size_t checksumSize = checksumCalculator->checksumByteSize();
+	 const size_t totalSize = sizeWithoutChecksum + checksumSize;
+	buf = stream->alloc(totalSize);
+	ptr = buf;
+	int tmp = OP_rcCreateBuffer2;memcpy(ptr, &tmp, 4); ptr += 4;
+	memcpy(ptr, &totalSize, 4);  ptr += 4;
+
+		memcpy(ptr, &size, 8); ptr += 8;
+		memcpy(ptr, &memoryProperty, 4); ptr += 4;
+
+	if (useChecksum) checksumCalculator->addBuffer(buf, ptr-buf);
+	if (useChecksum) checksumCalculator->writeChecksum(ptr, checksumSize); ptr += checksumSize;
+
+
+	uint32_t retval;
+	stream->readback(&retval, 4);
+	if (useChecksum) checksumCalculator->addBuffer(&retval, 4);
+	if (useChecksum) {
+		unsigned char *checksumBufPtr = NULL;
+		unsigned char checksumBuf[ChecksumCalculator::kMaxChecksumSize];
+		if (checksumSize > 0) checksumBufPtr = &checksumBuf[0];
+		stream->readback(checksumBufPtr, checksumSize);
+		if (!checksumCalculator->validate(checksumBufPtr, checksumSize)) {
+			ALOGE("rcCreateBuffer2: GL communication error, please report this issue to b.android.com.\n");
+			abort();
+		}
+	}
+	return retval;
+}
+
+int rcMapGpaToBufferHandle2_enc(void *self , uint32_t bufferHandle, uint64_t gpa, uint64_t size)
+{
+	AEMU_SCOPED_TRACE("rcMapGpaToBufferHandle2 encode");
+
+	renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
+	IOStream *stream = ctx->m_stream;
+	ChecksumCalculator *checksumCalculator = ctx->m_checksumCalculator;
+	bool useChecksum = checksumCalculator->getVersion() > 0;
+
+	 unsigned char *ptr;
+	 unsigned char *buf;
+	 const size_t sizeWithoutChecksum = 8 + 4 + 8 + 8;
+	 const size_t checksumSize = checksumCalculator->checksumByteSize();
+	 const size_t totalSize = sizeWithoutChecksum + checksumSize;
+	buf = stream->alloc(totalSize);
+	ptr = buf;
+	int tmp = OP_rcMapGpaToBufferHandle2;memcpy(ptr, &tmp, 4); ptr += 4;
+	memcpy(ptr, &totalSize, 4);  ptr += 4;
+
+		memcpy(ptr, &bufferHandle, 4); ptr += 4;
+		memcpy(ptr, &gpa, 8); ptr += 8;
+		memcpy(ptr, &size, 8); ptr += 8;
+
+	if (useChecksum) checksumCalculator->addBuffer(buf, ptr-buf);
+	if (useChecksum) checksumCalculator->writeChecksum(ptr, checksumSize); ptr += checksumSize;
+
+
+	int retval;
+	stream->readback(&retval, 4);
+	if (useChecksum) checksumCalculator->addBuffer(&retval, 4);
+	if (useChecksum) {
+		unsigned char *checksumBufPtr = NULL;
+		unsigned char checksumBuf[ChecksumCalculator::kMaxChecksumSize];
+		if (checksumSize > 0) checksumBufPtr = &checksumBuf[0];
+		stream->readback(checksumBufPtr, checksumSize);
+		if (!checksumCalculator->validate(checksumBufPtr, checksumSize)) {
+			ALOGE("rcMapGpaToBufferHandle2: GL communication error, please report this issue to b.android.com.\n");
+			abort();
+		}
+	}
+	return retval;
+}
+
 }  // namespace
 
 renderControl_encoder_context_t::renderControl_encoder_context_t(IOStream *stream, ChecksumCalculator *checksumCalculator)
@@ -2024,5 +2246,9 @@
 	this->rcCreateColorBufferWithHandle = &rcCreateColorBufferWithHandle_enc;
 	this->rcCreateBuffer = &rcCreateBuffer_enc;
 	this->rcCloseBuffer = &rcCloseBuffer_enc;
+	this->rcSetColorBufferVulkanMode2 = &rcSetColorBufferVulkanMode2_enc;
+	this->rcMapGpaToBufferHandle = &rcMapGpaToBufferHandle_enc;
+	this->rcCreateBuffer2 = &rcCreateBuffer2_enc;
+	this->rcMapGpaToBufferHandle2 = &rcMapGpaToBufferHandle2_enc;
 }
 
diff --git a/system/renderControl_enc/renderControl_entry.cpp b/system/renderControl_enc/renderControl_entry.cpp
index ffa0cdd..0ea37d6 100644
--- a/system/renderControl_enc/renderControl_entry.cpp
+++ b/system/renderControl_enc/renderControl_entry.cpp
@@ -56,6 +56,10 @@
 	void rcCreateColorBufferWithHandle(uint32_t width, uint32_t height, GLenum internalFormat, uint32_t handle);
 	uint32_t rcCreateBuffer(uint32_t size);
 	void rcCloseBuffer(uint32_t buffer);
+	GLint rcSetColorBufferVulkanMode2(uint32_t colorBuffer, uint32_t mode, uint32_t memoryProperty);
+	int rcMapGpaToBufferHandle(uint32_t bufferHandle, uint64_t gpa);
+	uint32_t rcCreateBuffer2(uint64_t size, uint32_t memoryProperty);
+	int rcMapGpaToBufferHandle2(uint32_t bufferHandle, uint64_t gpa, uint64_t size);
 };
 
 #ifndef GET_CONTEXT
@@ -370,3 +374,27 @@
 	ctx->rcCloseBuffer(ctx, buffer);
 }
 
+GLint rcSetColorBufferVulkanMode2(uint32_t colorBuffer, uint32_t mode, uint32_t memoryProperty)
+{
+	GET_CONTEXT;
+	return ctx->rcSetColorBufferVulkanMode2(ctx, colorBuffer, mode, memoryProperty);
+}
+
+int rcMapGpaToBufferHandle(uint32_t bufferHandle, uint64_t gpa)
+{
+	GET_CONTEXT;
+	return ctx->rcMapGpaToBufferHandle(ctx, bufferHandle, gpa);
+}
+
+uint32_t rcCreateBuffer2(uint64_t size, uint32_t memoryProperty)
+{
+	GET_CONTEXT;
+	return ctx->rcCreateBuffer2(ctx, size, memoryProperty);
+}
+
+int rcMapGpaToBufferHandle2(uint32_t bufferHandle, uint64_t gpa, uint64_t size)
+{
+	GET_CONTEXT;
+	return ctx->rcMapGpaToBufferHandle2(ctx, bufferHandle, gpa, size);
+}
+
diff --git a/system/renderControl_enc/renderControl_ftable.h b/system/renderControl_enc/renderControl_ftable.h
index 13aebed..247a0bd 100644
--- a/system/renderControl_enc/renderControl_ftable.h
+++ b/system/renderControl_enc/renderControl_ftable.h
@@ -59,6 +59,10 @@
 	{"rcCreateColorBufferWithHandle", (void*)rcCreateColorBufferWithHandle},
 	{"rcCreateBuffer", (void*)rcCreateBuffer},
 	{"rcCloseBuffer", (void*)rcCloseBuffer},
+	{"rcSetColorBufferVulkanMode2", (void*)rcSetColorBufferVulkanMode2},
+	{"rcMapGpaToBufferHandle", (void*)rcMapGpaToBufferHandle},
+	{"rcCreateBuffer2", (void*)rcCreateBuffer2},
+	{"rcMapGpaToBufferHandle2", (void*)rcMapGpaToBufferHandle2},
 };
 static const int renderControl_num_funcs = sizeof(renderControl_funcs_by_name) / sizeof(struct _renderControl_funcs_by_name);
 
diff --git a/system/renderControl_enc/renderControl_opcodes.h b/system/renderControl_enc/renderControl_opcodes.h
index f1207f2..16c0214 100644
--- a/system/renderControl_enc/renderControl_opcodes.h
+++ b/system/renderControl_enc/renderControl_opcodes.h
@@ -54,7 +54,11 @@
 #define OP_rcCreateColorBufferWithHandle 					10048
 #define OP_rcCreateBuffer 					10049
 #define OP_rcCloseBuffer 					10050
-#define OP_last 					10051
+#define OP_rcSetColorBufferVulkanMode2 					10051
+#define OP_rcMapGpaToBufferHandle 					10052
+#define OP_rcCreateBuffer2 					10053
+#define OP_rcMapGpaToBufferHandle2 					10054
+#define OP_last 					10055
 
 
 #endif
diff --git a/system/vulkan/CMakeLists.txt b/system/vulkan/CMakeLists.txt
index 65bc00a..eb2f612 100644
--- a/system/vulkan/CMakeLists.txt
+++ b/system/vulkan/CMakeLists.txt
@@ -4,7 +4,7 @@
 android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/vulkan/Android.mk" "5cb873c72cc859fac3800961059c1b203ed1abb400ee643178c18e04961d49e8")
 set(vulkan.ranchu_src func_table.cpp goldfish_vulkan.cpp)
 android_add_library(TARGET vulkan.ranchu SHARED LICENSE Apache-2.0 SRC func_table.cpp goldfish_vulkan.cpp)
-target_include_directories(vulkan.ranchu PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/system/vulkan ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/host/include)
-target_compile_definitions(vulkan.ranchu PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"goldfish_vulkan\"" "-DVK_USE_PLATFORM_ANDROID_KHR" "-DVK_NO_PROTOTYPES")
+target_include_directories(vulkan.ranchu PRIVATE ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon/bionic-include ${GOLDFISH_DEVICE_ROOT}/system/OpenglSystemCommon ${GOLDFISH_DEVICE_ROOT}/bionic/libc/private ${GOLDFISH_DEVICE_ROOT}/bionic/libc/platform ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/shared/gralloc_cb/include ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv2_enc ${GOLDFISH_DEVICE_ROOT}/system/GLESv1_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/system/vulkan ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/host/include)
+target_compile_definitions(vulkan.ranchu PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"goldfish_vulkan\"" "-DVK_USE_PLATFORM_ANDROID_KHR" "-DVK_NO_PROTOTYPES")
 target_compile_options(vulkan.ranchu PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-fvisibility=hidden" "-fstrict-aliasing" "-Wno-unused-function")
-target_link_libraries(vulkan.ranchu PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui androidemu cutils utils log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
+target_link_libraries(vulkan.ranchu PRIVATE OpenglSystemCommon android-emu-shared vulkan_enc gui log _renderControl_enc GLESv2_enc GLESv1_enc OpenglCodecCommon_host cutils utils androidemu PRIVATE gralloc_cb_host GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
diff --git a/system/vulkan/func_table.cpp b/system/vulkan/func_table.cpp
index 51913e8..6a4a128 100644
--- a/system/vulkan/func_table.cpp
+++ b/system/vulkan/func_table.cpp
@@ -5338,6 +5338,33 @@
     vkEnc->vkQueueBindSparseAsyncGOOGLE(queue, bindInfoCount, pBindInfo, fence);
 }
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+static void entry_vkGetLinearImageLayoutGOOGLE(
+    VkDevice device,
+    VkFormat format,
+    VkDeviceSize* pOffset,
+    VkDeviceSize* pRowPitchAlignment)
+{
+    AEMU_SCOPED_TRACE("vkGetLinearImageLayoutGOOGLE");
+    auto vkEnc = HostConnection::get()->vkEncoder();
+    vkEnc->vkGetLinearImageLayoutGOOGLE(device, format, pOffset, pRowPitchAlignment);
+}
+static void dynCheck_entry_vkGetLinearImageLayoutGOOGLE(
+    VkDevice device,
+    VkFormat format,
+    VkDeviceSize* pOffset,
+    VkDeviceSize* pRowPitchAlignment)
+{
+    auto resources = ResourceTracker::get();
+    if (!resources->hasDeviceExtension(device, "VK_GOOGLE_linear_image_layout"))
+    {
+        sOnInvalidDynamicallyCheckedCall("vkGetLinearImageLayoutGOOGLE", "VK_GOOGLE_linear_image_layout");
+    }
+    AEMU_SCOPED_TRACE("vkGetLinearImageLayoutGOOGLE");
+    auto vkEnc = HostConnection::get()->vkEncoder();
+    vkEnc->vkGetLinearImageLayoutGOOGLE(device, format, pOffset, pRowPitchAlignment);
+}
+#endif
 void* goldfish_vulkan_get_proc_address(const char* name){
 #ifdef VK_VERSION_1_0
     if (!strcmp(name, "vkCreateInstance"))
@@ -6813,6 +6840,12 @@
         return nullptr;
     }
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+    if (!strcmp(name, "vkGetLinearImageLayoutGOOGLE"))
+    {
+        return nullptr;
+    }
+#endif
     return nullptr;
 }
 void* goldfish_vulkan_get_instance_proc_address(VkInstance instance, const char* name){
@@ -8389,6 +8422,12 @@
         return hasExt ? (void*)entry_vkQueueBindSparseAsyncGOOGLE : nullptr;
     }
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+    if (!strcmp(name, "vkGetLinearImageLayoutGOOGLE"))
+    {
+        return (void*)dynCheck_entry_vkGetLinearImageLayoutGOOGLE;
+    }
+#endif
     return nullptr;
 }
 void* goldfish_vulkan_get_device_proc_address(VkDevice device, const char* name){
@@ -10036,6 +10075,13 @@
         return hasExt ? (void*)entry_vkQueueBindSparseAsyncGOOGLE : nullptr;
     }
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+    if (!strcmp(name, "vkGetLinearImageLayoutGOOGLE"))
+    {
+        bool hasExt = resources->hasDeviceExtension(device, "VK_GOOGLE_linear_image_layout");
+        return hasExt ? (void*)entry_vkGetLinearImageLayoutGOOGLE : nullptr;
+    }
+#endif
     return nullptr;
 }
 
diff --git a/system/vulkan/func_table.h b/system/vulkan/func_table.h
index 9c2e5be..a3a7f99 100644
--- a/system/vulkan/func_table.h
+++ b/system/vulkan/func_table.h
@@ -294,6 +294,8 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 void* goldfish_vulkan_get_proc_address(const char* name);
 void* goldfish_vulkan_get_instance_proc_address(VkInstance instance, const char* name);
 void* goldfish_vulkan_get_device_proc_address(VkDevice device, const char* name);
diff --git a/system/vulkan_enc/CMakeLists.txt b/system/vulkan_enc/CMakeLists.txt
index 5b97015..4488658 100644
--- a/system/vulkan_enc/CMakeLists.txt
+++ b/system/vulkan_enc/CMakeLists.txt
@@ -4,7 +4,7 @@
 android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc/Android.mk" "103f3f10c8af73d3d5c4263c4faa5bb70ebdbfbc9ed6f068a338d57344e2aa45")
 set(vulkan_enc_src AndroidHardwareBuffer.cpp HostVisibleMemoryVirtualization.cpp Resources.cpp Validation.cpp VulkanStreamGuest.cpp VulkanHandleMapping.cpp ResourceTracker.cpp VkEncoder.cpp goldfish_vk_extension_structs_guest.cpp goldfish_vk_marshaling_guest.cpp goldfish_vk_deepcopy_guest.cpp goldfish_vk_handlemap_guest.cpp goldfish_vk_transform_guest.cpp)
 android_add_library(TARGET vulkan_enc SHARED LICENSE Apache-2.0 SRC AndroidHardwareBuffer.cpp HostVisibleMemoryVirtualization.cpp Resources.cpp Validation.cpp VulkanStreamGuest.cpp VulkanHandleMapping.cpp ResourceTracker.cpp VkEncoder.cpp goldfish_vk_extension_structs_guest.cpp goldfish_vk_marshaling_guest.cpp goldfish_vk_deepcopy_guest.cpp goldfish_vk_handlemap_guest.cpp goldfish_vk_transform_guest.cpp)
-target_include_directories(vulkan_enc PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/host/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/host/include/vulkan)
-target_compile_definitions(vulkan_enc PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGOLDFISH_VULKAN" "-DLOG_TAG=\"goldfish_vulkan\"" "-DVK_ANDROID_native_buffer" "-DVK_GOOGLE_address_space" "-DVK_USE_PLATFORM_ANDROID_KHR" "-DVK_NO_PROTOTYPES" "-D__ANDROID_API__=28")
+target_include_directories(vulkan_enc PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/system/renderControl_enc ${GOLDFISH_DEVICE_ROOT}/shared/OpenglCodecCommon ${GOLDFISH_DEVICE_ROOT}/android-emu ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include-types ${GOLDFISH_DEVICE_ROOT}/shared/qemupipe/include ${GOLDFISH_DEVICE_ROOT}/system/vulkan_enc ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/host/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/host/include/vulkan)
+target_compile_definitions(vulkan_enc PRIVATE "-DWITH_GLES2" "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DEMULATOR_OPENGL_POST_O=1" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"goldfish_vulkan\"" "-DVK_ANDROID_native_buffer" "-DVK_GOOGLE_address_space" "-DVK_USE_PLATFORM_ANDROID_KHR" "-DVK_NO_PROTOTYPES" "-D__ANDROID_API__=28")
 target_compile_options(vulkan_enc PRIVATE "-fvisibility=default" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-Werror" "-fstrict-aliasing")
-target_link_libraries(vulkan_enc PRIVATE gui log android-emu-shared androidemu cutils utils _renderControl_enc OpenglCodecCommon_host PRIVATE GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
+target_link_libraries(vulkan_enc PRIVATE gui log android-emu-shared _renderControl_enc OpenglCodecCommon_host cutils utils androidemu PRIVATE GoldfishAddressSpace_host qemupipe_host)
\ No newline at end of file
diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp
index 2293df0..b00a562 100644
--- a/system/vulkan_enc/ResourceTracker.cpp
+++ b/system/vulkan_enc/ResourceTracker.cpp
@@ -46,16 +46,21 @@
 #ifdef VK_USE_PLATFORM_FUCHSIA
 
 #include <cutils/native_handle.h>
-#include <fuchsia/hardware/goldfish/cpp/fidl.h>
-#include <fuchsia/sysmem/cpp/fidl.h>
+#include <fuchsia/hardware/goldfish/llcpp/fidl.h>
+#include <fuchsia/sysmem/llcpp/fidl.h>
 #include <lib/zx/channel.h>
 #include <lib/zx/vmo.h>
+#include <zircon/errors.h>
 #include <zircon/process.h>
+#include <zircon/rights.h>
 #include <zircon/syscalls.h>
 #include <zircon/syscalls/object.h>
 
 #include "services/service_connector.h"
 
+#define GET_STATUS_SAFE(result, member) \
+    ((result).ok() ? ((result).Unwrap()->member) : ZX_OK)
+
 struct AHardwareBuffer;
 
 void AHardwareBuffer_release(AHardwareBuffer*) { }
@@ -271,12 +276,12 @@
     };
 
     struct VkCommandBuffer_Info {
-        VkEncoder** lastUsedEncoderPtr = nullptr;
+        VkEncoder* lastUsedEncoder = nullptr;
         uint32_t sequenceNumber = 0;
     };
 
     struct VkQueue_Info {
-        VkEncoder** lastUsedEncoderPtr = nullptr;
+        VkEncoder* lastUsedEncoder = nullptr;
         uint32_t sequenceNumber = 0;
     };
 
@@ -394,15 +399,10 @@
         auto it = info_VkCommandBuffer.find(commandBuffer);
         if (it == info_VkCommandBuffer.end()) return;
         auto& info = it->second;
-        auto lastUsedEncoder =
-            info.lastUsedEncoderPtr ?
-            *(info.lastUsedEncoderPtr) : nullptr;
-
-        if (lastUsedEncoder) {
-            delete info.lastUsedEncoderPtr;
-            info.lastUsedEncoderPtr = nullptr;
+        if (info.lastUsedEncoder) {
+            info.lastUsedEncoder->decRef();
         }
-
+        info.lastUsedEncoder = nullptr;
         info_VkCommandBuffer.erase(commandBuffer);
     }
 
@@ -412,15 +412,11 @@
         auto it = info_VkQueue.find(queue);
         if (it == info_VkQueue.end()) return;
         auto& info = it->second;
-        auto lastUsedEncoder =
-            info.lastUsedEncoderPtr ?
-            *(info.lastUsedEncoderPtr) : nullptr;
-
-        if (lastUsedEncoder) {
-            delete info.lastUsedEncoderPtr;
-            info.lastUsedEncoderPtr = nullptr;
+        auto lastUsedEncoder = info.lastUsedEncoder;
+        if (info.lastUsedEncoder) {
+            info.lastUsedEncoder->decRef();
         }
-
+        info.lastUsedEncoder = nullptr;
         info_VkQueue.erase(queue);
     }
 
@@ -811,13 +807,17 @@
                 ALOGE("failed to open control device");
                 abort();
             }
-            mControlDevice.Bind(std::move(channel));
+            mControlDevice = std::make_unique<
+                llcpp::fuchsia::hardware::goldfish::ControlDevice::SyncClient>(
+                std::move(channel));
 
             zx::channel sysmem_channel(GetConnectToServiceFunction()("/svc/fuchsia.sysmem.Allocator"));
             if (!sysmem_channel) {
                 ALOGE("failed to open sysmem connection");
             }
-            mSysmemAllocator.Bind(std::move(sysmem_channel));
+            mSysmemAllocator =
+                std::make_unique<llcpp::fuchsia::sysmem::Allocator::SyncClient>(
+                    std::move(sysmem_channel));
         }
 #endif
 
@@ -1676,24 +1676,47 @@
         const VkBufferCollectionCreateInfoFUCHSIA* pInfo,
         const VkAllocationCallbacks*,
         VkBufferCollectionFUCHSIA* pCollection) {
-        fuchsia::sysmem::BufferCollectionTokenSyncPtr token;
+        zx::channel token_client;
+
         if (pInfo->collectionToken) {
-            token.Bind(zx::channel(pInfo->collectionToken));
+            token_client = zx::channel(pInfo->collectionToken);
         } else {
-            zx_status_t status = mSysmemAllocator->AllocateSharedCollection(token.NewRequest());
+            zx::channel token_server;
+            zx_status_t status =
+                zx::channel::create(0, &token_server, &token_client);
             if (status != ZX_OK) {
-                ALOGE("AllocateSharedCollection failed: %d", status);
+                ALOGE("zx_channel_create failed: %d", status);
+                return VK_ERROR_INITIALIZATION_FAILED;
+            }
+
+            auto result = mSysmemAllocator->AllocateSharedCollection(
+                std::move(token_server));
+            if (!result.ok()) {
+                ALOGE("AllocateSharedCollection failed: %d", result.status());
                 return VK_ERROR_INITIALIZATION_FAILED;
             }
         }
-        auto sysmem_collection = new fuchsia::sysmem::BufferCollectionSyncPtr;
-        zx_status_t status = mSysmemAllocator->BindSharedCollection(
-            std::move(token), sysmem_collection->NewRequest());
+
+        zx::channel collection_client, collection_server;
+        zx_status_t status =
+            zx::channel::create(0, &collection_client, &collection_server);
         if (status != ZX_OK) {
-            ALOGE("BindSharedCollection failed: %d", status);
+            ALOGE("zx_channel_create failed: %d", status);
             return VK_ERROR_INITIALIZATION_FAILED;
         }
+
+        auto result = mSysmemAllocator->BindSharedCollection(
+            std::move(token_client), std::move(collection_server));
+        if (!result.ok()) {
+            ALOGE("BindSharedCollection failed: %d", result.status());
+            return VK_ERROR_INITIALIZATION_FAILED;
+        }
+
+        auto sysmem_collection =
+            new llcpp::fuchsia::sysmem::BufferCollection::SyncClient(
+                std::move(collection_client));
         *pCollection = reinterpret_cast<VkBufferCollectionFUCHSIA>(sysmem_collection);
+
         return VK_SUCCESS;
     }
 
@@ -1701,32 +1724,37 @@
         void*, VkResult, VkDevice,
         VkBufferCollectionFUCHSIA collection,
         const VkAllocationCallbacks*) {
-        auto sysmem_collection = reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(collection);
-        if (sysmem_collection->is_bound()) {
-            (*sysmem_collection)->Close();
+        auto sysmem_collection = reinterpret_cast<
+            llcpp::fuchsia::sysmem::BufferCollection::SyncClient*>(collection);
+        if (sysmem_collection) {
+            sysmem_collection->Close();
         }
         delete sysmem_collection;
     }
 
-    inline fuchsia::sysmem::BufferCollectionConstraints
-    defaultBufferCollectionConstraints(size_t min_size_bytes,
-                                       size_t buffer_count) {
-        fuchsia::sysmem::BufferCollectionConstraints constraints = {};
+    inline llcpp::fuchsia::sysmem::BufferCollectionConstraints defaultBufferCollectionConstraints(
+        size_t min_size_bytes,
+        size_t buffer_count) {
+        llcpp::fuchsia::sysmem::BufferCollectionConstraints constraints = {};
         constraints.min_buffer_count = buffer_count;
         constraints.has_buffer_memory_constraints = true;
-        fuchsia::sysmem::BufferMemoryConstraints& buffer_constraints =
+        llcpp::fuchsia::sysmem::BufferMemoryConstraints& buffer_constraints =
             constraints.buffer_memory_constraints;
 
         buffer_constraints.min_size_bytes = min_size_bytes;
         buffer_constraints.max_size_bytes = 0xffffffff;
         buffer_constraints.physically_contiguous_required = false;
         buffer_constraints.secure_required = false;
-        buffer_constraints.ram_domain_supported = false;
-        buffer_constraints.cpu_domain_supported = false;
+
+        // No restrictions on coherency domain or Heaps.
+        buffer_constraints.ram_domain_supported = true;
+        buffer_constraints.cpu_domain_supported = true;
         buffer_constraints.inaccessible_domain_supported = true;
-        buffer_constraints.heap_permitted_count = 1;
+        buffer_constraints.heap_permitted_count = 2;
         buffer_constraints.heap_permitted[0] =
-            fuchsia::sysmem::HeapType::GOLDFISH_DEVICE_LOCAL;
+            llcpp::fuchsia::sysmem::HeapType::GOLDFISH_DEVICE_LOCAL;
+        buffer_constraints.heap_permitted[1] =
+            llcpp::fuchsia::sysmem::HeapType::GOLDFISH_HOST_VISIBLE;
 
         return constraints;
     }
@@ -1736,9 +1764,9 @@
         uint32_t usage = 0u;
         VkImageUsageFlags imageUsage = pImageInfo->usage;
 
-#define SetUsageBit(USAGE)                                    \
-    if (imageUsage & VK_IMAGE_USAGE_##USAGE##_BIT) {          \
-        usage |= fuchsia::sysmem::VULKAN_IMAGE_USAGE_##USAGE; \
+#define SetUsageBit(USAGE)                                           \
+    if (imageUsage & VK_IMAGE_USAGE_##USAGE##_BIT) {                 \
+        usage |= llcpp::fuchsia::sysmem::VULKAN_IMAGE_USAGE_##USAGE; \
     }
 
         SetUsageBit(COLOR_ATTACHMENT);
@@ -1756,9 +1784,9 @@
         VkBufferUsageFlags bufferUsage =
             pBufferConstraintsInfo->pBufferCreateInfo->usage;
 
-#define SetUsageBit(USAGE)                                     \
-    if (bufferUsage & VK_BUFFER_USAGE_##USAGE##_BIT) {         \
-        usage |= fuchsia::sysmem::VULKAN_BUFFER_USAGE_##USAGE; \
+#define SetUsageBit(USAGE)                                            \
+    if (bufferUsage & VK_BUFFER_USAGE_##USAGE##_BIT) {                \
+        usage |= llcpp::fuchsia::sysmem::VULKAN_BUFFER_USAGE_##USAGE; \
     }
 
         SetUsageBit(TRANSFER_SRC);
@@ -1776,20 +1804,17 @@
     }
 
     VkResult setBufferCollectionConstraints(
-        fuchsia::sysmem::BufferCollectionSyncPtr* collection,
+        VkEncoder* enc, VkDevice device,
+        llcpp::fuchsia::sysmem::BufferCollection::SyncClient* collection,
         const VkImageCreateInfo* pImageInfo) {
         if (pImageInfo == nullptr) {
             ALOGE("setBufferCollectionConstraints: pImageInfo cannot be null.");
             return VK_ERROR_OUT_OF_DEVICE_MEMORY;
         }
 
-        // TODO(liyl): Currently the size only works for RGBA8 and BGRA8 images.
-        // We should set the size based on its actual format.
-        fuchsia::sysmem::BufferCollectionConstraints constraints =
+        llcpp::fuchsia::sysmem::BufferCollectionConstraints constraints =
             defaultBufferCollectionConstraints(
-                /* min_size_bytes */ pImageInfo->extent.width *
-                    pImageInfo->extent.height * 4,
-                /* buffer_count */ 1u);
+                /* min_size_bytes */ 0, /* buffer_count */ 1u);
 
         constraints.usage.vulkan =
             getBufferCollectionConstraintsVulkanImageUsage(pImageInfo);
@@ -1805,11 +1830,46 @@
                         VK_FORMAT_B8G8R8A8_UNORM,
                         VK_FORMAT_R8G8B8A8_UNORM,
                 };
+            } else {
+                // If image format is predefined, check on host if the format,
+                // tiling and usage is supported.
+                AutoLock lock(mLock);
+                auto deviceIt = info_VkDevice.find(device);
+                if (deviceIt == info_VkDevice.end()) {
+                    return VK_ERROR_INITIALIZATION_FAILED;
+                }
+                auto& deviceInfo = deviceIt->second;
+
+                VkImageFormatProperties format_properties;
+                auto result = enc->vkGetPhysicalDeviceImageFormatProperties(
+                    deviceInfo.physdev, pImageInfo->format, pImageInfo->imageType,
+                    pImageInfo->tiling, pImageInfo->usage, pImageInfo->flags, &format_properties);
+                if (result != VK_SUCCESS) {
+                    ALOGE(
+                        "%s: Image format (%u) type (%u) tiling (%u) "
+                        "usage (%u) flags (%u) not supported by physical "
+                        "device",
+                        __func__, static_cast<uint32_t>(pImageInfo->format),
+                        static_cast<uint32_t>(pImageInfo->imageType),
+                        static_cast<uint32_t>(pImageInfo->tiling),
+                        static_cast<uint32_t>(pImageInfo->usage),
+                        static_cast<uint32_t>(pImageInfo->flags));
+                    return VK_ERROR_FORMAT_NOT_SUPPORTED;
+                }
             }
             constraints.image_format_constraints_count = formats.size();
             uint32_t format_index = 0;
             for (VkFormat format : formats) {
-                fuchsia::sysmem::ImageFormatConstraints& image_constraints =
+                // Get row alignment from host GPU.
+                VkDeviceSize offset;
+                VkDeviceSize rowPitchAlignment;
+                enc->vkGetLinearImageLayoutGOOGLE(device, format, &offset, &rowPitchAlignment);
+
+                ALOGD("vkGetLinearImageLayoutGOOGLE: format %d offset %lu rowPitchAlignment = %lu",
+                    (int)format, offset, rowPitchAlignment);
+
+                llcpp::fuchsia::sysmem::ImageFormatConstraints&
+                    image_constraints =
                         constraints.image_format_constraints[format_index++];
                 switch (format) {
                     case VK_FORMAT_B8G8R8A8_SINT:
@@ -1819,7 +1879,7 @@
                     case VK_FORMAT_B8G8R8A8_SSCALED:
                     case VK_FORMAT_B8G8R8A8_USCALED:
                         image_constraints.pixel_format.type =
-                                fuchsia::sysmem::PixelFormatType::BGRA32;
+                            llcpp::fuchsia::sysmem::PixelFormatType::BGRA32;
                         break;
                     case VK_FORMAT_R8G8B8A8_SINT:
                     case VK_FORMAT_R8G8B8A8_UNORM:
@@ -1828,39 +1888,45 @@
                     case VK_FORMAT_R8G8B8A8_SSCALED:
                     case VK_FORMAT_R8G8B8A8_USCALED:
                         image_constraints.pixel_format.type =
-                                fuchsia::sysmem::PixelFormatType::R8G8B8A8;
+                            llcpp::fuchsia::sysmem::PixelFormatType::R8G8B8A8;
                         break;
                     default:
                         return VK_ERROR_FORMAT_NOT_SUPPORTED;
                 }
                 image_constraints.color_spaces_count = 1;
                 image_constraints.color_space[0].type =
-                        fuchsia::sysmem::ColorSpaceType::SRGB;
+                    llcpp::fuchsia::sysmem::ColorSpaceType::SRGB;
                 image_constraints.min_coded_width = pImageInfo->extent.width;
                 image_constraints.max_coded_width = 0xfffffff;
                 image_constraints.min_coded_height = pImageInfo->extent.height;
                 image_constraints.max_coded_height = 0xffffffff;
-                image_constraints.min_bytes_per_row =
-                        pImageInfo->extent.width * 4;
+                // The min_bytes_per_row can be calculated by sysmem using
+                // |min_coded_width|, |bytes_per_row_divisor| and color format.
+                image_constraints.min_bytes_per_row = 0;
                 image_constraints.max_bytes_per_row = 0xffffffff;
                 image_constraints.max_coded_width_times_coded_height =
                         0xffffffff;
                 image_constraints.layers = 1;
                 image_constraints.coded_width_divisor = 1;
                 image_constraints.coded_height_divisor = 1;
-                image_constraints.bytes_per_row_divisor = 1;
+                image_constraints.bytes_per_row_divisor = rowPitchAlignment;
                 image_constraints.start_offset_divisor = 1;
                 image_constraints.display_width_divisor = 1;
                 image_constraints.display_height_divisor = 1;
             }
         }
 
-        (*collection)->SetConstraints(true, constraints);
+        auto result = collection->SetConstraints(true, std::move(constraints));
+        if (!result.ok()) {
+            ALOGE("setBufferCollectionConstraints: SetConstraints failed: %d",
+                  result.status());
+            return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+        }
         return VK_SUCCESS;
     }
 
     VkResult setBufferCollectionBufferConstraints(
-        fuchsia::sysmem::BufferCollectionSyncPtr* collection,
+        llcpp::fuchsia::sysmem::BufferCollection::SyncClient* collection,
         const VkBufferConstraintsInfoFUCHSIA* pBufferConstraintsInfo) {
         if (pBufferConstraintsInfo == nullptr) {
             ALOGE(
@@ -1869,26 +1935,31 @@
             return VK_ERROR_OUT_OF_DEVICE_MEMORY;
         }
 
-        fuchsia::sysmem::BufferCollectionConstraints constraints =
+        llcpp::fuchsia::sysmem::BufferCollectionConstraints constraints =
             defaultBufferCollectionConstraints(
-                /* min_size_bytes */ pBufferConstraintsInfo->pBufferCreateInfo
-                    ->size,
+                /* min_size_bytes */ pBufferConstraintsInfo->pBufferCreateInfo->size,
                 /* buffer_count */ pBufferConstraintsInfo->minCount);
         constraints.usage.vulkan =
             getBufferCollectionConstraintsVulkanBufferUsage(
                 pBufferConstraintsInfo);
 
-        (*collection)->SetConstraints(true, constraints);
+        auto result = collection->SetConstraints(true, std::move(constraints));
+        if (!result.ok()) {
+            ALOGE("setBufferCollectionConstraints: SetConstraints failed: %d",
+                  result.status());
+            return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+        }
         return VK_SUCCESS;
     }
 
     VkResult on_vkSetBufferCollectionConstraintsFUCHSIA(
-        void*, VkResult, VkDevice,
+        void* context, VkResult, VkDevice device,
         VkBufferCollectionFUCHSIA collection,
         const VkImageCreateInfo* pImageInfo) {
-        auto sysmem_collection =
-            reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(collection);
-        return setBufferCollectionConstraints(sysmem_collection, pImageInfo);
+        VkEncoder* enc = (VkEncoder*)context;
+        auto sysmem_collection = reinterpret_cast<
+            llcpp::fuchsia::sysmem::BufferCollection::SyncClient*>(collection);
+        return setBufferCollectionConstraints(enc, device, sysmem_collection, pImageInfo);
     }
 
     VkResult on_vkSetBufferCollectionBufferConstraintsFUCHSIA(
@@ -1897,9 +1968,8 @@
         VkDevice,
         VkBufferCollectionFUCHSIA collection,
         const VkBufferConstraintsInfoFUCHSIA* pBufferConstraintsInfo) {
-        auto sysmem_collection =
-            reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(
-                collection);
+        auto sysmem_collection = reinterpret_cast<
+            llcpp::fuchsia::sysmem::BufferCollection::SyncClient*>(collection);
         return setBufferCollectionBufferConstraints(sysmem_collection,
                                                     pBufferConstraintsInfo);
     }
@@ -1909,17 +1979,28 @@
         VkDevice device,
         VkBufferCollectionFUCHSIA collection,
         VkBufferCollectionPropertiesFUCHSIA* pProperties) {
-        auto sysmem_collection = reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(collection);
-        fuchsia::sysmem::BufferCollectionInfo_2 info;
-        zx_status_t status2;
-        zx_status_t status = (*sysmem_collection)->WaitForBuffersAllocated(&status2, &info);
-        if (status != ZX_OK || status2 != ZX_OK) {
-            ALOGE("Failed wait for allocation: %d %d", status, status2);
+        auto sysmem_collection = reinterpret_cast<
+            llcpp::fuchsia::sysmem::BufferCollection::SyncClient*>(collection);
+
+        auto result = sysmem_collection->WaitForBuffersAllocated();
+        if (!result.ok() || result.Unwrap()->status != ZX_OK) {
+            ALOGE("Failed wait for allocation: %d %d", result.status(),
+                  GET_STATUS_SAFE(result, status));
             return VK_ERROR_INITIALIZATION_FAILED;
         }
-        if (!info.settings.has_image_format_constraints) {
+        llcpp::fuchsia::sysmem::BufferCollectionInfo_2 info =
+            std::move(result.Unwrap()->buffer_collection_info);
+
+        bool is_host_visible = info.settings.buffer_settings.heap ==
+                               llcpp::fuchsia::sysmem::HeapType::GOLDFISH_HOST_VISIBLE;
+        bool is_device_local = info.settings.buffer_settings.heap ==
+                               llcpp::fuchsia::sysmem::HeapType::GOLDFISH_DEVICE_LOCAL;
+        if (!is_host_visible && !is_device_local) {
+            ALOGE("buffer collection uses a non-goldfish heap (type 0x%lu)",
+                static_cast<uint64_t>(info.settings.buffer_settings.heap));
             return VK_ERROR_INITIALIZATION_FAILED;
         }
+
         pProperties->count = info.buffer_count;
 
         AutoLock lock(mLock);
@@ -1935,8 +2016,10 @@
         // Device local memory type supported.
         pProperties->memoryTypeBits = 0;
         for (uint32_t i = 0; i < deviceInfo.memProps.memoryTypeCount; ++i) {
-            if (deviceInfo.memProps.memoryTypes[i].propertyFlags &
-                VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
+            if ((is_device_local && (deviceInfo.memProps.memoryTypes[i].propertyFlags &
+                                     VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) ||
+                (is_host_visible && (deviceInfo.memProps.memoryTypes[i].propertyFlags &
+                                     VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))) {
                 pProperties->memoryTypeBits |= 1ull << i;
             }
         }
@@ -2057,9 +2140,9 @@
                     abort();
                 }
 
-                struct drm_virtgpu_map map_info = {
-                    .handle = drm_rc_blob.bo_handle,
-                };
+                drm_virtgpu_map map_info;
+                memset(&map_info, 0, sizeof(map_info));
+                map_info.handle = drm_rc_blob.bo_handle;
 
                 res = drmIoctl(mRendernodeFd, DRM_IOCTL_VIRTGPU_MAP, &map_info);
                 if (res) {
@@ -2298,15 +2381,17 @@
         if (importBufferCollection) {
 
 #ifdef VK_USE_PLATFORM_FUCHSIA
-            auto collection = reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(
+            auto collection = reinterpret_cast<
+                llcpp::fuchsia::sysmem::BufferCollection::SyncClient*>(
                 importBufferCollectionInfoPtr->collection);
-            fuchsia::sysmem::BufferCollectionInfo_2 info;
-            zx_status_t status2;
-            zx_status_t status = (*collection)->WaitForBuffersAllocated(&status2, &info);
-            if (status != ZX_OK || status2 != ZX_OK) {
-                ALOGE("WaitForBuffersAllocated failed: %d %d", status);
+            auto result = collection->WaitForBuffersAllocated();
+            if (!result.ok() || result.Unwrap()->status != ZX_OK) {
+                ALOGE("WaitForBuffersAllocated failed: %d %d", result.status(),
+                      GET_STATUS_SAFE(result, status));
                 return VK_ERROR_INITIALIZATION_FAILED;
             }
+            llcpp::fuchsia::sysmem::BufferCollectionInfo_2& info =
+                result.Unwrap()->buffer_collection_info;
             uint32_t index = importBufferCollectionInfoPtr->index;
             if (info.buffer_count < index) {
                 ALOGE("Invalid buffer index: %d %d", index);
@@ -2381,25 +2466,52 @@
                     pBufferConstraintsInfo);
 
             if (hasDedicatedImage || hasDedicatedBuffer) {
-                fuchsia::sysmem::BufferCollectionTokenSyncPtr token;
-                zx_status_t status = mSysmemAllocator->AllocateSharedCollection(
-                    token.NewRequest());
+                zx::channel token_server, token_client;
+                zx_status_t status =
+                    zx::channel::create(0, &token_server, &token_client);
                 if (status != ZX_OK) {
-                    ALOGE("AllocateSharedCollection failed: %d", status);
+                    ALOGE("zx_channel_create failed: %d", status);
                     abort();
                 }
 
-                fuchsia::sysmem::BufferCollectionSyncPtr collection;
-                status = mSysmemAllocator->BindSharedCollection(
-                    std::move(token), collection.NewRequest());
+                {
+                    auto result = mSysmemAllocator->AllocateSharedCollection(
+                        std::move(token_server));
+                    if (!result.ok()) {
+                        ALOGE("AllocateSharedCollection failed: %d",
+                              result.status());
+                        abort();
+                    }
+                }
+
+                zx::channel collection_server, collection_client;
+                status = zx::channel::create(0, &collection_server,
+                                             &collection_client);
                 if (status != ZX_OK) {
-                    ALOGE("BindSharedCollection failed: %d", status);
+                    ALOGE("zx_channel_create failed: %d", status);
                     abort();
                 }
 
+                {
+                    auto result = mSysmemAllocator->BindSharedCollection(
+                        std::move(token_client), std::move(collection_server));
+                    if (!result.ok()) {
+                        ALOGE("BindSharedCollection failed: %d",
+                              result.status());
+                        abort();
+                    }
+                }
+
+                llcpp::fuchsia::sysmem::BufferCollection::SyncClient collection(
+                    std::move(collection_client));
                 if (hasDedicatedImage) {
                     VkResult res = setBufferCollectionConstraints(
-                        &collection, pImageCreateInfo);
+                        enc, device, &collection, pImageCreateInfo);
+                    if (res == VK_ERROR_FORMAT_NOT_SUPPORTED) {
+                      ALOGE("setBufferCollectionConstraints failed: format %u is not supported",
+                            pImageCreateInfo->format);
+                      return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+                    }
                     if (res != VK_SUCCESS) {
                         ALOGE("setBufferCollectionConstraints failed: %d", res);
                         abort();
@@ -2416,25 +2528,30 @@
                     }
                 }
 
-                fuchsia::sysmem::BufferCollectionInfo_2 info;
-                zx_status_t status2;
-                status = collection->WaitForBuffersAllocated(&status2, &info);
-                if (status == ZX_OK && status2 == ZX_OK) {
-                    if (!info.buffer_count) {
-                      ALOGE("WaitForBuffersAllocated returned invalid count: %d", status);
-                      abort();
+                {
+                    auto result = collection.WaitForBuffersAllocated();
+                    if (result.ok() && result.Unwrap()->status == ZX_OK) {
+                        llcpp::fuchsia::sysmem::BufferCollectionInfo_2& info =
+                            result.Unwrap()->buffer_collection_info;
+                        if (!info.buffer_count) {
+                            ALOGE(
+                                "WaitForBuffersAllocated returned "
+                                "invalid count: %d",
+                                info.buffer_count);
+                            abort();
+                        }
+                        vmo_handle = info.buffers[0].vmo.release();
+                    } else {
+                        ALOGE("WaitForBuffersAllocated failed: %d %d",
+                              result.status(), GET_STATUS_SAFE(result, status));
+                        abort();
                     }
-                    vmo_handle = info.buffers[0].vmo.release();
-                } else {
-                    ALOGE("WaitForBuffersAllocated failed: %d %d", status, status2);
-                    abort();
                 }
 
-                collection->Close();
+                collection.Close();
 
                 zx::vmo vmo_copy;
-                status = zx_handle_duplicate(vmo_handle,
-                                             ZX_RIGHT_SAME_RIGHTS,
+                status = zx_handle_duplicate(vmo_handle, ZX_RIGHT_SAME_RIGHTS,
                                              vmo_copy.reset_and_get_address());
                 if (status != ZX_OK) {
                     ALOGE("Failed to duplicate VMO: %d", status);
@@ -2442,7 +2559,8 @@
                 }
 
                 if (pImageCreateInfo) {
-                    fuchsia::hardware::goldfish::ColorBufferFormatType format;
+                    llcpp::fuchsia::hardware::goldfish::ColorBufferFormatType
+                        format;
                     switch (pImageCreateInfo->format) {
                         case VK_FORMAT_B8G8R8A8_SINT:
                         case VK_FORMAT_B8G8R8A8_UNORM:
@@ -2450,7 +2568,7 @@
                         case VK_FORMAT_B8G8R8A8_SNORM:
                         case VK_FORMAT_B8G8R8A8_SSCALED:
                         case VK_FORMAT_B8G8R8A8_USCALED:
-                            format = fuchsia::hardware::goldfish::
+                            format = llcpp::fuchsia::hardware::goldfish::
                                 ColorBufferFormatType::BGRA;
                             break;
                         case VK_FORMAT_R8G8B8A8_SINT:
@@ -2459,7 +2577,7 @@
                         case VK_FORMAT_R8G8B8A8_SNORM:
                         case VK_FORMAT_R8G8B8A8_SSCALED:
                         case VK_FORMAT_R8G8B8A8_USCALED:
-                            format = fuchsia::hardware::goldfish::
+                            format = llcpp::fuchsia::hardware::goldfish::
                                 ColorBufferFormatType::RGBA;
                             break;
                         default:
@@ -2468,23 +2586,42 @@
                             abort();
                     }
 
-                    status = mControlDevice->CreateColorBuffer(
-                        std::move(vmo_copy), pImageCreateInfo->extent.width,
-                        pImageCreateInfo->extent.height, format, &status2);
-                    if (status != ZX_OK || status2 != ZX_OK) {
-                        ALOGE("CreateColorBuffer failed: %d:%d", status,
-                              status2);
-                        abort();
+                    auto createParams =
+                        llcpp::fuchsia::hardware::goldfish::CreateColorBuffer2Params::Builder(
+                            std::make_unique<llcpp::fuchsia::hardware::goldfish::
+                                                 CreateColorBuffer2Params::Frame>())
+                            .set_width(std::make_unique<uint32_t>(pImageCreateInfo->extent.width))
+                            .set_height(std::make_unique<uint32_t>(pImageCreateInfo->extent.height))
+                            .set_format(std::make_unique<
+                                        llcpp::fuchsia::hardware::goldfish::ColorBufferFormatType>(
+                                format))
+                            .set_memory_property(std::make_unique<uint32_t>(
+                                llcpp::fuchsia::hardware::goldfish::MEMORY_PROPERTY_DEVICE_LOCAL))
+                            .build();
+
+                    auto result = mControlDevice->CreateColorBuffer2(std::move(vmo_copy),
+                                                                     std::move(createParams));
+                    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+                        if (result.ok() &&
+                            result.Unwrap()->res == ZX_ERR_ALREADY_EXISTS) {
+                            ALOGD("CreateColorBuffer: color buffer already "
+                                  "exists\n");
+                        } else {
+                            ALOGE("CreateColorBuffer failed: %d:%d",
+                                  result.status(),
+                                  GET_STATUS_SAFE(result, res));
+                            abort();
+                        }
                     }
                 }
 
                 if (pBufferConstraintsInfo) {
-                    status = mControlDevice->CreateBuffer(
+                    auto result = mControlDevice->CreateBuffer(
                         std::move(vmo_copy),
-                        pBufferConstraintsInfo->pBufferCreateInfo->size,
-                        &status2);
-                    if (status != ZX_OK || status2 != ZX_OK) {
-                        ALOGE("CreateBuffer failed: %d:%d", status, status2);
+                        pBufferConstraintsInfo->pBufferCreateInfo->size);
+                    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+                        ALOGE("CreateBuffer failed: %d:%d", result.status(),
+                              GET_STATUS_SAFE(result, res));
                         abort();
                     }
                 }
@@ -2502,23 +2639,23 @@
             }
             zx_status_t status2 = ZX_OK;
 
-            fuchsia::hardware::goldfish::BufferHandleType handle_type;
-            uint32_t buffer_handle;
-
-            status = mControlDevice->GetBufferHandle(std::move(vmo_copy),
-                                                     &status2, &buffer_handle,
-                                                     &handle_type);
-            if (status != ZX_OK || status2 != ZX_OK) {
-                ALOGE("GetBufferHandle failed: %d:%d", status, status2);
-            }
-
-            if (handle_type ==
-                fuchsia::hardware::goldfish::BufferHandleType::BUFFER) {
-                importBufferInfo.buffer = buffer_handle;
-                vk_append_struct(&structChainIter, &importBufferInfo);
+            auto result = mControlDevice->GetBufferHandle(std::move(vmo_copy));
+            if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+                ALOGE("GetBufferHandle failed: %d:%d", result.status(),
+                      GET_STATUS_SAFE(result, res));
             } else {
-                importCbInfo.colorBuffer = buffer_handle;
-                vk_append_struct(&structChainIter, &importCbInfo);
+                llcpp::fuchsia::hardware::goldfish::BufferHandleType
+                    handle_type = result.Unwrap()->type;
+                uint32_t buffer_handle = result.Unwrap()->id;
+
+                if (handle_type == llcpp::fuchsia::hardware::goldfish::
+                                       BufferHandleType::BUFFER) {
+                    importBufferInfo.buffer = buffer_handle;
+                    vk_append_struct(&structChainIter, &importBufferInfo);
+                } else {
+                    importCbInfo.colorBuffer = buffer_handle;
+                    vk_append_struct(&structChainIter, &importCbInfo);
+                }
             }
         }
 #endif
@@ -2554,12 +2691,44 @@
             abort();
         }
 
+#ifdef VK_USE_PLATFORM_FUCHSIA
         if (vmo_handle != ZX_HANDLE_INVALID) {
-            ALOGE("%s: Host visible export/import allocation "
-                  "of VMO is not supported yet.",
-                  __func__);
-            abort();
+            input_result = enc->vkAllocateMemory(device, &finalAllocInfo, pAllocator, pMemory);
+
+            // Get VMO handle rights, and only use allowed rights to map the
+            // host memory.
+            zx_info_handle_basic handle_info;
+            zx_status_t status = zx_object_get_info(vmo_handle, ZX_INFO_HANDLE_BASIC, &handle_info,
+                                        sizeof(handle_info), nullptr, nullptr);
+            if (status != ZX_OK) {
+                ALOGE("%s: cannot get vmo object info: vmo = %u status: %d.", __func__, vmo_handle,
+                      status);
+                return VK_ERROR_OUT_OF_HOST_MEMORY;
+            }
+
+            zx_vm_option_t vm_permission = 0u;
+            vm_permission |= (handle_info.rights & ZX_RIGHT_READ) ? ZX_VM_PERM_READ : 0;
+            vm_permission |= (handle_info.rights & ZX_RIGHT_WRITE) ? ZX_VM_PERM_WRITE : 0;
+
+            zx_paddr_t addr;
+            status = zx_vmar_map(zx_vmar_root_self(), vm_permission, 0, vmo_handle, 0,
+                finalAllocInfo.allocationSize, &addr);
+            if (status != ZX_OK) {
+                ALOGE("%s: cannot map vmar: status %d.", __func__, status);
+                return VK_ERROR_OUT_OF_HOST_MEMORY;
+            }
+
+            D("host visible alloc (external): "
+              "size 0x%llx host ptr %p mapped size 0x%llx",
+              (unsigned long long)finalAllocInfo.allocationSize, mappedPtr,
+              (unsigned long long)mappedSize);
+            setDeviceMemoryInfo(device, *pMemory,
+                finalAllocInfo.allocationSize, finalAllocInfo.allocationSize,
+                reinterpret_cast<uint8_t*>(addr), finalAllocInfo.memoryTypeIndex,
+                /*ahw=*/nullptr, vmo_handle);
+            return VK_SUCCESS;
         }
+#endif
 
         // Host visible memory, non external
         bool directMappingSupported = usingDirectMapping();
@@ -2655,6 +2824,17 @@
         if (it == info_VkDeviceMemory.end()) return;
         auto& info = it->second;
 
+#ifdef VK_USE_PLATFORM_FUCHSIA
+        if (info.vmoHandle && info.mappedPtr) {
+            zx_status_t status = zx_vmar_unmap(
+                zx_vmar_root_self(), reinterpret_cast<zx_paddr_t>(info.mappedPtr), info.mappedSize);
+            if (status != ZX_OK) {
+                ALOGE("%s: Cannot unmap mappedPtr: status %d", status);
+            }
+            info.mappedPtr = nullptr;
+        }
+#endif
+
         if (!info.directMapped) {
             lock.unlock();
             VkEncoder* enc = (VkEncoder*)context;
@@ -2893,35 +3073,90 @@
         const VkBufferCollectionImageCreateInfoFUCHSIA* extBufferCollectionPtr =
             vk_find_struct<VkBufferCollectionImageCreateInfoFUCHSIA>(pCreateInfo);
         bool isSysmemBackedMemory = false;
+
+        if (extImgCiPtr &&
+            (extImgCiPtr->handleTypes &
+             VK_EXTERNAL_MEMORY_HANDLE_TYPE_TEMP_ZIRCON_VMO_BIT_FUCHSIA)) {
+            isSysmemBackedMemory = true;
+        }
+
         if (extBufferCollectionPtr) {
-            auto collection = reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(
+            auto collection = reinterpret_cast<
+                llcpp::fuchsia::sysmem::BufferCollection::SyncClient*>(
                 extBufferCollectionPtr->collection);
             uint32_t index = extBufferCollectionPtr->index;
             zx::vmo vmo;
 
-            fuchsia::sysmem::BufferCollectionInfo_2 info;
-            zx_status_t status2;
-            zx_status_t status = (*collection)->WaitForBuffersAllocated(&status2, &info);
-            if (status == ZX_OK && status2 == ZX_OK) {
+            llcpp::fuchsia::sysmem::BufferCollectionInfo_2 info;
+
+            auto result = collection->WaitForBuffersAllocated();
+            if (result.ok() && result.Unwrap()->status == ZX_OK) {
+                info = std::move(result.Unwrap()->buffer_collection_info);
                 if (index < info.buffer_count && info.settings.has_image_format_constraints) {
                     vmo = std::move(info.buffers[index].vmo);
                 }
             } else {
-                ALOGE("WaitForBuffersAllocated failed: %d %d", status, status2);
+                ALOGE("WaitForBuffersAllocated failed: %d %d", result.status(),
+                      GET_STATUS_SAFE(result, status));
             }
 
             if (vmo.is_valid()) {
-                zx_status_t status2 = ZX_OK;
-                status = mControlDevice->CreateColorBuffer(
-                    std::move(vmo),
-                    info.settings.image_format_constraints.min_coded_width,
-                    info.settings.image_format_constraints.min_coded_height,
-                    info.settings.image_format_constraints.pixel_format.type == fuchsia::sysmem::PixelFormatType::R8G8B8A8
-                        ? fuchsia::hardware::goldfish::ColorBufferFormatType::RGBA
-                        : fuchsia::hardware::goldfish::ColorBufferFormatType::BGRA,
-                    &status2);
-                if (status != ZX_OK || (status2 != ZX_OK && status2 != ZX_ERR_ALREADY_EXISTS)) {
-                    ALOGE("CreateColorBuffer failed: %d:%d", status, status2);
+                zx::vmo vmo_dup;
+                if (zx_status_t status = vmo.duplicate(ZX_RIGHT_SAME_RIGHTS, &vmo_dup);
+                    status != ZX_OK) {
+                    ALOGE("%s: zx_vmo_duplicate failed: %d", __func__, status);
+                    abort();
+                }
+
+                auto buffer_handle_result = mControlDevice->GetBufferHandle(std::move(vmo_dup));
+                if (!buffer_handle_result.ok()) {
+                    ALOGE("%s: GetBufferHandle FIDL error: %d", __func__,
+                          buffer_handle_result.status());
+                    abort();
+                }
+                if (buffer_handle_result.value().res == ZX_OK) {
+                    // Buffer handle already exists.
+                    // If it is a ColorBuffer, no-op; Otherwise return error.
+                    if (buffer_handle_result.value().type !=
+                        llcpp::fuchsia::hardware::goldfish::BufferHandleType::COLOR_BUFFER) {
+                        ALOGE("%s: BufferHandle %u is not a ColorBuffer", __func__,
+                              buffer_handle_result.value().id);
+                        return VK_ERROR_OUT_OF_HOST_MEMORY;
+                    }
+                } else if (buffer_handle_result.value().res == ZX_ERR_NOT_FOUND) {
+                    // Buffer handle not found. Create ColorBuffer based on buffer settings.
+                    auto format =
+                        info.settings.image_format_constraints.pixel_format.type ==
+                                llcpp::fuchsia::sysmem::PixelFormatType::R8G8B8A8
+                            ? llcpp::fuchsia::hardware::goldfish::ColorBufferFormatType::RGBA
+                            : llcpp::fuchsia::hardware::goldfish::ColorBufferFormatType::BGRA;
+
+                    uint32_t memory_property =
+                        info.settings.buffer_settings.heap ==
+                                llcpp::fuchsia::sysmem::HeapType::GOLDFISH_DEVICE_LOCAL
+                            ? llcpp::fuchsia::hardware::goldfish::MEMORY_PROPERTY_DEVICE_LOCAL
+                            : llcpp::fuchsia::hardware::goldfish::MEMORY_PROPERTY_HOST_VISIBLE;
+
+                    auto createParams =
+                        llcpp::fuchsia::hardware::goldfish::CreateColorBuffer2Params::Builder(
+                            std::make_unique<llcpp::fuchsia::hardware::goldfish::
+                                                 CreateColorBuffer2Params::Frame>())
+                            .set_width(std::make_unique<uint32_t>(
+                                info.settings.image_format_constraints.min_coded_width))
+                            .set_height(std::make_unique<uint32_t>(
+                                info.settings.image_format_constraints.min_coded_height))
+                            .set_format(std::make_unique<
+                                        llcpp::fuchsia::hardware::goldfish::ColorBufferFormatType>(
+                                format))
+                            .set_memory_property(std::make_unique<uint32_t>(memory_property))
+                            .build();
+
+                    auto result =
+                        mControlDevice->CreateColorBuffer2(std::move(vmo), std::move(createParams));
+                    if (!result.ok() || result.Unwrap()->res != ZX_OK) {
+                        ALOGE("CreateColorBuffer failed: %d:%d", result.status(),
+                              GET_STATUS_SAFE(result, res));
+                    }
                 }
             }
             isSysmemBackedMemory = true;
@@ -3733,37 +3968,44 @@
         Optional<zx::vmo> vmo;
         bool isSysmemBackedMemory = false;
 
+        const VkExternalMemoryBufferCreateInfo* extBufCiPtr =
+            vk_find_struct<VkExternalMemoryBufferCreateInfo>(pCreateInfo);
+        if (extBufCiPtr &&
+            (extBufCiPtr->handleTypes &
+             VK_EXTERNAL_MEMORY_HANDLE_TYPE_TEMP_ZIRCON_VMO_BIT_FUCHSIA)) {
+            isSysmemBackedMemory = true;
+        }
+
         const auto* extBufferCollectionPtr =
                 vk_find_struct<VkBufferCollectionBufferCreateInfoFUCHSIA>(
                         pCreateInfo);
 
         if (extBufferCollectionPtr) {
-            auto collection =
-                    reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(
-                            extBufferCollectionPtr->collection);
+            auto collection = reinterpret_cast<
+                llcpp::fuchsia::sysmem::BufferCollection::SyncClient*>(
+                extBufferCollectionPtr->collection);
             uint32_t index = extBufferCollectionPtr->index;
 
-            fuchsia::sysmem::BufferCollectionInfo_2 info;
-            zx_status_t status2;
-            zx_status_t status =
-                    (*collection)->WaitForBuffersAllocated(&status2, &info);
-
-            if (status == ZX_OK && status2 == ZX_OK) {
+            auto result = collection->WaitForBuffersAllocated();
+            if (result.ok() && result.Unwrap()->status == ZX_OK) {
+                auto& info = result.Unwrap()->buffer_collection_info;
                 if (index < info.buffer_count) {
                     vmo = android::base::makeOptional(
                             std::move(info.buffers[index].vmo));
                 }
             } else {
-                ALOGE("WaitForBuffersAllocated failed: %d %d", status, status2);
+                ALOGE("WaitForBuffersAllocated failed: %d %d", result.status(),
+                      GET_STATUS_SAFE(result, status));
             }
 
             if (vmo && vmo->is_valid()) {
-                zx_status_t status2 = ZX_OK;
-                status = mControlDevice->CreateBuffer(
-                        std::move(*vmo), pCreateInfo->size, &status2);
-                if (status != ZX_OK ||
-                    (status2 != ZX_OK && status2 != ZX_ERR_ALREADY_EXISTS)) {
-                    ALOGE("CreateBuffer failed: %d:%d", status, status2);
+                auto result = mControlDevice->CreateBuffer(std::move(*vmo),
+                                                           pCreateInfo->size);
+                if (!result.ok() ||
+                    (result.Unwrap()->res != ZX_OK &&
+                     result.Unwrap()->res != ZX_ERR_ALREADY_EXISTS)) {
+                    ALOGE("CreateBuffer failed: %d:%d", result.status(),
+                          GET_STATUS_SAFE(result, res));
                 }
                 isSysmemBackedMemory = true;
             }
@@ -4583,6 +4825,35 @@
         VkEncoder* enc = (VkEncoder*)context;
         (void)input_result;
 
+#ifdef VK_USE_PLATFORM_FUCHSIA
+
+        constexpr VkFormat kExternalImageSupportedFormats[] = {
+            VK_FORMAT_B8G8R8A8_SINT,
+            VK_FORMAT_B8G8R8A8_UNORM,
+            VK_FORMAT_B8G8R8A8_SRGB,
+            VK_FORMAT_B8G8R8A8_SNORM,
+            VK_FORMAT_B8G8R8A8_SSCALED,
+            VK_FORMAT_B8G8R8A8_USCALED,
+            VK_FORMAT_R8G8B8A8_SINT,
+            VK_FORMAT_R8G8B8A8_UNORM,
+            VK_FORMAT_R8G8B8A8_SRGB,
+            VK_FORMAT_R8G8B8A8_SNORM,
+            VK_FORMAT_R8G8B8A8_SSCALED,
+            VK_FORMAT_R8G8B8A8_USCALED,
+        };
+
+        VkExternalImageFormatProperties* ext_img_properties =
+            vk_find_struct<VkExternalImageFormatProperties>(pImageFormatProperties);
+
+        if (ext_img_properties) {
+          if (std::find(std::begin(kExternalImageSupportedFormats),
+                        std::end(kExternalImageSupportedFormats),
+                        pImageFormatInfo->format) == std::end(kExternalImageSupportedFormats)) {
+            return VK_ERROR_FORMAT_NOT_SUPPORTED;
+          }
+        }
+#endif
+
         VkAndroidHardwareBufferUsageANDROID* output_ahw_usage =
             vk_find_struct<VkAndroidHardwareBufferUsageANDROID>(pImageFormatProperties);
 
@@ -4663,48 +4934,39 @@
 
         auto& info = it->second;
 
-        if (!info.lastUsedEncoderPtr) {
-            info.lastUsedEncoderPtr = new VkEncoder*;
-            *(info.lastUsedEncoderPtr) = currentEncoder;
+        currentEncoder->incRef();
+
+        auto lastEncoder = info.lastUsedEncoder;
+        info.lastUsedEncoder = currentEncoder;
+        if (!lastEncoder) return 0;
+        auto oldSeq = info.sequenceNumber;
+        bool lookupAgain = false;
+
+        if (lastEncoder != currentEncoder) {
+            info.sequenceNumber += 2;
+            lookupAgain = true;
+            lock.unlock();
+
+            lastEncoder->vkCommandBufferHostSyncGOOGLE(commandBuffer, false, oldSeq + 1);
+            lastEncoder->flush();
+
+            currentEncoder->vkCommandBufferHostSyncGOOGLE(commandBuffer, true, oldSeq + 2);
+
+            lock.lock();
         }
 
-        auto lastUsedEncoderPtr = info.lastUsedEncoderPtr;
-
-        auto lastEncoder = *(lastUsedEncoderPtr);
-
-        // We always make lastUsedEncoderPtr track
-        // the current encoder, even if the last encoder
-        // is null.
-        *(lastUsedEncoderPtr) = currentEncoder;
-
-        if (!lastEncoder) return 0;
-        if (lastEncoder == currentEncoder) return 0;
-
-        auto oldSeq = info.sequenceNumber;
-
-        lock.unlock();
-
-        lastEncoder->vkCommandBufferHostSyncGOOGLE(commandBuffer, false, oldSeq + 1);
-        lastEncoder->flush();
-        currentEncoder->vkCommandBufferHostSyncGOOGLE(commandBuffer, true, oldSeq + 2);
-
-        unregisterEncoderCleanupCallback(lastEncoder, commandBuffer);
-
-        registerEncoderCleanupCallback(currentEncoder, commandBuffer, [this, currentEncoder, commandBuffer]() {
-            AutoLock lock(mLock);
-            auto it = info_VkCommandBuffer.find(commandBuffer);
-            if (it == info_VkCommandBuffer.end()) return;
-
-            auto& info = it->second;
-            if (!info.lastUsedEncoderPtr) return;
-            if (!*(info.lastUsedEncoderPtr)) return;
-
-            if (currentEncoder == *(info.lastUsedEncoderPtr)) {
-                *(info.lastUsedEncoderPtr) = nullptr;
+        if (lastEncoder->decRef()) {
+            if (lookupAgain) {
+                auto it2 = info_VkCommandBuffer.find(commandBuffer);
+                if (it2 == info_VkCommandBuffer.end()) return 0;
+                auto& info2 = it2->second;
+                info2.lastUsedEncoder = nullptr;
+            } else {
+                info.lastUsedEncoder = nullptr;
             }
-        });
+        }
 
-        return 1;
+        return 0;
     }
 
     uint32_t syncEncodersForQueue(VkQueue queue, VkEncoder* currentEncoder) {
@@ -4719,52 +4981,38 @@
 
         auto& info = it->second;
 
-        if (!info.lastUsedEncoderPtr) {
-            info.lastUsedEncoderPtr = new VkEncoder*;
-            *(info.lastUsedEncoderPtr) = currentEncoder;
+        currentEncoder->incRef();
+
+        auto lastEncoder = info.lastUsedEncoder;
+        info.lastUsedEncoder = currentEncoder;
+        if (!lastEncoder) return 0;
+        auto oldSeq = info.sequenceNumber;
+        bool lookupAgain = false;
+
+        if (lastEncoder != currentEncoder) {
+            info.sequenceNumber += 2;
+            lookupAgain = true;
+            lock.unlock();
+
+            lastEncoder->vkQueueHostSyncGOOGLE(queue, false, oldSeq + 1);
+            lastEncoder->flush();
+            currentEncoder->vkQueueHostSyncGOOGLE(queue, true, oldSeq + 2);
+
+            lock.lock();
         }
 
-        auto lastUsedEncoderPtr = info.lastUsedEncoderPtr;
-
-        auto lastEncoder = *(lastUsedEncoderPtr);
-
-        // We always make lastUsedEncoderPtr track
-        // the current encoder, even if the last encoder
-        // is null.
-        *(lastUsedEncoderPtr) = currentEncoder;
-
-        if (!lastEncoder) return 0;
-        if (lastEncoder == currentEncoder) return 0;
-
-        auto oldSeq = info.sequenceNumber;
-
-        info.sequenceNumber += 2;
-
-        lock.unlock();
-
-        // at this point the seqno for the old thread is determined
-
-        lastEncoder->vkQueueHostSyncGOOGLE(queue, false, oldSeq + 1);
-        lastEncoder->flush();
-        currentEncoder->vkQueueHostSyncGOOGLE(queue, true, oldSeq + 2);
-
-        unregisterEncoderCleanupCallback(lastEncoder, queue);
-
-        registerEncoderCleanupCallback(currentEncoder, queue, [this, currentEncoder, queue]() {
-            AutoLock lock(mLock);
-            auto it = info_VkQueue.find(queue);
-            if (it == info_VkQueue.end()) return;
-
-            auto& info = it->second;
-            if (!info.lastUsedEncoderPtr) return;
-            if (!*(info.lastUsedEncoderPtr)) return;
-
-            if (currentEncoder == *(info.lastUsedEncoderPtr)) {
-                *(info.lastUsedEncoderPtr) = nullptr;
+        if (lastEncoder->decRef()) {
+            if (lookupAgain) {
+                auto it2 = info_VkQueue.find(queue);
+                if (it2 == info_VkQueue.end()) return 0;
+                auto& info2 = it2->second;
+                info2.lastUsedEncoder = nullptr;
+            } else {
+                info.lastUsedEncoder = nullptr;
             }
-        });
+        }
 
-        return 1;
+        return 0;
     }
 
     VkResult on_vkBeginCommandBuffer(
@@ -4904,8 +5152,11 @@
 #endif
 
 #ifdef VK_USE_PLATFORM_FUCHSIA
-    fuchsia::hardware::goldfish::ControlDeviceSyncPtr mControlDevice;
-    fuchsia::sysmem::AllocatorSyncPtr mSysmemAllocator;
+    std::unique_ptr<
+        llcpp::fuchsia::hardware::goldfish::ControlDevice::SyncClient>
+        mControlDevice;
+    std::unique_ptr<llcpp::fuchsia::sysmem::Allocator::SyncClient>
+        mSysmemAllocator;
 #endif
 
     WorkPool mWorkPool { 4 };
diff --git a/system/vulkan_enc/VkEncoder.cpp b/system/vulkan_enc/VkEncoder.cpp
index 0eeba15..8f16a52 100644
--- a/system/vulkan_enc/VkEncoder.cpp
+++ b/system/vulkan_enc/VkEncoder.cpp
@@ -59,105 +59,7 @@
 using android::base::guest::Lock;
 using android::base::Pool;
 
-class VkEncoder::Impl {
-public:
-    Impl(IOStream* stream) : m_stream(stream), m_logEncodes(false) {
-        const char* emuVkLogEncodesPropName = "qemu.vk.log";
-        char encodeProp[PROPERTY_VALUE_MAX];
-        if (property_get(emuVkLogEncodesPropName, encodeProp, nullptr) > 0) {
-            m_logEncodes = atoi(encodeProp) > 0;
-        }
-    }
-
-    ~Impl() { }
-
-    VulkanCountingStream* countingStream() { return &m_countingStream; }
-    VulkanStreamGuest* stream() { return &m_stream; }
-    Pool* pool() { return &m_pool; }
-    ResourceTracker* resources() { return ResourceTracker::get(); }
-    Validation* validation() { return &m_validation; }
-
-    void log(const char* text) {
-        if (!m_logEncodes) return;
-        ALOGD("encoder log: %s", text);
-    }
-
-    void flush() {
-        lock();
-        m_stream.flush();
-        unlock();
-    }
-
-    // can be recursive
-    void lock() {
-        if (this == sAcquiredEncoderThreadLocal) {
-            ++sAcquiredEncoderThreadLockLevels;
-            return; // recursive
-        }
-        while (mLock.test_and_set(std::memory_order_acquire));
-        sAcquiredEncoderThreadLocal = this;
-        sAcquiredEncoderThreadLockLevels = 1;
-    }
-
-    void unlock() {
-        if (this != sAcquiredEncoderThreadLocal) {
-            // error, trying to unlock without having locked first
-            return;
-        }
-
-        --sAcquiredEncoderThreadLockLevels;
-        if (0 == sAcquiredEncoderThreadLockLevels) {
-            mLock.clear(std::memory_order_release);
-            sAcquiredEncoderThreadLocal = nullptr;
-        }
-    }
-
-private:
-    VulkanCountingStream m_countingStream;
-    VulkanStreamGuest m_stream;
-    Pool m_pool { 8, 4096, 64 };
-
-    Validation m_validation;
-    bool m_logEncodes;
-    std::atomic_flag mLock = ATOMIC_FLAG_INIT;
-    static thread_local Impl* sAcquiredEncoderThreadLocal;
-    static thread_local uint32_t sAcquiredEncoderThreadLockLevels;
-};
-
-VkEncoder::~VkEncoder() {
-    auto rt = ResourceTracker::get();
-    if (!rt) return;
-    rt->onEncoderDeleted(this);
-}
-
-// static
-thread_local VkEncoder::Impl* VkEncoder::Impl::sAcquiredEncoderThreadLocal = nullptr;
-thread_local uint32_t VkEncoder::Impl::sAcquiredEncoderThreadLockLevels = 0;
-
-struct EncoderAutoLock {
-    EncoderAutoLock(VkEncoder* enc) : mEnc(enc) {
-        mEnc->lock();
-    }
-    ~EncoderAutoLock() {
-        mEnc->unlock();
-    }
-    VkEncoder* mEnc;
-};
-
-VkEncoder::VkEncoder(IOStream *stream) :
-    mImpl(new VkEncoder::Impl(stream)) { }
-
-void VkEncoder::flush() {
-    mImpl->flush();
-}
-
-void VkEncoder::lock() {
-    mImpl->lock();
-}
-
-void VkEncoder::unlock() {
-    mImpl->unlock();
-}
+#include "VkEncoder.cpp.inl"
 
 #define VALIDATE_RET(retType, success, validate) \
     retType goldfish_vk_validateResult = validate; \
@@ -174,7 +76,6 @@
     VkInstance* pInstance)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateInstance encode");
     mImpl->log("start vkCreateInstance");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -236,13 +137,11 @@
     stream->handleMapping()->mapHandles_VkInstance_u64(pInstance, &cgen_var_3, 1);
     stream->write((uint64_t*)&cgen_var_3, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateInstance readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_4;
     stream->read((uint64_t*)&cgen_var_4, 8);
     stream->handleMapping()->mapHandles_u64_VkInstance(&cgen_var_4, (VkInstance*)pInstance, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateInstance returnUnmarshal");
     VkResult vkCreateInstance_VkResult_return = (VkResult)0;
     stream->read(&vkCreateInstance_VkResult_return, sizeof(VkResult));
     mImpl->resources()->on_vkCreateInstance(this, vkCreateInstance_VkResult_return, pCreateInfo, pAllocator, pInstance);
@@ -258,7 +157,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyInstance encode");
     mImpl->log("start vkDestroyInstance");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -307,8 +205,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyInstance readParams");
-    AEMU_SCOPED_TRACE("vkDestroyInstance returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkInstance((VkInstance*)&instance);
     pool->freeAll();
     countingStream->clearPool();
@@ -322,7 +218,6 @@
     VkPhysicalDevice* pPhysicalDevices)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDevices encode");
     mImpl->log("start vkEnumeratePhysicalDevices");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -387,7 +282,6 @@
         }
     }
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDevices readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPhysicalDeviceCount;
     check_pPhysicalDeviceCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -418,7 +312,6 @@
         }
     }
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDevices returnUnmarshal");
     VkResult vkEnumeratePhysicalDevices_VkResult_return = (VkResult)0;
     stream->read(&vkEnumeratePhysicalDevices_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -433,7 +326,6 @@
     VkPhysicalDeviceFeatures* pFeatures)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures encode");
     mImpl->log("start vkGetPhysicalDeviceFeatures");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -458,13 +350,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_21, 1);
     stream->write((uint64_t*)&cgen_var_21, 1 * 8);
     marshal_VkPhysicalDeviceFeatures(stream, (VkPhysicalDeviceFeatures*)(pFeatures));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures readParams");
     unmarshal_VkPhysicalDeviceFeatures(stream, (VkPhysicalDeviceFeatures*)(pFeatures));
     if (pFeatures)
     {
         transform_fromhost_VkPhysicalDeviceFeatures(mImpl->resources(), (VkPhysicalDeviceFeatures*)(pFeatures));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -477,7 +367,6 @@
     VkFormatProperties* pFormatProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties encode");
     mImpl->log("start vkGetPhysicalDeviceFormatProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -506,13 +395,11 @@
     stream->write((uint64_t*)&cgen_var_23, 1 * 8);
     stream->write((VkFormat*)&local_format, sizeof(VkFormat));
     marshal_VkFormatProperties(stream, (VkFormatProperties*)(pFormatProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties readParams");
     unmarshal_VkFormatProperties(stream, (VkFormatProperties*)(pFormatProperties));
     if (pFormatProperties)
     {
         transform_fromhost_VkFormatProperties(mImpl->resources(), (VkFormatProperties*)(pFormatProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -529,7 +416,6 @@
     VkImageFormatProperties* pImageFormatProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties encode");
     mImpl->log("start vkGetPhysicalDeviceImageFormatProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -574,13 +460,11 @@
     stream->write((VkImageUsageFlags*)&local_usage, sizeof(VkImageUsageFlags));
     stream->write((VkImageCreateFlags*)&local_flags, sizeof(VkImageCreateFlags));
     marshal_VkImageFormatProperties(stream, (VkImageFormatProperties*)(pImageFormatProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties readParams");
     unmarshal_VkImageFormatProperties(stream, (VkImageFormatProperties*)(pImageFormatProperties));
     if (pImageFormatProperties)
     {
         transform_fromhost_VkImageFormatProperties(mImpl->resources(), (VkImageFormatProperties*)(pImageFormatProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties returnUnmarshal");
     VkResult vkGetPhysicalDeviceImageFormatProperties_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceImageFormatProperties_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -595,7 +479,6 @@
     VkPhysicalDeviceProperties* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties encode");
     mImpl->log("start vkGetPhysicalDeviceProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -620,13 +503,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_27, 1);
     stream->write((uint64_t*)&cgen_var_27, 1 * 8);
     marshal_VkPhysicalDeviceProperties(stream, (VkPhysicalDeviceProperties*)(pProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties readParams");
     unmarshal_VkPhysicalDeviceProperties(stream, (VkPhysicalDeviceProperties*)(pProperties));
     if (pProperties)
     {
         transform_fromhost_VkPhysicalDeviceProperties(mImpl->resources(), (VkPhysicalDeviceProperties*)(pProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties returnUnmarshal");
     mImpl->resources()->on_vkGetPhysicalDeviceProperties(this, physicalDevice, pProperties);
     pool->freeAll();
     countingStream->clearPool();
@@ -640,7 +521,6 @@
     VkQueueFamilyProperties* pQueueFamilyProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties encode");
     mImpl->log("start vkGetPhysicalDeviceQueueFamilyProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -697,7 +577,6 @@
             marshal_VkQueueFamilyProperties(stream, (VkQueueFamilyProperties*)(pQueueFamilyProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties readParams");
     // WARNING PTR CHECK
     uint32_t* check_pQueueFamilyPropertyCount;
     check_pQueueFamilyPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -730,7 +609,6 @@
             transform_fromhost_VkQueueFamilyProperties(mImpl->resources(), (VkQueueFamilyProperties*)(pQueueFamilyProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -742,7 +620,6 @@
     VkPhysicalDeviceMemoryProperties* pMemoryProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties encode");
     mImpl->log("start vkGetPhysicalDeviceMemoryProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -767,13 +644,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_37, 1);
     stream->write((uint64_t*)&cgen_var_37, 1 * 8);
     marshal_VkPhysicalDeviceMemoryProperties(stream, (VkPhysicalDeviceMemoryProperties*)(pMemoryProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties readParams");
     unmarshal_VkPhysicalDeviceMemoryProperties(stream, (VkPhysicalDeviceMemoryProperties*)(pMemoryProperties));
     if (pMemoryProperties)
     {
         transform_fromhost_VkPhysicalDeviceMemoryProperties(mImpl->resources(), (VkPhysicalDeviceMemoryProperties*)(pMemoryProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties returnUnmarshal");
     mImpl->resources()->on_vkGetPhysicalDeviceMemoryProperties(this, physicalDevice, pMemoryProperties);
     pool->freeAll();
     countingStream->clearPool();
@@ -786,7 +661,6 @@
     const char* pName)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetInstanceProcAddr encode");
     mImpl->log("start vkGetInstanceProcAddr");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -817,8 +691,6 @@
     stream->handleMapping()->mapHandles_VkInstance_u64(&local_instance, &cgen_var_39, 1);
     stream->write((uint64_t*)&cgen_var_39, 1 * 8);
     stream->putString(local_pName);
-    AEMU_SCOPED_TRACE("vkGetInstanceProcAddr readParams");
-    AEMU_SCOPED_TRACE("vkGetInstanceProcAddr returnUnmarshal");
     PFN_vkVoidFunction vkGetInstanceProcAddr_PFN_vkVoidFunction_return = (PFN_vkVoidFunction)0;
     stream->read(&vkGetInstanceProcAddr_PFN_vkVoidFunction_return, sizeof(PFN_vkVoidFunction));
     pool->freeAll();
@@ -833,7 +705,6 @@
     const char* pName)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDeviceProcAddr encode");
     mImpl->log("start vkGetDeviceProcAddr");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -864,8 +735,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_41, 1);
     stream->write((uint64_t*)&cgen_var_41, 1 * 8);
     stream->putString(local_pName);
-    AEMU_SCOPED_TRACE("vkGetDeviceProcAddr readParams");
-    AEMU_SCOPED_TRACE("vkGetDeviceProcAddr returnUnmarshal");
     PFN_vkVoidFunction vkGetDeviceProcAddr_PFN_vkVoidFunction_return = (PFN_vkVoidFunction)0;
     stream->read(&vkGetDeviceProcAddr_PFN_vkVoidFunction_return, sizeof(PFN_vkVoidFunction));
     pool->freeAll();
@@ -882,7 +751,6 @@
     VkDevice* pDevice)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDevice encode");
     mImpl->log("start vkCreateDevice");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -952,13 +820,11 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(pDevice, &cgen_var_47, 1);
     stream->write((uint64_t*)&cgen_var_47, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDevice readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_48;
     stream->read((uint64_t*)&cgen_var_48, 8);
     stream->handleMapping()->mapHandles_u64_VkDevice(&cgen_var_48, (VkDevice*)pDevice, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateDevice returnUnmarshal");
     VkResult vkCreateDevice_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDevice_VkResult_return, sizeof(VkResult));
     mImpl->resources()->on_vkCreateDevice(this, vkCreateDevice_VkResult_return, physicalDevice, pCreateInfo, pAllocator, pDevice);
@@ -974,7 +840,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyDevice encode");
     mImpl->log("start vkDestroyDevice");
     mImpl->resources()->on_vkDestroyDevice_pre(this, device, pAllocator);
     auto stream = mImpl->stream();
@@ -1024,8 +889,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyDevice readParams");
-    AEMU_SCOPED_TRACE("vkDestroyDevice returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkDevice((VkDevice*)&device);
     stream->flush();
     pool->freeAll();
@@ -1040,7 +903,6 @@
     VkExtensionProperties* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceExtensionProperties encode");
     mImpl->log("start vkEnumerateInstanceExtensionProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1123,7 +985,6 @@
             marshal_VkExtensionProperties(stream, (VkExtensionProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceExtensionProperties readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -1156,7 +1017,6 @@
             transform_fromhost_VkExtensionProperties(mImpl->resources(), (VkExtensionProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceExtensionProperties returnUnmarshal");
     VkResult vkEnumerateInstanceExtensionProperties_VkResult_return = (VkResult)0;
     stream->read(&vkEnumerateInstanceExtensionProperties_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -1173,7 +1033,6 @@
     VkExtensionProperties* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEnumerateDeviceExtensionProperties encode");
     mImpl->log("start vkEnumerateDeviceExtensionProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1264,7 +1123,6 @@
             marshal_VkExtensionProperties(stream, (VkExtensionProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumerateDeviceExtensionProperties readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -1297,7 +1155,6 @@
             transform_fromhost_VkExtensionProperties(mImpl->resources(), (VkExtensionProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumerateDeviceExtensionProperties returnUnmarshal");
     VkResult vkEnumerateDeviceExtensionProperties_VkResult_return = (VkResult)0;
     stream->read(&vkEnumerateDeviceExtensionProperties_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -1312,7 +1169,6 @@
     VkLayerProperties* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceLayerProperties encode");
     mImpl->log("start vkEnumerateInstanceLayerProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1361,7 +1217,6 @@
             marshal_VkLayerProperties(stream, (VkLayerProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceLayerProperties readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -1394,7 +1249,6 @@
             transform_fromhost_VkLayerProperties(mImpl->resources(), (VkLayerProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceLayerProperties returnUnmarshal");
     VkResult vkEnumerateInstanceLayerProperties_VkResult_return = (VkResult)0;
     stream->read(&vkEnumerateInstanceLayerProperties_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -1410,7 +1264,6 @@
     VkLayerProperties* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEnumerateDeviceLayerProperties encode");
     mImpl->log("start vkEnumerateDeviceLayerProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1467,7 +1320,6 @@
             marshal_VkLayerProperties(stream, (VkLayerProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumerateDeviceLayerProperties readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -1500,7 +1352,6 @@
             transform_fromhost_VkLayerProperties(mImpl->resources(), (VkLayerProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumerateDeviceLayerProperties returnUnmarshal");
     VkResult vkEnumerateDeviceLayerProperties_VkResult_return = (VkResult)0;
     stream->read(&vkEnumerateDeviceLayerProperties_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -1517,7 +1368,6 @@
     VkQueue* pQueue)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDeviceQueue encode");
     mImpl->log("start vkGetDeviceQueue");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1556,13 +1406,11 @@
     stream->handleMapping()->mapHandles_VkQueue_u64(pQueue, &cgen_var_88, 1);
     stream->write((uint64_t*)&cgen_var_88, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkGetDeviceQueue readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_89;
     stream->read((uint64_t*)&cgen_var_89, 8);
     stream->handleMapping()->mapHandles_u64_VkQueue(&cgen_var_89, (VkQueue*)pQueue, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkGetDeviceQueue returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -1576,7 +1424,6 @@
     VkFence fence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueSubmit encode");
     mImpl->log("start vkQueueSubmit");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1636,8 +1483,6 @@
     uint64_t cgen_var_93;
     stream->handleMapping()->mapHandles_VkFence_u64(&local_fence, &cgen_var_93, 1);
     stream->write((uint64_t*)&cgen_var_93, 1 * 8);
-    AEMU_SCOPED_TRACE("vkQueueSubmit readParams");
-    AEMU_SCOPED_TRACE("vkQueueSubmit returnUnmarshal");
     VkResult vkQueueSubmit_VkResult_return = (VkResult)0;
     stream->read(&vkQueueSubmit_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -1651,7 +1496,6 @@
     VkQueue queue)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueWaitIdle encode");
     mImpl->log("start vkQueueWaitIdle");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1674,8 +1518,6 @@
     uint64_t cgen_var_95;
     stream->handleMapping()->mapHandles_VkQueue_u64(&local_queue, &cgen_var_95, 1);
     stream->write((uint64_t*)&cgen_var_95, 1 * 8);
-    AEMU_SCOPED_TRACE("vkQueueWaitIdle readParams");
-    AEMU_SCOPED_TRACE("vkQueueWaitIdle returnUnmarshal");
     VkResult vkQueueWaitIdle_VkResult_return = (VkResult)0;
     stream->read(&vkQueueWaitIdle_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -1689,7 +1531,6 @@
     VkDevice device)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDeviceWaitIdle encode");
     mImpl->log("start vkDeviceWaitIdle");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1712,8 +1553,6 @@
     uint64_t cgen_var_97;
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_97, 1);
     stream->write((uint64_t*)&cgen_var_97, 1 * 8);
-    AEMU_SCOPED_TRACE("vkDeviceWaitIdle readParams");
-    AEMU_SCOPED_TRACE("vkDeviceWaitIdle returnUnmarshal");
     VkResult vkDeviceWaitIdle_VkResult_return = (VkResult)0;
     stream->read(&vkDeviceWaitIdle_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -1730,7 +1569,6 @@
     VkDeviceMemory* pMemory)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkAllocateMemory encode");
     mImpl->log("start vkAllocateMemory");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1800,13 +1638,11 @@
     stream->handleMapping()->mapHandles_VkDeviceMemory_u64(pMemory, &cgen_var_103, 1);
     stream->write((uint64_t*)&cgen_var_103, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkAllocateMemory readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_104;
     stream->read((uint64_t*)&cgen_var_104, 8);
     stream->handleMapping()->mapHandles_u64_VkDeviceMemory(&cgen_var_104, (VkDeviceMemory*)pMemory, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkAllocateMemory returnUnmarshal");
     VkResult vkAllocateMemory_VkResult_return = (VkResult)0;
     stream->read(&vkAllocateMemory_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -1822,7 +1658,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkFreeMemory encode");
     mImpl->log("start vkFreeMemory");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -1876,8 +1711,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkFreeMemory readParams");
-    AEMU_SCOPED_TRACE("vkFreeMemory returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkDeviceMemory((VkDeviceMemory*)&memory);
     pool->freeAll();
     countingStream->clearPool();
@@ -1893,7 +1726,6 @@
     VkMemoryMapFlags flags,
     void** ppData)
 {
-    AEMU_SCOPED_TRACE("vkMapMemory resourceEvent");
     VkResult vkMapMemory_VkResult_return = (VkResult)0;
     vkMapMemory_VkResult_return = mImpl->resources()->on_vkMapMemory(this, VK_SUCCESS, device, memory, offset, size, flags, ppData);
     mImpl->log("finish vkMapMemory");;
@@ -1904,7 +1736,6 @@
     VkDevice device,
     VkDeviceMemory memory)
 {
-    AEMU_SCOPED_TRACE("vkUnmapMemory resourceEvent");
     mImpl->resources()->on_vkUnmapMemory(this, device, memory);
 }
 
@@ -1914,7 +1745,6 @@
     const VkMappedMemoryRange* pMemoryRanges)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkFlushMappedMemoryRanges encode");
     mImpl->log("start vkFlushMappedMemoryRanges");
     VALIDATE_RET(VkResult, VK_SUCCESS, mImpl->validation()->on_vkFlushMappedMemoryRanges(this, VK_SUCCESS, device, memoryRangeCount, pMemoryRanges));
     auto stream = mImpl->stream();
@@ -2005,8 +1835,6 @@
             stream->write(targetRange, actualSize);
         }
     }
-    AEMU_SCOPED_TRACE("vkFlushMappedMemoryRanges readParams");
-    AEMU_SCOPED_TRACE("vkFlushMappedMemoryRanges returnUnmarshal");
     VkResult vkFlushMappedMemoryRanges_VkResult_return = (VkResult)0;
     stream->read(&vkFlushMappedMemoryRanges_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -2022,7 +1850,6 @@
     const VkMappedMemoryRange* pMemoryRanges)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkInvalidateMappedMemoryRanges encode");
     mImpl->log("start vkInvalidateMappedMemoryRanges");
     VALIDATE_RET(VkResult, VK_SUCCESS, mImpl->validation()->on_vkInvalidateMappedMemoryRanges(this, VK_SUCCESS, device, memoryRangeCount, pMemoryRanges));
     auto stream = mImpl->stream();
@@ -2075,8 +1902,6 @@
     {
         marshal_VkMappedMemoryRange(stream, (VkMappedMemoryRange*)(local_pMemoryRanges + i));
     }
-    AEMU_SCOPED_TRACE("vkInvalidateMappedMemoryRanges readParams");
-    AEMU_SCOPED_TRACE("vkInvalidateMappedMemoryRanges returnUnmarshal");
     VkResult vkInvalidateMappedMemoryRanges_VkResult_return = (VkResult)0;
     stream->read(&vkInvalidateMappedMemoryRanges_VkResult_return, sizeof(VkResult));
     if (!resources->usingDirectMapping())
@@ -2111,7 +1936,6 @@
     VkDeviceSize* pCommittedMemoryInBytes)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDeviceMemoryCommitment encode");
     mImpl->log("start vkGetDeviceMemoryCommitment");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2145,9 +1969,7 @@
     stream->handleMapping()->mapHandles_VkDeviceMemory_u64(&local_memory, &cgen_var_118, 1);
     stream->write((uint64_t*)&cgen_var_118, 1 * 8);
     stream->write((VkDeviceSize*)pCommittedMemoryInBytes, sizeof(VkDeviceSize));
-    AEMU_SCOPED_TRACE("vkGetDeviceMemoryCommitment readParams");
     stream->read((VkDeviceSize*)pCommittedMemoryInBytes, sizeof(VkDeviceSize));
-    AEMU_SCOPED_TRACE("vkGetDeviceMemoryCommitment returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -2161,7 +1983,6 @@
     VkDeviceSize memoryOffset)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkBindBufferMemory encode");
     mImpl->log("start vkBindBufferMemory");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2205,8 +2026,6 @@
     stream->handleMapping()->mapHandles_VkDeviceMemory_u64(&local_memory, &cgen_var_124, 1);
     stream->write((uint64_t*)&cgen_var_124, 1 * 8);
     stream->write((VkDeviceSize*)&local_memoryOffset, sizeof(VkDeviceSize));
-    AEMU_SCOPED_TRACE("vkBindBufferMemory readParams");
-    AEMU_SCOPED_TRACE("vkBindBufferMemory returnUnmarshal");
     VkResult vkBindBufferMemory_VkResult_return = (VkResult)0;
     stream->read(&vkBindBufferMemory_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -2223,7 +2042,6 @@
     VkDeviceSize memoryOffset)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkBindImageMemory encode");
     mImpl->log("start vkBindImageMemory");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2267,8 +2085,6 @@
     stream->handleMapping()->mapHandles_VkDeviceMemory_u64(&local_memory, &cgen_var_130, 1);
     stream->write((uint64_t*)&cgen_var_130, 1 * 8);
     stream->write((VkDeviceSize*)&local_memoryOffset, sizeof(VkDeviceSize));
-    AEMU_SCOPED_TRACE("vkBindImageMemory readParams");
-    AEMU_SCOPED_TRACE("vkBindImageMemory returnUnmarshal");
     VkResult vkBindImageMemory_VkResult_return = (VkResult)0;
     stream->read(&vkBindImageMemory_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -2284,7 +2100,6 @@
     VkMemoryRequirements* pMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements encode");
     mImpl->log("start vkGetBufferMemoryRequirements");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2317,13 +2132,11 @@
     stream->handleMapping()->mapHandles_VkBuffer_u64(&local_buffer, &cgen_var_134, 1);
     stream->write((uint64_t*)&cgen_var_134, 1 * 8);
     marshal_VkMemoryRequirements(stream, (VkMemoryRequirements*)(pMemoryRequirements));
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements readParams");
     unmarshal_VkMemoryRequirements(stream, (VkMemoryRequirements*)(pMemoryRequirements));
     if (pMemoryRequirements)
     {
         transform_fromhost_VkMemoryRequirements(mImpl->resources(), (VkMemoryRequirements*)(pMemoryRequirements));
     }
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -2336,7 +2149,6 @@
     VkMemoryRequirements* pMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements encode");
     mImpl->log("start vkGetImageMemoryRequirements");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2369,13 +2181,11 @@
     stream->handleMapping()->mapHandles_VkImage_u64(&local_image, &cgen_var_138, 1);
     stream->write((uint64_t*)&cgen_var_138, 1 * 8);
     marshal_VkMemoryRequirements(stream, (VkMemoryRequirements*)(pMemoryRequirements));
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements readParams");
     unmarshal_VkMemoryRequirements(stream, (VkMemoryRequirements*)(pMemoryRequirements));
     if (pMemoryRequirements)
     {
         transform_fromhost_VkMemoryRequirements(mImpl->resources(), (VkMemoryRequirements*)(pMemoryRequirements));
     }
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -2389,7 +2199,6 @@
     VkSparseImageMemoryRequirements* pSparseMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements encode");
     mImpl->log("start vkGetImageSparseMemoryRequirements");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2454,7 +2263,6 @@
             marshal_VkSparseImageMemoryRequirements(stream, (VkSparseImageMemoryRequirements*)(pSparseMemoryRequirements + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements readParams");
     // WARNING PTR CHECK
     uint32_t* check_pSparseMemoryRequirementCount;
     check_pSparseMemoryRequirementCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -2487,7 +2295,6 @@
             transform_fromhost_VkSparseImageMemoryRequirements(mImpl->resources(), (VkSparseImageMemoryRequirements*)(pSparseMemoryRequirements + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -2505,7 +2312,6 @@
     VkSparseImageFormatProperties* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties encode");
     mImpl->log("start vkGetPhysicalDeviceSparseImageFormatProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2582,7 +2388,6 @@
             marshal_VkSparseImageFormatProperties(stream, (VkSparseImageFormatProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -2615,7 +2420,6 @@
             transform_fromhost_VkSparseImageFormatProperties(mImpl->resources(), (VkSparseImageFormatProperties*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -2629,7 +2433,6 @@
     VkFence fence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueBindSparse encode");
     mImpl->log("start vkQueueBindSparse");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2689,8 +2492,6 @@
     uint64_t cgen_var_160;
     stream->handleMapping()->mapHandles_VkFence_u64(&local_fence, &cgen_var_160, 1);
     stream->write((uint64_t*)&cgen_var_160, 1 * 8);
-    AEMU_SCOPED_TRACE("vkQueueBindSparse readParams");
-    AEMU_SCOPED_TRACE("vkQueueBindSparse returnUnmarshal");
     VkResult vkQueueBindSparse_VkResult_return = (VkResult)0;
     stream->read(&vkQueueBindSparse_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -2707,7 +2508,6 @@
     VkFence* pFence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateFence encode");
     mImpl->log("start vkCreateFence");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2777,13 +2577,11 @@
     stream->handleMapping()->mapHandles_VkFence_u64(pFence, &cgen_var_166, 1);
     stream->write((uint64_t*)&cgen_var_166, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateFence readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_167;
     stream->read((uint64_t*)&cgen_var_167, 8);
     stream->handleMapping()->mapHandles_u64_VkFence(&cgen_var_167, (VkFence*)pFence, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateFence returnUnmarshal");
     VkResult vkCreateFence_VkResult_return = (VkResult)0;
     stream->read(&vkCreateFence_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -2799,7 +2597,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyFence encode");
     mImpl->log("start vkDestroyFence");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2856,8 +2653,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyFence readParams");
-    AEMU_SCOPED_TRACE("vkDestroyFence returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkFence((VkFence*)&fence);
     pool->freeAll();
     countingStream->clearPool();
@@ -2871,7 +2666,6 @@
     const VkFence* pFences)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkResetFences encode");
     mImpl->log("start vkResetFences");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2918,8 +2712,6 @@
         stream->handleMapping()->mapHandles_VkFence_u64(local_pFences, cgen_var_177, ((fenceCount)));
         stream->write((uint64_t*)cgen_var_177, ((fenceCount)) * 8);
     }
-    AEMU_SCOPED_TRACE("vkResetFences readParams");
-    AEMU_SCOPED_TRACE("vkResetFences returnUnmarshal");
     VkResult vkResetFences_VkResult_return = (VkResult)0;
     stream->read(&vkResetFences_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -2934,7 +2726,6 @@
     VkFence fence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetFenceStatus encode");
     mImpl->log("start vkGetFenceStatus");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -2965,8 +2756,6 @@
     uint64_t cgen_var_181;
     stream->handleMapping()->mapHandles_VkFence_u64(&local_fence, &cgen_var_181, 1);
     stream->write((uint64_t*)&cgen_var_181, 1 * 8);
-    AEMU_SCOPED_TRACE("vkGetFenceStatus readParams");
-    AEMU_SCOPED_TRACE("vkGetFenceStatus returnUnmarshal");
     VkResult vkGetFenceStatus_VkResult_return = (VkResult)0;
     stream->read(&vkGetFenceStatus_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -2984,7 +2773,6 @@
     uint64_t timeout)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkWaitForFences encode");
     mImpl->log("start vkWaitForFences");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3039,8 +2827,6 @@
     }
     stream->write((VkBool32*)&local_waitAll, sizeof(VkBool32));
     stream->write((uint64_t*)&local_timeout, sizeof(uint64_t));
-    AEMU_SCOPED_TRACE("vkWaitForFences readParams");
-    AEMU_SCOPED_TRACE("vkWaitForFences returnUnmarshal");
     VkResult vkWaitForFences_VkResult_return = (VkResult)0;
     stream->read(&vkWaitForFences_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3057,7 +2843,6 @@
     VkSemaphore* pSemaphore)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateSemaphore encode");
     mImpl->log("start vkCreateSemaphore");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3127,13 +2912,11 @@
     stream->handleMapping()->mapHandles_VkSemaphore_u64(pSemaphore, &cgen_var_191, 1);
     stream->write((uint64_t*)&cgen_var_191, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateSemaphore readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_192;
     stream->read((uint64_t*)&cgen_var_192, 8);
     stream->handleMapping()->mapHandles_u64_VkSemaphore(&cgen_var_192, (VkSemaphore*)pSemaphore, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateSemaphore returnUnmarshal");
     VkResult vkCreateSemaphore_VkResult_return = (VkResult)0;
     stream->read(&vkCreateSemaphore_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3149,7 +2932,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroySemaphore encode");
     mImpl->log("start vkDestroySemaphore");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3206,8 +2988,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroySemaphore readParams");
-    AEMU_SCOPED_TRACE("vkDestroySemaphore returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkSemaphore((VkSemaphore*)&semaphore);
     pool->freeAll();
     countingStream->clearPool();
@@ -3222,7 +3002,6 @@
     VkEvent* pEvent)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateEvent encode");
     mImpl->log("start vkCreateEvent");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3292,13 +3071,11 @@
     stream->handleMapping()->mapHandles_VkEvent_u64(pEvent, &cgen_var_204, 1);
     stream->write((uint64_t*)&cgen_var_204, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateEvent readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_205;
     stream->read((uint64_t*)&cgen_var_205, 8);
     stream->handleMapping()->mapHandles_u64_VkEvent(&cgen_var_205, (VkEvent*)pEvent, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateEvent returnUnmarshal");
     VkResult vkCreateEvent_VkResult_return = (VkResult)0;
     stream->read(&vkCreateEvent_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3314,7 +3091,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyEvent encode");
     mImpl->log("start vkDestroyEvent");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3371,8 +3147,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyEvent readParams");
-    AEMU_SCOPED_TRACE("vkDestroyEvent returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkEvent((VkEvent*)&event);
     pool->freeAll();
     countingStream->clearPool();
@@ -3385,7 +3159,6 @@
     VkEvent event)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetEventStatus encode");
     mImpl->log("start vkGetEventStatus");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3416,8 +3189,6 @@
     uint64_t cgen_var_215;
     stream->handleMapping()->mapHandles_VkEvent_u64(&local_event, &cgen_var_215, 1);
     stream->write((uint64_t*)&cgen_var_215, 1 * 8);
-    AEMU_SCOPED_TRACE("vkGetEventStatus readParams");
-    AEMU_SCOPED_TRACE("vkGetEventStatus returnUnmarshal");
     VkResult vkGetEventStatus_VkResult_return = (VkResult)0;
     stream->read(&vkGetEventStatus_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3432,7 +3203,6 @@
     VkEvent event)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkSetEvent encode");
     mImpl->log("start vkSetEvent");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3463,8 +3233,6 @@
     uint64_t cgen_var_219;
     stream->handleMapping()->mapHandles_VkEvent_u64(&local_event, &cgen_var_219, 1);
     stream->write((uint64_t*)&cgen_var_219, 1 * 8);
-    AEMU_SCOPED_TRACE("vkSetEvent readParams");
-    AEMU_SCOPED_TRACE("vkSetEvent returnUnmarshal");
     VkResult vkSetEvent_VkResult_return = (VkResult)0;
     stream->read(&vkSetEvent_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3479,7 +3247,6 @@
     VkEvent event)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkResetEvent encode");
     mImpl->log("start vkResetEvent");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3510,8 +3277,6 @@
     uint64_t cgen_var_223;
     stream->handleMapping()->mapHandles_VkEvent_u64(&local_event, &cgen_var_223, 1);
     stream->write((uint64_t*)&cgen_var_223, 1 * 8);
-    AEMU_SCOPED_TRACE("vkResetEvent readParams");
-    AEMU_SCOPED_TRACE("vkResetEvent returnUnmarshal");
     VkResult vkResetEvent_VkResult_return = (VkResult)0;
     stream->read(&vkResetEvent_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3528,7 +3293,6 @@
     VkQueryPool* pQueryPool)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateQueryPool encode");
     mImpl->log("start vkCreateQueryPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3598,13 +3362,11 @@
     stream->handleMapping()->mapHandles_VkQueryPool_u64(pQueryPool, &cgen_var_229, 1);
     stream->write((uint64_t*)&cgen_var_229, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateQueryPool readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_230;
     stream->read((uint64_t*)&cgen_var_230, 8);
     stream->handleMapping()->mapHandles_u64_VkQueryPool(&cgen_var_230, (VkQueryPool*)pQueryPool, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateQueryPool returnUnmarshal");
     VkResult vkCreateQueryPool_VkResult_return = (VkResult)0;
     stream->read(&vkCreateQueryPool_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3620,7 +3382,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyQueryPool encode");
     mImpl->log("start vkDestroyQueryPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3677,8 +3438,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyQueryPool readParams");
-    AEMU_SCOPED_TRACE("vkDestroyQueryPool returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkQueryPool((VkQueryPool*)&queryPool);
     pool->freeAll();
     countingStream->clearPool();
@@ -3697,7 +3456,6 @@
     VkQueryResultFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetQueryPoolResults encode");
     mImpl->log("start vkGetQueryPoolResults");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3752,9 +3510,7 @@
     stream->write((void*)pData, ((dataSize)) * sizeof(uint8_t));
     stream->write((VkDeviceSize*)&local_stride, sizeof(VkDeviceSize));
     stream->write((VkQueryResultFlags*)&local_flags, sizeof(VkQueryResultFlags));
-    AEMU_SCOPED_TRACE("vkGetQueryPoolResults readParams");
     stream->read((void*)pData, ((dataSize)) * sizeof(uint8_t));
-    AEMU_SCOPED_TRACE("vkGetQueryPoolResults returnUnmarshal");
     VkResult vkGetQueryPoolResults_VkResult_return = (VkResult)0;
     stream->read(&vkGetQueryPoolResults_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3771,7 +3527,6 @@
     VkBuffer* pBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateBuffer encode");
     mImpl->log("start vkCreateBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3841,13 +3596,11 @@
     stream->handleMapping()->mapHandles_VkBuffer_u64(pBuffer, &cgen_var_248, 1);
     stream->write((uint64_t*)&cgen_var_248, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateBuffer readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_249;
     stream->read((uint64_t*)&cgen_var_249, 8);
     stream->handleMapping()->mapHandles_u64_VkBuffer(&cgen_var_249, (VkBuffer*)pBuffer, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateBuffer returnUnmarshal");
     VkResult vkCreateBuffer_VkResult_return = (VkResult)0;
     stream->read(&vkCreateBuffer_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -3863,7 +3616,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyBuffer encode");
     mImpl->log("start vkDestroyBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -3920,8 +3672,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyBuffer readParams");
-    AEMU_SCOPED_TRACE("vkDestroyBuffer returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkBuffer((VkBuffer*)&buffer);
     pool->freeAll();
     countingStream->clearPool();
@@ -3936,7 +3686,6 @@
     VkBufferView* pView)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateBufferView encode");
     mImpl->log("start vkCreateBufferView");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4006,13 +3755,11 @@
     stream->handleMapping()->mapHandles_VkBufferView_u64(pView, &cgen_var_261, 1);
     stream->write((uint64_t*)&cgen_var_261, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateBufferView readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_262;
     stream->read((uint64_t*)&cgen_var_262, 8);
     stream->handleMapping()->mapHandles_u64_VkBufferView(&cgen_var_262, (VkBufferView*)pView, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateBufferView returnUnmarshal");
     VkResult vkCreateBufferView_VkResult_return = (VkResult)0;
     stream->read(&vkCreateBufferView_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -4028,7 +3775,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyBufferView encode");
     mImpl->log("start vkDestroyBufferView");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4085,8 +3831,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyBufferView readParams");
-    AEMU_SCOPED_TRACE("vkDestroyBufferView returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkBufferView((VkBufferView*)&bufferView);
     pool->freeAll();
     countingStream->clearPool();
@@ -4101,7 +3845,6 @@
     VkImage* pImage)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateImage encode");
     mImpl->log("start vkCreateImage");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4172,13 +3915,11 @@
     stream->handleMapping()->mapHandles_VkImage_u64(pImage, &cgen_var_274, 1);
     stream->write((uint64_t*)&cgen_var_274, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateImage readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_275;
     stream->read((uint64_t*)&cgen_var_275, 8);
     stream->handleMapping()->mapHandles_u64_VkImage(&cgen_var_275, (VkImage*)pImage, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateImage returnUnmarshal");
     VkResult vkCreateImage_VkResult_return = (VkResult)0;
     stream->read(&vkCreateImage_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -4194,7 +3935,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyImage encode");
     mImpl->log("start vkDestroyImage");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4251,8 +3991,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyImage readParams");
-    AEMU_SCOPED_TRACE("vkDestroyImage returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkImage((VkImage*)&image);
     pool->freeAll();
     countingStream->clearPool();
@@ -4267,7 +4005,6 @@
     VkSubresourceLayout* pLayout)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetImageSubresourceLayout encode");
     mImpl->log("start vkGetImageSubresourceLayout");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4313,13 +4050,11 @@
     stream->write((uint64_t*)&cgen_var_285, 1 * 8);
     marshal_VkImageSubresource(stream, (VkImageSubresource*)(local_pSubresource));
     marshal_VkSubresourceLayout(stream, (VkSubresourceLayout*)(pLayout));
-    AEMU_SCOPED_TRACE("vkGetImageSubresourceLayout readParams");
     unmarshal_VkSubresourceLayout(stream, (VkSubresourceLayout*)(pLayout));
     if (pLayout)
     {
         transform_fromhost_VkSubresourceLayout(mImpl->resources(), (VkSubresourceLayout*)(pLayout));
     }
-    AEMU_SCOPED_TRACE("vkGetImageSubresourceLayout returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -4333,7 +4068,6 @@
     VkImageView* pView)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateImageView encode");
     mImpl->log("start vkCreateImageView");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4403,13 +4137,11 @@
     stream->handleMapping()->mapHandles_VkImageView_u64(pView, &cgen_var_291, 1);
     stream->write((uint64_t*)&cgen_var_291, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateImageView readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_292;
     stream->read((uint64_t*)&cgen_var_292, 8);
     stream->handleMapping()->mapHandles_u64_VkImageView(&cgen_var_292, (VkImageView*)pView, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateImageView returnUnmarshal");
     VkResult vkCreateImageView_VkResult_return = (VkResult)0;
     stream->read(&vkCreateImageView_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -4425,7 +4157,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyImageView encode");
     mImpl->log("start vkDestroyImageView");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4482,8 +4213,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyImageView readParams");
-    AEMU_SCOPED_TRACE("vkDestroyImageView returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkImageView((VkImageView*)&imageView);
     pool->freeAll();
     countingStream->clearPool();
@@ -4498,7 +4227,6 @@
     VkShaderModule* pShaderModule)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateShaderModule encode");
     mImpl->log("start vkCreateShaderModule");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4568,13 +4296,11 @@
     stream->handleMapping()->mapHandles_VkShaderModule_u64(pShaderModule, &cgen_var_304, 1);
     stream->write((uint64_t*)&cgen_var_304, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateShaderModule readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_305;
     stream->read((uint64_t*)&cgen_var_305, 8);
     stream->handleMapping()->mapHandles_u64_VkShaderModule(&cgen_var_305, (VkShaderModule*)pShaderModule, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateShaderModule returnUnmarshal");
     VkResult vkCreateShaderModule_VkResult_return = (VkResult)0;
     stream->read(&vkCreateShaderModule_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -4590,7 +4316,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyShaderModule encode");
     mImpl->log("start vkDestroyShaderModule");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4647,8 +4372,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyShaderModule readParams");
-    AEMU_SCOPED_TRACE("vkDestroyShaderModule returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkShaderModule((VkShaderModule*)&shaderModule);
     pool->freeAll();
     countingStream->clearPool();
@@ -4663,7 +4386,6 @@
     VkPipelineCache* pPipelineCache)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreatePipelineCache encode");
     mImpl->log("start vkCreatePipelineCache");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4733,13 +4455,11 @@
     stream->handleMapping()->mapHandles_VkPipelineCache_u64(pPipelineCache, &cgen_var_317, 1);
     stream->write((uint64_t*)&cgen_var_317, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreatePipelineCache readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_318;
     stream->read((uint64_t*)&cgen_var_318, 8);
     stream->handleMapping()->mapHandles_u64_VkPipelineCache(&cgen_var_318, (VkPipelineCache*)pPipelineCache, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreatePipelineCache returnUnmarshal");
     VkResult vkCreatePipelineCache_VkResult_return = (VkResult)0;
     stream->read(&vkCreatePipelineCache_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -4755,7 +4475,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyPipelineCache encode");
     mImpl->log("start vkDestroyPipelineCache");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4812,8 +4531,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyPipelineCache readParams");
-    AEMU_SCOPED_TRACE("vkDestroyPipelineCache returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkPipelineCache((VkPipelineCache*)&pipelineCache);
     pool->freeAll();
     countingStream->clearPool();
@@ -4828,7 +4545,6 @@
     void* pData)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPipelineCacheData encode");
     mImpl->log("start vkGetPipelineCacheData");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4889,7 +4605,6 @@
     {
         stream->write((void*)pData, (*(pDataSize)) * sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkGetPipelineCacheData readParams");
     // WARNING PTR CHECK
     size_t* check_pDataSize;
     check_pDataSize = (size_t*)(uintptr_t)stream->getBe64();
@@ -4912,7 +4627,6 @@
         }
         stream->read((void*)pData, (*(pDataSize)) * sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkGetPipelineCacheData returnUnmarshal");
     VkResult vkGetPipelineCacheData_VkResult_return = (VkResult)0;
     stream->read(&vkGetPipelineCacheData_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -4929,7 +4643,6 @@
     const VkPipelineCache* pSrcCaches)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkMergePipelineCaches encode");
     mImpl->log("start vkMergePipelineCaches");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -4984,8 +4697,6 @@
         stream->handleMapping()->mapHandles_VkPipelineCache_u64(local_pSrcCaches, cgen_var_343, ((srcCacheCount)));
         stream->write((uint64_t*)cgen_var_343, ((srcCacheCount)) * 8);
     }
-    AEMU_SCOPED_TRACE("vkMergePipelineCaches readParams");
-    AEMU_SCOPED_TRACE("vkMergePipelineCaches returnUnmarshal");
     VkResult vkMergePipelineCaches_VkResult_return = (VkResult)0;
     stream->read(&vkMergePipelineCaches_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -5004,7 +4715,6 @@
     VkPipeline* pPipelines)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateGraphicsPipelines encode");
     mImpl->log("start vkCreateGraphicsPipelines");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5106,7 +4816,6 @@
         stream->write((uint64_t*)cgen_var_351, ((createInfoCount)) * 8);
     }
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateGraphicsPipelines readParams");
     stream->setHandleMapping(resources->createMapping());
     if (((createInfoCount)))
     {
@@ -5116,7 +4825,6 @@
         stream->handleMapping()->mapHandles_u64_VkPipeline(cgen_var_352, (VkPipeline*)pPipelines, ((createInfoCount)));
     }
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateGraphicsPipelines returnUnmarshal");
     VkResult vkCreateGraphicsPipelines_VkResult_return = (VkResult)0;
     stream->read(&vkCreateGraphicsPipelines_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -5135,7 +4843,6 @@
     VkPipeline* pPipelines)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateComputePipelines encode");
     mImpl->log("start vkCreateComputePipelines");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5237,7 +4944,6 @@
         stream->write((uint64_t*)cgen_var_360, ((createInfoCount)) * 8);
     }
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateComputePipelines readParams");
     stream->setHandleMapping(resources->createMapping());
     if (((createInfoCount)))
     {
@@ -5247,7 +4953,6 @@
         stream->handleMapping()->mapHandles_u64_VkPipeline(cgen_var_361, (VkPipeline*)pPipelines, ((createInfoCount)));
     }
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateComputePipelines returnUnmarshal");
     VkResult vkCreateComputePipelines_VkResult_return = (VkResult)0;
     stream->read(&vkCreateComputePipelines_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -5263,7 +4968,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyPipeline encode");
     mImpl->log("start vkDestroyPipeline");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5320,8 +5024,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyPipeline readParams");
-    AEMU_SCOPED_TRACE("vkDestroyPipeline returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkPipeline((VkPipeline*)&pipeline);
     pool->freeAll();
     countingStream->clearPool();
@@ -5336,7 +5038,6 @@
     VkPipelineLayout* pPipelineLayout)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreatePipelineLayout encode");
     mImpl->log("start vkCreatePipelineLayout");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5406,13 +5107,11 @@
     stream->handleMapping()->mapHandles_VkPipelineLayout_u64(pPipelineLayout, &cgen_var_373, 1);
     stream->write((uint64_t*)&cgen_var_373, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreatePipelineLayout readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_374;
     stream->read((uint64_t*)&cgen_var_374, 8);
     stream->handleMapping()->mapHandles_u64_VkPipelineLayout(&cgen_var_374, (VkPipelineLayout*)pPipelineLayout, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreatePipelineLayout returnUnmarshal");
     VkResult vkCreatePipelineLayout_VkResult_return = (VkResult)0;
     stream->read(&vkCreatePipelineLayout_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -5428,7 +5127,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyPipelineLayout encode");
     mImpl->log("start vkDestroyPipelineLayout");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5485,8 +5183,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyPipelineLayout readParams");
-    AEMU_SCOPED_TRACE("vkDestroyPipelineLayout returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkPipelineLayout((VkPipelineLayout*)&pipelineLayout);
     pool->freeAll();
     countingStream->clearPool();
@@ -5501,7 +5197,6 @@
     VkSampler* pSampler)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateSampler encode");
     mImpl->log("start vkCreateSampler");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5571,13 +5266,11 @@
     stream->handleMapping()->mapHandles_VkSampler_u64(pSampler, &cgen_var_386, 1);
     stream->write((uint64_t*)&cgen_var_386, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateSampler readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_387;
     stream->read((uint64_t*)&cgen_var_387, 8);
     stream->handleMapping()->mapHandles_u64_VkSampler(&cgen_var_387, (VkSampler*)pSampler, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateSampler returnUnmarshal");
     VkResult vkCreateSampler_VkResult_return = (VkResult)0;
     stream->read(&vkCreateSampler_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -5593,7 +5286,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroySampler encode");
     mImpl->log("start vkDestroySampler");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5650,8 +5342,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroySampler readParams");
-    AEMU_SCOPED_TRACE("vkDestroySampler returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkSampler((VkSampler*)&sampler);
     pool->freeAll();
     countingStream->clearPool();
@@ -5666,7 +5356,6 @@
     VkDescriptorSetLayout* pSetLayout)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDescriptorSetLayout encode");
     mImpl->log("start vkCreateDescriptorSetLayout");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5736,13 +5425,11 @@
     stream->handleMapping()->mapHandles_VkDescriptorSetLayout_u64(pSetLayout, &cgen_var_399, 1);
     stream->write((uint64_t*)&cgen_var_399, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDescriptorSetLayout readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_400;
     stream->read((uint64_t*)&cgen_var_400, 8);
     stream->handleMapping()->mapHandles_u64_VkDescriptorSetLayout(&cgen_var_400, (VkDescriptorSetLayout*)pSetLayout, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateDescriptorSetLayout returnUnmarshal");
     VkResult vkCreateDescriptorSetLayout_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDescriptorSetLayout_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -5758,7 +5445,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorSetLayout encode");
     mImpl->log("start vkDestroyDescriptorSetLayout");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5815,8 +5501,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorSetLayout readParams");
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorSetLayout returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkDescriptorSetLayout((VkDescriptorSetLayout*)&descriptorSetLayout);
     pool->freeAll();
     countingStream->clearPool();
@@ -5831,7 +5515,6 @@
     VkDescriptorPool* pDescriptorPool)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDescriptorPool encode");
     mImpl->log("start vkCreateDescriptorPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5901,13 +5584,11 @@
     stream->handleMapping()->mapHandles_VkDescriptorPool_u64(pDescriptorPool, &cgen_var_412, 1);
     stream->write((uint64_t*)&cgen_var_412, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDescriptorPool readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_413;
     stream->read((uint64_t*)&cgen_var_413, 8);
     stream->handleMapping()->mapHandles_u64_VkDescriptorPool(&cgen_var_413, (VkDescriptorPool*)pDescriptorPool, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateDescriptorPool returnUnmarshal");
     VkResult vkCreateDescriptorPool_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDescriptorPool_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -5923,7 +5604,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorPool encode");
     mImpl->log("start vkDestroyDescriptorPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -5980,8 +5660,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorPool readParams");
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorPool returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkDescriptorPool((VkDescriptorPool*)&descriptorPool);
     pool->freeAll();
     countingStream->clearPool();
@@ -5995,7 +5673,6 @@
     VkDescriptorPoolResetFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkResetDescriptorPool encode");
     mImpl->log("start vkResetDescriptorPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6030,8 +5707,6 @@
     stream->handleMapping()->mapHandles_VkDescriptorPool_u64(&local_descriptorPool, &cgen_var_423, 1);
     stream->write((uint64_t*)&cgen_var_423, 1 * 8);
     stream->write((VkDescriptorPoolResetFlags*)&local_flags, sizeof(VkDescriptorPoolResetFlags));
-    AEMU_SCOPED_TRACE("vkResetDescriptorPool readParams");
-    AEMU_SCOPED_TRACE("vkResetDescriptorPool returnUnmarshal");
     VkResult vkResetDescriptorPool_VkResult_return = (VkResult)0;
     stream->read(&vkResetDescriptorPool_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -6047,7 +5722,6 @@
     VkDescriptorSet* pDescriptorSets)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkAllocateDescriptorSets encode");
     mImpl->log("start vkAllocateDescriptorSets");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6099,7 +5773,6 @@
         stream->write((uint64_t*)cgen_var_427, pAllocateInfo->descriptorSetCount * 8);
     }
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkAllocateDescriptorSets readParams");
     stream->setHandleMapping(resources->createMapping());
     if (pAllocateInfo->descriptorSetCount)
     {
@@ -6109,7 +5782,6 @@
         stream->handleMapping()->mapHandles_u64_VkDescriptorSet(cgen_var_428, (VkDescriptorSet*)pDescriptorSets, pAllocateInfo->descriptorSetCount);
     }
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkAllocateDescriptorSets returnUnmarshal");
     VkResult vkAllocateDescriptorSets_VkResult_return = (VkResult)0;
     stream->read(&vkAllocateDescriptorSets_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -6126,7 +5798,6 @@
     const VkDescriptorSet* pDescriptorSets)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkFreeDescriptorSets encode");
     mImpl->log("start vkFreeDescriptorSets");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6193,8 +5864,6 @@
             stream->write((uint64_t*)cgen_var_436, ((descriptorSetCount)) * 8);
         }
     }
-    AEMU_SCOPED_TRACE("vkFreeDescriptorSets readParams");
-    AEMU_SCOPED_TRACE("vkFreeDescriptorSets returnUnmarshal");
     VkResult vkFreeDescriptorSets_VkResult_return = (VkResult)0;
     stream->read(&vkFreeDescriptorSets_VkResult_return, sizeof(VkResult));
     if (pDescriptorSets)
@@ -6216,7 +5885,6 @@
     const VkCopyDescriptorSet* pDescriptorCopies)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSets encode");
     mImpl->log("start vkUpdateDescriptorSets");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6297,8 +5965,6 @@
     {
         marshal_VkCopyDescriptorSet(stream, (VkCopyDescriptorSet*)(local_pDescriptorCopies + i));
     }
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSets readParams");
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSets returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -6312,7 +5978,6 @@
     VkFramebuffer* pFramebuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateFramebuffer encode");
     mImpl->log("start vkCreateFramebuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6382,13 +6047,11 @@
     stream->handleMapping()->mapHandles_VkFramebuffer_u64(pFramebuffer, &cgen_var_444, 1);
     stream->write((uint64_t*)&cgen_var_444, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateFramebuffer readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_445;
     stream->read((uint64_t*)&cgen_var_445, 8);
     stream->handleMapping()->mapHandles_u64_VkFramebuffer(&cgen_var_445, (VkFramebuffer*)pFramebuffer, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateFramebuffer returnUnmarshal");
     VkResult vkCreateFramebuffer_VkResult_return = (VkResult)0;
     stream->read(&vkCreateFramebuffer_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -6404,7 +6067,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyFramebuffer encode");
     mImpl->log("start vkDestroyFramebuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6461,8 +6123,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyFramebuffer readParams");
-    AEMU_SCOPED_TRACE("vkDestroyFramebuffer returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkFramebuffer((VkFramebuffer*)&framebuffer);
     pool->freeAll();
     countingStream->clearPool();
@@ -6477,7 +6137,6 @@
     VkRenderPass* pRenderPass)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateRenderPass encode");
     mImpl->log("start vkCreateRenderPass");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6547,13 +6206,11 @@
     stream->handleMapping()->mapHandles_VkRenderPass_u64(pRenderPass, &cgen_var_457, 1);
     stream->write((uint64_t*)&cgen_var_457, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateRenderPass readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_458;
     stream->read((uint64_t*)&cgen_var_458, 8);
     stream->handleMapping()->mapHandles_u64_VkRenderPass(&cgen_var_458, (VkRenderPass*)pRenderPass, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateRenderPass returnUnmarshal");
     VkResult vkCreateRenderPass_VkResult_return = (VkResult)0;
     stream->read(&vkCreateRenderPass_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -6569,7 +6226,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyRenderPass encode");
     mImpl->log("start vkDestroyRenderPass");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6626,8 +6282,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyRenderPass readParams");
-    AEMU_SCOPED_TRACE("vkDestroyRenderPass returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkRenderPass((VkRenderPass*)&renderPass);
     pool->freeAll();
     countingStream->clearPool();
@@ -6641,7 +6295,6 @@
     VkExtent2D* pGranularity)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetRenderAreaGranularity encode");
     mImpl->log("start vkGetRenderAreaGranularity");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6674,13 +6327,11 @@
     stream->handleMapping()->mapHandles_VkRenderPass_u64(&local_renderPass, &cgen_var_468, 1);
     stream->write((uint64_t*)&cgen_var_468, 1 * 8);
     marshal_VkExtent2D(stream, (VkExtent2D*)(pGranularity));
-    AEMU_SCOPED_TRACE("vkGetRenderAreaGranularity readParams");
     unmarshal_VkExtent2D(stream, (VkExtent2D*)(pGranularity));
     if (pGranularity)
     {
         transform_fromhost_VkExtent2D(mImpl->resources(), (VkExtent2D*)(pGranularity));
     }
-    AEMU_SCOPED_TRACE("vkGetRenderAreaGranularity returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -6694,7 +6345,6 @@
     VkCommandPool* pCommandPool)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateCommandPool encode");
     mImpl->log("start vkCreateCommandPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6764,13 +6414,11 @@
     stream->handleMapping()->mapHandles_VkCommandPool_u64(pCommandPool, &cgen_var_474, 1);
     stream->write((uint64_t*)&cgen_var_474, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateCommandPool readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_475;
     stream->read((uint64_t*)&cgen_var_475, 8);
     stream->handleMapping()->mapHandles_u64_VkCommandPool(&cgen_var_475, (VkCommandPool*)pCommandPool, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateCommandPool returnUnmarshal");
     VkResult vkCreateCommandPool_VkResult_return = (VkResult)0;
     stream->read(&vkCreateCommandPool_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -6786,7 +6434,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyCommandPool encode");
     mImpl->log("start vkDestroyCommandPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6843,8 +6490,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyCommandPool readParams");
-    AEMU_SCOPED_TRACE("vkDestroyCommandPool returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkCommandPool((VkCommandPool*)&commandPool);
     pool->freeAll();
     countingStream->clearPool();
@@ -6858,7 +6503,6 @@
     VkCommandPoolResetFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkResetCommandPool encode");
     mImpl->log("start vkResetCommandPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6893,8 +6537,6 @@
     stream->handleMapping()->mapHandles_VkCommandPool_u64(&local_commandPool, &cgen_var_485, 1);
     stream->write((uint64_t*)&cgen_var_485, 1 * 8);
     stream->write((VkCommandPoolResetFlags*)&local_flags, sizeof(VkCommandPoolResetFlags));
-    AEMU_SCOPED_TRACE("vkResetCommandPool readParams");
-    AEMU_SCOPED_TRACE("vkResetCommandPool returnUnmarshal");
     VkResult vkResetCommandPool_VkResult_return = (VkResult)0;
     stream->read(&vkResetCommandPool_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -6910,7 +6552,6 @@
     VkCommandBuffer* pCommandBuffers)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkAllocateCommandBuffers encode");
     mImpl->log("start vkAllocateCommandBuffers");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -6962,7 +6603,6 @@
         stream->write((uint64_t*)cgen_var_489, pAllocateInfo->commandBufferCount * 8);
     }
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkAllocateCommandBuffers readParams");
     stream->setHandleMapping(resources->createMapping());
     if (pAllocateInfo->commandBufferCount)
     {
@@ -6972,7 +6612,6 @@
         stream->handleMapping()->mapHandles_u64_VkCommandBuffer(cgen_var_490, (VkCommandBuffer*)pCommandBuffers, pAllocateInfo->commandBufferCount);
     }
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkAllocateCommandBuffers returnUnmarshal");
     VkResult vkAllocateCommandBuffers_VkResult_return = (VkResult)0;
     stream->read(&vkAllocateCommandBuffers_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -6989,7 +6628,6 @@
     const VkCommandBuffer* pCommandBuffers)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkFreeCommandBuffers encode");
     mImpl->log("start vkFreeCommandBuffers");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7056,8 +6694,6 @@
             stream->write((uint64_t*)cgen_var_498, ((commandBufferCount)) * 8);
         }
     }
-    AEMU_SCOPED_TRACE("vkFreeCommandBuffers readParams");
-    AEMU_SCOPED_TRACE("vkFreeCommandBuffers returnUnmarshal");
     if (pCommandBuffers)
     {
         resources->destroyMapping()->mapHandles_VkCommandBuffer((VkCommandBuffer*)pCommandBuffers, ((commandBufferCount)));
@@ -7073,7 +6709,6 @@
     const VkCommandBufferBeginInfo* pBeginInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkBeginCommandBuffer encode");
     mImpl->log("start vkBeginCommandBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7109,8 +6744,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_500, 1);
     stream->write((uint64_t*)&cgen_var_500, 1 * 8);
     marshal_VkCommandBufferBeginInfo(stream, (VkCommandBufferBeginInfo*)(local_pBeginInfo));
-    AEMU_SCOPED_TRACE("vkBeginCommandBuffer readParams");
-    AEMU_SCOPED_TRACE("vkBeginCommandBuffer returnUnmarshal");
     VkResult vkBeginCommandBuffer_VkResult_return = (VkResult)0;
     stream->read(&vkBeginCommandBuffer_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -7124,7 +6757,6 @@
     VkCommandBuffer commandBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEndCommandBuffer encode");
     mImpl->log("start vkEndCommandBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7147,8 +6779,6 @@
     uint64_t cgen_var_502;
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_502, 1);
     stream->write((uint64_t*)&cgen_var_502, 1 * 8);
-    AEMU_SCOPED_TRACE("vkEndCommandBuffer readParams");
-    AEMU_SCOPED_TRACE("vkEndCommandBuffer returnUnmarshal");
     VkResult vkEndCommandBuffer_VkResult_return = (VkResult)0;
     stream->read(&vkEndCommandBuffer_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -7163,7 +6793,6 @@
     VkCommandBufferResetFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkResetCommandBuffer encode");
     mImpl->log("start vkResetCommandBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7190,8 +6819,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_504, 1);
     stream->write((uint64_t*)&cgen_var_504, 1 * 8);
     stream->write((VkCommandBufferResetFlags*)&local_flags, sizeof(VkCommandBufferResetFlags));
-    AEMU_SCOPED_TRACE("vkResetCommandBuffer readParams");
-    AEMU_SCOPED_TRACE("vkResetCommandBuffer returnUnmarshal");
     VkResult vkResetCommandBuffer_VkResult_return = (VkResult)0;
     stream->read(&vkResetCommandBuffer_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -7207,7 +6834,6 @@
     VkPipeline pipeline)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBindPipeline encode");
     mImpl->log("start vkCmdBindPipeline");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7242,8 +6868,6 @@
     uint64_t cgen_var_508;
     stream->handleMapping()->mapHandles_VkPipeline_u64(&local_pipeline, &cgen_var_508, 1);
     stream->write((uint64_t*)&cgen_var_508, 1 * 8);
-    AEMU_SCOPED_TRACE("vkCmdBindPipeline readParams");
-    AEMU_SCOPED_TRACE("vkCmdBindPipeline returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7257,7 +6881,6 @@
     const VkViewport* pViewports)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetViewport encode");
     mImpl->log("start vkCmdSetViewport");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7313,8 +6936,6 @@
     {
         marshal_VkViewport(stream, (VkViewport*)(local_pViewports + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdSetViewport readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetViewport returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7328,7 +6949,6 @@
     const VkRect2D* pScissors)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetScissor encode");
     mImpl->log("start vkCmdSetScissor");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7384,8 +7004,6 @@
     {
         marshal_VkRect2D(stream, (VkRect2D*)(local_pScissors + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdSetScissor readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetScissor returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7397,7 +7015,6 @@
     float lineWidth)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetLineWidth encode");
     mImpl->log("start vkCmdSetLineWidth");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7424,8 +7041,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_514, 1);
     stream->write((uint64_t*)&cgen_var_514, 1 * 8);
     stream->write((float*)&local_lineWidth, sizeof(float));
-    AEMU_SCOPED_TRACE("vkCmdSetLineWidth readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetLineWidth returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7439,7 +7054,6 @@
     float depthBiasSlopeFactor)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetDepthBias encode");
     mImpl->log("start vkCmdSetDepthBias");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7474,8 +7088,6 @@
     stream->write((float*)&local_depthBiasConstantFactor, sizeof(float));
     stream->write((float*)&local_depthBiasClamp, sizeof(float));
     stream->write((float*)&local_depthBiasSlopeFactor, sizeof(float));
-    AEMU_SCOPED_TRACE("vkCmdSetDepthBias readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetDepthBias returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7487,7 +7099,6 @@
     const float blendConstants[4])
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetBlendConstants encode");
     mImpl->log("start vkCmdSetBlendConstants");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7514,8 +7125,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_518, 1);
     stream->write((uint64_t*)&cgen_var_518, 1 * 8);
     stream->write((float*)local_blendConstants, 4 * sizeof(float));
-    AEMU_SCOPED_TRACE("vkCmdSetBlendConstants readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetBlendConstants returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7528,7 +7137,6 @@
     float maxDepthBounds)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetDepthBounds encode");
     mImpl->log("start vkCmdSetDepthBounds");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7559,8 +7167,6 @@
     stream->write((uint64_t*)&cgen_var_520, 1 * 8);
     stream->write((float*)&local_minDepthBounds, sizeof(float));
     stream->write((float*)&local_maxDepthBounds, sizeof(float));
-    AEMU_SCOPED_TRACE("vkCmdSetDepthBounds readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetDepthBounds returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7573,7 +7179,6 @@
     uint32_t compareMask)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetStencilCompareMask encode");
     mImpl->log("start vkCmdSetStencilCompareMask");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7604,8 +7209,6 @@
     stream->write((uint64_t*)&cgen_var_522, 1 * 8);
     stream->write((VkStencilFaceFlags*)&local_faceMask, sizeof(VkStencilFaceFlags));
     stream->write((uint32_t*)&local_compareMask, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdSetStencilCompareMask readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetStencilCompareMask returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7618,7 +7221,6 @@
     uint32_t writeMask)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetStencilWriteMask encode");
     mImpl->log("start vkCmdSetStencilWriteMask");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7649,8 +7251,6 @@
     stream->write((uint64_t*)&cgen_var_524, 1 * 8);
     stream->write((VkStencilFaceFlags*)&local_faceMask, sizeof(VkStencilFaceFlags));
     stream->write((uint32_t*)&local_writeMask, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdSetStencilWriteMask readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetStencilWriteMask returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7663,7 +7263,6 @@
     uint32_t reference)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetStencilReference encode");
     mImpl->log("start vkCmdSetStencilReference");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7694,8 +7293,6 @@
     stream->write((uint64_t*)&cgen_var_526, 1 * 8);
     stream->write((VkStencilFaceFlags*)&local_faceMask, sizeof(VkStencilFaceFlags));
     stream->write((uint32_t*)&local_reference, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdSetStencilReference readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetStencilReference returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7713,7 +7310,6 @@
     const uint32_t* pDynamicOffsets)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBindDescriptorSets encode");
     mImpl->log("start vkCmdBindDescriptorSets");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7788,8 +7384,6 @@
     }
     stream->write((uint32_t*)&local_dynamicOffsetCount, sizeof(uint32_t));
     stream->write((uint32_t*)local_pDynamicOffsets, ((dynamicOffsetCount)) * sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdBindDescriptorSets readParams");
-    AEMU_SCOPED_TRACE("vkCmdBindDescriptorSets returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7803,7 +7397,6 @@
     VkIndexType indexType)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBindIndexBuffer encode");
     mImpl->log("start vkCmdBindIndexBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7842,8 +7435,6 @@
     stream->write((uint64_t*)&cgen_var_536, 1 * 8);
     stream->write((VkDeviceSize*)&local_offset, sizeof(VkDeviceSize));
     stream->write((VkIndexType*)&local_indexType, sizeof(VkIndexType));
-    AEMU_SCOPED_TRACE("vkCmdBindIndexBuffer readParams");
-    AEMU_SCOPED_TRACE("vkCmdBindIndexBuffer returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7858,7 +7449,6 @@
     const VkDeviceSize* pOffsets)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBindVertexBuffers encode");
     mImpl->log("start vkCmdBindVertexBuffers");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7917,8 +7507,6 @@
         stream->write((uint64_t*)cgen_var_540, ((bindingCount)) * 8);
     }
     stream->write((VkDeviceSize*)local_pOffsets, ((bindingCount)) * sizeof(VkDeviceSize));
-    AEMU_SCOPED_TRACE("vkCmdBindVertexBuffers readParams");
-    AEMU_SCOPED_TRACE("vkCmdBindVertexBuffers returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7933,7 +7521,6 @@
     uint32_t firstInstance)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDraw encode");
     mImpl->log("start vkCmdDraw");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -7972,8 +7559,6 @@
     stream->write((uint32_t*)&local_instanceCount, sizeof(uint32_t));
     stream->write((uint32_t*)&local_firstVertex, sizeof(uint32_t));
     stream->write((uint32_t*)&local_firstInstance, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDraw readParams");
-    AEMU_SCOPED_TRACE("vkCmdDraw returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -7989,7 +7574,6 @@
     uint32_t firstInstance)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexed encode");
     mImpl->log("start vkCmdDrawIndexed");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8032,8 +7616,6 @@
     stream->write((uint32_t*)&local_firstIndex, sizeof(uint32_t));
     stream->write((int32_t*)&local_vertexOffset, sizeof(int32_t));
     stream->write((uint32_t*)&local_firstInstance, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexed readParams");
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexed returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8048,7 +7630,6 @@
     uint32_t stride)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirect encode");
     mImpl->log("start vkCmdDrawIndirect");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8091,8 +7672,6 @@
     stream->write((VkDeviceSize*)&local_offset, sizeof(VkDeviceSize));
     stream->write((uint32_t*)&local_drawCount, sizeof(uint32_t));
     stream->write((uint32_t*)&local_stride, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirect readParams");
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirect returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8107,7 +7686,6 @@
     uint32_t stride)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirect encode");
     mImpl->log("start vkCmdDrawIndexedIndirect");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8150,8 +7728,6 @@
     stream->write((VkDeviceSize*)&local_offset, sizeof(VkDeviceSize));
     stream->write((uint32_t*)&local_drawCount, sizeof(uint32_t));
     stream->write((uint32_t*)&local_stride, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirect readParams");
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirect returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8165,7 +7741,6 @@
     uint32_t groupCountZ)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDispatch encode");
     mImpl->log("start vkCmdDispatch");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8200,8 +7775,6 @@
     stream->write((uint32_t*)&local_groupCountX, sizeof(uint32_t));
     stream->write((uint32_t*)&local_groupCountY, sizeof(uint32_t));
     stream->write((uint32_t*)&local_groupCountZ, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDispatch readParams");
-    AEMU_SCOPED_TRACE("vkCmdDispatch returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8214,7 +7787,6 @@
     VkDeviceSize offset)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDispatchIndirect encode");
     mImpl->log("start vkCmdDispatchIndirect");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8249,8 +7821,6 @@
     stream->handleMapping()->mapHandles_VkBuffer_u64(&local_buffer, &cgen_var_558, 1);
     stream->write((uint64_t*)&cgen_var_558, 1 * 8);
     stream->write((VkDeviceSize*)&local_offset, sizeof(VkDeviceSize));
-    AEMU_SCOPED_TRACE("vkCmdDispatchIndirect readParams");
-    AEMU_SCOPED_TRACE("vkCmdDispatchIndirect returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8265,7 +7835,6 @@
     const VkBufferCopy* pRegions)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdCopyBuffer encode");
     mImpl->log("start vkCmdCopyBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8333,8 +7902,6 @@
     {
         marshal_VkBufferCopy(stream, (VkBufferCopy*)(local_pRegions + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdCopyBuffer readParams");
-    AEMU_SCOPED_TRACE("vkCmdCopyBuffer returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8351,7 +7918,6 @@
     const VkImageCopy* pRegions)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdCopyImage encode");
     mImpl->log("start vkCmdCopyImage");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8427,8 +7993,6 @@
     {
         marshal_VkImageCopy(stream, (VkImageCopy*)(local_pRegions + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdCopyImage readParams");
-    AEMU_SCOPED_TRACE("vkCmdCopyImage returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8446,7 +8010,6 @@
     VkFilter filter)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBlitImage encode");
     mImpl->log("start vkCmdBlitImage");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8526,8 +8089,6 @@
         marshal_VkImageBlit(stream, (VkImageBlit*)(local_pRegions + i));
     }
     stream->write((VkFilter*)&local_filter, sizeof(VkFilter));
-    AEMU_SCOPED_TRACE("vkCmdBlitImage readParams");
-    AEMU_SCOPED_TRACE("vkCmdBlitImage returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8543,7 +8104,6 @@
     const VkBufferImageCopy* pRegions)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdCopyBufferToImage encode");
     mImpl->log("start vkCmdCopyBufferToImage");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8615,8 +8175,6 @@
     {
         marshal_VkBufferImageCopy(stream, (VkBufferImageCopy*)(local_pRegions + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdCopyBufferToImage readParams");
-    AEMU_SCOPED_TRACE("vkCmdCopyBufferToImage returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8632,7 +8190,6 @@
     const VkBufferImageCopy* pRegions)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdCopyImageToBuffer encode");
     mImpl->log("start vkCmdCopyImageToBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8704,8 +8261,6 @@
     {
         marshal_VkBufferImageCopy(stream, (VkBufferImageCopy*)(local_pRegions + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdCopyImageToBuffer readParams");
-    AEMU_SCOPED_TRACE("vkCmdCopyImageToBuffer returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8720,7 +8275,6 @@
     const void* pData)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdUpdateBuffer encode");
     mImpl->log("start vkCmdUpdateBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8767,8 +8321,6 @@
     stream->write((VkDeviceSize*)&local_dstOffset, sizeof(VkDeviceSize));
     stream->write((VkDeviceSize*)&local_dataSize, sizeof(VkDeviceSize));
     stream->write((void*)local_pData, ((dataSize)) * sizeof(uint8_t));
-    AEMU_SCOPED_TRACE("vkCmdUpdateBuffer readParams");
-    AEMU_SCOPED_TRACE("vkCmdUpdateBuffer returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8783,7 +8335,6 @@
     uint32_t data)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdFillBuffer encode");
     mImpl->log("start vkCmdFillBuffer");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8826,8 +8377,6 @@
     stream->write((VkDeviceSize*)&local_dstOffset, sizeof(VkDeviceSize));
     stream->write((VkDeviceSize*)&local_size, sizeof(VkDeviceSize));
     stream->write((uint32_t*)&local_data, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdFillBuffer readParams");
-    AEMU_SCOPED_TRACE("vkCmdFillBuffer returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8843,7 +8392,6 @@
     const VkImageSubresourceRange* pRanges)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdClearColorImage encode");
     mImpl->log("start vkCmdClearColorImage");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -8920,8 +8468,6 @@
     {
         marshal_VkImageSubresourceRange(stream, (VkImageSubresourceRange*)(local_pRanges + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdClearColorImage readParams");
-    AEMU_SCOPED_TRACE("vkCmdClearColorImage returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -8937,7 +8483,6 @@
     const VkImageSubresourceRange* pRanges)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdClearDepthStencilImage encode");
     mImpl->log("start vkCmdClearDepthStencilImage");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9014,8 +8559,6 @@
     {
         marshal_VkImageSubresourceRange(stream, (VkImageSubresourceRange*)(local_pRanges + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdClearDepthStencilImage readParams");
-    AEMU_SCOPED_TRACE("vkCmdClearDepthStencilImage returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9030,7 +8573,6 @@
     const VkClearRect* pRects)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdClearAttachments encode");
     mImpl->log("start vkCmdClearAttachments");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9111,8 +8653,6 @@
     {
         marshal_VkClearRect(stream, (VkClearRect*)(local_pRects + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdClearAttachments readParams");
-    AEMU_SCOPED_TRACE("vkCmdClearAttachments returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9129,7 +8669,6 @@
     const VkImageResolve* pRegions)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdResolveImage encode");
     mImpl->log("start vkCmdResolveImage");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9205,8 +8744,6 @@
     {
         marshal_VkImageResolve(stream, (VkImageResolve*)(local_pRegions + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdResolveImage readParams");
-    AEMU_SCOPED_TRACE("vkCmdResolveImage returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9219,7 +8756,6 @@
     VkPipelineStageFlags stageMask)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetEvent encode");
     mImpl->log("start vkCmdSetEvent");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9254,8 +8790,6 @@
     stream->handleMapping()->mapHandles_VkEvent_u64(&local_event, &cgen_var_616, 1);
     stream->write((uint64_t*)&cgen_var_616, 1 * 8);
     stream->write((VkPipelineStageFlags*)&local_stageMask, sizeof(VkPipelineStageFlags));
-    AEMU_SCOPED_TRACE("vkCmdSetEvent readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetEvent returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9268,7 +8802,6 @@
     VkPipelineStageFlags stageMask)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdResetEvent encode");
     mImpl->log("start vkCmdResetEvent");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9303,8 +8836,6 @@
     stream->handleMapping()->mapHandles_VkEvent_u64(&local_event, &cgen_var_620, 1);
     stream->write((uint64_t*)&cgen_var_620, 1 * 8);
     stream->write((VkPipelineStageFlags*)&local_stageMask, sizeof(VkPipelineStageFlags));
-    AEMU_SCOPED_TRACE("vkCmdResetEvent readParams");
-    AEMU_SCOPED_TRACE("vkCmdResetEvent returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9325,7 +8856,6 @@
     const VkImageMemoryBarrier* pImageMemoryBarriers)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdWaitEvents encode");
     mImpl->log("start vkCmdWaitEvents");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9467,8 +8997,6 @@
     {
         marshal_VkImageMemoryBarrier(stream, (VkImageMemoryBarrier*)(local_pImageMemoryBarriers + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdWaitEvents readParams");
-    AEMU_SCOPED_TRACE("vkCmdWaitEvents returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9488,7 +9016,6 @@
     const VkImageMemoryBarrier* pImageMemoryBarriers)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdPipelineBarrier encode");
     mImpl->log("start vkCmdPipelineBarrier");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9610,8 +9137,6 @@
     {
         marshal_VkImageMemoryBarrier(stream, (VkImageMemoryBarrier*)(local_pImageMemoryBarriers + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdPipelineBarrier readParams");
-    AEMU_SCOPED_TRACE("vkCmdPipelineBarrier returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9625,7 +9150,6 @@
     VkQueryControlFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBeginQuery encode");
     mImpl->log("start vkCmdBeginQuery");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9664,8 +9188,6 @@
     stream->write((uint64_t*)&cgen_var_630, 1 * 8);
     stream->write((uint32_t*)&local_query, sizeof(uint32_t));
     stream->write((VkQueryControlFlags*)&local_flags, sizeof(VkQueryControlFlags));
-    AEMU_SCOPED_TRACE("vkCmdBeginQuery readParams");
-    AEMU_SCOPED_TRACE("vkCmdBeginQuery returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9678,7 +9200,6 @@
     uint32_t query)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdEndQuery encode");
     mImpl->log("start vkCmdEndQuery");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9713,8 +9234,6 @@
     stream->handleMapping()->mapHandles_VkQueryPool_u64(&local_queryPool, &cgen_var_634, 1);
     stream->write((uint64_t*)&cgen_var_634, 1 * 8);
     stream->write((uint32_t*)&local_query, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdEndQuery readParams");
-    AEMU_SCOPED_TRACE("vkCmdEndQuery returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9728,7 +9247,6 @@
     uint32_t queryCount)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdResetQueryPool encode");
     mImpl->log("start vkCmdResetQueryPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9767,8 +9285,6 @@
     stream->write((uint64_t*)&cgen_var_638, 1 * 8);
     stream->write((uint32_t*)&local_firstQuery, sizeof(uint32_t));
     stream->write((uint32_t*)&local_queryCount, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdResetQueryPool readParams");
-    AEMU_SCOPED_TRACE("vkCmdResetQueryPool returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9782,7 +9298,6 @@
     uint32_t query)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdWriteTimestamp encode");
     mImpl->log("start vkCmdWriteTimestamp");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9821,8 +9336,6 @@
     stream->handleMapping()->mapHandles_VkQueryPool_u64(&local_queryPool, &cgen_var_642, 1);
     stream->write((uint64_t*)&cgen_var_642, 1 * 8);
     stream->write((uint32_t*)&local_query, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdWriteTimestamp readParams");
-    AEMU_SCOPED_TRACE("vkCmdWriteTimestamp returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9840,7 +9353,6 @@
     VkQueryResultFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdCopyQueryPoolResults encode");
     mImpl->log("start vkCmdCopyQueryPoolResults");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9899,8 +9411,6 @@
     stream->write((VkDeviceSize*)&local_dstOffset, sizeof(VkDeviceSize));
     stream->write((VkDeviceSize*)&local_stride, sizeof(VkDeviceSize));
     stream->write((VkQueryResultFlags*)&local_flags, sizeof(VkQueryResultFlags));
-    AEMU_SCOPED_TRACE("vkCmdCopyQueryPoolResults readParams");
-    AEMU_SCOPED_TRACE("vkCmdCopyQueryPoolResults returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9916,7 +9426,6 @@
     const void* pValues)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdPushConstants encode");
     mImpl->log("start vkCmdPushConstants");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -9967,8 +9476,6 @@
     stream->write((uint32_t*)&local_offset, sizeof(uint32_t));
     stream->write((uint32_t*)&local_size, sizeof(uint32_t));
     stream->write((void*)local_pValues, ((size)) * sizeof(uint8_t));
-    AEMU_SCOPED_TRACE("vkCmdPushConstants readParams");
-    AEMU_SCOPED_TRACE("vkCmdPushConstants returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -9981,7 +9488,6 @@
     VkSubpassContents contents)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBeginRenderPass encode");
     mImpl->log("start vkCmdBeginRenderPass");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10021,8 +9527,6 @@
     stream->write((uint64_t*)&cgen_var_654, 1 * 8);
     marshal_VkRenderPassBeginInfo(stream, (VkRenderPassBeginInfo*)(local_pRenderPassBegin));
     stream->write((VkSubpassContents*)&local_contents, sizeof(VkSubpassContents));
-    AEMU_SCOPED_TRACE("vkCmdBeginRenderPass readParams");
-    AEMU_SCOPED_TRACE("vkCmdBeginRenderPass returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10034,7 +9538,6 @@
     VkSubpassContents contents)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdNextSubpass encode");
     mImpl->log("start vkCmdNextSubpass");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10061,8 +9564,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_656, 1);
     stream->write((uint64_t*)&cgen_var_656, 1 * 8);
     stream->write((VkSubpassContents*)&local_contents, sizeof(VkSubpassContents));
-    AEMU_SCOPED_TRACE("vkCmdNextSubpass readParams");
-    AEMU_SCOPED_TRACE("vkCmdNextSubpass returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10073,7 +9574,6 @@
     VkCommandBuffer commandBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdEndRenderPass encode");
     mImpl->log("start vkCmdEndRenderPass");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10096,8 +9596,6 @@
     uint64_t cgen_var_658;
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_658, 1);
     stream->write((uint64_t*)&cgen_var_658, 1 * 8);
-    AEMU_SCOPED_TRACE("vkCmdEndRenderPass readParams");
-    AEMU_SCOPED_TRACE("vkCmdEndRenderPass returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10110,7 +9608,6 @@
     const VkCommandBuffer* pCommandBuffers)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdExecuteCommands encode");
     mImpl->log("start vkCmdExecuteCommands");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10157,8 +9654,6 @@
         stream->handleMapping()->mapHandles_VkCommandBuffer_u64(local_pCommandBuffers, cgen_var_662, ((commandBufferCount)));
         stream->write((uint64_t*)cgen_var_662, ((commandBufferCount)) * 8);
     }
-    AEMU_SCOPED_TRACE("vkCmdExecuteCommands readParams");
-    AEMU_SCOPED_TRACE("vkCmdExecuteCommands returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10171,7 +9666,6 @@
     uint32_t* pApiVersion)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceVersion encode");
     mImpl->log("start vkEnumerateInstanceVersion");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10188,9 +9682,7 @@
     stream->write(&opcode_vkEnumerateInstanceVersion, sizeof(uint32_t));
     stream->write(&packetSize_vkEnumerateInstanceVersion, sizeof(uint32_t));
     stream->write((uint32_t*)pApiVersion, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceVersion readParams");
     stream->read((uint32_t*)pApiVersion, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkEnumerateInstanceVersion returnUnmarshal");
     VkResult vkEnumerateInstanceVersion_VkResult_return = (VkResult)0;
     stream->read(&vkEnumerateInstanceVersion_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -10206,7 +9698,6 @@
     const VkBindBufferMemoryInfo* pBindInfos)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkBindBufferMemory2 encode");
     mImpl->log("start vkBindBufferMemory2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10258,8 +9749,6 @@
     {
         marshal_VkBindBufferMemoryInfo(stream, (VkBindBufferMemoryInfo*)(local_pBindInfos + i));
     }
-    AEMU_SCOPED_TRACE("vkBindBufferMemory2 readParams");
-    AEMU_SCOPED_TRACE("vkBindBufferMemory2 returnUnmarshal");
     VkResult vkBindBufferMemory2_VkResult_return = (VkResult)0;
     stream->read(&vkBindBufferMemory2_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -10275,7 +9764,6 @@
     const VkBindImageMemoryInfo* pBindInfos)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkBindImageMemory2 encode");
     mImpl->log("start vkBindImageMemory2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10327,8 +9815,6 @@
     {
         marshal_VkBindImageMemoryInfo(stream, (VkBindImageMemoryInfo*)(local_pBindInfos + i));
     }
-    AEMU_SCOPED_TRACE("vkBindImageMemory2 readParams");
-    AEMU_SCOPED_TRACE("vkBindImageMemory2 returnUnmarshal");
     VkResult vkBindImageMemory2_VkResult_return = (VkResult)0;
     stream->read(&vkBindImageMemory2_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -10346,7 +9832,6 @@
     VkPeerMemoryFeatureFlags* pPeerMemoryFeatures)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPeerMemoryFeatures encode");
     mImpl->log("start vkGetDeviceGroupPeerMemoryFeatures");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10383,9 +9868,7 @@
     stream->write((uint32_t*)&local_localDeviceIndex, sizeof(uint32_t));
     stream->write((uint32_t*)&local_remoteDeviceIndex, sizeof(uint32_t));
     stream->write((VkPeerMemoryFeatureFlags*)pPeerMemoryFeatures, sizeof(VkPeerMemoryFeatureFlags));
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPeerMemoryFeatures readParams");
     stream->read((VkPeerMemoryFeatureFlags*)pPeerMemoryFeatures, sizeof(VkPeerMemoryFeatureFlags));
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPeerMemoryFeatures returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10397,7 +9880,6 @@
     uint32_t deviceMask)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetDeviceMask encode");
     mImpl->log("start vkCmdSetDeviceMask");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10424,8 +9906,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_670, 1);
     stream->write((uint64_t*)&cgen_var_670, 1 * 8);
     stream->write((uint32_t*)&local_deviceMask, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdSetDeviceMask readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetDeviceMask returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10442,7 +9922,6 @@
     uint32_t groupCountZ)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDispatchBase encode");
     mImpl->log("start vkCmdDispatchBase");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10489,8 +9968,6 @@
     stream->write((uint32_t*)&local_groupCountX, sizeof(uint32_t));
     stream->write((uint32_t*)&local_groupCountY, sizeof(uint32_t));
     stream->write((uint32_t*)&local_groupCountZ, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDispatchBase readParams");
-    AEMU_SCOPED_TRACE("vkCmdDispatchBase returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10503,7 +9980,6 @@
     VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDeviceGroups encode");
     mImpl->log("start vkEnumeratePhysicalDeviceGroups");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10560,7 +10036,6 @@
             marshal_VkPhysicalDeviceGroupProperties(stream, (VkPhysicalDeviceGroupProperties*)(pPhysicalDeviceGroupProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDeviceGroups readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPhysicalDeviceGroupCount;
     check_pPhysicalDeviceGroupCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -10593,7 +10068,6 @@
             transform_fromhost_VkPhysicalDeviceGroupProperties(mImpl->resources(), (VkPhysicalDeviceGroupProperties*)(pPhysicalDeviceGroupProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDeviceGroups returnUnmarshal");
     VkResult vkEnumeratePhysicalDeviceGroups_VkResult_return = (VkResult)0;
     stream->read(&vkEnumeratePhysicalDeviceGroups_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -10609,7 +10083,6 @@
     VkMemoryRequirements2* pMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements2 encode");
     mImpl->log("start vkGetImageMemoryRequirements2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10647,13 +10120,11 @@
     stream->write((uint64_t*)&cgen_var_682, 1 * 8);
     marshal_VkImageMemoryRequirementsInfo2(stream, (VkImageMemoryRequirementsInfo2*)(local_pInfo));
     marshal_VkMemoryRequirements2(stream, (VkMemoryRequirements2*)(pMemoryRequirements));
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements2 readParams");
     unmarshal_VkMemoryRequirements2(stream, (VkMemoryRequirements2*)(pMemoryRequirements));
     if (pMemoryRequirements)
     {
         transform_fromhost_VkMemoryRequirements2(mImpl->resources(), (VkMemoryRequirements2*)(pMemoryRequirements));
     }
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements2 returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10666,7 +10137,6 @@
     VkMemoryRequirements2* pMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements2 encode");
     mImpl->log("start vkGetBufferMemoryRequirements2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10704,13 +10174,11 @@
     stream->write((uint64_t*)&cgen_var_684, 1 * 8);
     marshal_VkBufferMemoryRequirementsInfo2(stream, (VkBufferMemoryRequirementsInfo2*)(local_pInfo));
     marshal_VkMemoryRequirements2(stream, (VkMemoryRequirements2*)(pMemoryRequirements));
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements2 readParams");
     unmarshal_VkMemoryRequirements2(stream, (VkMemoryRequirements2*)(pMemoryRequirements));
     if (pMemoryRequirements)
     {
         transform_fromhost_VkMemoryRequirements2(mImpl->resources(), (VkMemoryRequirements2*)(pMemoryRequirements));
     }
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements2 returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10724,7 +10192,6 @@
     VkSparseImageMemoryRequirements2* pSparseMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements2 encode");
     mImpl->log("start vkGetImageSparseMemoryRequirements2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10794,7 +10261,6 @@
             marshal_VkSparseImageMemoryRequirements2(stream, (VkSparseImageMemoryRequirements2*)(pSparseMemoryRequirements + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements2 readParams");
     // WARNING PTR CHECK
     uint32_t* check_pSparseMemoryRequirementCount;
     check_pSparseMemoryRequirementCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -10827,7 +10293,6 @@
             transform_fromhost_VkSparseImageMemoryRequirements2(mImpl->resources(), (VkSparseImageMemoryRequirements2*)(pSparseMemoryRequirements + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements2 returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10839,7 +10304,6 @@
     VkPhysicalDeviceFeatures2* pFeatures)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures2 encode");
     mImpl->log("start vkGetPhysicalDeviceFeatures2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10864,13 +10328,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_694, 1);
     stream->write((uint64_t*)&cgen_var_694, 1 * 8);
     marshal_VkPhysicalDeviceFeatures2(stream, (VkPhysicalDeviceFeatures2*)(pFeatures));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures2 readParams");
     unmarshal_VkPhysicalDeviceFeatures2(stream, (VkPhysicalDeviceFeatures2*)(pFeatures));
     if (pFeatures)
     {
         transform_fromhost_VkPhysicalDeviceFeatures2(mImpl->resources(), (VkPhysicalDeviceFeatures2*)(pFeatures));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures2 returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10882,7 +10344,6 @@
     VkPhysicalDeviceProperties2* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties2 encode");
     mImpl->log("start vkGetPhysicalDeviceProperties2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10907,13 +10368,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_696, 1);
     stream->write((uint64_t*)&cgen_var_696, 1 * 8);
     marshal_VkPhysicalDeviceProperties2(stream, (VkPhysicalDeviceProperties2*)(pProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties2 readParams");
     unmarshal_VkPhysicalDeviceProperties2(stream, (VkPhysicalDeviceProperties2*)(pProperties));
     if (pProperties)
     {
         transform_fromhost_VkPhysicalDeviceProperties2(mImpl->resources(), (VkPhysicalDeviceProperties2*)(pProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties2 returnUnmarshal");
     mImpl->resources()->on_vkGetPhysicalDeviceProperties2(this, physicalDevice, pProperties);
     pool->freeAll();
     countingStream->clearPool();
@@ -10927,7 +10386,6 @@
     VkFormatProperties2* pFormatProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties2 encode");
     mImpl->log("start vkGetPhysicalDeviceFormatProperties2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -10956,13 +10414,11 @@
     stream->write((uint64_t*)&cgen_var_698, 1 * 8);
     stream->write((VkFormat*)&local_format, sizeof(VkFormat));
     marshal_VkFormatProperties2(stream, (VkFormatProperties2*)(pFormatProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties2 readParams");
     unmarshal_VkFormatProperties2(stream, (VkFormatProperties2*)(pFormatProperties));
     if (pFormatProperties)
     {
         transform_fromhost_VkFormatProperties2(mImpl->resources(), (VkFormatProperties2*)(pFormatProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties2 returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -10975,7 +10431,6 @@
     VkImageFormatProperties2* pImageFormatProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties2 encode");
     mImpl->log("start vkGetPhysicalDeviceImageFormatProperties2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11013,13 +10468,11 @@
     stream->write((uint64_t*)&cgen_var_700, 1 * 8);
     marshal_VkPhysicalDeviceImageFormatInfo2(stream, (VkPhysicalDeviceImageFormatInfo2*)(local_pImageFormatInfo));
     marshal_VkImageFormatProperties2(stream, (VkImageFormatProperties2*)(pImageFormatProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties2 readParams");
     unmarshal_VkImageFormatProperties2(stream, (VkImageFormatProperties2*)(pImageFormatProperties));
     if (pImageFormatProperties)
     {
         transform_fromhost_VkImageFormatProperties2(mImpl->resources(), (VkImageFormatProperties2*)(pImageFormatProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties2 returnUnmarshal");
     VkResult vkGetPhysicalDeviceImageFormatProperties2_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceImageFormatProperties2_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -11035,7 +10488,6 @@
     VkQueueFamilyProperties2* pQueueFamilyProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties2 encode");
     mImpl->log("start vkGetPhysicalDeviceQueueFamilyProperties2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11092,7 +10544,6 @@
             marshal_VkQueueFamilyProperties2(stream, (VkQueueFamilyProperties2*)(pQueueFamilyProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties2 readParams");
     // WARNING PTR CHECK
     uint32_t* check_pQueueFamilyPropertyCount;
     check_pQueueFamilyPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -11125,7 +10576,6 @@
             transform_fromhost_VkQueueFamilyProperties2(mImpl->resources(), (VkQueueFamilyProperties2*)(pQueueFamilyProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties2 returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -11137,7 +10587,6 @@
     VkPhysicalDeviceMemoryProperties2* pMemoryProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties2 encode");
     mImpl->log("start vkGetPhysicalDeviceMemoryProperties2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11162,13 +10611,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_710, 1);
     stream->write((uint64_t*)&cgen_var_710, 1 * 8);
     marshal_VkPhysicalDeviceMemoryProperties2(stream, (VkPhysicalDeviceMemoryProperties2*)(pMemoryProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties2 readParams");
     unmarshal_VkPhysicalDeviceMemoryProperties2(stream, (VkPhysicalDeviceMemoryProperties2*)(pMemoryProperties));
     if (pMemoryProperties)
     {
         transform_fromhost_VkPhysicalDeviceMemoryProperties2(mImpl->resources(), (VkPhysicalDeviceMemoryProperties2*)(pMemoryProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties2 returnUnmarshal");
     mImpl->resources()->on_vkGetPhysicalDeviceMemoryProperties2(this, physicalDevice, pMemoryProperties);
     pool->freeAll();
     countingStream->clearPool();
@@ -11183,7 +10630,6 @@
     VkSparseImageFormatProperties2* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties2 encode");
     mImpl->log("start vkGetPhysicalDeviceSparseImageFormatProperties2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11253,7 +10699,6 @@
             marshal_VkSparseImageFormatProperties2(stream, (VkSparseImageFormatProperties2*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties2 readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -11286,7 +10731,6 @@
             transform_fromhost_VkSparseImageFormatProperties2(mImpl->resources(), (VkSparseImageFormatProperties2*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties2 returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -11299,7 +10743,6 @@
     VkCommandPoolTrimFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkTrimCommandPool encode");
     mImpl->log("start vkTrimCommandPool");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11334,8 +10777,6 @@
     stream->handleMapping()->mapHandles_VkCommandPool_u64(&local_commandPool, &cgen_var_722, 1);
     stream->write((uint64_t*)&cgen_var_722, 1 * 8);
     stream->write((VkCommandPoolTrimFlags*)&local_flags, sizeof(VkCommandPoolTrimFlags));
-    AEMU_SCOPED_TRACE("vkTrimCommandPool readParams");
-    AEMU_SCOPED_TRACE("vkTrimCommandPool returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -11348,7 +10789,6 @@
     VkQueue* pQueue)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDeviceQueue2 encode");
     mImpl->log("start vkGetDeviceQueue2");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11392,11 +10832,9 @@
     stream->handleMapping()->mapHandles_VkQueue_u64(pQueue, &cgen_var_726, 1);
     stream->write((uint64_t*)&cgen_var_726, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkGetDeviceQueue2 readParams");
     uint64_t cgen_var_727;
     stream->read((uint64_t*)&cgen_var_727, 8);
     stream->handleMapping()->mapHandles_u64_VkQueue(&cgen_var_727, (VkQueue*)pQueue, 1);
-    AEMU_SCOPED_TRACE("vkGetDeviceQueue2 returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -11410,7 +10848,6 @@
     VkSamplerYcbcrConversion* pYcbcrConversion)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateSamplerYcbcrConversion encode");
     mImpl->log("start vkCreateSamplerYcbcrConversion");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11480,13 +10917,11 @@
     stream->handleMapping()->mapHandles_VkSamplerYcbcrConversion_u64(pYcbcrConversion, &cgen_var_733, 1);
     stream->write((uint64_t*)&cgen_var_733, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateSamplerYcbcrConversion readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_734;
     stream->read((uint64_t*)&cgen_var_734, 8);
     stream->handleMapping()->mapHandles_u64_VkSamplerYcbcrConversion(&cgen_var_734, (VkSamplerYcbcrConversion*)pYcbcrConversion, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateSamplerYcbcrConversion returnUnmarshal");
     VkResult vkCreateSamplerYcbcrConversion_VkResult_return = (VkResult)0;
     stream->read(&vkCreateSamplerYcbcrConversion_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -11502,7 +10937,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroySamplerYcbcrConversion encode");
     mImpl->log("start vkDestroySamplerYcbcrConversion");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11559,8 +10993,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroySamplerYcbcrConversion readParams");
-    AEMU_SCOPED_TRACE("vkDestroySamplerYcbcrConversion returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkSamplerYcbcrConversion((VkSamplerYcbcrConversion*)&ycbcrConversion);
     pool->freeAll();
     countingStream->clearPool();
@@ -11575,7 +11007,6 @@
     VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDescriptorUpdateTemplate encode");
     mImpl->log("start vkCreateDescriptorUpdateTemplate");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11645,13 +11076,11 @@
     stream->handleMapping()->mapHandles_VkDescriptorUpdateTemplate_u64(pDescriptorUpdateTemplate, &cgen_var_746, 1);
     stream->write((uint64_t*)&cgen_var_746, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDescriptorUpdateTemplate readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_747;
     stream->read((uint64_t*)&cgen_var_747, 8);
     stream->handleMapping()->mapHandles_u64_VkDescriptorUpdateTemplate(&cgen_var_747, (VkDescriptorUpdateTemplate*)pDescriptorUpdateTemplate, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateDescriptorUpdateTemplate returnUnmarshal");
     VkResult vkCreateDescriptorUpdateTemplate_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDescriptorUpdateTemplate_VkResult_return, sizeof(VkResult));
     mImpl->resources()->on_vkCreateDescriptorUpdateTemplate(this, vkCreateDescriptorUpdateTemplate_VkResult_return, device, pCreateInfo, pAllocator, pDescriptorUpdateTemplate);
@@ -11668,7 +11097,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorUpdateTemplate encode");
     mImpl->log("start vkDestroyDescriptorUpdateTemplate");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11725,8 +11153,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorUpdateTemplate readParams");
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorUpdateTemplate returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkDescriptorUpdateTemplate((VkDescriptorUpdateTemplate*)&descriptorUpdateTemplate);
     pool->freeAll();
     countingStream->clearPool();
@@ -11741,7 +11167,6 @@
     const void* pData)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplate encode");
     mImpl->log("start vkUpdateDescriptorSetWithTemplate");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11800,8 +11225,6 @@
     {
         stream->write((void*)local_pData, sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplate readParams");
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplate returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -11814,7 +11237,6 @@
     VkExternalBufferProperties* pExternalBufferProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalBufferProperties encode");
     mImpl->log("start vkGetPhysicalDeviceExternalBufferProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11853,14 +11275,12 @@
     stream->write((uint64_t*)&cgen_var_763, 1 * 8);
     marshal_VkPhysicalDeviceExternalBufferInfo(stream, (VkPhysicalDeviceExternalBufferInfo*)(local_pExternalBufferInfo));
     marshal_VkExternalBufferProperties(stream, (VkExternalBufferProperties*)(pExternalBufferProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalBufferProperties readParams");
     unmarshal_VkExternalBufferProperties(stream, (VkExternalBufferProperties*)(pExternalBufferProperties));
     if (pExternalBufferProperties)
     {
         mImpl->resources()->transformImpl_VkExternalBufferProperties_fromhost(pExternalBufferProperties, 1);
         transform_fromhost_VkExternalBufferProperties(mImpl->resources(), (VkExternalBufferProperties*)(pExternalBufferProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalBufferProperties returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -11873,7 +11293,6 @@
     VkExternalFenceProperties* pExternalFenceProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalFenceProperties encode");
     mImpl->log("start vkGetPhysicalDeviceExternalFenceProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11911,13 +11330,11 @@
     stream->write((uint64_t*)&cgen_var_765, 1 * 8);
     marshal_VkPhysicalDeviceExternalFenceInfo(stream, (VkPhysicalDeviceExternalFenceInfo*)(local_pExternalFenceInfo));
     marshal_VkExternalFenceProperties(stream, (VkExternalFenceProperties*)(pExternalFenceProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalFenceProperties readParams");
     unmarshal_VkExternalFenceProperties(stream, (VkExternalFenceProperties*)(pExternalFenceProperties));
     if (pExternalFenceProperties)
     {
         transform_fromhost_VkExternalFenceProperties(mImpl->resources(), (VkExternalFenceProperties*)(pExternalFenceProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalFenceProperties returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -11930,7 +11347,6 @@
     VkExternalSemaphoreProperties* pExternalSemaphoreProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalSemaphoreProperties encode");
     mImpl->log("start vkGetPhysicalDeviceExternalSemaphoreProperties");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -11968,13 +11384,11 @@
     stream->write((uint64_t*)&cgen_var_767, 1 * 8);
     marshal_VkPhysicalDeviceExternalSemaphoreInfo(stream, (VkPhysicalDeviceExternalSemaphoreInfo*)(local_pExternalSemaphoreInfo));
     marshal_VkExternalSemaphoreProperties(stream, (VkExternalSemaphoreProperties*)(pExternalSemaphoreProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalSemaphoreProperties readParams");
     unmarshal_VkExternalSemaphoreProperties(stream, (VkExternalSemaphoreProperties*)(pExternalSemaphoreProperties));
     if (pExternalSemaphoreProperties)
     {
         transform_fromhost_VkExternalSemaphoreProperties(mImpl->resources(), (VkExternalSemaphoreProperties*)(pExternalSemaphoreProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalSemaphoreProperties returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -11987,7 +11401,6 @@
     VkDescriptorSetLayoutSupport* pSupport)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDescriptorSetLayoutSupport encode");
     mImpl->log("start vkGetDescriptorSetLayoutSupport");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12025,13 +11438,11 @@
     stream->write((uint64_t*)&cgen_var_769, 1 * 8);
     marshal_VkDescriptorSetLayoutCreateInfo(stream, (VkDescriptorSetLayoutCreateInfo*)(local_pCreateInfo));
     marshal_VkDescriptorSetLayoutSupport(stream, (VkDescriptorSetLayoutSupport*)(pSupport));
-    AEMU_SCOPED_TRACE("vkGetDescriptorSetLayoutSupport readParams");
     unmarshal_VkDescriptorSetLayoutSupport(stream, (VkDescriptorSetLayoutSupport*)(pSupport));
     if (pSupport)
     {
         transform_fromhost_VkDescriptorSetLayoutSupport(mImpl->resources(), (VkDescriptorSetLayoutSupport*)(pSupport));
     }
-    AEMU_SCOPED_TRACE("vkGetDescriptorSetLayoutSupport returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -12046,7 +11457,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroySurfaceKHR encode");
     mImpl->log("start vkDestroySurfaceKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12103,8 +11513,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroySurfaceKHR readParams");
-    AEMU_SCOPED_TRACE("vkDestroySurfaceKHR returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkSurfaceKHR((VkSurfaceKHR*)&surface);
     pool->freeAll();
     countingStream->clearPool();
@@ -12119,7 +11527,6 @@
     VkBool32* pSupported)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceSupportKHR encode");
     mImpl->log("start vkGetPhysicalDeviceSurfaceSupportKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12156,9 +11563,7 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(&local_surface, &cgen_var_779, 1);
     stream->write((uint64_t*)&cgen_var_779, 1 * 8);
     stream->write((VkBool32*)pSupported, sizeof(VkBool32));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceSupportKHR readParams");
     stream->read((VkBool32*)pSupported, sizeof(VkBool32));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceSupportKHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceSurfaceSupportKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceSurfaceSupportKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12174,7 +11579,6 @@
     VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilitiesKHR encode");
     mImpl->log("start vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12207,13 +11611,11 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(&local_surface, &cgen_var_783, 1);
     stream->write((uint64_t*)&cgen_var_783, 1 * 8);
     marshal_VkSurfaceCapabilitiesKHR(stream, (VkSurfaceCapabilitiesKHR*)(pSurfaceCapabilities));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilitiesKHR readParams");
     unmarshal_VkSurfaceCapabilitiesKHR(stream, (VkSurfaceCapabilitiesKHR*)(pSurfaceCapabilities));
     if (pSurfaceCapabilities)
     {
         transform_fromhost_VkSurfaceCapabilitiesKHR(mImpl->resources(), (VkSurfaceCapabilitiesKHR*)(pSurfaceCapabilities));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilitiesKHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceSurfaceCapabilitiesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceSurfaceCapabilitiesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12230,7 +11632,6 @@
     VkSurfaceFormatKHR* pSurfaceFormats)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceFormatsKHR encode");
     mImpl->log("start vkGetPhysicalDeviceSurfaceFormatsKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12295,7 +11696,6 @@
             marshal_VkSurfaceFormatKHR(stream, (VkSurfaceFormatKHR*)(pSurfaceFormats + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceFormatsKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pSurfaceFormatCount;
     check_pSurfaceFormatCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -12328,7 +11728,6 @@
             transform_fromhost_VkSurfaceFormatKHR(mImpl->resources(), (VkSurfaceFormatKHR*)(pSurfaceFormats + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceFormatsKHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceSurfaceFormatsKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceSurfaceFormatsKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12345,7 +11744,6 @@
     VkPresentModeKHR* pPresentModes)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfacePresentModesKHR encode");
     mImpl->log("start vkGetPhysicalDeviceSurfacePresentModesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12404,7 +11802,6 @@
     {
         stream->write((VkPresentModeKHR*)pPresentModes, (*(pPresentModeCount)) * sizeof(VkPresentModeKHR));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfacePresentModesKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPresentModeCount;
     check_pPresentModeCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -12427,7 +11824,6 @@
         }
         stream->read((VkPresentModeKHR*)pPresentModes, (*(pPresentModeCount)) * sizeof(VkPresentModeKHR));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfacePresentModesKHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceSurfacePresentModesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceSurfacePresentModesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12446,7 +11842,6 @@
     VkSwapchainKHR* pSwapchain)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateSwapchainKHR encode");
     mImpl->log("start vkCreateSwapchainKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12516,13 +11911,11 @@
     stream->handleMapping()->mapHandles_VkSwapchainKHR_u64(pSwapchain, &cgen_var_809, 1);
     stream->write((uint64_t*)&cgen_var_809, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateSwapchainKHR readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_810;
     stream->read((uint64_t*)&cgen_var_810, 8);
     stream->handleMapping()->mapHandles_u64_VkSwapchainKHR(&cgen_var_810, (VkSwapchainKHR*)pSwapchain, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateSwapchainKHR returnUnmarshal");
     VkResult vkCreateSwapchainKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateSwapchainKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12538,7 +11931,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroySwapchainKHR encode");
     mImpl->log("start vkDestroySwapchainKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12595,8 +11987,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroySwapchainKHR readParams");
-    AEMU_SCOPED_TRACE("vkDestroySwapchainKHR returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkSwapchainKHR((VkSwapchainKHR*)&swapchain);
     pool->freeAll();
     countingStream->clearPool();
@@ -12611,7 +12001,6 @@
     VkImage* pSwapchainImages)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetSwapchainImagesKHR encode");
     mImpl->log("start vkGetSwapchainImagesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12684,7 +12073,6 @@
         }
     }
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkGetSwapchainImagesKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pSwapchainImageCount;
     check_pSwapchainImageCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -12713,7 +12101,6 @@
             stream->handleMapping()->mapHandles_u64_VkImage(cgen_var_829, (VkImage*)pSwapchainImages, (*(pSwapchainImageCount)));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetSwapchainImagesKHR returnUnmarshal");
     VkResult vkGetSwapchainImagesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetSwapchainImagesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12732,7 +12119,6 @@
     uint32_t* pImageIndex)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkAcquireNextImageKHR encode");
     mImpl->log("start vkAcquireNextImageKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12785,9 +12171,7 @@
     stream->handleMapping()->mapHandles_VkFence_u64(&local_fence, &cgen_var_837, 1);
     stream->write((uint64_t*)&cgen_var_837, 1 * 8);
     stream->write((uint32_t*)pImageIndex, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkAcquireNextImageKHR readParams");
     stream->read((uint32_t*)pImageIndex, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkAcquireNextImageKHR returnUnmarshal");
     VkResult vkAcquireNextImageKHR_VkResult_return = (VkResult)0;
     stream->read(&vkAcquireNextImageKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12802,7 +12186,6 @@
     const VkPresentInfoKHR* pPresentInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueuePresentKHR encode");
     mImpl->log("start vkQueuePresentKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12838,8 +12221,6 @@
     stream->handleMapping()->mapHandles_VkQueue_u64(&local_queue, &cgen_var_839, 1);
     stream->write((uint64_t*)&cgen_var_839, 1 * 8);
     marshal_VkPresentInfoKHR(stream, (VkPresentInfoKHR*)(local_pPresentInfo));
-    AEMU_SCOPED_TRACE("vkQueuePresentKHR readParams");
-    AEMU_SCOPED_TRACE("vkQueuePresentKHR returnUnmarshal");
     VkResult vkQueuePresentKHR_VkResult_return = (VkResult)0;
     stream->read(&vkQueuePresentKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12854,7 +12235,6 @@
     VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPresentCapabilitiesKHR encode");
     mImpl->log("start vkGetDeviceGroupPresentCapabilitiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12879,13 +12259,11 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_841, 1);
     stream->write((uint64_t*)&cgen_var_841, 1 * 8);
     marshal_VkDeviceGroupPresentCapabilitiesKHR(stream, (VkDeviceGroupPresentCapabilitiesKHR*)(pDeviceGroupPresentCapabilities));
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPresentCapabilitiesKHR readParams");
     unmarshal_VkDeviceGroupPresentCapabilitiesKHR(stream, (VkDeviceGroupPresentCapabilitiesKHR*)(pDeviceGroupPresentCapabilities));
     if (pDeviceGroupPresentCapabilities)
     {
         transform_fromhost_VkDeviceGroupPresentCapabilitiesKHR(mImpl->resources(), (VkDeviceGroupPresentCapabilitiesKHR*)(pDeviceGroupPresentCapabilities));
     }
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPresentCapabilitiesKHR returnUnmarshal");
     VkResult vkGetDeviceGroupPresentCapabilitiesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetDeviceGroupPresentCapabilitiesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12901,7 +12279,6 @@
     VkDeviceGroupPresentModeFlagsKHR* pModes)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupSurfacePresentModesKHR encode");
     mImpl->log("start vkGetDeviceGroupSurfacePresentModesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -12946,7 +12323,6 @@
     {
         stream->write((VkDeviceGroupPresentModeFlagsKHR*)pModes, sizeof(VkDeviceGroupPresentModeFlagsKHR));
     }
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupSurfacePresentModesKHR readParams");
     // WARNING PTR CHECK
     VkDeviceGroupPresentModeFlagsKHR* check_pModes;
     check_pModes = (VkDeviceGroupPresentModeFlagsKHR*)(uintptr_t)stream->getBe64();
@@ -12958,7 +12334,6 @@
         }
         stream->read((VkDeviceGroupPresentModeFlagsKHR*)pModes, sizeof(VkDeviceGroupPresentModeFlagsKHR));
     }
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupSurfacePresentModesKHR returnUnmarshal");
     VkResult vkGetDeviceGroupSurfacePresentModesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetDeviceGroupSurfacePresentModesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -12975,7 +12350,6 @@
     VkRect2D* pRects)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDevicePresentRectanglesKHR encode");
     mImpl->log("start vkGetPhysicalDevicePresentRectanglesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13040,7 +12414,6 @@
             marshal_VkRect2D(stream, (VkRect2D*)(pRects + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDevicePresentRectanglesKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pRectCount;
     check_pRectCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -13073,7 +12446,6 @@
             transform_fromhost_VkRect2D(mImpl->resources(), (VkRect2D*)(pRects + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDevicePresentRectanglesKHR returnUnmarshal");
     VkResult vkGetPhysicalDevicePresentRectanglesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDevicePresentRectanglesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13089,7 +12461,6 @@
     uint32_t* pImageIndex)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkAcquireNextImage2KHR encode");
     mImpl->log("start vkAcquireNextImage2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13127,9 +12498,7 @@
     stream->write((uint64_t*)&cgen_var_860, 1 * 8);
     marshal_VkAcquireNextImageInfoKHR(stream, (VkAcquireNextImageInfoKHR*)(local_pAcquireInfo));
     stream->write((uint32_t*)pImageIndex, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkAcquireNextImage2KHR readParams");
     stream->read((uint32_t*)pImageIndex, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkAcquireNextImage2KHR returnUnmarshal");
     VkResult vkAcquireNextImage2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkAcquireNextImage2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13147,7 +12516,6 @@
     VkDisplayPropertiesKHR* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPropertiesKHR encode");
     mImpl->log("start vkGetPhysicalDeviceDisplayPropertiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13204,7 +12572,6 @@
             marshal_VkDisplayPropertiesKHR(stream, (VkDisplayPropertiesKHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPropertiesKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -13237,7 +12604,6 @@
             transform_fromhost_VkDisplayPropertiesKHR(mImpl->resources(), (VkDisplayPropertiesKHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPropertiesKHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceDisplayPropertiesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceDisplayPropertiesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13253,7 +12619,6 @@
     VkDisplayPlanePropertiesKHR* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPlanePropertiesKHR encode");
     mImpl->log("start vkGetPhysicalDeviceDisplayPlanePropertiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13310,7 +12675,6 @@
             marshal_VkDisplayPlanePropertiesKHR(stream, (VkDisplayPlanePropertiesKHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPlanePropertiesKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -13343,7 +12707,6 @@
             transform_fromhost_VkDisplayPlanePropertiesKHR(mImpl->resources(), (VkDisplayPlanePropertiesKHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPlanePropertiesKHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceDisplayPlanePropertiesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceDisplayPlanePropertiesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13360,7 +12723,6 @@
     VkDisplayKHR* pDisplays)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneSupportedDisplaysKHR encode");
     mImpl->log("start vkGetDisplayPlaneSupportedDisplaysKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13429,7 +12791,6 @@
         }
     }
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneSupportedDisplaysKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pDisplayCount;
     check_pDisplayCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -13458,7 +12819,6 @@
             stream->handleMapping()->mapHandles_u64_VkDisplayKHR(cgen_var_887, (VkDisplayKHR*)pDisplays, (*(pDisplayCount)));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneSupportedDisplaysKHR returnUnmarshal");
     VkResult vkGetDisplayPlaneSupportedDisplaysKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetDisplayPlaneSupportedDisplaysKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13475,7 +12835,6 @@
     VkDisplayModePropertiesKHR* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDisplayModePropertiesKHR encode");
     mImpl->log("start vkGetDisplayModePropertiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13540,7 +12899,6 @@
             marshal_VkDisplayModePropertiesKHR(stream, (VkDisplayModePropertiesKHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetDisplayModePropertiesKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -13573,7 +12931,6 @@
             transform_fromhost_VkDisplayModePropertiesKHR(mImpl->resources(), (VkDisplayModePropertiesKHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetDisplayModePropertiesKHR returnUnmarshal");
     VkResult vkGetDisplayModePropertiesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetDisplayModePropertiesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13591,7 +12948,6 @@
     VkDisplayModeKHR* pMode)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDisplayModeKHR encode");
     mImpl->log("start vkCreateDisplayModeKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13669,13 +13025,11 @@
     stream->handleMapping()->mapHandles_VkDisplayModeKHR_u64(pMode, &cgen_var_905, 1);
     stream->write((uint64_t*)&cgen_var_905, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDisplayModeKHR readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_906;
     stream->read((uint64_t*)&cgen_var_906, 8);
     stream->handleMapping()->mapHandles_u64_VkDisplayModeKHR(&cgen_var_906, (VkDisplayModeKHR*)pMode, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateDisplayModeKHR returnUnmarshal");
     VkResult vkCreateDisplayModeKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDisplayModeKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13692,7 +13046,6 @@
     VkDisplayPlaneCapabilitiesKHR* pCapabilities)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneCapabilitiesKHR encode");
     mImpl->log("start vkGetDisplayPlaneCapabilitiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13729,13 +13082,11 @@
     stream->write((uint64_t*)&cgen_var_910, 1 * 8);
     stream->write((uint32_t*)&local_planeIndex, sizeof(uint32_t));
     marshal_VkDisplayPlaneCapabilitiesKHR(stream, (VkDisplayPlaneCapabilitiesKHR*)(pCapabilities));
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneCapabilitiesKHR readParams");
     unmarshal_VkDisplayPlaneCapabilitiesKHR(stream, (VkDisplayPlaneCapabilitiesKHR*)(pCapabilities));
     if (pCapabilities)
     {
         transform_fromhost_VkDisplayPlaneCapabilitiesKHR(mImpl->resources(), (VkDisplayPlaneCapabilitiesKHR*)(pCapabilities));
     }
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneCapabilitiesKHR returnUnmarshal");
     VkResult vkGetDisplayPlaneCapabilitiesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetDisplayPlaneCapabilitiesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13752,7 +13103,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDisplayPlaneSurfaceKHR encode");
     mImpl->log("start vkCreateDisplayPlaneSurfaceKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13822,11 +13172,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_916, 1);
     stream->write((uint64_t*)&cgen_var_916, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDisplayPlaneSurfaceKHR readParams");
     uint64_t cgen_var_917;
     stream->read((uint64_t*)&cgen_var_917, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_917, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateDisplayPlaneSurfaceKHR returnUnmarshal");
     VkResult vkCreateDisplayPlaneSurfaceKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDisplayPlaneSurfaceKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13846,7 +13194,6 @@
     VkSwapchainKHR* pSwapchains)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateSharedSwapchainsKHR encode");
     mImpl->log("start vkCreateSharedSwapchainsKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -13940,7 +13287,6 @@
         stream->write((uint64_t*)cgen_var_923, ((swapchainCount)) * 8);
     }
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateSharedSwapchainsKHR readParams");
     if (((swapchainCount)))
     {
         uint64_t* cgen_var_924;
@@ -13948,7 +13294,6 @@
         stream->read((uint64_t*)cgen_var_924, ((swapchainCount)) * 8);
         stream->handleMapping()->mapHandles_u64_VkSwapchainKHR(cgen_var_924, (VkSwapchainKHR*)pSwapchains, ((swapchainCount)));
     }
-    AEMU_SCOPED_TRACE("vkCreateSharedSwapchainsKHR returnUnmarshal");
     VkResult vkCreateSharedSwapchainsKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateSharedSwapchainsKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -13967,7 +13312,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateXlibSurfaceKHR encode");
     mImpl->log("start vkCreateXlibSurfaceKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14037,11 +13381,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_930, 1);
     stream->write((uint64_t*)&cgen_var_930, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateXlibSurfaceKHR readParams");
     uint64_t cgen_var_931;
     stream->read((uint64_t*)&cgen_var_931, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_931, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateXlibSurfaceKHR returnUnmarshal");
     VkResult vkCreateXlibSurfaceKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateXlibSurfaceKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -14058,7 +13400,6 @@
     VisualID visualID)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceXlibPresentationSupportKHR encode");
     mImpl->log("start vkGetPhysicalDeviceXlibPresentationSupportKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14091,9 +13432,7 @@
     stream->write((uint32_t*)&local_queueFamilyIndex, sizeof(uint32_t));
     stream->write((Display*)dpy, sizeof(Display));
     stream->write((VisualID*)&local_visualID, sizeof(VisualID));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceXlibPresentationSupportKHR readParams");
     stream->read((Display*)dpy, sizeof(Display));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceXlibPresentationSupportKHR returnUnmarshal");
     VkBool32 vkGetPhysicalDeviceXlibPresentationSupportKHR_VkBool32_return = (VkBool32)0;
     stream->read(&vkGetPhysicalDeviceXlibPresentationSupportKHR_VkBool32_return, sizeof(VkBool32));
     pool->freeAll();
@@ -14112,7 +13451,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateXcbSurfaceKHR encode");
     mImpl->log("start vkCreateXcbSurfaceKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14182,11 +13520,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_939, 1);
     stream->write((uint64_t*)&cgen_var_939, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateXcbSurfaceKHR readParams");
     uint64_t cgen_var_940;
     stream->read((uint64_t*)&cgen_var_940, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_940, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateXcbSurfaceKHR returnUnmarshal");
     VkResult vkCreateXcbSurfaceKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateXcbSurfaceKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -14203,7 +13539,6 @@
     xcb_visualid_t visual_id)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceXcbPresentationSupportKHR encode");
     mImpl->log("start vkGetPhysicalDeviceXcbPresentationSupportKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14236,9 +13571,7 @@
     stream->write((uint32_t*)&local_queueFamilyIndex, sizeof(uint32_t));
     stream->write((xcb_connection_t*)connection, sizeof(xcb_connection_t));
     stream->write((xcb_visualid_t*)&local_visual_id, sizeof(xcb_visualid_t));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceXcbPresentationSupportKHR readParams");
     stream->read((xcb_connection_t*)connection, sizeof(xcb_connection_t));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceXcbPresentationSupportKHR returnUnmarshal");
     VkBool32 vkGetPhysicalDeviceXcbPresentationSupportKHR_VkBool32_return = (VkBool32)0;
     stream->read(&vkGetPhysicalDeviceXcbPresentationSupportKHR_VkBool32_return, sizeof(VkBool32));
     pool->freeAll();
@@ -14257,7 +13590,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateWaylandSurfaceKHR encode");
     mImpl->log("start vkCreateWaylandSurfaceKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14327,11 +13659,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_948, 1);
     stream->write((uint64_t*)&cgen_var_948, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateWaylandSurfaceKHR readParams");
     uint64_t cgen_var_949;
     stream->read((uint64_t*)&cgen_var_949, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_949, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateWaylandSurfaceKHR returnUnmarshal");
     VkResult vkCreateWaylandSurfaceKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateWaylandSurfaceKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -14347,7 +13677,6 @@
     wl_display* display)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceWaylandPresentationSupportKHR encode");
     mImpl->log("start vkGetPhysicalDeviceWaylandPresentationSupportKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14376,9 +13705,7 @@
     stream->write((uint64_t*)&cgen_var_951, 1 * 8);
     stream->write((uint32_t*)&local_queueFamilyIndex, sizeof(uint32_t));
     stream->write((wl_display*)display, sizeof(wl_display));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceWaylandPresentationSupportKHR readParams");
     stream->read((wl_display*)display, sizeof(wl_display));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceWaylandPresentationSupportKHR returnUnmarshal");
     VkBool32 vkGetPhysicalDeviceWaylandPresentationSupportKHR_VkBool32_return = (VkBool32)0;
     stream->read(&vkGetPhysicalDeviceWaylandPresentationSupportKHR_VkBool32_return, sizeof(VkBool32));
     pool->freeAll();
@@ -14397,7 +13724,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateMirSurfaceKHR encode");
     mImpl->log("start vkCreateMirSurfaceKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14467,11 +13793,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_957, 1);
     stream->write((uint64_t*)&cgen_var_957, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateMirSurfaceKHR readParams");
     uint64_t cgen_var_958;
     stream->read((uint64_t*)&cgen_var_958, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_958, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateMirSurfaceKHR returnUnmarshal");
     VkResult vkCreateMirSurfaceKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateMirSurfaceKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -14487,7 +13811,6 @@
     MirConnection* connection)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMirPresentationSupportKHR encode");
     mImpl->log("start vkGetPhysicalDeviceMirPresentationSupportKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14516,9 +13839,7 @@
     stream->write((uint64_t*)&cgen_var_960, 1 * 8);
     stream->write((uint32_t*)&local_queueFamilyIndex, sizeof(uint32_t));
     stream->write((MirConnection*)connection, sizeof(MirConnection));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMirPresentationSupportKHR readParams");
     stream->read((MirConnection*)connection, sizeof(MirConnection));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMirPresentationSupportKHR returnUnmarshal");
     VkBool32 vkGetPhysicalDeviceMirPresentationSupportKHR_VkBool32_return = (VkBool32)0;
     stream->read(&vkGetPhysicalDeviceMirPresentationSupportKHR_VkBool32_return, sizeof(VkBool32));
     pool->freeAll();
@@ -14537,7 +13858,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateAndroidSurfaceKHR encode");
     mImpl->log("start vkCreateAndroidSurfaceKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14607,11 +13927,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_966, 1);
     stream->write((uint64_t*)&cgen_var_966, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateAndroidSurfaceKHR readParams");
     uint64_t cgen_var_967;
     stream->read((uint64_t*)&cgen_var_967, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_967, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateAndroidSurfaceKHR returnUnmarshal");
     VkResult vkCreateAndroidSurfaceKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateAndroidSurfaceKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -14630,7 +13948,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateWin32SurfaceKHR encode");
     mImpl->log("start vkCreateWin32SurfaceKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14700,11 +14017,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_973, 1);
     stream->write((uint64_t*)&cgen_var_973, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateWin32SurfaceKHR readParams");
     uint64_t cgen_var_974;
     stream->read((uint64_t*)&cgen_var_974, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_974, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateWin32SurfaceKHR returnUnmarshal");
     VkResult vkCreateWin32SurfaceKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateWin32SurfaceKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -14719,7 +14034,6 @@
     uint32_t queueFamilyIndex)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceWin32PresentationSupportKHR encode");
     mImpl->log("start vkGetPhysicalDeviceWin32PresentationSupportKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14746,8 +14060,6 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_976, 1);
     stream->write((uint64_t*)&cgen_var_976, 1 * 8);
     stream->write((uint32_t*)&local_queueFamilyIndex, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceWin32PresentationSupportKHR readParams");
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceWin32PresentationSupportKHR returnUnmarshal");
     VkBool32 vkGetPhysicalDeviceWin32PresentationSupportKHR_VkBool32_return = (VkBool32)0;
     stream->read(&vkGetPhysicalDeviceWin32PresentationSupportKHR_VkBool32_return, sizeof(VkBool32));
     pool->freeAll();
@@ -14768,7 +14080,6 @@
     VkPhysicalDeviceFeatures2* pFeatures)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceFeatures2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14793,13 +14104,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_978, 1);
     stream->write((uint64_t*)&cgen_var_978, 1 * 8);
     marshal_VkPhysicalDeviceFeatures2(stream, (VkPhysicalDeviceFeatures2*)(pFeatures));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures2KHR readParams");
     unmarshal_VkPhysicalDeviceFeatures2(stream, (VkPhysicalDeviceFeatures2*)(pFeatures));
     if (pFeatures)
     {
         transform_fromhost_VkPhysicalDeviceFeatures2(mImpl->resources(), (VkPhysicalDeviceFeatures2*)(pFeatures));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFeatures2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -14811,7 +14120,6 @@
     VkPhysicalDeviceProperties2* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14836,13 +14144,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_980, 1);
     stream->write((uint64_t*)&cgen_var_980, 1 * 8);
     marshal_VkPhysicalDeviceProperties2(stream, (VkPhysicalDeviceProperties2*)(pProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties2KHR readParams");
     unmarshal_VkPhysicalDeviceProperties2(stream, (VkPhysicalDeviceProperties2*)(pProperties));
     if (pProperties)
     {
         transform_fromhost_VkPhysicalDeviceProperties2(mImpl->resources(), (VkPhysicalDeviceProperties2*)(pProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceProperties2KHR returnUnmarshal");
     mImpl->resources()->on_vkGetPhysicalDeviceProperties2KHR(this, physicalDevice, pProperties);
     pool->freeAll();
     countingStream->clearPool();
@@ -14856,7 +14162,6 @@
     VkFormatProperties2* pFormatProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceFormatProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14885,13 +14190,11 @@
     stream->write((uint64_t*)&cgen_var_982, 1 * 8);
     stream->write((VkFormat*)&local_format, sizeof(VkFormat));
     marshal_VkFormatProperties2(stream, (VkFormatProperties2*)(pFormatProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties2KHR readParams");
     unmarshal_VkFormatProperties2(stream, (VkFormatProperties2*)(pFormatProperties));
     if (pFormatProperties)
     {
         transform_fromhost_VkFormatProperties2(mImpl->resources(), (VkFormatProperties2*)(pFormatProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceFormatProperties2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -14904,7 +14207,6 @@
     VkImageFormatProperties2* pImageFormatProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceImageFormatProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -14942,13 +14244,11 @@
     stream->write((uint64_t*)&cgen_var_984, 1 * 8);
     marshal_VkPhysicalDeviceImageFormatInfo2(stream, (VkPhysicalDeviceImageFormatInfo2*)(local_pImageFormatInfo));
     marshal_VkImageFormatProperties2(stream, (VkImageFormatProperties2*)(pImageFormatProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties2KHR readParams");
     unmarshal_VkImageFormatProperties2(stream, (VkImageFormatProperties2*)(pImageFormatProperties));
     if (pImageFormatProperties)
     {
         transform_fromhost_VkImageFormatProperties2(mImpl->resources(), (VkImageFormatProperties2*)(pImageFormatProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceImageFormatProperties2KHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceImageFormatProperties2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceImageFormatProperties2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -14964,7 +14264,6 @@
     VkQueueFamilyProperties2* pQueueFamilyProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceQueueFamilyProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15021,7 +14320,6 @@
             marshal_VkQueueFamilyProperties2(stream, (VkQueueFamilyProperties2*)(pQueueFamilyProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties2KHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pQueueFamilyPropertyCount;
     check_pQueueFamilyPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -15054,7 +14352,6 @@
             transform_fromhost_VkQueueFamilyProperties2(mImpl->resources(), (VkQueueFamilyProperties2*)(pQueueFamilyProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceQueueFamilyProperties2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -15066,7 +14363,6 @@
     VkPhysicalDeviceMemoryProperties2* pMemoryProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceMemoryProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15091,13 +14387,11 @@
     stream->handleMapping()->mapHandles_VkPhysicalDevice_u64(&local_physicalDevice, &cgen_var_994, 1);
     stream->write((uint64_t*)&cgen_var_994, 1 * 8);
     marshal_VkPhysicalDeviceMemoryProperties2(stream, (VkPhysicalDeviceMemoryProperties2*)(pMemoryProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties2KHR readParams");
     unmarshal_VkPhysicalDeviceMemoryProperties2(stream, (VkPhysicalDeviceMemoryProperties2*)(pMemoryProperties));
     if (pMemoryProperties)
     {
         transform_fromhost_VkPhysicalDeviceMemoryProperties2(mImpl->resources(), (VkPhysicalDeviceMemoryProperties2*)(pMemoryProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMemoryProperties2KHR returnUnmarshal");
     mImpl->resources()->on_vkGetPhysicalDeviceMemoryProperties2KHR(this, physicalDevice, pMemoryProperties);
     pool->freeAll();
     countingStream->clearPool();
@@ -15112,7 +14406,6 @@
     VkSparseImageFormatProperties2* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceSparseImageFormatProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15182,7 +14475,6 @@
             marshal_VkSparseImageFormatProperties2(stream, (VkSparseImageFormatProperties2*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties2KHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -15215,7 +14507,6 @@
             transform_fromhost_VkSparseImageFormatProperties2(mImpl->resources(), (VkSparseImageFormatProperties2*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSparseImageFormatProperties2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -15232,7 +14523,6 @@
     VkPeerMemoryFeatureFlags* pPeerMemoryFeatures)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPeerMemoryFeaturesKHR encode");
     mImpl->log("start vkGetDeviceGroupPeerMemoryFeaturesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15269,9 +14559,7 @@
     stream->write((uint32_t*)&local_localDeviceIndex, sizeof(uint32_t));
     stream->write((uint32_t*)&local_remoteDeviceIndex, sizeof(uint32_t));
     stream->write((VkPeerMemoryFeatureFlags*)pPeerMemoryFeatures, sizeof(VkPeerMemoryFeatureFlags));
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPeerMemoryFeaturesKHR readParams");
     stream->read((VkPeerMemoryFeatureFlags*)pPeerMemoryFeatures, sizeof(VkPeerMemoryFeatureFlags));
-    AEMU_SCOPED_TRACE("vkGetDeviceGroupPeerMemoryFeaturesKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -15283,7 +14571,6 @@
     uint32_t deviceMask)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetDeviceMaskKHR encode");
     mImpl->log("start vkCmdSetDeviceMaskKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15310,8 +14597,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1006, 1);
     stream->write((uint64_t*)&cgen_var_1006, 1 * 8);
     stream->write((uint32_t*)&local_deviceMask, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdSetDeviceMaskKHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetDeviceMaskKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -15328,7 +14613,6 @@
     uint32_t groupCountZ)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDispatchBaseKHR encode");
     mImpl->log("start vkCmdDispatchBaseKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15375,8 +14659,6 @@
     stream->write((uint32_t*)&local_groupCountX, sizeof(uint32_t));
     stream->write((uint32_t*)&local_groupCountY, sizeof(uint32_t));
     stream->write((uint32_t*)&local_groupCountZ, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDispatchBaseKHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdDispatchBaseKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -15393,7 +14675,6 @@
     VkCommandPoolTrimFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkTrimCommandPoolKHR encode");
     mImpl->log("start vkTrimCommandPoolKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15428,8 +14709,6 @@
     stream->handleMapping()->mapHandles_VkCommandPool_u64(&local_commandPool, &cgen_var_1012, 1);
     stream->write((uint64_t*)&cgen_var_1012, 1 * 8);
     stream->write((VkCommandPoolTrimFlags*)&local_flags, sizeof(VkCommandPoolTrimFlags));
-    AEMU_SCOPED_TRACE("vkTrimCommandPoolKHR readParams");
-    AEMU_SCOPED_TRACE("vkTrimCommandPoolKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -15444,7 +14723,6 @@
     VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDeviceGroupsKHR encode");
     mImpl->log("start vkEnumeratePhysicalDeviceGroupsKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15501,7 +14779,6 @@
             marshal_VkPhysicalDeviceGroupProperties(stream, (VkPhysicalDeviceGroupProperties*)(pPhysicalDeviceGroupProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDeviceGroupsKHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPhysicalDeviceGroupCount;
     check_pPhysicalDeviceGroupCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -15534,7 +14811,6 @@
             transform_fromhost_VkPhysicalDeviceGroupProperties(mImpl->resources(), (VkPhysicalDeviceGroupProperties*)(pPhysicalDeviceGroupProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkEnumeratePhysicalDeviceGroupsKHR returnUnmarshal");
     VkResult vkEnumeratePhysicalDeviceGroupsKHR_VkResult_return = (VkResult)0;
     stream->read(&vkEnumeratePhysicalDeviceGroupsKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -15552,7 +14828,6 @@
     VkExternalBufferProperties* pExternalBufferProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalBufferPropertiesKHR encode");
     mImpl->log("start vkGetPhysicalDeviceExternalBufferPropertiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15591,14 +14866,12 @@
     stream->write((uint64_t*)&cgen_var_1022, 1 * 8);
     marshal_VkPhysicalDeviceExternalBufferInfo(stream, (VkPhysicalDeviceExternalBufferInfo*)(local_pExternalBufferInfo));
     marshal_VkExternalBufferProperties(stream, (VkExternalBufferProperties*)(pExternalBufferProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalBufferPropertiesKHR readParams");
     unmarshal_VkExternalBufferProperties(stream, (VkExternalBufferProperties*)(pExternalBufferProperties));
     if (pExternalBufferProperties)
     {
         mImpl->resources()->transformImpl_VkExternalBufferProperties_fromhost(pExternalBufferProperties, 1);
         transform_fromhost_VkExternalBufferProperties(mImpl->resources(), (VkExternalBufferProperties*)(pExternalBufferProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalBufferPropertiesKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -15615,7 +14888,6 @@
     HANDLE* pHandle)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandleKHR encode");
     mImpl->log("start vkGetMemoryWin32HandleKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15653,9 +14925,7 @@
     stream->write((uint64_t*)&cgen_var_1024, 1 * 8);
     marshal_VkMemoryGetWin32HandleInfoKHR(stream, (VkMemoryGetWin32HandleInfoKHR*)(local_pGetWin32HandleInfo));
     stream->write((HANDLE*)pHandle, sizeof(HANDLE));
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandleKHR readParams");
     stream->read((HANDLE*)pHandle, sizeof(HANDLE));
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandleKHR returnUnmarshal");
     VkResult vkGetMemoryWin32HandleKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetMemoryWin32HandleKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -15672,7 +14942,6 @@
     VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandlePropertiesKHR encode");
     mImpl->log("start vkGetMemoryWin32HandlePropertiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15705,13 +14974,11 @@
     stream->write((VkExternalMemoryHandleTypeFlagBits*)&local_handleType, sizeof(VkExternalMemoryHandleTypeFlagBits));
     stream->write((HANDLE*)&local_handle, sizeof(HANDLE));
     marshal_VkMemoryWin32HandlePropertiesKHR(stream, (VkMemoryWin32HandlePropertiesKHR*)(pMemoryWin32HandleProperties));
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandlePropertiesKHR readParams");
     unmarshal_VkMemoryWin32HandlePropertiesKHR(stream, (VkMemoryWin32HandlePropertiesKHR*)(pMemoryWin32HandleProperties));
     if (pMemoryWin32HandleProperties)
     {
         transform_fromhost_VkMemoryWin32HandlePropertiesKHR(mImpl->resources(), (VkMemoryWin32HandlePropertiesKHR*)(pMemoryWin32HandleProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandlePropertiesKHR returnUnmarshal");
     VkResult vkGetMemoryWin32HandlePropertiesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetMemoryWin32HandlePropertiesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -15729,7 +14996,6 @@
     int* pFd)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetMemoryFdKHR encode");
     mImpl->log("start vkGetMemoryFdKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15767,9 +15033,7 @@
     stream->write((uint64_t*)&cgen_var_1028, 1 * 8);
     marshal_VkMemoryGetFdInfoKHR(stream, (VkMemoryGetFdInfoKHR*)(local_pGetFdInfo));
     stream->write((int*)pFd, sizeof(int));
-    AEMU_SCOPED_TRACE("vkGetMemoryFdKHR readParams");
     stream->read((int*)pFd, sizeof(int));
-    AEMU_SCOPED_TRACE("vkGetMemoryFdKHR returnUnmarshal");
     VkResult vkGetMemoryFdKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetMemoryFdKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -15786,7 +15050,6 @@
     VkMemoryFdPropertiesKHR* pMemoryFdProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetMemoryFdPropertiesKHR encode");
     mImpl->log("start vkGetMemoryFdPropertiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15819,13 +15082,11 @@
     stream->write((VkExternalMemoryHandleTypeFlagBits*)&local_handleType, sizeof(VkExternalMemoryHandleTypeFlagBits));
     stream->write((int*)&local_fd, sizeof(int));
     marshal_VkMemoryFdPropertiesKHR(stream, (VkMemoryFdPropertiesKHR*)(pMemoryFdProperties));
-    AEMU_SCOPED_TRACE("vkGetMemoryFdPropertiesKHR readParams");
     unmarshal_VkMemoryFdPropertiesKHR(stream, (VkMemoryFdPropertiesKHR*)(pMemoryFdProperties));
     if (pMemoryFdProperties)
     {
         transform_fromhost_VkMemoryFdPropertiesKHR(mImpl->resources(), (VkMemoryFdPropertiesKHR*)(pMemoryFdProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetMemoryFdPropertiesKHR returnUnmarshal");
     VkResult vkGetMemoryFdPropertiesKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetMemoryFdPropertiesKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -15845,7 +15106,6 @@
     VkExternalSemaphoreProperties* pExternalSemaphoreProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalSemaphorePropertiesKHR encode");
     mImpl->log("start vkGetPhysicalDeviceExternalSemaphorePropertiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15883,13 +15143,11 @@
     stream->write((uint64_t*)&cgen_var_1032, 1 * 8);
     marshal_VkPhysicalDeviceExternalSemaphoreInfo(stream, (VkPhysicalDeviceExternalSemaphoreInfo*)(local_pExternalSemaphoreInfo));
     marshal_VkExternalSemaphoreProperties(stream, (VkExternalSemaphoreProperties*)(pExternalSemaphoreProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalSemaphorePropertiesKHR readParams");
     unmarshal_VkExternalSemaphoreProperties(stream, (VkExternalSemaphoreProperties*)(pExternalSemaphoreProperties));
     if (pExternalSemaphoreProperties)
     {
         transform_fromhost_VkExternalSemaphoreProperties(mImpl->resources(), (VkExternalSemaphoreProperties*)(pExternalSemaphoreProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalSemaphorePropertiesKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -15905,7 +15163,6 @@
     const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkImportSemaphoreWin32HandleKHR encode");
     mImpl->log("start vkImportSemaphoreWin32HandleKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15941,8 +15198,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1034, 1);
     stream->write((uint64_t*)&cgen_var_1034, 1 * 8);
     marshal_VkImportSemaphoreWin32HandleInfoKHR(stream, (VkImportSemaphoreWin32HandleInfoKHR*)(local_pImportSemaphoreWin32HandleInfo));
-    AEMU_SCOPED_TRACE("vkImportSemaphoreWin32HandleKHR readParams");
-    AEMU_SCOPED_TRACE("vkImportSemaphoreWin32HandleKHR returnUnmarshal");
     VkResult vkImportSemaphoreWin32HandleKHR_VkResult_return = (VkResult)0;
     stream->read(&vkImportSemaphoreWin32HandleKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -15958,7 +15213,6 @@
     HANDLE* pHandle)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetSemaphoreWin32HandleKHR encode");
     mImpl->log("start vkGetSemaphoreWin32HandleKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -15996,9 +15250,7 @@
     stream->write((uint64_t*)&cgen_var_1036, 1 * 8);
     marshal_VkSemaphoreGetWin32HandleInfoKHR(stream, (VkSemaphoreGetWin32HandleInfoKHR*)(local_pGetWin32HandleInfo));
     stream->write((HANDLE*)pHandle, sizeof(HANDLE));
-    AEMU_SCOPED_TRACE("vkGetSemaphoreWin32HandleKHR readParams");
     stream->read((HANDLE*)pHandle, sizeof(HANDLE));
-    AEMU_SCOPED_TRACE("vkGetSemaphoreWin32HandleKHR returnUnmarshal");
     VkResult vkGetSemaphoreWin32HandleKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetSemaphoreWin32HandleKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -16015,7 +15267,6 @@
     const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkImportSemaphoreFdKHR encode");
     mImpl->log("start vkImportSemaphoreFdKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16051,8 +15302,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1038, 1);
     stream->write((uint64_t*)&cgen_var_1038, 1 * 8);
     marshal_VkImportSemaphoreFdInfoKHR(stream, (VkImportSemaphoreFdInfoKHR*)(local_pImportSemaphoreFdInfo));
-    AEMU_SCOPED_TRACE("vkImportSemaphoreFdKHR readParams");
-    AEMU_SCOPED_TRACE("vkImportSemaphoreFdKHR returnUnmarshal");
     VkResult vkImportSemaphoreFdKHR_VkResult_return = (VkResult)0;
     stream->read(&vkImportSemaphoreFdKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -16068,7 +15317,6 @@
     int* pFd)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetSemaphoreFdKHR encode");
     mImpl->log("start vkGetSemaphoreFdKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16106,9 +15354,7 @@
     stream->write((uint64_t*)&cgen_var_1040, 1 * 8);
     marshal_VkSemaphoreGetFdInfoKHR(stream, (VkSemaphoreGetFdInfoKHR*)(local_pGetFdInfo));
     stream->write((int*)pFd, sizeof(int));
-    AEMU_SCOPED_TRACE("vkGetSemaphoreFdKHR readParams");
     stream->read((int*)pFd, sizeof(int));
-    AEMU_SCOPED_TRACE("vkGetSemaphoreFdKHR returnUnmarshal");
     VkResult vkGetSemaphoreFdKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetSemaphoreFdKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -16129,7 +15375,6 @@
     const VkWriteDescriptorSet* pDescriptorWrites)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdPushDescriptorSetKHR encode");
     mImpl->log("start vkCmdPushDescriptorSetKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16197,8 +15442,6 @@
     {
         marshal_VkWriteDescriptorSet(stream, (VkWriteDescriptorSet*)(local_pDescriptorWrites + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdPushDescriptorSetKHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdPushDescriptorSetKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -16213,7 +15456,6 @@
     const void* pData)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdPushDescriptorSetWithTemplateKHR encode");
     mImpl->log("start vkCmdPushDescriptorSetWithTemplateKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16276,8 +15518,6 @@
     {
         stream->write((void*)local_pData, sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkCmdPushDescriptorSetWithTemplateKHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdPushDescriptorSetWithTemplateKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -16297,7 +15537,6 @@
     VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDescriptorUpdateTemplateKHR encode");
     mImpl->log("start vkCreateDescriptorUpdateTemplateKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16367,13 +15606,11 @@
     stream->handleMapping()->mapHandles_VkDescriptorUpdateTemplate_u64(pDescriptorUpdateTemplate, &cgen_var_1058, 1);
     stream->write((uint64_t*)&cgen_var_1058, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDescriptorUpdateTemplateKHR readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1059;
     stream->read((uint64_t*)&cgen_var_1059, 8);
     stream->handleMapping()->mapHandles_u64_VkDescriptorUpdateTemplate(&cgen_var_1059, (VkDescriptorUpdateTemplate*)pDescriptorUpdateTemplate, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateDescriptorUpdateTemplateKHR returnUnmarshal");
     VkResult vkCreateDescriptorUpdateTemplateKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDescriptorUpdateTemplateKHR_VkResult_return, sizeof(VkResult));
     mImpl->resources()->on_vkCreateDescriptorUpdateTemplateKHR(this, vkCreateDescriptorUpdateTemplateKHR_VkResult_return, device, pCreateInfo, pAllocator, pDescriptorUpdateTemplate);
@@ -16390,7 +15627,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorUpdateTemplateKHR encode");
     mImpl->log("start vkDestroyDescriptorUpdateTemplateKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16447,8 +15683,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorUpdateTemplateKHR readParams");
-    AEMU_SCOPED_TRACE("vkDestroyDescriptorUpdateTemplateKHR returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkDescriptorUpdateTemplate((VkDescriptorUpdateTemplate*)&descriptorUpdateTemplate);
     pool->freeAll();
     countingStream->clearPool();
@@ -16463,7 +15697,6 @@
     const void* pData)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplateKHR encode");
     mImpl->log("start vkUpdateDescriptorSetWithTemplateKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16522,8 +15755,6 @@
     {
         stream->write((void*)local_pData, sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplateKHR readParams");
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplateKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -16539,7 +15770,6 @@
     VkRenderPass* pRenderPass)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateRenderPass2KHR encode");
     mImpl->log("start vkCreateRenderPass2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16609,11 +15839,9 @@
     stream->handleMapping()->mapHandles_VkRenderPass_u64(pRenderPass, &cgen_var_1079, 1);
     stream->write((uint64_t*)&cgen_var_1079, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateRenderPass2KHR readParams");
     uint64_t cgen_var_1080;
     stream->read((uint64_t*)&cgen_var_1080, 8);
     stream->handleMapping()->mapHandles_u64_VkRenderPass(&cgen_var_1080, (VkRenderPass*)pRenderPass, 1);
-    AEMU_SCOPED_TRACE("vkCreateRenderPass2KHR returnUnmarshal");
     VkResult vkCreateRenderPass2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateRenderPass2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -16629,7 +15857,6 @@
     const VkSubpassBeginInfoKHR* pSubpassBeginInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBeginRenderPass2KHR encode");
     mImpl->log("start vkCmdBeginRenderPass2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16678,8 +15905,6 @@
     stream->write((uint64_t*)&cgen_var_1082, 1 * 8);
     marshal_VkRenderPassBeginInfo(stream, (VkRenderPassBeginInfo*)(local_pRenderPassBegin));
     marshal_VkSubpassBeginInfoKHR(stream, (VkSubpassBeginInfoKHR*)(local_pSubpassBeginInfo));
-    AEMU_SCOPED_TRACE("vkCmdBeginRenderPass2KHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdBeginRenderPass2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -16692,7 +15917,6 @@
     const VkSubpassEndInfoKHR* pSubpassEndInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdNextSubpass2KHR encode");
     mImpl->log("start vkCmdNextSubpass2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16741,8 +15965,6 @@
     stream->write((uint64_t*)&cgen_var_1084, 1 * 8);
     marshal_VkSubpassBeginInfoKHR(stream, (VkSubpassBeginInfoKHR*)(local_pSubpassBeginInfo));
     marshal_VkSubpassEndInfoKHR(stream, (VkSubpassEndInfoKHR*)(local_pSubpassEndInfo));
-    AEMU_SCOPED_TRACE("vkCmdNextSubpass2KHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdNextSubpass2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -16754,7 +15976,6 @@
     const VkSubpassEndInfoKHR* pSubpassEndInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdEndRenderPass2KHR encode");
     mImpl->log("start vkCmdEndRenderPass2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16790,8 +16011,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1086, 1);
     stream->write((uint64_t*)&cgen_var_1086, 1 * 8);
     marshal_VkSubpassEndInfoKHR(stream, (VkSubpassEndInfoKHR*)(local_pSubpassEndInfo));
-    AEMU_SCOPED_TRACE("vkCmdEndRenderPass2KHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdEndRenderPass2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -16805,7 +16024,6 @@
     VkSwapchainKHR swapchain)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetSwapchainStatusKHR encode");
     mImpl->log("start vkGetSwapchainStatusKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16836,8 +16054,6 @@
     uint64_t cgen_var_1090;
     stream->handleMapping()->mapHandles_VkSwapchainKHR_u64(&local_swapchain, &cgen_var_1090, 1);
     stream->write((uint64_t*)&cgen_var_1090, 1 * 8);
-    AEMU_SCOPED_TRACE("vkGetSwapchainStatusKHR readParams");
-    AEMU_SCOPED_TRACE("vkGetSwapchainStatusKHR returnUnmarshal");
     VkResult vkGetSwapchainStatusKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetSwapchainStatusKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -16855,7 +16071,6 @@
     VkExternalFenceProperties* pExternalFenceProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalFencePropertiesKHR encode");
     mImpl->log("start vkGetPhysicalDeviceExternalFencePropertiesKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16893,13 +16108,11 @@
     stream->write((uint64_t*)&cgen_var_1092, 1 * 8);
     marshal_VkPhysicalDeviceExternalFenceInfo(stream, (VkPhysicalDeviceExternalFenceInfo*)(local_pExternalFenceInfo));
     marshal_VkExternalFenceProperties(stream, (VkExternalFenceProperties*)(pExternalFenceProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalFencePropertiesKHR readParams");
     unmarshal_VkExternalFenceProperties(stream, (VkExternalFenceProperties*)(pExternalFenceProperties));
     if (pExternalFenceProperties)
     {
         transform_fromhost_VkExternalFenceProperties(mImpl->resources(), (VkExternalFenceProperties*)(pExternalFenceProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalFencePropertiesKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -16915,7 +16128,6 @@
     const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkImportFenceWin32HandleKHR encode");
     mImpl->log("start vkImportFenceWin32HandleKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -16951,8 +16163,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1094, 1);
     stream->write((uint64_t*)&cgen_var_1094, 1 * 8);
     marshal_VkImportFenceWin32HandleInfoKHR(stream, (VkImportFenceWin32HandleInfoKHR*)(local_pImportFenceWin32HandleInfo));
-    AEMU_SCOPED_TRACE("vkImportFenceWin32HandleKHR readParams");
-    AEMU_SCOPED_TRACE("vkImportFenceWin32HandleKHR returnUnmarshal");
     VkResult vkImportFenceWin32HandleKHR_VkResult_return = (VkResult)0;
     stream->read(&vkImportFenceWin32HandleKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -16968,7 +16178,6 @@
     HANDLE* pHandle)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetFenceWin32HandleKHR encode");
     mImpl->log("start vkGetFenceWin32HandleKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17006,9 +16215,7 @@
     stream->write((uint64_t*)&cgen_var_1096, 1 * 8);
     marshal_VkFenceGetWin32HandleInfoKHR(stream, (VkFenceGetWin32HandleInfoKHR*)(local_pGetWin32HandleInfo));
     stream->write((HANDLE*)pHandle, sizeof(HANDLE));
-    AEMU_SCOPED_TRACE("vkGetFenceWin32HandleKHR readParams");
     stream->read((HANDLE*)pHandle, sizeof(HANDLE));
-    AEMU_SCOPED_TRACE("vkGetFenceWin32HandleKHR returnUnmarshal");
     VkResult vkGetFenceWin32HandleKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetFenceWin32HandleKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17025,7 +16232,6 @@
     const VkImportFenceFdInfoKHR* pImportFenceFdInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkImportFenceFdKHR encode");
     mImpl->log("start vkImportFenceFdKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17061,8 +16267,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1098, 1);
     stream->write((uint64_t*)&cgen_var_1098, 1 * 8);
     marshal_VkImportFenceFdInfoKHR(stream, (VkImportFenceFdInfoKHR*)(local_pImportFenceFdInfo));
-    AEMU_SCOPED_TRACE("vkImportFenceFdKHR readParams");
-    AEMU_SCOPED_TRACE("vkImportFenceFdKHR returnUnmarshal");
     VkResult vkImportFenceFdKHR_VkResult_return = (VkResult)0;
     stream->read(&vkImportFenceFdKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17078,7 +16282,6 @@
     int* pFd)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetFenceFdKHR encode");
     mImpl->log("start vkGetFenceFdKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17116,9 +16319,7 @@
     stream->write((uint64_t*)&cgen_var_1100, 1 * 8);
     marshal_VkFenceGetFdInfoKHR(stream, (VkFenceGetFdInfoKHR*)(local_pGetFdInfo));
     stream->write((int*)pFd, sizeof(int));
-    AEMU_SCOPED_TRACE("vkGetFenceFdKHR readParams");
     stream->read((int*)pFd, sizeof(int));
-    AEMU_SCOPED_TRACE("vkGetFenceFdKHR returnUnmarshal");
     VkResult vkGetFenceFdKHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetFenceFdKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17138,7 +16339,6 @@
     VkSurfaceCapabilities2KHR* pSurfaceCapabilities)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilities2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceSurfaceCapabilities2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17176,13 +16376,11 @@
     stream->write((uint64_t*)&cgen_var_1102, 1 * 8);
     marshal_VkPhysicalDeviceSurfaceInfo2KHR(stream, (VkPhysicalDeviceSurfaceInfo2KHR*)(local_pSurfaceInfo));
     marshal_VkSurfaceCapabilities2KHR(stream, (VkSurfaceCapabilities2KHR*)(pSurfaceCapabilities));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilities2KHR readParams");
     unmarshal_VkSurfaceCapabilities2KHR(stream, (VkSurfaceCapabilities2KHR*)(pSurfaceCapabilities));
     if (pSurfaceCapabilities)
     {
         transform_fromhost_VkSurfaceCapabilities2KHR(mImpl->resources(), (VkSurfaceCapabilities2KHR*)(pSurfaceCapabilities));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilities2KHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceSurfaceCapabilities2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceSurfaceCapabilities2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17199,7 +16397,6 @@
     VkSurfaceFormat2KHR* pSurfaceFormats)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceFormats2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceSurfaceFormats2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17269,7 +16466,6 @@
             marshal_VkSurfaceFormat2KHR(stream, (VkSurfaceFormat2KHR*)(pSurfaceFormats + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceFormats2KHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pSurfaceFormatCount;
     check_pSurfaceFormatCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -17302,7 +16498,6 @@
             transform_fromhost_VkSurfaceFormat2KHR(mImpl->resources(), (VkSurfaceFormat2KHR*)(pSurfaceFormats + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceFormats2KHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceSurfaceFormats2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceSurfaceFormats2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17322,7 +16517,6 @@
     VkDisplayProperties2KHR* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayProperties2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceDisplayProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17379,7 +16573,6 @@
             marshal_VkDisplayProperties2KHR(stream, (VkDisplayProperties2KHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayProperties2KHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -17412,7 +16605,6 @@
             transform_fromhost_VkDisplayProperties2KHR(mImpl->resources(), (VkDisplayProperties2KHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayProperties2KHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceDisplayProperties2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceDisplayProperties2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17428,7 +16620,6 @@
     VkDisplayPlaneProperties2KHR* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPlaneProperties2KHR encode");
     mImpl->log("start vkGetPhysicalDeviceDisplayPlaneProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17485,7 +16676,6 @@
             marshal_VkDisplayPlaneProperties2KHR(stream, (VkDisplayPlaneProperties2KHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPlaneProperties2KHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -17518,7 +16708,6 @@
             transform_fromhost_VkDisplayPlaneProperties2KHR(mImpl->resources(), (VkDisplayPlaneProperties2KHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceDisplayPlaneProperties2KHR returnUnmarshal");
     VkResult vkGetPhysicalDeviceDisplayPlaneProperties2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceDisplayPlaneProperties2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17535,7 +16724,6 @@
     VkDisplayModeProperties2KHR* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDisplayModeProperties2KHR encode");
     mImpl->log("start vkGetDisplayModeProperties2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17600,7 +16788,6 @@
             marshal_VkDisplayModeProperties2KHR(stream, (VkDisplayModeProperties2KHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetDisplayModeProperties2KHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPropertyCount;
     check_pPropertyCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -17633,7 +16820,6 @@
             transform_fromhost_VkDisplayModeProperties2KHR(mImpl->resources(), (VkDisplayModeProperties2KHR*)(pProperties + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetDisplayModeProperties2KHR returnUnmarshal");
     VkResult vkGetDisplayModeProperties2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetDisplayModeProperties2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17649,7 +16835,6 @@
     VkDisplayPlaneCapabilities2KHR* pCapabilities)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneCapabilities2KHR encode");
     mImpl->log("start vkGetDisplayPlaneCapabilities2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17687,13 +16872,11 @@
     stream->write((uint64_t*)&cgen_var_1138, 1 * 8);
     marshal_VkDisplayPlaneInfo2KHR(stream, (VkDisplayPlaneInfo2KHR*)(local_pDisplayPlaneInfo));
     marshal_VkDisplayPlaneCapabilities2KHR(stream, (VkDisplayPlaneCapabilities2KHR*)(pCapabilities));
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneCapabilities2KHR readParams");
     unmarshal_VkDisplayPlaneCapabilities2KHR(stream, (VkDisplayPlaneCapabilities2KHR*)(pCapabilities));
     if (pCapabilities)
     {
         transform_fromhost_VkDisplayPlaneCapabilities2KHR(mImpl->resources(), (VkDisplayPlaneCapabilities2KHR*)(pCapabilities));
     }
-    AEMU_SCOPED_TRACE("vkGetDisplayPlaneCapabilities2KHR returnUnmarshal");
     VkResult vkGetDisplayPlaneCapabilities2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkGetDisplayPlaneCapabilities2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -17717,7 +16900,6 @@
     VkMemoryRequirements2* pMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements2KHR encode");
     mImpl->log("start vkGetImageMemoryRequirements2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17755,13 +16937,11 @@
     stream->write((uint64_t*)&cgen_var_1140, 1 * 8);
     marshal_VkImageMemoryRequirementsInfo2(stream, (VkImageMemoryRequirementsInfo2*)(local_pInfo));
     marshal_VkMemoryRequirements2(stream, (VkMemoryRequirements2*)(pMemoryRequirements));
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements2KHR readParams");
     unmarshal_VkMemoryRequirements2(stream, (VkMemoryRequirements2*)(pMemoryRequirements));
     if (pMemoryRequirements)
     {
         transform_fromhost_VkMemoryRequirements2(mImpl->resources(), (VkMemoryRequirements2*)(pMemoryRequirements));
     }
-    AEMU_SCOPED_TRACE("vkGetImageMemoryRequirements2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -17774,7 +16954,6 @@
     VkMemoryRequirements2* pMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements2KHR encode");
     mImpl->log("start vkGetBufferMemoryRequirements2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17812,13 +16991,11 @@
     stream->write((uint64_t*)&cgen_var_1142, 1 * 8);
     marshal_VkBufferMemoryRequirementsInfo2(stream, (VkBufferMemoryRequirementsInfo2*)(local_pInfo));
     marshal_VkMemoryRequirements2(stream, (VkMemoryRequirements2*)(pMemoryRequirements));
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements2KHR readParams");
     unmarshal_VkMemoryRequirements2(stream, (VkMemoryRequirements2*)(pMemoryRequirements));
     if (pMemoryRequirements)
     {
         transform_fromhost_VkMemoryRequirements2(mImpl->resources(), (VkMemoryRequirements2*)(pMemoryRequirements));
     }
-    AEMU_SCOPED_TRACE("vkGetBufferMemoryRequirements2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -17832,7 +17009,6 @@
     VkSparseImageMemoryRequirements2* pSparseMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements2KHR encode");
     mImpl->log("start vkGetImageSparseMemoryRequirements2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -17902,7 +17078,6 @@
             marshal_VkSparseImageMemoryRequirements2(stream, (VkSparseImageMemoryRequirements2*)(pSparseMemoryRequirements + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements2KHR readParams");
     // WARNING PTR CHECK
     uint32_t* check_pSparseMemoryRequirementCount;
     check_pSparseMemoryRequirementCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -17935,7 +17110,6 @@
             transform_fromhost_VkSparseImageMemoryRequirements2(mImpl->resources(), (VkSparseImageMemoryRequirements2*)(pSparseMemoryRequirements + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetImageSparseMemoryRequirements2KHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -17953,7 +17127,6 @@
     VkSamplerYcbcrConversion* pYcbcrConversion)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateSamplerYcbcrConversionKHR encode");
     mImpl->log("start vkCreateSamplerYcbcrConversionKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18023,13 +17196,11 @@
     stream->handleMapping()->mapHandles_VkSamplerYcbcrConversion_u64(pYcbcrConversion, &cgen_var_1156, 1);
     stream->write((uint64_t*)&cgen_var_1156, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateSamplerYcbcrConversionKHR readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1157;
     stream->read((uint64_t*)&cgen_var_1157, 8);
     stream->handleMapping()->mapHandles_u64_VkSamplerYcbcrConversion(&cgen_var_1157, (VkSamplerYcbcrConversion*)pYcbcrConversion, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateSamplerYcbcrConversionKHR returnUnmarshal");
     VkResult vkCreateSamplerYcbcrConversionKHR_VkResult_return = (VkResult)0;
     stream->read(&vkCreateSamplerYcbcrConversionKHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -18045,7 +17216,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroySamplerYcbcrConversionKHR encode");
     mImpl->log("start vkDestroySamplerYcbcrConversionKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18102,8 +17272,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroySamplerYcbcrConversionKHR readParams");
-    AEMU_SCOPED_TRACE("vkDestroySamplerYcbcrConversionKHR returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkSamplerYcbcrConversion((VkSamplerYcbcrConversion*)&ycbcrConversion);
     pool->freeAll();
     countingStream->clearPool();
@@ -18119,7 +17287,6 @@
     const VkBindBufferMemoryInfo* pBindInfos)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkBindBufferMemory2KHR encode");
     mImpl->log("start vkBindBufferMemory2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18171,8 +17338,6 @@
     {
         marshal_VkBindBufferMemoryInfo(stream, (VkBindBufferMemoryInfo*)(local_pBindInfos + i));
     }
-    AEMU_SCOPED_TRACE("vkBindBufferMemory2KHR readParams");
-    AEMU_SCOPED_TRACE("vkBindBufferMemory2KHR returnUnmarshal");
     VkResult vkBindBufferMemory2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkBindBufferMemory2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -18188,7 +17353,6 @@
     const VkBindImageMemoryInfo* pBindInfos)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkBindImageMemory2KHR encode");
     mImpl->log("start vkBindImageMemory2KHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18240,8 +17404,6 @@
     {
         marshal_VkBindImageMemoryInfo(stream, (VkBindImageMemoryInfo*)(local_pBindInfos + i));
     }
-    AEMU_SCOPED_TRACE("vkBindImageMemory2KHR readParams");
-    AEMU_SCOPED_TRACE("vkBindImageMemory2KHR returnUnmarshal");
     VkResult vkBindImageMemory2KHR_VkResult_return = (VkResult)0;
     stream->read(&vkBindImageMemory2KHR_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -18259,7 +17421,6 @@
     VkDescriptorSetLayoutSupport* pSupport)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetDescriptorSetLayoutSupportKHR encode");
     mImpl->log("start vkGetDescriptorSetLayoutSupportKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18297,13 +17458,11 @@
     stream->write((uint64_t*)&cgen_var_1169, 1 * 8);
     marshal_VkDescriptorSetLayoutCreateInfo(stream, (VkDescriptorSetLayoutCreateInfo*)(local_pCreateInfo));
     marshal_VkDescriptorSetLayoutSupport(stream, (VkDescriptorSetLayoutSupport*)(pSupport));
-    AEMU_SCOPED_TRACE("vkGetDescriptorSetLayoutSupportKHR readParams");
     unmarshal_VkDescriptorSetLayoutSupport(stream, (VkDescriptorSetLayoutSupport*)(pSupport));
     if (pSupport)
     {
         transform_fromhost_VkDescriptorSetLayoutSupport(mImpl->resources(), (VkDescriptorSetLayoutSupport*)(pSupport));
     }
-    AEMU_SCOPED_TRACE("vkGetDescriptorSetLayoutSupportKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -18322,7 +17481,6 @@
     uint32_t stride)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirectCountKHR encode");
     mImpl->log("start vkCmdDrawIndirectCountKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18377,8 +17535,6 @@
     stream->write((VkDeviceSize*)&local_countBufferOffset, sizeof(VkDeviceSize));
     stream->write((uint32_t*)&local_maxDrawCount, sizeof(uint32_t));
     stream->write((uint32_t*)&local_stride, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirectCountKHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirectCountKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -18395,7 +17551,6 @@
     uint32_t stride)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirectCountKHR encode");
     mImpl->log("start vkCmdDrawIndexedIndirectCountKHR");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18450,8 +17605,6 @@
     stream->write((VkDeviceSize*)&local_countBufferOffset, sizeof(VkDeviceSize));
     stream->write((uint32_t*)&local_maxDrawCount, sizeof(uint32_t));
     stream->write((uint32_t*)&local_stride, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirectCountKHR readParams");
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirectCountKHR returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -18471,7 +17624,6 @@
     int* grallocUsage)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetSwapchainGrallocUsageANDROID encode");
     mImpl->log("start vkGetSwapchainGrallocUsageANDROID");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18504,9 +17656,7 @@
     stream->write((VkFormat*)&local_format, sizeof(VkFormat));
     stream->write((VkImageUsageFlags*)&local_imageUsage, sizeof(VkImageUsageFlags));
     stream->write((int*)grallocUsage, sizeof(int));
-    AEMU_SCOPED_TRACE("vkGetSwapchainGrallocUsageANDROID readParams");
     stream->read((int*)grallocUsage, sizeof(int));
-    AEMU_SCOPED_TRACE("vkGetSwapchainGrallocUsageANDROID returnUnmarshal");
     VkResult vkGetSwapchainGrallocUsageANDROID_VkResult_return = (VkResult)0;
     stream->read(&vkGetSwapchainGrallocUsageANDROID_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -18524,7 +17674,6 @@
     VkFence fence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkAcquireImageANDROID encode");
     mImpl->log("start vkAcquireImageANDROID");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18576,8 +17725,6 @@
     uint64_t cgen_var_1191;
     stream->handleMapping()->mapHandles_VkFence_u64(&local_fence, &cgen_var_1191, 1);
     stream->write((uint64_t*)&cgen_var_1191, 1 * 8);
-    AEMU_SCOPED_TRACE("vkAcquireImageANDROID readParams");
-    AEMU_SCOPED_TRACE("vkAcquireImageANDROID returnUnmarshal");
     VkResult vkAcquireImageANDROID_VkResult_return = (VkResult)0;
     stream->read(&vkAcquireImageANDROID_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -18595,7 +17742,6 @@
     int* pNativeFenceFd)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueSignalReleaseImageANDROID encode");
     mImpl->log("start vkQueueSignalReleaseImageANDROID");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18664,9 +17810,7 @@
     stream->handleMapping()->mapHandles_VkImage_u64(&local_image, &cgen_var_1199, 1);
     stream->write((uint64_t*)&cgen_var_1199, 1 * 8);
     stream->write((int*)pNativeFenceFd, sizeof(int));
-    AEMU_SCOPED_TRACE("vkQueueSignalReleaseImageANDROID readParams");
     stream->read((int*)pNativeFenceFd, sizeof(int));
-    AEMU_SCOPED_TRACE("vkQueueSignalReleaseImageANDROID returnUnmarshal");
     VkResult vkQueueSignalReleaseImageANDROID_VkResult_return = (VkResult)0;
     stream->read(&vkQueueSignalReleaseImageANDROID_VkResult_return, sizeof(VkResult));
     stream->flush();
@@ -18686,7 +17830,6 @@
     VkDebugReportCallbackEXT* pCallback)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDebugReportCallbackEXT encode");
     mImpl->log("start vkCreateDebugReportCallbackEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18756,13 +17899,11 @@
     stream->handleMapping()->mapHandles_VkDebugReportCallbackEXT_u64(pCallback, &cgen_var_1205, 1);
     stream->write((uint64_t*)&cgen_var_1205, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDebugReportCallbackEXT readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1206;
     stream->read((uint64_t*)&cgen_var_1206, 8);
     stream->handleMapping()->mapHandles_u64_VkDebugReportCallbackEXT(&cgen_var_1206, (VkDebugReportCallbackEXT*)pCallback, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateDebugReportCallbackEXT returnUnmarshal");
     VkResult vkCreateDebugReportCallbackEXT_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDebugReportCallbackEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -18778,7 +17919,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyDebugReportCallbackEXT encode");
     mImpl->log("start vkDestroyDebugReportCallbackEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18835,8 +17975,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyDebugReportCallbackEXT readParams");
-    AEMU_SCOPED_TRACE("vkDestroyDebugReportCallbackEXT returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkDebugReportCallbackEXT((VkDebugReportCallbackEXT*)&callback);
     pool->freeAll();
     countingStream->clearPool();
@@ -18855,7 +17993,6 @@
     const char* pMessage)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDebugReportMessageEXT encode");
     mImpl->log("start vkDebugReportMessageEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18916,8 +18053,6 @@
     stream->write((int32_t*)&local_messageCode, sizeof(int32_t));
     stream->putString(local_pLayerPrefix);
     stream->putString(local_pMessage);
-    AEMU_SCOPED_TRACE("vkDebugReportMessageEXT readParams");
-    AEMU_SCOPED_TRACE("vkDebugReportMessageEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -18943,7 +18078,6 @@
     const VkDebugMarkerObjectTagInfoEXT* pTagInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDebugMarkerSetObjectTagEXT encode");
     mImpl->log("start vkDebugMarkerSetObjectTagEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -18979,8 +18113,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1218, 1);
     stream->write((uint64_t*)&cgen_var_1218, 1 * 8);
     marshal_VkDebugMarkerObjectTagInfoEXT(stream, (VkDebugMarkerObjectTagInfoEXT*)(local_pTagInfo));
-    AEMU_SCOPED_TRACE("vkDebugMarkerSetObjectTagEXT readParams");
-    AEMU_SCOPED_TRACE("vkDebugMarkerSetObjectTagEXT returnUnmarshal");
     VkResult vkDebugMarkerSetObjectTagEXT_VkResult_return = (VkResult)0;
     stream->read(&vkDebugMarkerSetObjectTagEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -18995,7 +18127,6 @@
     const VkDebugMarkerObjectNameInfoEXT* pNameInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDebugMarkerSetObjectNameEXT encode");
     mImpl->log("start vkDebugMarkerSetObjectNameEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19031,8 +18162,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1220, 1);
     stream->write((uint64_t*)&cgen_var_1220, 1 * 8);
     marshal_VkDebugMarkerObjectNameInfoEXT(stream, (VkDebugMarkerObjectNameInfoEXT*)(local_pNameInfo));
-    AEMU_SCOPED_TRACE("vkDebugMarkerSetObjectNameEXT readParams");
-    AEMU_SCOPED_TRACE("vkDebugMarkerSetObjectNameEXT returnUnmarshal");
     VkResult vkDebugMarkerSetObjectNameEXT_VkResult_return = (VkResult)0;
     stream->read(&vkDebugMarkerSetObjectNameEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -19047,7 +18176,6 @@
     const VkDebugMarkerMarkerInfoEXT* pMarkerInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerBeginEXT encode");
     mImpl->log("start vkCmdDebugMarkerBeginEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19083,8 +18211,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1222, 1);
     stream->write((uint64_t*)&cgen_var_1222, 1 * 8);
     marshal_VkDebugMarkerMarkerInfoEXT(stream, (VkDebugMarkerMarkerInfoEXT*)(local_pMarkerInfo));
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerBeginEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerBeginEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19095,7 +18221,6 @@
     VkCommandBuffer commandBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerEndEXT encode");
     mImpl->log("start vkCmdDebugMarkerEndEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19118,8 +18243,6 @@
     uint64_t cgen_var_1224;
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1224, 1);
     stream->write((uint64_t*)&cgen_var_1224, 1 * 8);
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerEndEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerEndEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19131,7 +18254,6 @@
     const VkDebugMarkerMarkerInfoEXT* pMarkerInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerInsertEXT encode");
     mImpl->log("start vkCmdDebugMarkerInsertEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19167,8 +18289,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1226, 1);
     stream->write((uint64_t*)&cgen_var_1226, 1 * 8);
     marshal_VkDebugMarkerMarkerInfoEXT(stream, (VkDebugMarkerMarkerInfoEXT*)(local_pMarkerInfo));
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerInsertEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdDebugMarkerInsertEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19191,7 +18311,6 @@
     uint32_t stride)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirectCountAMD encode");
     mImpl->log("start vkCmdDrawIndirectCountAMD");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19246,8 +18365,6 @@
     stream->write((VkDeviceSize*)&local_countBufferOffset, sizeof(VkDeviceSize));
     stream->write((uint32_t*)&local_maxDrawCount, sizeof(uint32_t));
     stream->write((uint32_t*)&local_stride, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirectCountAMD readParams");
-    AEMU_SCOPED_TRACE("vkCmdDrawIndirectCountAMD returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19264,7 +18381,6 @@
     uint32_t stride)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirectCountAMD encode");
     mImpl->log("start vkCmdDrawIndexedIndirectCountAMD");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19319,8 +18435,6 @@
     stream->write((VkDeviceSize*)&local_countBufferOffset, sizeof(VkDeviceSize));
     stream->write((uint32_t*)&local_maxDrawCount, sizeof(uint32_t));
     stream->write((uint32_t*)&local_stride, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirectCountAMD readParams");
-    AEMU_SCOPED_TRACE("vkCmdDrawIndexedIndirectCountAMD returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19346,7 +18460,6 @@
     void* pInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetShaderInfoAMD encode");
     mImpl->log("start vkGetShaderInfoAMD");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19415,7 +18528,6 @@
     {
         stream->write((void*)pInfo, (*(pInfoSize)) * sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkGetShaderInfoAMD readParams");
     // WARNING PTR CHECK
     size_t* check_pInfoSize;
     check_pInfoSize = (size_t*)(uintptr_t)stream->getBe64();
@@ -19438,7 +18550,6 @@
         }
         stream->read((void*)pInfo, (*(pInfoSize)) * sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkGetShaderInfoAMD returnUnmarshal");
     VkResult vkGetShaderInfoAMD_VkResult_return = (VkResult)0;
     stream->read(&vkGetShaderInfoAMD_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -19465,7 +18576,6 @@
     VkExternalImageFormatPropertiesNV* pExternalImageFormatProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalImageFormatPropertiesNV encode");
     mImpl->log("start vkGetPhysicalDeviceExternalImageFormatPropertiesNV");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19514,13 +18624,11 @@
     stream->write((VkImageCreateFlags*)&local_flags, sizeof(VkImageCreateFlags));
     stream->write((VkExternalMemoryHandleTypeFlagsNV*)&local_externalHandleType, sizeof(VkExternalMemoryHandleTypeFlagsNV));
     marshal_VkExternalImageFormatPropertiesNV(stream, (VkExternalImageFormatPropertiesNV*)(pExternalImageFormatProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalImageFormatPropertiesNV readParams");
     unmarshal_VkExternalImageFormatPropertiesNV(stream, (VkExternalImageFormatPropertiesNV*)(pExternalImageFormatProperties));
     if (pExternalImageFormatProperties)
     {
         transform_fromhost_VkExternalImageFormatPropertiesNV(mImpl->resources(), (VkExternalImageFormatPropertiesNV*)(pExternalImageFormatProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceExternalImageFormatPropertiesNV returnUnmarshal");
     VkResult vkGetPhysicalDeviceExternalImageFormatPropertiesNV_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceExternalImageFormatPropertiesNV_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -19541,7 +18649,6 @@
     HANDLE* pHandle)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandleNV encode");
     mImpl->log("start vkGetMemoryWin32HandleNV");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19579,9 +18686,7 @@
     stream->write((uint64_t*)&cgen_var_1257, 1 * 8);
     stream->write((VkExternalMemoryHandleTypeFlagsNV*)&local_handleType, sizeof(VkExternalMemoryHandleTypeFlagsNV));
     stream->write((HANDLE*)pHandle, sizeof(HANDLE));
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandleNV readParams");
     stream->read((HANDLE*)pHandle, sizeof(HANDLE));
-    AEMU_SCOPED_TRACE("vkGetMemoryWin32HandleNV returnUnmarshal");
     VkResult vkGetMemoryWin32HandleNV_VkResult_return = (VkResult)0;
     stream->read(&vkGetMemoryWin32HandleNV_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -19604,7 +18709,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateViSurfaceNN encode");
     mImpl->log("start vkCreateViSurfaceNN");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19674,11 +18778,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_1263, 1);
     stream->write((uint64_t*)&cgen_var_1263, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateViSurfaceNN readParams");
     uint64_t cgen_var_1264;
     stream->read((uint64_t*)&cgen_var_1264, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_1264, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateViSurfaceNN returnUnmarshal");
     VkResult vkCreateViSurfaceNN_VkResult_return = (VkResult)0;
     stream->read(&vkCreateViSurfaceNN_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -19699,7 +18801,6 @@
     const VkConditionalRenderingBeginInfoEXT* pConditionalRenderingBegin)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBeginConditionalRenderingEXT encode");
     mImpl->log("start vkCmdBeginConditionalRenderingEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19735,8 +18836,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1266, 1);
     stream->write((uint64_t*)&cgen_var_1266, 1 * 8);
     marshal_VkConditionalRenderingBeginInfoEXT(stream, (VkConditionalRenderingBeginInfoEXT*)(local_pConditionalRenderingBegin));
-    AEMU_SCOPED_TRACE("vkCmdBeginConditionalRenderingEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdBeginConditionalRenderingEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19747,7 +18846,6 @@
     VkCommandBuffer commandBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdEndConditionalRenderingEXT encode");
     mImpl->log("start vkCmdEndConditionalRenderingEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19770,8 +18868,6 @@
     uint64_t cgen_var_1268;
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1268, 1);
     stream->write((uint64_t*)&cgen_var_1268, 1 * 8);
-    AEMU_SCOPED_TRACE("vkCmdEndConditionalRenderingEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdEndConditionalRenderingEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19785,7 +18881,6 @@
     const VkCmdProcessCommandsInfoNVX* pProcessCommandsInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdProcessCommandsNVX encode");
     mImpl->log("start vkCmdProcessCommandsNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19821,8 +18916,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1270, 1);
     stream->write((uint64_t*)&cgen_var_1270, 1 * 8);
     marshal_VkCmdProcessCommandsInfoNVX(stream, (VkCmdProcessCommandsInfoNVX*)(local_pProcessCommandsInfo));
-    AEMU_SCOPED_TRACE("vkCmdProcessCommandsNVX readParams");
-    AEMU_SCOPED_TRACE("vkCmdProcessCommandsNVX returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19834,7 +18927,6 @@
     const VkCmdReserveSpaceForCommandsInfoNVX* pReserveSpaceInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdReserveSpaceForCommandsNVX encode");
     mImpl->log("start vkCmdReserveSpaceForCommandsNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19870,8 +18962,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1272, 1);
     stream->write((uint64_t*)&cgen_var_1272, 1 * 8);
     marshal_VkCmdReserveSpaceForCommandsInfoNVX(stream, (VkCmdReserveSpaceForCommandsInfoNVX*)(local_pReserveSpaceInfo));
-    AEMU_SCOPED_TRACE("vkCmdReserveSpaceForCommandsNVX readParams");
-    AEMU_SCOPED_TRACE("vkCmdReserveSpaceForCommandsNVX returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -19885,7 +18975,6 @@
     VkIndirectCommandsLayoutNVX* pIndirectCommandsLayout)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateIndirectCommandsLayoutNVX encode");
     mImpl->log("start vkCreateIndirectCommandsLayoutNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -19955,13 +19044,11 @@
     stream->handleMapping()->mapHandles_VkIndirectCommandsLayoutNVX_u64(pIndirectCommandsLayout, &cgen_var_1278, 1);
     stream->write((uint64_t*)&cgen_var_1278, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateIndirectCommandsLayoutNVX readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1279;
     stream->read((uint64_t*)&cgen_var_1279, 8);
     stream->handleMapping()->mapHandles_u64_VkIndirectCommandsLayoutNVX(&cgen_var_1279, (VkIndirectCommandsLayoutNVX*)pIndirectCommandsLayout, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateIndirectCommandsLayoutNVX returnUnmarshal");
     VkResult vkCreateIndirectCommandsLayoutNVX_VkResult_return = (VkResult)0;
     stream->read(&vkCreateIndirectCommandsLayoutNVX_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -19977,7 +19064,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyIndirectCommandsLayoutNVX encode");
     mImpl->log("start vkDestroyIndirectCommandsLayoutNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20034,8 +19120,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyIndirectCommandsLayoutNVX readParams");
-    AEMU_SCOPED_TRACE("vkDestroyIndirectCommandsLayoutNVX returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkIndirectCommandsLayoutNVX((VkIndirectCommandsLayoutNVX*)&indirectCommandsLayout);
     pool->freeAll();
     countingStream->clearPool();
@@ -20050,7 +19134,6 @@
     VkObjectTableNVX* pObjectTable)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateObjectTableNVX encode");
     mImpl->log("start vkCreateObjectTableNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20120,13 +19203,11 @@
     stream->handleMapping()->mapHandles_VkObjectTableNVX_u64(pObjectTable, &cgen_var_1291, 1);
     stream->write((uint64_t*)&cgen_var_1291, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateObjectTableNVX readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1292;
     stream->read((uint64_t*)&cgen_var_1292, 8);
     stream->handleMapping()->mapHandles_u64_VkObjectTableNVX(&cgen_var_1292, (VkObjectTableNVX*)pObjectTable, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateObjectTableNVX returnUnmarshal");
     VkResult vkCreateObjectTableNVX_VkResult_return = (VkResult)0;
     stream->read(&vkCreateObjectTableNVX_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20142,7 +19223,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyObjectTableNVX encode");
     mImpl->log("start vkDestroyObjectTableNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20199,8 +19279,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyObjectTableNVX readParams");
-    AEMU_SCOPED_TRACE("vkDestroyObjectTableNVX returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkObjectTableNVX((VkObjectTableNVX*)&objectTable);
     pool->freeAll();
     countingStream->clearPool();
@@ -20216,7 +19294,6 @@
     const uint32_t* pObjectIndices)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkRegisterObjectsNVX encode");
     mImpl->log("start vkRegisterObjectsNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20264,8 +19341,6 @@
     stream->write((uint32_t*)&local_objectCount, sizeof(uint32_t));
     (void)local_ppObjectTableEntries;
     stream->write((uint32_t*)local_pObjectIndices, ((objectCount)) * sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkRegisterObjectsNVX readParams");
-    AEMU_SCOPED_TRACE("vkRegisterObjectsNVX returnUnmarshal");
     VkResult vkRegisterObjectsNVX_VkResult_return = (VkResult)0;
     stream->read(&vkRegisterObjectsNVX_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20283,7 +19358,6 @@
     const uint32_t* pObjectIndices)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkUnregisterObjectsNVX encode");
     mImpl->log("start vkUnregisterObjectsNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20334,8 +19408,6 @@
     stream->write((uint32_t*)&local_objectCount, sizeof(uint32_t));
     stream->write((VkObjectEntryTypeNVX*)local_pObjectEntryTypes, ((objectCount)) * sizeof(VkObjectEntryTypeNVX));
     stream->write((uint32_t*)local_pObjectIndices, ((objectCount)) * sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkUnregisterObjectsNVX readParams");
-    AEMU_SCOPED_TRACE("vkUnregisterObjectsNVX returnUnmarshal");
     VkResult vkUnregisterObjectsNVX_VkResult_return = (VkResult)0;
     stream->read(&vkUnregisterObjectsNVX_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20351,7 +19423,6 @@
     VkDeviceGeneratedCommandsLimitsNVX* pLimits)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX encode");
     mImpl->log("start vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20378,7 +19449,6 @@
     stream->write((uint64_t*)&cgen_var_1308, 1 * 8);
     marshal_VkDeviceGeneratedCommandsFeaturesNVX(stream, (VkDeviceGeneratedCommandsFeaturesNVX*)(pFeatures));
     marshal_VkDeviceGeneratedCommandsLimitsNVX(stream, (VkDeviceGeneratedCommandsLimitsNVX*)(pLimits));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX readParams");
     unmarshal_VkDeviceGeneratedCommandsFeaturesNVX(stream, (VkDeviceGeneratedCommandsFeaturesNVX*)(pFeatures));
     if (pFeatures)
     {
@@ -20389,7 +19459,6 @@
     {
         transform_fromhost_VkDeviceGeneratedCommandsLimitsNVX(mImpl->resources(), (VkDeviceGeneratedCommandsLimitsNVX*)(pLimits));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -20405,7 +19474,6 @@
     const VkViewportWScalingNV* pViewportWScalings)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetViewportWScalingNV encode");
     mImpl->log("start vkCmdSetViewportWScalingNV");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20461,8 +19529,6 @@
     {
         marshal_VkViewportWScalingNV(stream, (VkViewportWScalingNV*)(local_pViewportWScalings + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdSetViewportWScalingNV readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetViewportWScalingNV returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -20476,7 +19542,6 @@
     VkDisplayKHR display)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkReleaseDisplayEXT encode");
     mImpl->log("start vkReleaseDisplayEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20507,8 +19572,6 @@
     uint64_t cgen_var_1314;
     stream->handleMapping()->mapHandles_VkDisplayKHR_u64(&local_display, &cgen_var_1314, 1);
     stream->write((uint64_t*)&cgen_var_1314, 1 * 8);
-    AEMU_SCOPED_TRACE("vkReleaseDisplayEXT readParams");
-    AEMU_SCOPED_TRACE("vkReleaseDisplayEXT returnUnmarshal");
     VkResult vkReleaseDisplayEXT_VkResult_return = (VkResult)0;
     stream->read(&vkReleaseDisplayEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20526,7 +19589,6 @@
     VkDisplayKHR display)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkAcquireXlibDisplayEXT encode");
     mImpl->log("start vkAcquireXlibDisplayEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20559,9 +19621,7 @@
     uint64_t cgen_var_1318;
     stream->handleMapping()->mapHandles_VkDisplayKHR_u64(&local_display, &cgen_var_1318, 1);
     stream->write((uint64_t*)&cgen_var_1318, 1 * 8);
-    AEMU_SCOPED_TRACE("vkAcquireXlibDisplayEXT readParams");
     stream->read((Display*)dpy, sizeof(Display));
-    AEMU_SCOPED_TRACE("vkAcquireXlibDisplayEXT returnUnmarshal");
     VkResult vkAcquireXlibDisplayEXT_VkResult_return = (VkResult)0;
     stream->read(&vkAcquireXlibDisplayEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20578,7 +19638,6 @@
     VkDisplayKHR* pDisplay)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetRandROutputDisplayEXT encode");
     mImpl->log("start vkGetRandROutputDisplayEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20615,12 +19674,10 @@
     stream->handleMapping()->mapHandles_VkDisplayKHR_u64(pDisplay, &cgen_var_1322, 1);
     stream->write((uint64_t*)&cgen_var_1322, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkGetRandROutputDisplayEXT readParams");
     stream->read((Display*)dpy, sizeof(Display));
     uint64_t cgen_var_1323;
     stream->read((uint64_t*)&cgen_var_1323, 8);
     stream->handleMapping()->mapHandles_u64_VkDisplayKHR(&cgen_var_1323, (VkDisplayKHR*)pDisplay, 1);
-    AEMU_SCOPED_TRACE("vkGetRandROutputDisplayEXT returnUnmarshal");
     VkResult vkGetRandROutputDisplayEXT_VkResult_return = (VkResult)0;
     stream->read(&vkGetRandROutputDisplayEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20638,7 +19695,6 @@
     VkSurfaceCapabilities2EXT* pSurfaceCapabilities)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilities2EXT encode");
     mImpl->log("start vkGetPhysicalDeviceSurfaceCapabilities2EXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20671,13 +19727,11 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(&local_surface, &cgen_var_1327, 1);
     stream->write((uint64_t*)&cgen_var_1327, 1 * 8);
     marshal_VkSurfaceCapabilities2EXT(stream, (VkSurfaceCapabilities2EXT*)(pSurfaceCapabilities));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilities2EXT readParams");
     unmarshal_VkSurfaceCapabilities2EXT(stream, (VkSurfaceCapabilities2EXT*)(pSurfaceCapabilities));
     if (pSurfaceCapabilities)
     {
         transform_fromhost_VkSurfaceCapabilities2EXT(mImpl->resources(), (VkSurfaceCapabilities2EXT*)(pSurfaceCapabilities));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceSurfaceCapabilities2EXT returnUnmarshal");
     VkResult vkGetPhysicalDeviceSurfaceCapabilities2EXT_VkResult_return = (VkResult)0;
     stream->read(&vkGetPhysicalDeviceSurfaceCapabilities2EXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20695,7 +19749,6 @@
     const VkDisplayPowerInfoEXT* pDisplayPowerInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDisplayPowerControlEXT encode");
     mImpl->log("start vkDisplayPowerControlEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20739,8 +19792,6 @@
     stream->handleMapping()->mapHandles_VkDisplayKHR_u64(&local_display, &cgen_var_1331, 1);
     stream->write((uint64_t*)&cgen_var_1331, 1 * 8);
     marshal_VkDisplayPowerInfoEXT(stream, (VkDisplayPowerInfoEXT*)(local_pDisplayPowerInfo));
-    AEMU_SCOPED_TRACE("vkDisplayPowerControlEXT readParams");
-    AEMU_SCOPED_TRACE("vkDisplayPowerControlEXT returnUnmarshal");
     VkResult vkDisplayPowerControlEXT_VkResult_return = (VkResult)0;
     stream->read(&vkDisplayPowerControlEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20757,7 +19808,6 @@
     VkFence* pFence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkRegisterDeviceEventEXT encode");
     mImpl->log("start vkRegisterDeviceEventEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20827,11 +19877,9 @@
     stream->handleMapping()->mapHandles_VkFence_u64(pFence, &cgen_var_1337, 1);
     stream->write((uint64_t*)&cgen_var_1337, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkRegisterDeviceEventEXT readParams");
     uint64_t cgen_var_1338;
     stream->read((uint64_t*)&cgen_var_1338, 8);
     stream->handleMapping()->mapHandles_u64_VkFence(&cgen_var_1338, (VkFence*)pFence, 1);
-    AEMU_SCOPED_TRACE("vkRegisterDeviceEventEXT returnUnmarshal");
     VkResult vkRegisterDeviceEventEXT_VkResult_return = (VkResult)0;
     stream->read(&vkRegisterDeviceEventEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20849,7 +19897,6 @@
     VkFence* pFence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkRegisterDisplayEventEXT encode");
     mImpl->log("start vkRegisterDisplayEventEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20927,11 +19974,9 @@
     stream->handleMapping()->mapHandles_VkFence_u64(pFence, &cgen_var_1346, 1);
     stream->write((uint64_t*)&cgen_var_1346, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkRegisterDisplayEventEXT readParams");
     uint64_t cgen_var_1347;
     stream->read((uint64_t*)&cgen_var_1347, 8);
     stream->handleMapping()->mapHandles_u64_VkFence(&cgen_var_1347, (VkFence*)pFence, 1);
-    AEMU_SCOPED_TRACE("vkRegisterDisplayEventEXT returnUnmarshal");
     VkResult vkRegisterDisplayEventEXT_VkResult_return = (VkResult)0;
     stream->read(&vkRegisterDisplayEventEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -20948,7 +19993,6 @@
     uint64_t* pCounterValue)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetSwapchainCounterEXT encode");
     mImpl->log("start vkGetSwapchainCounterEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -20985,9 +20029,7 @@
     stream->write((uint64_t*)&cgen_var_1351, 1 * 8);
     stream->write((VkSurfaceCounterFlagBitsEXT*)&local_counter, sizeof(VkSurfaceCounterFlagBitsEXT));
     stream->write((uint64_t*)pCounterValue, sizeof(uint64_t));
-    AEMU_SCOPED_TRACE("vkGetSwapchainCounterEXT readParams");
     stream->read((uint64_t*)pCounterValue, sizeof(uint64_t));
-    AEMU_SCOPED_TRACE("vkGetSwapchainCounterEXT returnUnmarshal");
     VkResult vkGetSwapchainCounterEXT_VkResult_return = (VkResult)0;
     stream->read(&vkGetSwapchainCounterEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -21005,7 +20047,6 @@
     VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetRefreshCycleDurationGOOGLE encode");
     mImpl->log("start vkGetRefreshCycleDurationGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21038,13 +20079,11 @@
     stream->handleMapping()->mapHandles_VkSwapchainKHR_u64(&local_swapchain, &cgen_var_1355, 1);
     stream->write((uint64_t*)&cgen_var_1355, 1 * 8);
     marshal_VkRefreshCycleDurationGOOGLE(stream, (VkRefreshCycleDurationGOOGLE*)(pDisplayTimingProperties));
-    AEMU_SCOPED_TRACE("vkGetRefreshCycleDurationGOOGLE readParams");
     unmarshal_VkRefreshCycleDurationGOOGLE(stream, (VkRefreshCycleDurationGOOGLE*)(pDisplayTimingProperties));
     if (pDisplayTimingProperties)
     {
         transform_fromhost_VkRefreshCycleDurationGOOGLE(mImpl->resources(), (VkRefreshCycleDurationGOOGLE*)(pDisplayTimingProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetRefreshCycleDurationGOOGLE returnUnmarshal");
     VkResult vkGetRefreshCycleDurationGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkGetRefreshCycleDurationGOOGLE_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -21061,7 +20100,6 @@
     VkPastPresentationTimingGOOGLE* pPresentationTimings)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPastPresentationTimingGOOGLE encode");
     mImpl->log("start vkGetPastPresentationTimingGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21126,7 +20164,6 @@
             marshal_VkPastPresentationTimingGOOGLE(stream, (VkPastPresentationTimingGOOGLE*)(pPresentationTimings + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPastPresentationTimingGOOGLE readParams");
     // WARNING PTR CHECK
     uint32_t* check_pPresentationTimingCount;
     check_pPresentationTimingCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -21159,7 +20196,6 @@
             transform_fromhost_VkPastPresentationTimingGOOGLE(mImpl->resources(), (VkPastPresentationTimingGOOGLE*)(pPresentationTimings + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetPastPresentationTimingGOOGLE returnUnmarshal");
     VkResult vkGetPastPresentationTimingGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkGetPastPresentationTimingGOOGLE_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -21188,7 +20224,6 @@
     const VkRect2D* pDiscardRectangles)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetDiscardRectangleEXT encode");
     mImpl->log("start vkCmdSetDiscardRectangleEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21244,8 +20279,6 @@
     {
         marshal_VkRect2D(stream, (VkRect2D*)(local_pDiscardRectangles + i));
     }
-    AEMU_SCOPED_TRACE("vkCmdSetDiscardRectangleEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetDiscardRectangleEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -21265,7 +20298,6 @@
     const VkHdrMetadataEXT* pMetadata)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkSetHdrMetadataEXT encode");
     mImpl->log("start vkSetHdrMetadataEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21337,8 +20369,6 @@
     {
         marshal_VkHdrMetadataEXT(stream, (VkHdrMetadataEXT*)(local_pMetadata + i));
     }
-    AEMU_SCOPED_TRACE("vkSetHdrMetadataEXT readParams");
-    AEMU_SCOPED_TRACE("vkSetHdrMetadataEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -21354,7 +20384,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateIOSSurfaceMVK encode");
     mImpl->log("start vkCreateIOSSurfaceMVK");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21424,11 +20453,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_1377, 1);
     stream->write((uint64_t*)&cgen_var_1377, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateIOSSurfaceMVK readParams");
     uint64_t cgen_var_1378;
     stream->read((uint64_t*)&cgen_var_1378, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_1378, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateIOSSurfaceMVK returnUnmarshal");
     VkResult vkCreateIOSSurfaceMVK_VkResult_return = (VkResult)0;
     stream->read(&vkCreateIOSSurfaceMVK_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -21447,7 +20474,6 @@
     VkSurfaceKHR* pSurface)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateMacOSSurfaceMVK encode");
     mImpl->log("start vkCreateMacOSSurfaceMVK");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21517,11 +20543,9 @@
     stream->handleMapping()->mapHandles_VkSurfaceKHR_u64(pSurface, &cgen_var_1384, 1);
     stream->write((uint64_t*)&cgen_var_1384, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateMacOSSurfaceMVK readParams");
     uint64_t cgen_var_1385;
     stream->read((uint64_t*)&cgen_var_1385, 8);
     stream->handleMapping()->mapHandles_u64_VkSurfaceKHR(&cgen_var_1385, (VkSurfaceKHR*)pSurface, 1);
-    AEMU_SCOPED_TRACE("vkCreateMacOSSurfaceMVK returnUnmarshal");
     VkResult vkCreateMacOSSurfaceMVK_VkResult_return = (VkResult)0;
     stream->read(&vkCreateMacOSSurfaceMVK_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -21542,7 +20566,6 @@
     const VkDebugUtilsObjectNameInfoEXT* pNameInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkSetDebugUtilsObjectNameEXT encode");
     mImpl->log("start vkSetDebugUtilsObjectNameEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21578,8 +20601,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1387, 1);
     stream->write((uint64_t*)&cgen_var_1387, 1 * 8);
     marshal_VkDebugUtilsObjectNameInfoEXT(stream, (VkDebugUtilsObjectNameInfoEXT*)(local_pNameInfo));
-    AEMU_SCOPED_TRACE("vkSetDebugUtilsObjectNameEXT readParams");
-    AEMU_SCOPED_TRACE("vkSetDebugUtilsObjectNameEXT returnUnmarshal");
     VkResult vkSetDebugUtilsObjectNameEXT_VkResult_return = (VkResult)0;
     stream->read(&vkSetDebugUtilsObjectNameEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -21594,7 +20615,6 @@
     const VkDebugUtilsObjectTagInfoEXT* pTagInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkSetDebugUtilsObjectTagEXT encode");
     mImpl->log("start vkSetDebugUtilsObjectTagEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21630,8 +20650,6 @@
     stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1389, 1);
     stream->write((uint64_t*)&cgen_var_1389, 1 * 8);
     marshal_VkDebugUtilsObjectTagInfoEXT(stream, (VkDebugUtilsObjectTagInfoEXT*)(local_pTagInfo));
-    AEMU_SCOPED_TRACE("vkSetDebugUtilsObjectTagEXT readParams");
-    AEMU_SCOPED_TRACE("vkSetDebugUtilsObjectTagEXT returnUnmarshal");
     VkResult vkSetDebugUtilsObjectTagEXT_VkResult_return = (VkResult)0;
     stream->read(&vkSetDebugUtilsObjectTagEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -21646,7 +20664,6 @@
     const VkDebugUtilsLabelEXT* pLabelInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueBeginDebugUtilsLabelEXT encode");
     mImpl->log("start vkQueueBeginDebugUtilsLabelEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21682,8 +20699,6 @@
     stream->handleMapping()->mapHandles_VkQueue_u64(&local_queue, &cgen_var_1391, 1);
     stream->write((uint64_t*)&cgen_var_1391, 1 * 8);
     marshal_VkDebugUtilsLabelEXT(stream, (VkDebugUtilsLabelEXT*)(local_pLabelInfo));
-    AEMU_SCOPED_TRACE("vkQueueBeginDebugUtilsLabelEXT readParams");
-    AEMU_SCOPED_TRACE("vkQueueBeginDebugUtilsLabelEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -21694,7 +20709,6 @@
     VkQueue queue)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueEndDebugUtilsLabelEXT encode");
     mImpl->log("start vkQueueEndDebugUtilsLabelEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21717,8 +20731,6 @@
     uint64_t cgen_var_1393;
     stream->handleMapping()->mapHandles_VkQueue_u64(&local_queue, &cgen_var_1393, 1);
     stream->write((uint64_t*)&cgen_var_1393, 1 * 8);
-    AEMU_SCOPED_TRACE("vkQueueEndDebugUtilsLabelEXT readParams");
-    AEMU_SCOPED_TRACE("vkQueueEndDebugUtilsLabelEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -21730,7 +20742,6 @@
     const VkDebugUtilsLabelEXT* pLabelInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueInsertDebugUtilsLabelEXT encode");
     mImpl->log("start vkQueueInsertDebugUtilsLabelEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21766,8 +20777,6 @@
     stream->handleMapping()->mapHandles_VkQueue_u64(&local_queue, &cgen_var_1395, 1);
     stream->write((uint64_t*)&cgen_var_1395, 1 * 8);
     marshal_VkDebugUtilsLabelEXT(stream, (VkDebugUtilsLabelEXT*)(local_pLabelInfo));
-    AEMU_SCOPED_TRACE("vkQueueInsertDebugUtilsLabelEXT readParams");
-    AEMU_SCOPED_TRACE("vkQueueInsertDebugUtilsLabelEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -21779,7 +20788,6 @@
     const VkDebugUtilsLabelEXT* pLabelInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdBeginDebugUtilsLabelEXT encode");
     mImpl->log("start vkCmdBeginDebugUtilsLabelEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21815,8 +20823,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1397, 1);
     stream->write((uint64_t*)&cgen_var_1397, 1 * 8);
     marshal_VkDebugUtilsLabelEXT(stream, (VkDebugUtilsLabelEXT*)(local_pLabelInfo));
-    AEMU_SCOPED_TRACE("vkCmdBeginDebugUtilsLabelEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdBeginDebugUtilsLabelEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -21827,7 +20833,6 @@
     VkCommandBuffer commandBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdEndDebugUtilsLabelEXT encode");
     mImpl->log("start vkCmdEndDebugUtilsLabelEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21850,8 +20855,6 @@
     uint64_t cgen_var_1399;
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1399, 1);
     stream->write((uint64_t*)&cgen_var_1399, 1 * 8);
-    AEMU_SCOPED_TRACE("vkCmdEndDebugUtilsLabelEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdEndDebugUtilsLabelEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -21863,7 +20866,6 @@
     const VkDebugUtilsLabelEXT* pLabelInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdInsertDebugUtilsLabelEXT encode");
     mImpl->log("start vkCmdInsertDebugUtilsLabelEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21899,8 +20901,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1401, 1);
     stream->write((uint64_t*)&cgen_var_1401, 1 * 8);
     marshal_VkDebugUtilsLabelEXT(stream, (VkDebugUtilsLabelEXT*)(local_pLabelInfo));
-    AEMU_SCOPED_TRACE("vkCmdInsertDebugUtilsLabelEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdInsertDebugUtilsLabelEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -21914,7 +20914,6 @@
     VkDebugUtilsMessengerEXT* pMessenger)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateDebugUtilsMessengerEXT encode");
     mImpl->log("start vkCreateDebugUtilsMessengerEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -21984,13 +20983,11 @@
     stream->handleMapping()->mapHandles_VkDebugUtilsMessengerEXT_u64(pMessenger, &cgen_var_1407, 1);
     stream->write((uint64_t*)&cgen_var_1407, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateDebugUtilsMessengerEXT readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1408;
     stream->read((uint64_t*)&cgen_var_1408, 8);
     stream->handleMapping()->mapHandles_u64_VkDebugUtilsMessengerEXT(&cgen_var_1408, (VkDebugUtilsMessengerEXT*)pMessenger, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateDebugUtilsMessengerEXT returnUnmarshal");
     VkResult vkCreateDebugUtilsMessengerEXT_VkResult_return = (VkResult)0;
     stream->read(&vkCreateDebugUtilsMessengerEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -22006,7 +21003,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyDebugUtilsMessengerEXT encode");
     mImpl->log("start vkDestroyDebugUtilsMessengerEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22063,8 +21059,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyDebugUtilsMessengerEXT readParams");
-    AEMU_SCOPED_TRACE("vkDestroyDebugUtilsMessengerEXT returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkDebugUtilsMessengerEXT((VkDebugUtilsMessengerEXT*)&messenger);
     pool->freeAll();
     countingStream->clearPool();
@@ -22079,7 +21073,6 @@
     const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkSubmitDebugUtilsMessageEXT encode");
     mImpl->log("start vkSubmitDebugUtilsMessageEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22123,8 +21116,6 @@
     stream->write((VkDebugUtilsMessageSeverityFlagBitsEXT*)&local_messageSeverity, sizeof(VkDebugUtilsMessageSeverityFlagBitsEXT));
     stream->write((VkDebugUtilsMessageTypeFlagsEXT*)&local_messageTypes, sizeof(VkDebugUtilsMessageTypeFlagsEXT));
     marshal_VkDebugUtilsMessengerCallbackDataEXT(stream, (VkDebugUtilsMessengerCallbackDataEXT*)(local_pCallbackData));
-    AEMU_SCOPED_TRACE("vkSubmitDebugUtilsMessageEXT readParams");
-    AEMU_SCOPED_TRACE("vkSubmitDebugUtilsMessageEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -22139,7 +21130,6 @@
     VkAndroidHardwareBufferPropertiesANDROID* pProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetAndroidHardwareBufferPropertiesANDROID encode");
     mImpl->log("start vkGetAndroidHardwareBufferPropertiesANDROID");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22172,13 +21162,11 @@
     stream->write((uint64_t*)&cgen_var_1418, 1 * 8);
     stream->write((AHardwareBuffer*)local_buffer, sizeof(AHardwareBuffer));
     marshal_VkAndroidHardwareBufferPropertiesANDROID(stream, (VkAndroidHardwareBufferPropertiesANDROID*)(pProperties));
-    AEMU_SCOPED_TRACE("vkGetAndroidHardwareBufferPropertiesANDROID readParams");
     unmarshal_VkAndroidHardwareBufferPropertiesANDROID(stream, (VkAndroidHardwareBufferPropertiesANDROID*)(pProperties));
     if (pProperties)
     {
         transform_fromhost_VkAndroidHardwareBufferPropertiesANDROID(mImpl->resources(), (VkAndroidHardwareBufferPropertiesANDROID*)(pProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetAndroidHardwareBufferPropertiesANDROID returnUnmarshal");
     VkResult vkGetAndroidHardwareBufferPropertiesANDROID_VkResult_return = (VkResult)0;
     stream->read(&vkGetAndroidHardwareBufferPropertiesANDROID_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -22194,7 +21182,6 @@
     AHardwareBuffer** pBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetMemoryAndroidHardwareBufferANDROID encode");
     mImpl->log("start vkGetMemoryAndroidHardwareBufferANDROID");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22232,9 +21219,7 @@
     stream->write((uint64_t*)&cgen_var_1420, 1 * 8);
     marshal_VkMemoryGetAndroidHardwareBufferInfoANDROID(stream, (VkMemoryGetAndroidHardwareBufferInfoANDROID*)(local_pInfo));
     stream->write((AHardwareBuffer**)pBuffer, sizeof(AHardwareBuffer*));
-    AEMU_SCOPED_TRACE("vkGetMemoryAndroidHardwareBufferANDROID readParams");
     stream->read((AHardwareBuffer**)pBuffer, sizeof(AHardwareBuffer*));
-    AEMU_SCOPED_TRACE("vkGetMemoryAndroidHardwareBufferANDROID returnUnmarshal");
     VkResult vkGetMemoryAndroidHardwareBufferANDROID_VkResult_return = (VkResult)0;
     stream->read(&vkGetMemoryAndroidHardwareBufferANDROID_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -22261,7 +21246,6 @@
     const VkSampleLocationsInfoEXT* pSampleLocationsInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetSampleLocationsEXT encode");
     mImpl->log("start vkCmdSetSampleLocationsEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22297,8 +21281,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1422, 1);
     stream->write((uint64_t*)&cgen_var_1422, 1 * 8);
     marshal_VkSampleLocationsInfoEXT(stream, (VkSampleLocationsInfoEXT*)(local_pSampleLocationsInfo));
-    AEMU_SCOPED_TRACE("vkCmdSetSampleLocationsEXT readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetSampleLocationsEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -22311,7 +21293,6 @@
     VkMultisamplePropertiesEXT* pMultisampleProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMultisamplePropertiesEXT encode");
     mImpl->log("start vkGetPhysicalDeviceMultisamplePropertiesEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22340,13 +21321,11 @@
     stream->write((uint64_t*)&cgen_var_1424, 1 * 8);
     stream->write((VkSampleCountFlagBits*)&local_samples, sizeof(VkSampleCountFlagBits));
     marshal_VkMultisamplePropertiesEXT(stream, (VkMultisamplePropertiesEXT*)(pMultisampleProperties));
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMultisamplePropertiesEXT readParams");
     unmarshal_VkMultisamplePropertiesEXT(stream, (VkMultisamplePropertiesEXT*)(pMultisampleProperties));
     if (pMultisampleProperties)
     {
         transform_fromhost_VkMultisamplePropertiesEXT(mImpl->resources(), (VkMultisamplePropertiesEXT*)(pMultisampleProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetPhysicalDeviceMultisamplePropertiesEXT returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -22372,7 +21351,6 @@
     VkValidationCacheEXT* pValidationCache)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateValidationCacheEXT encode");
     mImpl->log("start vkCreateValidationCacheEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22442,13 +21420,11 @@
     stream->handleMapping()->mapHandles_VkValidationCacheEXT_u64(pValidationCache, &cgen_var_1430, 1);
     stream->write((uint64_t*)&cgen_var_1430, 8);
     stream->setHandleMapping(resources->unwrapMapping());
-    AEMU_SCOPED_TRACE("vkCreateValidationCacheEXT readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1431;
     stream->read((uint64_t*)&cgen_var_1431, 8);
     stream->handleMapping()->mapHandles_u64_VkValidationCacheEXT(&cgen_var_1431, (VkValidationCacheEXT*)pValidationCache, 1);
     stream->unsetHandleMapping();
-    AEMU_SCOPED_TRACE("vkCreateValidationCacheEXT returnUnmarshal");
     VkResult vkCreateValidationCacheEXT_VkResult_return = (VkResult)0;
     stream->read(&vkCreateValidationCacheEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -22464,7 +21440,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkDestroyValidationCacheEXT encode");
     mImpl->log("start vkDestroyValidationCacheEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22521,8 +21496,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkDestroyValidationCacheEXT readParams");
-    AEMU_SCOPED_TRACE("vkDestroyValidationCacheEXT returnUnmarshal");
     resources->destroyMapping()->mapHandles_VkValidationCacheEXT((VkValidationCacheEXT*)&validationCache);
     pool->freeAll();
     countingStream->clearPool();
@@ -22537,7 +21510,6 @@
     const VkValidationCacheEXT* pSrcCaches)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkMergeValidationCachesEXT encode");
     mImpl->log("start vkMergeValidationCachesEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22592,8 +21564,6 @@
         stream->handleMapping()->mapHandles_VkValidationCacheEXT_u64(local_pSrcCaches, cgen_var_1443, ((srcCacheCount)));
         stream->write((uint64_t*)cgen_var_1443, ((srcCacheCount)) * 8);
     }
-    AEMU_SCOPED_TRACE("vkMergeValidationCachesEXT readParams");
-    AEMU_SCOPED_TRACE("vkMergeValidationCachesEXT returnUnmarshal");
     VkResult vkMergeValidationCachesEXT_VkResult_return = (VkResult)0;
     stream->read(&vkMergeValidationCachesEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -22610,7 +21580,6 @@
     void* pData)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetValidationCacheDataEXT encode");
     mImpl->log("start vkGetValidationCacheDataEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22671,7 +21640,6 @@
     {
         stream->write((void*)pData, (*(pDataSize)) * sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkGetValidationCacheDataEXT readParams");
     // WARNING PTR CHECK
     size_t* check_pDataSize;
     check_pDataSize = (size_t*)(uintptr_t)stream->getBe64();
@@ -22694,7 +21662,6 @@
         }
         stream->read((void*)pData, (*(pDataSize)) * sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkGetValidationCacheDataEXT returnUnmarshal");
     VkResult vkGetValidationCacheDataEXT_VkResult_return = (VkResult)0;
     stream->read(&vkGetValidationCacheDataEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -22719,7 +21686,6 @@
     VkMemoryHostPointerPropertiesEXT* pMemoryHostPointerProperties)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetMemoryHostPointerPropertiesEXT encode");
     mImpl->log("start vkGetMemoryHostPointerPropertiesEXT");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22768,13 +21734,11 @@
         stream->write((void*)local_pHostPointer, sizeof(uint8_t));
     }
     marshal_VkMemoryHostPointerPropertiesEXT(stream, (VkMemoryHostPointerPropertiesEXT*)(pMemoryHostPointerProperties));
-    AEMU_SCOPED_TRACE("vkGetMemoryHostPointerPropertiesEXT readParams");
     unmarshal_VkMemoryHostPointerPropertiesEXT(stream, (VkMemoryHostPointerPropertiesEXT*)(pMemoryHostPointerProperties));
     if (pMemoryHostPointerProperties)
     {
         transform_fromhost_VkMemoryHostPointerPropertiesEXT(mImpl->resources(), (VkMemoryHostPointerPropertiesEXT*)(pMemoryHostPointerProperties));
     }
-    AEMU_SCOPED_TRACE("vkGetMemoryHostPointerPropertiesEXT returnUnmarshal");
     VkResult vkGetMemoryHostPointerPropertiesEXT_VkResult_return = (VkResult)0;
     stream->read(&vkGetMemoryHostPointerPropertiesEXT_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -22794,7 +21758,6 @@
     uint32_t marker)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdWriteBufferMarkerAMD encode");
     mImpl->log("start vkCmdWriteBufferMarkerAMD");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22837,8 +21800,6 @@
     stream->write((uint64_t*)&cgen_var_1464, 1 * 8);
     stream->write((VkDeviceSize*)&local_dstOffset, sizeof(VkDeviceSize));
     stream->write((uint32_t*)&local_marker, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCmdWriteBufferMarkerAMD readParams");
-    AEMU_SCOPED_TRACE("vkCmdWriteBufferMarkerAMD returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -22858,7 +21819,6 @@
     const void* pCheckpointMarker)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCmdSetCheckpointNV encode");
     mImpl->log("start vkCmdSetCheckpointNV");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22901,8 +21861,6 @@
     {
         stream->write((void*)local_pCheckpointMarker, sizeof(uint8_t));
     }
-    AEMU_SCOPED_TRACE("vkCmdSetCheckpointNV readParams");
-    AEMU_SCOPED_TRACE("vkCmdSetCheckpointNV returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -22915,7 +21873,6 @@
     VkCheckpointDataNV* pCheckpointData)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetQueueCheckpointDataNV encode");
     mImpl->log("start vkGetQueueCheckpointDataNV");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -22972,7 +21929,6 @@
             marshal_VkCheckpointDataNV(stream, (VkCheckpointDataNV*)(pCheckpointData + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetQueueCheckpointDataNV readParams");
     // WARNING PTR CHECK
     uint32_t* check_pCheckpointDataCount;
     check_pCheckpointDataCount = (uint32_t*)(uintptr_t)stream->getBe64();
@@ -23005,7 +21961,6 @@
             transform_fromhost_VkCheckpointDataNV(mImpl->resources(), (VkCheckpointDataNV*)(pCheckpointData + i));
         }
     }
-    AEMU_SCOPED_TRACE("vkGetQueueCheckpointDataNV returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -23020,7 +21975,6 @@
     uint64_t* pAddress)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkMapMemoryIntoAddressSpaceGOOGLE encode");
     mImpl->log("start vkMapMemoryIntoAddressSpaceGOOGLE");
     mImpl->resources()->on_vkMapMemoryIntoAddressSpaceGOOGLE_pre(this, VK_SUCCESS, device, memory, pAddress);
     auto stream = mImpl->stream();
@@ -23067,7 +22021,6 @@
     {
         stream->write((uint64_t*)pAddress, sizeof(uint64_t));
     }
-    AEMU_SCOPED_TRACE("vkMapMemoryIntoAddressSpaceGOOGLE readParams");
     // WARNING PTR CHECK
     uint64_t* check_pAddress;
     check_pAddress = (uint64_t*)(uintptr_t)stream->getBe64();
@@ -23079,7 +22032,6 @@
         }
         stream->read((uint64_t*)pAddress, sizeof(uint64_t));
     }
-    AEMU_SCOPED_TRACE("vkMapMemoryIntoAddressSpaceGOOGLE returnUnmarshal");
     VkResult vkMapMemoryIntoAddressSpaceGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkMapMemoryIntoAddressSpaceGOOGLE_VkResult_return, sizeof(VkResult));
     mImpl->resources()->on_vkMapMemoryIntoAddressSpaceGOOGLE(this, vkMapMemoryIntoAddressSpaceGOOGLE_VkResult_return, device, memory, pAddress);
@@ -23098,7 +22050,6 @@
     uint32_t colorBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkRegisterImageColorBufferGOOGLE encode");
     mImpl->log("start vkRegisterImageColorBufferGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23133,8 +22084,6 @@
     stream->handleMapping()->mapHandles_VkImage_u64(&local_image, &cgen_var_1487, 1);
     stream->write((uint64_t*)&cgen_var_1487, 1 * 8);
     stream->write((uint32_t*)&local_colorBuffer, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkRegisterImageColorBufferGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkRegisterImageColorBufferGOOGLE returnUnmarshal");
     VkResult vkRegisterImageColorBufferGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkRegisterImageColorBufferGOOGLE_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -23150,7 +22099,6 @@
     uint32_t colorBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkRegisterBufferColorBufferGOOGLE encode");
     mImpl->log("start vkRegisterBufferColorBufferGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23185,8 +22133,6 @@
     stream->handleMapping()->mapHandles_VkBuffer_u64(&local_buffer, &cgen_var_1491, 1);
     stream->write((uint64_t*)&cgen_var_1491, 1 * 8);
     stream->write((uint32_t*)&local_colorBuffer, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkRegisterBufferColorBufferGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkRegisterBufferColorBufferGOOGLE returnUnmarshal");
     VkResult vkRegisterBufferColorBufferGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkRegisterBufferColorBufferGOOGLE_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -23213,7 +22159,6 @@
     const VkBufferView* pBufferViews)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplateSizedGOOGLE encode");
     mImpl->log("start vkUpdateDescriptorSetWithTemplateSizedGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23430,8 +22375,6 @@
             stream->write((uint64_t*)cgen_var_1511, ((bufferViewCount)) * 8);
         }
     }
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplateSizedGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkUpdateDescriptorSetWithTemplateSizedGOOGLE returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -23445,7 +22388,6 @@
     const VkCommandBufferBeginInfo* pBeginInfo)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkBeginCommandBufferAsyncGOOGLE encode");
     mImpl->log("start vkBeginCommandBufferAsyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23481,8 +22423,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1513, 1);
     stream->write((uint64_t*)&cgen_var_1513, 1 * 8);
     marshal_VkCommandBufferBeginInfo(stream, (VkCommandBufferBeginInfo*)(local_pBeginInfo));
-    AEMU_SCOPED_TRACE("vkBeginCommandBufferAsyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkBeginCommandBufferAsyncGOOGLE returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -23493,7 +22433,6 @@
     VkCommandBuffer commandBuffer)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkEndCommandBufferAsyncGOOGLE encode");
     mImpl->log("start vkEndCommandBufferAsyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23516,8 +22455,6 @@
     uint64_t cgen_var_1515;
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1515, 1);
     stream->write((uint64_t*)&cgen_var_1515, 1 * 8);
-    AEMU_SCOPED_TRACE("vkEndCommandBufferAsyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkEndCommandBufferAsyncGOOGLE returnUnmarshal");
     stream->flush();
     pool->freeAll();
     countingStream->clearPool();
@@ -23530,7 +22467,6 @@
     VkCommandBufferResetFlags flags)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkResetCommandBufferAsyncGOOGLE encode");
     mImpl->log("start vkResetCommandBufferAsyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23557,8 +22493,6 @@
     stream->handleMapping()->mapHandles_VkCommandBuffer_u64(&local_commandBuffer, &cgen_var_1517, 1);
     stream->write((uint64_t*)&cgen_var_1517, 1 * 8);
     stream->write((VkCommandBufferResetFlags*)&local_flags, sizeof(VkCommandBufferResetFlags));
-    AEMU_SCOPED_TRACE("vkResetCommandBufferAsyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkResetCommandBufferAsyncGOOGLE returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -23571,7 +22505,6 @@
     uint32_t sequenceNumber)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCommandBufferHostSyncGOOGLE encode");
     mImpl->log("start vkCommandBufferHostSyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23602,8 +22535,6 @@
     stream->write((uint64_t*)&cgen_var_1519, 1 * 8);
     stream->write((uint32_t*)&local_needHostSync, sizeof(uint32_t));
     stream->write((uint32_t*)&local_sequenceNumber, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkCommandBufferHostSyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkCommandBufferHostSyncGOOGLE returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -23620,7 +22551,6 @@
     VkMemoryRequirements* pMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateImageWithRequirementsGOOGLE encode");
     mImpl->log("start vkCreateImageWithRequirementsGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23693,7 +22623,6 @@
     stream->write((uint64_t*)&cgen_var_1525, 8);
     stream->setHandleMapping(resources->unwrapMapping());
     marshal_VkMemoryRequirements(stream, (VkMemoryRequirements*)(pMemoryRequirements));
-    AEMU_SCOPED_TRACE("vkCreateImageWithRequirementsGOOGLE readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1526;
     stream->read((uint64_t*)&cgen_var_1526, 8);
@@ -23704,7 +22633,6 @@
     {
         transform_fromhost_VkMemoryRequirements(mImpl->resources(), (VkMemoryRequirements*)(pMemoryRequirements));
     }
-    AEMU_SCOPED_TRACE("vkCreateImageWithRequirementsGOOGLE returnUnmarshal");
     VkResult vkCreateImageWithRequirementsGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkCreateImageWithRequirementsGOOGLE_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -23722,7 +22650,6 @@
     VkMemoryRequirements* pMemoryRequirements)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkCreateBufferWithRequirementsGOOGLE encode");
     mImpl->log("start vkCreateBufferWithRequirementsGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23794,7 +22721,6 @@
     stream->write((uint64_t*)&cgen_var_1532, 8);
     stream->setHandleMapping(resources->unwrapMapping());
     marshal_VkMemoryRequirements(stream, (VkMemoryRequirements*)(pMemoryRequirements));
-    AEMU_SCOPED_TRACE("vkCreateBufferWithRequirementsGOOGLE readParams");
     stream->setHandleMapping(resources->createMapping());
     uint64_t cgen_var_1533;
     stream->read((uint64_t*)&cgen_var_1533, 8);
@@ -23805,7 +22731,6 @@
     {
         transform_fromhost_VkMemoryRequirements(mImpl->resources(), (VkMemoryRequirements*)(pMemoryRequirements));
     }
-    AEMU_SCOPED_TRACE("vkCreateBufferWithRequirementsGOOGLE returnUnmarshal");
     VkResult vkCreateBufferWithRequirementsGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkCreateBufferWithRequirementsGOOGLE_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -23825,7 +22750,6 @@
     uint64_t* pHostmemId)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkGetMemoryHostAddressInfoGOOGLE encode");
     mImpl->log("start vkGetMemoryHostAddressInfoGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -23899,7 +22823,6 @@
     {
         stream->write((uint64_t*)pHostmemId, sizeof(uint64_t));
     }
-    AEMU_SCOPED_TRACE("vkGetMemoryHostAddressInfoGOOGLE readParams");
     // WARNING PTR CHECK
     uint64_t* check_pAddress;
     check_pAddress = (uint64_t*)(uintptr_t)stream->getBe64();
@@ -23933,7 +22856,6 @@
         }
         stream->read((uint64_t*)pHostmemId, sizeof(uint64_t));
     }
-    AEMU_SCOPED_TRACE("vkGetMemoryHostAddressInfoGOOGLE returnUnmarshal");
     VkResult vkGetMemoryHostAddressInfoGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkGetMemoryHostAddressInfoGOOGLE_VkResult_return, sizeof(VkResult));
     pool->freeAll();
@@ -23951,7 +22873,6 @@
     const VkAllocationCallbacks* pAllocator)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkFreeMemorySyncGOOGLE encode");
     mImpl->log("start vkFreeMemorySyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -24005,8 +22926,6 @@
     {
         marshal_VkAllocationCallbacks(stream, (VkAllocationCallbacks*)(local_pAllocator));
     }
-    AEMU_SCOPED_TRACE("vkFreeMemorySyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkFreeMemorySyncGOOGLE returnUnmarshal");
     VkResult vkFreeMemorySyncGOOGLE_VkResult_return = (VkResult)0;
     stream->read(&vkFreeMemorySyncGOOGLE_VkResult_return, sizeof(VkResult));
     resources->destroyMapping()->mapHandles_VkDeviceMemory((VkDeviceMemory*)&memory);
@@ -24025,7 +22944,6 @@
     uint32_t sequenceNumber)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueHostSyncGOOGLE encode");
     mImpl->log("start vkQueueHostSyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -24056,8 +22974,6 @@
     stream->write((uint64_t*)&cgen_var_1554, 1 * 8);
     stream->write((uint32_t*)&local_needHostSync, sizeof(uint32_t));
     stream->write((uint32_t*)&local_sequenceNumber, sizeof(uint32_t));
-    AEMU_SCOPED_TRACE("vkQueueHostSyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkQueueHostSyncGOOGLE returnUnmarshal");
     pool->freeAll();
     countingStream->clearPool();
     stream->clearPool();
@@ -24071,7 +22987,6 @@
     VkFence fence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueSubmitAsyncGOOGLE encode");
     mImpl->log("start vkQueueSubmitAsyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -24131,8 +23046,6 @@
     uint64_t cgen_var_1558;
     stream->handleMapping()->mapHandles_VkFence_u64(&local_fence, &cgen_var_1558, 1);
     stream->write((uint64_t*)&cgen_var_1558, 1 * 8);
-    AEMU_SCOPED_TRACE("vkQueueSubmitAsyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkQueueSubmitAsyncGOOGLE returnUnmarshal");
     stream->flush();
     pool->freeAll();
     countingStream->clearPool();
@@ -24144,7 +23057,6 @@
     VkQueue queue)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueWaitIdleAsyncGOOGLE encode");
     mImpl->log("start vkQueueWaitIdleAsyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -24167,8 +23079,6 @@
     uint64_t cgen_var_1560;
     stream->handleMapping()->mapHandles_VkQueue_u64(&local_queue, &cgen_var_1560, 1);
     stream->write((uint64_t*)&cgen_var_1560, 1 * 8);
-    AEMU_SCOPED_TRACE("vkQueueWaitIdleAsyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkQueueWaitIdleAsyncGOOGLE returnUnmarshal");
     stream->flush();
     pool->freeAll();
     countingStream->clearPool();
@@ -24183,7 +23093,6 @@
     VkFence fence)
 {
     EncoderAutoLock encoderLock(this);
-    AEMU_SCOPED_TRACE("vkQueueBindSparseAsyncGOOGLE encode");
     mImpl->log("start vkQueueBindSparseAsyncGOOGLE");
     auto stream = mImpl->stream();
     auto countingStream = mImpl->countingStream();
@@ -24243,8 +23152,6 @@
     uint64_t cgen_var_1564;
     stream->handleMapping()->mapHandles_VkFence_u64(&local_fence, &cgen_var_1564, 1);
     stream->write((uint64_t*)&cgen_var_1564, 1 * 8);
-    AEMU_SCOPED_TRACE("vkQueueBindSparseAsyncGOOGLE readParams");
-    AEMU_SCOPED_TRACE("vkQueueBindSparseAsyncGOOGLE returnUnmarshal");
     stream->flush();
     pool->freeAll();
     countingStream->clearPool();
@@ -24253,5 +23160,52 @@
 }
 
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+void VkEncoder::vkGetLinearImageLayoutGOOGLE(
+    VkDevice device,
+    VkFormat format,
+    VkDeviceSize* pOffset,
+    VkDeviceSize* pRowPitchAlignment)
+{
+    EncoderAutoLock encoderLock(this);
+    mImpl->log("start vkGetLinearImageLayoutGOOGLE");
+    auto stream = mImpl->stream();
+    auto countingStream = mImpl->countingStream();
+    auto resources = mImpl->resources();
+    auto pool = mImpl->pool();
+    stream->setHandleMapping(resources->unwrapMapping());
+    VkDevice local_device;
+    VkFormat local_format;
+    local_device = device;
+    local_format = format;
+    countingStream->rewind();
+    {
+        uint64_t cgen_var_1565;
+        countingStream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1565, 1);
+        countingStream->write((uint64_t*)&cgen_var_1565, 1 * 8);
+        countingStream->write((VkFormat*)&local_format, sizeof(VkFormat));
+        countingStream->write((VkDeviceSize*)pOffset, sizeof(VkDeviceSize));
+        countingStream->write((VkDeviceSize*)pRowPitchAlignment, sizeof(VkDeviceSize));
+    }
+    uint32_t packetSize_vkGetLinearImageLayoutGOOGLE = 4 + 4 + (uint32_t)countingStream->bytesWritten();
+    countingStream->rewind();
+    uint32_t opcode_vkGetLinearImageLayoutGOOGLE = OP_vkGetLinearImageLayoutGOOGLE;
+    stream->write(&opcode_vkGetLinearImageLayoutGOOGLE, sizeof(uint32_t));
+    stream->write(&packetSize_vkGetLinearImageLayoutGOOGLE, sizeof(uint32_t));
+    uint64_t cgen_var_1566;
+    stream->handleMapping()->mapHandles_VkDevice_u64(&local_device, &cgen_var_1566, 1);
+    stream->write((uint64_t*)&cgen_var_1566, 1 * 8);
+    stream->write((VkFormat*)&local_format, sizeof(VkFormat));
+    stream->write((VkDeviceSize*)pOffset, sizeof(VkDeviceSize));
+    stream->write((VkDeviceSize*)pRowPitchAlignment, sizeof(VkDeviceSize));
+    stream->read((VkDeviceSize*)pOffset, sizeof(VkDeviceSize));
+    stream->read((VkDeviceSize*)pRowPitchAlignment, sizeof(VkDeviceSize));
+    pool->freeAll();
+    countingStream->clearPool();
+    stream->clearPool();
+    mImpl->log("finish vkGetLinearImageLayoutGOOGLE");;
+}
+
+#endif
 
 } // namespace goldfish_vk
diff --git a/system/vulkan_enc/VkEncoder.cpp.inl b/system/vulkan_enc/VkEncoder.cpp.inl
new file mode 100644
index 0000000..5e1c5f3
--- /dev/null
+++ b/system/vulkan_enc/VkEncoder.cpp.inl
@@ -0,0 +1,124 @@
+
+class VkEncoder::Impl {
+public:
+    Impl(IOStream* stream) : m_stream(stream), m_logEncodes(false) {
+        m_stream.incStreamRef();
+        const char* emuVkLogEncodesPropName = "qemu.vk.log";
+        char encodeProp[PROPERTY_VALUE_MAX];
+        if (property_get(emuVkLogEncodesPropName, encodeProp, nullptr) > 0) {
+            m_logEncodes = atoi(encodeProp) > 0;
+        }
+    }
+
+    ~Impl() {
+        m_stream.decStreamRef();
+    }
+
+    VulkanCountingStream* countingStream() { return &m_countingStream; }
+    VulkanStreamGuest* stream() { return &m_stream; }
+    Pool* pool() { return &m_pool; }
+    ResourceTracker* resources() { return ResourceTracker::get(); }
+    Validation* validation() { return &m_validation; }
+
+    void log(const char* text) {
+        if (!m_logEncodes) return;
+        ALOGD("encoder log: %s", text);
+    }
+
+    void flush() {
+        lock();
+        m_stream.flush();
+        unlock();
+    }
+
+    // can be recursive
+    void lock() {
+        if (this == sAcquiredEncoderThreadLocal) {
+            ++sAcquiredEncoderThreadLockLevels;
+            return; // recursive
+        }
+        while (mLock.test_and_set(std::memory_order_acquire));
+        sAcquiredEncoderThreadLocal = this;
+        sAcquiredEncoderThreadLockLevels = 1;
+    }
+
+    void unlock() {
+        if (this != sAcquiredEncoderThreadLocal) {
+            // error, trying to unlock without having locked first
+            return;
+        }
+
+        --sAcquiredEncoderThreadLockLevels;
+        if (0 == sAcquiredEncoderThreadLockLevels) {
+            mLock.clear(std::memory_order_release);
+            sAcquiredEncoderThreadLocal = nullptr;
+        }
+    }
+
+    void incRef() {
+        __atomic_add_fetch(&m_refCount, 1, __ATOMIC_SEQ_CST);
+    }
+
+    bool decRef() {
+        if (0 == __atomic_sub_fetch(&m_refCount, 1, __ATOMIC_SEQ_CST)) {
+            return true;
+        }
+        return false;
+    }
+
+private:
+    VulkanCountingStream m_countingStream;
+    VulkanStreamGuest m_stream;
+    Pool m_pool { 8, 4096, 64 };
+
+    Validation m_validation;
+    bool m_logEncodes;
+    std::atomic_flag mLock = ATOMIC_FLAG_INIT;
+    static thread_local Impl* sAcquiredEncoderThreadLocal;
+    static thread_local uint32_t sAcquiredEncoderThreadLockLevels;
+    uint32_t m_refCount = 1;
+};
+
+VkEncoder::~VkEncoder() { }
+
+// static
+thread_local VkEncoder::Impl* VkEncoder::Impl::sAcquiredEncoderThreadLocal = nullptr;
+thread_local uint32_t VkEncoder::Impl::sAcquiredEncoderThreadLockLevels = 0;
+
+struct EncoderAutoLock {
+    EncoderAutoLock(VkEncoder* enc) : mEnc(enc) {
+        mEnc->lock();
+    }
+    ~EncoderAutoLock() {
+        mEnc->unlock();
+    }
+    VkEncoder* mEnc;
+};
+
+VkEncoder::VkEncoder(IOStream *stream) :
+    mImpl(new VkEncoder::Impl(stream)) { }
+
+void VkEncoder::flush() {
+    mImpl->flush();
+}
+
+void VkEncoder::lock() {
+    mImpl->lock();
+}
+
+void VkEncoder::unlock() {
+    mImpl->unlock();
+}
+
+void VkEncoder::incRef() {
+    mImpl->incRef();
+}
+
+bool VkEncoder::decRef() {
+    if (mImpl->decRef()) {
+        delete this;
+        return true;
+    }
+    return false;
+}
+
diff --git a/system/vulkan_enc/VkEncoder.h b/system/vulkan_enc/VkEncoder.h
index bde9ab8..d263823 100644
--- a/system/vulkan_enc/VkEncoder.h
+++ b/system/vulkan_enc/VkEncoder.h
@@ -40,9 +40,7 @@
     VkEncoder(IOStream* stream);
     ~VkEncoder();
 
-    void flush();
-    void lock();
-    void unlock();
+#include "VkEncoder.h.inl"
 #ifdef VK_VERSION_1_0
     VkResult vkCreateInstance(
     const VkInstanceCreateInfo* pCreateInfo,
@@ -1838,6 +1836,13 @@
         const VkBindSparseInfo* pBindInfo,
         VkFence fence);
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+    void vkGetLinearImageLayoutGOOGLE(
+    VkDevice device,
+        VkFormat format,
+        VkDeviceSize* pOffset,
+        VkDeviceSize* pRowPitchAlignment);
+#endif
 
 private:
     class Impl;
diff --git a/system/vulkan_enc/VkEncoder.h.inl b/system/vulkan_enc/VkEncoder.h.inl
new file mode 100644
index 0000000..d415596
--- /dev/null
+++ b/system/vulkan_enc/VkEncoder.h.inl
@@ -0,0 +1,5 @@
+    void flush();
+    void lock();
+    void unlock();
+    void incRef();
+    bool decRef();
diff --git a/system/vulkan_enc/VulkanStreamGuest.cpp b/system/vulkan_enc/VulkanStreamGuest.cpp
index 43f3706..32993b6 100644
--- a/system/vulkan_enc/VulkanStreamGuest.cpp
+++ b/system/vulkan_enc/VulkanStreamGuest.cpp
@@ -84,6 +84,14 @@
         return mFeatureBits;
     }
 
+    void incStreamRef() {
+        mStream->incRef();
+    }
+
+    bool decStreamRef() {
+        return mStream->decRef();
+    }
+
 private:
     size_t oustandingWriteBuffer() const {
         return mWritePos;
@@ -190,6 +198,14 @@
     return mImpl->getFeatureBits();
 }
 
+void VulkanStreamGuest::incStreamRef() {
+    mImpl->incStreamRef();
+}
+
+bool VulkanStreamGuest::decStreamRef() {
+    return mImpl->decStreamRef();
+}
+
 VulkanCountingStream::VulkanCountingStream() : VulkanStreamGuest(nullptr) { }
 VulkanCountingStream::~VulkanCountingStream() = default;
 
diff --git a/system/vulkan_enc/VulkanStreamGuest.h b/system/vulkan_enc/VulkanStreamGuest.h
index d70b9fb..e8425e1 100644
--- a/system/vulkan_enc/VulkanStreamGuest.h
+++ b/system/vulkan_enc/VulkanStreamGuest.h
@@ -56,6 +56,9 @@
 
     uint32_t getFeatureBits() const;
 
+    void incStreamRef();
+    bool decStreamRef();
+
 private:
     class Impl;
     std::unique_ptr<Impl> mImpl;
diff --git a/system/vulkan_enc/goldfish_vk_deepcopy_guest.cpp b/system/vulkan_enc/goldfish_vk_deepcopy_guest.cpp
index 4f59d21..512554f 100644
--- a/system/vulkan_enc/goldfish_vk_deepcopy_guest.cpp
+++ b/system/vulkan_enc/goldfish_vk_deepcopy_guest.cpp
@@ -6426,6 +6426,8 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 void deepcopy_extension_struct(
     Pool* pool,
     const void* structExtension,
diff --git a/system/vulkan_enc/goldfish_vk_deepcopy_guest.h b/system/vulkan_enc/goldfish_vk_deepcopy_guest.h
index 243240a..8cca9b1 100644
--- a/system/vulkan_enc/goldfish_vk_deepcopy_guest.h
+++ b/system/vulkan_enc/goldfish_vk_deepcopy_guest.h
@@ -2046,5 +2046,7 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 
 } // namespace goldfish_vk
diff --git a/system/vulkan_enc/goldfish_vk_extension_structs_guest.cpp b/system/vulkan_enc/goldfish_vk_extension_structs_guest.cpp
index 1bc69fa..ee84c21 100644
--- a/system/vulkan_enc/goldfish_vk_extension_structs_guest.cpp
+++ b/system/vulkan_enc/goldfish_vk_extension_structs_guest.cpp
@@ -292,6 +292,8 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 uint32_t goldfish_vk_struct_type(
     const void* structExtension)
 {
diff --git a/system/vulkan_enc/goldfish_vk_extension_structs_guest.h b/system/vulkan_enc/goldfish_vk_extension_structs_guest.h
index 9d91cdc..e549de9 100644
--- a/system/vulkan_enc/goldfish_vk_extension_structs_guest.h
+++ b/system/vulkan_enc/goldfish_vk_extension_structs_guest.h
@@ -313,5 +313,7 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 
 } // namespace goldfish_vk
diff --git a/system/vulkan_enc/goldfish_vk_handlemap_guest.cpp b/system/vulkan_enc/goldfish_vk_handlemap_guest.cpp
index 2e22fb0..ff9a069 100644
--- a/system/vulkan_enc/goldfish_vk_handlemap_guest.cpp
+++ b/system/vulkan_enc/goldfish_vk_handlemap_guest.cpp
@@ -4782,6 +4782,8 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 void handlemap_extension_struct(
     VulkanHandleMapping* handlemap,
     void* structExtension_out)
diff --git a/system/vulkan_enc/goldfish_vk_handlemap_guest.h b/system/vulkan_enc/goldfish_vk_handlemap_guest.h
index 79eeaf6..88fca6c 100644
--- a/system/vulkan_enc/goldfish_vk_handlemap_guest.h
+++ b/system/vulkan_enc/goldfish_vk_handlemap_guest.h
@@ -1697,5 +1697,7 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 
 } // namespace goldfish_vk
diff --git a/system/vulkan_enc/goldfish_vk_marshaling_guest.cpp b/system/vulkan_enc/goldfish_vk_marshaling_guest.cpp
index f857a2a..15fa96f 100644
--- a/system/vulkan_enc/goldfish_vk_marshaling_guest.cpp
+++ b/system/vulkan_enc/goldfish_vk_marshaling_guest.cpp
@@ -10370,6 +10370,8 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 void marshal_extension_struct(
     VulkanStreamGuest* vkStream,
     const void* structExtension)
@@ -13241,6 +13243,12 @@
             return "OP_vkQueueBindSparseAsyncGOOGLE";
         }
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+        case OP_vkGetLinearImageLayoutGOOGLE:
+        {
+            return "OP_vkGetLinearImageLayoutGOOGLE";
+        }
+#endif
         default:
         {
             return "OP_UNKNOWN_API_CALL";
diff --git a/system/vulkan_enc/goldfish_vk_marshaling_guest.h b/system/vulkan_enc/goldfish_vk_marshaling_guest.h
index df07272..d8cb1b0 100644
--- a/system/vulkan_enc/goldfish_vk_marshaling_guest.h
+++ b/system/vulkan_enc/goldfish_vk_marshaling_guest.h
@@ -3424,6 +3424,9 @@
 #define OP_vkQueueWaitIdleAsyncGOOGLE 20331
 #define OP_vkQueueBindSparseAsyncGOOGLE 20332
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#define OP_vkGetLinearImageLayoutGOOGLE 20333
+#endif
 const char* api_opcode_to_string(
     const uint32_t opcode);
 
diff --git a/system/vulkan_enc/goldfish_vk_private_defs.h b/system/vulkan_enc/goldfish_vk_private_defs.h
index dc4b7c6..b844cdd 100644
--- a/system/vulkan_enc/goldfish_vk_private_defs.h
+++ b/system/vulkan_enc/goldfish_vk_private_defs.h
@@ -282,6 +282,13 @@
      *   OpenGL ES: GL_STENCIL_INDEX8
      */
     AHARDWAREBUFFER_FORMAT_S8_UINT                  = 0x35,
+    /**
+     * YUV 420 888 format.
+     * Must have an even width and height. Can be accessed in OpenGL
+     * shaders through an external sampler. Does not support mip-maps
+     * cube-maps or multi-layered textures.
+     */
+    AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420             = 0x23,
 };
 /**
  * Buffer usage flags, specifying how the buffer will be accessed.
@@ -618,6 +625,10 @@
 typedef void (VKAPI_PTR *PFN_vkQueueBindSparseAsyncGOOGLE)(
     VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, VkFence fence);
 
+#define VK_GOOGLE_linear_image_layout 1
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetLinearImageLayoutGOOGLE)(VkDevice device, VkFormat format, VkDeviceSize* pOffset, VkDeviceSize* pRowPitchAlignment);
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/system/vulkan_enc/goldfish_vk_transform_guest.cpp b/system/vulkan_enc/goldfish_vk_transform_guest.cpp
index 6fc3e46..b829c49 100644
--- a/system/vulkan_enc/goldfish_vk_transform_guest.cpp
+++ b/system/vulkan_enc/goldfish_vk_transform_guest.cpp
@@ -9003,6 +9003,8 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 void transform_tohost_extension_struct(
     ResourceTracker* resourceTracker,
     void* structExtension_out)
diff --git a/system/vulkan_enc/goldfish_vk_transform_guest.h b/system/vulkan_enc/goldfish_vk_transform_guest.h
index b969958..b29e205 100644
--- a/system/vulkan_enc/goldfish_vk_transform_guest.h
+++ b/system/vulkan_enc/goldfish_vk_transform_guest.h
@@ -3093,5 +3093,7 @@
 #endif
 #ifdef VK_GOOGLE_async_queue_submit
 #endif
+#ifdef VK_GOOGLE_linear_image_layout
+#endif
 
 } // namespace goldfish_vk
diff --git a/system/vulkan_enc/vk_format_info.h b/system/vulkan_enc/vk_format_info.h
index dd9c99b..d80d9c3 100644
--- a/system/vulkan_enc/vk_format_info.h
+++ b/system/vulkan_enc/vk_format_info.h
@@ -29,6 +29,11 @@
 #include <stdbool.h>
 #ifdef VK_USE_PLATFORM_ANDROID_KHR
 #include <system/graphics.h>
+#else
+/* See system/graphics.h. */
+enum {
+    HAL_PIXEL_FORMAT_YV12 = 842094169,
+};
 #endif
 #include <vulkan/vulkan.h>
 #include <vndk/hardware_buffer.h>
@@ -36,6 +41,11 @@
 /* See i915_private_android_types.h in minigbm. */
 #define HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL 0x100
 
+// TODO(b/167698976): We should not use OMX_COLOR_FormatYUV420Planar
+// but we seem to miss a format translation somewhere.
+
+#define OMX_COLOR_FormatYUV420Planar 0x13
+
 static inline VkFormat
 vk_format_from_android(unsigned android_format)
 {
@@ -54,11 +64,12 @@
       return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
    case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL:
       return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
+   case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
+      return VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
 #ifdef VK_USE_PLATFORM_ANDROID_KHR
    case HAL_PIXEL_FORMAT_YV12:
-      // YUV converter will convert this format to R8G8B8A8
-      // TODO: should we use R8G8B8A8 for other YUV format as well?
-      return VK_FORMAT_R8G8B8A8_UNORM;
+   case OMX_COLOR_FormatYUV420Planar:
+      return VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
    case AHARDWAREBUFFER_FORMAT_BLOB:
 #endif
    default:
@@ -82,6 +93,8 @@
       return AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
    case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
       return HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL;
+   case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
+      return HAL_PIXEL_FORMAT_YV12;
    default:
       return AHARDWAREBUFFER_FORMAT_BLOB;
    }
@@ -92,6 +105,8 @@
 {
    switch (android_format) {
    case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL:
+   case OMX_COLOR_FormatYUV420Planar:
+   case HAL_PIXEL_FORMAT_YV12:
       return true;
 
    default:
diff --git a/system/vulkan_enc/vk_struct_id.h b/system/vulkan_enc/vk_struct_id.h
index b720edf..0aaf7a9 100644
--- a/system/vulkan_enc/vk_struct_id.h
+++ b/system/vulkan_enc/vk_struct_id.h
@@ -52,5 +52,6 @@
 REGISTER_VK_STRUCT_ID(VkFenceCreateInfo, VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
 REGISTER_VK_STRUCT_ID(VkExportFenceCreateInfo, VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO);
 REGISTER_VK_STRUCT_ID(VkImportBufferGOOGLE, VK_STRUCTURE_TYPE_IMPORT_BUFFER_GOOGLE);
+REGISTER_VK_STRUCT_ID(VkExternalImageFormatProperties, VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES);
 
 #undef REGISTER_VK_STRUCT_ID