aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCort Stratton <cort@google.com>2017-11-06 19:13:53 -0800
committerChris Forbes <chrisf@ijw.co.nz>2017-11-28 16:27:21 -0800
commit892762a4fa928b7f1ec2e2d5ecb32481cdb6cbdd (patch)
tree1dd997690322a2f57a30b6343559df8fb2352673
parent604b8697d2ab561e482e70db4ee9856e2fa0627a (diff)
downloadusermoji-892762a4fa928b7f1ec2e2d5ecb32481cdb6cbdd.tar.xz
Use SPIRV-Tools commit ID as validation cache version
-rw-r--r--CMakeLists.txt10
-rw-r--r--build-android/android-generate.bat1
-rw-r--r--layers/shader_validation.h20
-rw-r--r--scripts/external_revision_generator.py82
4 files changed, 104 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 83b9ef27..d5aa0c37 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -315,6 +315,14 @@ macro(run_vk_xml_generate dependency output)
)
endmacro()
+# Define macro used for generating header files containing commit IDs for external dependencies
+macro(run_external_revision_generate source_dir revision_file output)
+ add_custom_command(OUTPUT ${output}
+ COMMAND ${PYTHON_CMD} ${SCRIPTS_DIR}/external_revision_generator.py ${source_dir} ${revision_file} ${output}
+ DEPENDS ${SCRIPTS_DIR}/external_revision_generator.py ${revision_file}
+ )
+endmacro()
+
# Custom target for generated vulkan helper file dependencies
add_custom_target(generate_helper_files DEPENDS
vk_enum_string_helper.h
@@ -327,6 +335,7 @@ add_custom_target(generate_helper_files DEPENDS
vk_dispatch_table_helper.h
vk_extension_helper.h
vk_typemap_helper.h
+ spirv_tools_commit_id.h
)
# Rules to build generated helper files
@@ -340,6 +349,7 @@ run_vk_xml_generate(helper_file_generator.py vk_enum_string_helper.h)
run_vk_xml_generate(helper_file_generator.py vk_object_types.h)
run_vk_xml_generate(helper_file_generator.py vk_extension_helper.h)
run_vk_xml_generate(helper_file_generator.py vk_typemap_helper.h)
+run_external_revision_generate(${EXTERNAL_SOURCE_ROOT}/spirv-tools ${CMAKE_CURRENT_SOURCE_DIR}/external_revisions/spirv-tools_revision spirv_tools_commit_id.h)
if(NOT WIN32)
include(GNUInstallDirs)
diff --git a/build-android/android-generate.bat b/build-android/android-generate.bat
index d305abc3..171e6562 100644
--- a/build-android/android-generate.bat
+++ b/build-android/android-generate.bat
@@ -34,5 +34,6 @@ py -3 ../../../scripts/lvl_genvk.py -registry ../../../scripts/vk.xml vk_layer_d
py -3 ../../../scripts/lvl_genvk.py -registry ../../../scripts/vk.xml vk_extension_helper.h
py -3 ../../../scripts/lvl_genvk.py -registry ../../../scripts/vk.xml object_tracker.cpp
py -3 ../../../scripts/lvl_genvk.py -registry ../../../scripts/vk.xml vk_typemap_helper.h
+py -3 ../../../scripts/external_revision_generator.py ../../../external/spirv-tools ../../../external_revisions/spirv-tools_revision spirv_tools_commit_id.h
cd ../..
diff --git a/layers/shader_validation.h b/layers/shader_validation.h
index 99a784ca..069d1da7 100644
--- a/layers/shader_validation.h
+++ b/layers/shader_validation.h
@@ -20,6 +20,8 @@
#ifndef VULKAN_SHADER_VALIDATION_H
#define VULKAN_SHADER_VALIDATION_H
+#include <spirv_tools_commit_id.h>
+
// A forward iterator over spirv instructions. Provides easy access to len, opcode, and content words
// without the caller needing to care too much about the physical SPIRV module layout.
struct spirv_inst_iter {
@@ -100,9 +102,6 @@ struct shader_module {
void build_def_index();
};
-// TODO: Wire this up to SPIRV-Tools commit hash
-#define VALIDATION_CACHE_VERSION 1
-
class ValidationCache {
// hashes of shaders that have passed validation before, and can be skipped.
// we don't store negative results, as we would have to also store what was
@@ -128,8 +127,8 @@ public:
return;
if (data[1] != VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT)
return;
- if (data[2] != VALIDATION_CACHE_VERSION || data[3] || data[4] || data[5])
- return; // different version
+ if (strncmp((const char*)&data[2], SPIRV_TOOLS_COMMIT_ID, 16) != 0)
+ return; // different version
data += 6;
@@ -157,10 +156,13 @@ public:
// Write the header
*out++ = headerSize;
*out++ = VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT;
- *out++ = VALIDATION_CACHE_VERSION;
- *out++ = 0;
- *out++ = 0;
- *out++ = 0;
+ size_t commitIdSize = strlen(SPIRV_TOOLS_COMMIT_ID);
+ if (commitIdSize > 16) {
+ commitIdSize = 16;
+ }
+ out[0] = out[1] = out[2] = out[3] = 0;
+ memcpy(out, SPIRV_TOOLS_COMMIT_ID, commitIdSize);
+ out += 4;
for (auto it = good_shader_hashes.begin();
it != good_shader_hashes.end() && actualSize < *pDataSize;
diff --git a/scripts/external_revision_generator.py b/scripts/external_revision_generator.py
new file mode 100644
index 00000000..acfb42e3
--- /dev/null
+++ b/scripts/external_revision_generator.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2015-2016 The Khronos Group Inc.
+# Copyright (c) 2015-2016 Valve Corporation
+# Copyright (c) 2015-2016 LunarG, Inc.
+# Copyright (c) 2015-2016 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.
+#
+# Author: Cort Stratton <cort@google.com>
+
+import os
+import subprocess
+import sys
+
+
+
+if __name__ == '__main__':
+ if (len(sys.argv) != 4):
+ print("Usage: %s <SPIRV_TOOLS_SOURCE_DIR> <SPIRV_TOOLS_REVISION_FILE> <OUTPUT_HEADER_FILE>" % sys.argv[0])
+ sys.exit(os.EX_USAGE)
+
+ spirv_tools_source_dir = sys.argv[1]
+ spirv_tools_revision_file = sys.argv[2]
+ output_header_file = sys.argv[3]
+
+ # Load SPIRV-Tools revision
+ with open(spirv_tools_revision_file, "r") as rev_file:
+ revision = rev_file.read().replace('\n', '')
+
+ # The revision listed in the file may be symbolic; use "git rev-parse" to
+ # convert it to a commit hash
+ spirv_tools_commit_id = subprocess.check_output(["git", "rev-parse", revision], cwd=spirv_tools_source_dir).decode('utf-8').strip()
+
+ # Write commit ID to output header file
+ with open(output_header_file, "w") as header_file:
+ # File Comment
+ file_comment = '// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n'
+ file_comment += '// See external_revision_generator.py for modifications\n'
+ header_file.write(file_comment)
+ # Copyright Notice
+ copyright = ''
+ copyright += '\n'
+ copyright += '/***************************************************************************\n'
+ copyright += ' *\n'
+ copyright += ' * Copyright (c) 2015-2017 The Khronos Group Inc.\n'
+ copyright += ' * Copyright (c) 2015-2017 Valve Corporation\n'
+ copyright += ' * Copyright (c) 2015-2017 LunarG, Inc.\n'
+ copyright += ' * Copyright (c) 2015-2017 Google Inc.\n'
+ copyright += ' *\n'
+ copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n'
+ copyright += ' * you may not use this file except in compliance with the License.\n'
+ copyright += ' * You may obtain a copy of the License at\n'
+ copyright += ' *\n'
+ copyright += ' * http://www.apache.org/licenses/LICENSE-2.0\n'
+ copyright += ' *\n'
+ copyright += ' * Unless required by applicable law or agreed to in writing, software\n'
+ copyright += ' * distributed under the License is distributed on an "AS IS" BASIS,\n'
+ copyright += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
+ copyright += ' * See the License for the specific language governing permissions and\n'
+ copyright += ' * limitations under the License.\n'
+ copyright += ' *\n'
+ copyright += ' * Author: Chris Forbes <chrisforbes@google.com>\n'
+ copyright += ' * Author: Cort Stratton <cort@google.com>\n'
+ copyright += ' *\n'
+ copyright += ' ****************************************************************************/\n'
+ header_file.write(copyright)
+ # Contents
+ contents = '#pragma once\n\n'
+ contents += '#define SPIRV_TOOLS_COMMIT_ID "' + spirv_tools_commit_id + '"\n'
+ header_file.write(contents)
+ \ No newline at end of file