Vulkan: Autogen mandatory texture caps

* This commit includes a JS file to execute on the spec and
generate the JSON output of all the mandatory texture caps.

Bug: angleproject:2348

Change-Id: I57e969915bdd0e7104e00a73fd3743ff1ecf0a6d
Reviewed-on: https://chromium-review.googlesource.com/911615
Commit-Queue: Luc Ferron <lucferron@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/scripts/run_code_generation.py b/scripts/run_code_generation.py
index a0cded0..ac7887b 100755
--- a/scripts/run_code_generation.py
+++ b/scripts/run_code_generation.py
@@ -136,6 +136,17 @@
         ],
         'script': 'src/libANGLE/renderer/vulkan/gen_vk_format_table.py',
     },
+    'Vulkan mandatory format support table': {
+        'inputs': [
+            'src/libANGLE/renderer/angle_format.py',
+            'third_party/vulkan-validation-layers/src/scripts/vk.xml',
+            'src/libANGLE/renderer/vulkan/vk_mandatory_format_support_data.json',
+        ],
+        'outputs': [
+            'src/libANGLE/renderer/vulkan/vk_mandatory_format_support_table_autogen.cpp',
+        ],
+        'script': 'src/libANGLE/renderer/vulkan/gen_vk_mandatory_format_support_table.py',
+    },
 }
 
 root_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
diff --git a/scripts/vk_mandatory_format_support_capture_to_json.js b/scripts/vk_mandatory_format_support_capture_to_json.js
new file mode 100644
index 0000000..0839f83
--- /dev/null
+++ b/scripts/vk_mandatory_format_support_capture_to_json.js
@@ -0,0 +1,77 @@
+/**
+ * Copyright 2018 The ANGLE Project Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ * This script is meant to be executed agaisnt the vulkan spec 31.3.3 tables.
+ * Instructions: Copy all the tables from the HTML source to a plain document
+ * and add a textarea at the bottom with ID='result'. Execute this JS on load
+ * of the document and you should have a JSON string in the textarea with the
+ * mandatory specs included. If the spec changes format / CSS in any way, the
+ * selectors will need to be modified.
+ **/
+var indexToFeatureMap = [];
+var index = 12;
+
+var outputJson = {};
+
+// Map all features to indexes of squares.
+$("#features-formats-mandatory-features-subbyte td").each(function() {
+  $this = $(this);
+  $this.find("code").each(function() {
+    if ($(this).text().startsWith("VK_FORMAT_FEATURE")) {
+        indexToFeatureMap[index--] = $(this).text();
+    }
+  });
+});
+
+var allTableIds =
+  ["features-formats-mandatory-features-subbyte",
+  "features-formats-mandatory-features-2byte",
+  "features-formats-mandatory-features-4byte",
+  "features-formats-mandatory-features-10bit",
+  "features-formats-mandatory-features-16bit",
+  "features-formats-mandatory-features-32bit",
+  "features-formats-mandatory-features-64bit",
+  "features-formats-mandatory-features-depth-stencil",
+  "features-formats-mandatory-features-features-bcn",
+  "features-formats-mandatory-features-features-etc",
+  "features-formats-mandatory-features-features-astc"];
+
+for (var i = 0; i < allTableIds.length; i++) {
+  $("#" + allTableIds[i] + " td").each(function() {
+    $this = $(this);
+
+    $this.find("code").each(function() {
+      if (!$(this).text().startsWith("VK_FORMAT_FEATURE") &&
+          $(this).text().startsWith("VK_FORMAT")) {
+        // Found one vkFormat to features line.
+        var vkFormat = $(this).text();
+        var squareIndex = 0;
+        var features = [];
+        var skipEntry = false;
+
+        $(this).closest("tr").find("td.halign-center").each(function() {
+          // Find all squares with features.
+          if ($(this).text() === "✓") {
+            features.push(indexToFeatureMap[squareIndex]);
+          }
+          if ($(this).text() === "†") {
+            skipEntry = true;
+            return false; // Break;
+          }
+          squareIndex++;
+        });
+        if (!skipEntry &&
+              (features.length > 0)) {
+          Object.defineProperty(outputJson, vkFormat, {
+            value: features,
+            enumerable: true,
+            readable: true,
+            writable: false
+          });
+        }
+      }
+    });
+  });
+}
+$("#result").text(JSON.stringify(outputJson));