Commit d5ff4fad by Jamie Madill Committed by Commit Bot

Add standalone glslang_validator as a download hook.

This change allows us to download a copy of the standalone glslang validator during gclient runhooks. This decouples run_code_generation from the version of glslang stored in source tree. This prevents the error where a developer would run into a code generation conflict due to a change in version of glslang. Currently only the Windows version is stored in the tree. A follow-up CL will add Linux. The validator will only initially support Windows or Linux. Documentation for the script is located in tools/glslang/README.md. This CL also updates the Vulkan shader generation script to use the new binary for Windows. Bug: angleproject:3333 Change-Id: Ia6146a283a2bcfdf84c42411d6b5d8bae136bf1b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1553823 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org>
parent 9f958344
......@@ -26,6 +26,7 @@
.gclient_entries
/src/tests/third_party/gles_conformance_tests
/testing
/tools/glslang/glslang_validator.exe
/third_party/cherry
/third_party/deqp/src
/third_party/fuchsia-sdk
......
......@@ -295,6 +295,20 @@ hooks = [
'{angle_root}/build/fuchsia/update_sdk.py',
],
},
# Download glslang validator binary for Windows.
{
'name': 'win_glslang_validator',
'pattern': '.',
'condition': 'checkout_win and not build_with_chromium',
'action': [ 'download_from_google_storage',
'--no_resume',
'--platform=win32*',
'--no_auth',
'--bucket', 'angle-glslang-validator',
'-s', '{angle_root}/tools/glslang/glslang_validator.exe.sha1',
],
},
]
recursedeps = [
......
......@@ -192,7 +192,7 @@
"Vulkan format:src/libANGLE/renderer/vulkan/vk_format_table_autogen.cpp":
"ef0ea80cf33e60f76391bcfed10b3c0a",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py":
"4d8bd2e1c39b4f2443605c1a296f4b3d",
"2a1f6e5329769edfe8de7024799db223",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/gen/BufferUtils.comp.00000000.inc":
"caa03e84d757844a099d0e408a162c7e",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/gen/BufferUtils.comp.00000001.inc":
......@@ -349,8 +349,8 @@
"751f3554fe613d9b4739c7a4ac87b037",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/vk_internal_shaders_autogen.h":
"930fc6f4a705a0d2121770377d3bc764",
"Vulkan internal shader programs:third_party/glslang/src/glslang/Include/revision.h":
"9ed075c3634314a5e9190da21b530c17",
"Vulkan internal shader programs:tools/glslang/glslang_validator.exe.sha1":
"4e0076daa7a27051c1245b8b339ebd6d",
"Vulkan mandatory format support table:src/libANGLE/renderer/angle_format.py":
"b18ca0fe4835114a4a2f54977b19e798",
"Vulkan mandatory format support table:src/libANGLE/renderer/vulkan/gen_vk_mandatory_format_support_table.py":
......
......@@ -13,6 +13,7 @@ from datetime import date
import io
import json
import os
import platform
import re
import subprocess
import sys
......@@ -21,6 +22,9 @@ out_file_cpp = 'vk_internal_shaders_autogen.cpp'
out_file_h = 'vk_internal_shaders_autogen.h'
out_file_gni = 'vk_internal_shaders_autogen.gni'
is_windows = platform.system() == 'Windows'
is_linux = platform.system() == 'Linux'
# Templates for the generated files:
template_shader_library_cpp = u"""// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {input_file_name}
......@@ -174,21 +178,18 @@ def get_output_path(name):
return os.path.join('shaders', 'gen', name + ".inc")
# Finds a path to GN's out directory
def find_build_path():
path = sys.path[0] # Directory of this script
out = os.path.join(path, "../../../../out") # Out is in angle base dir
if (os.path.isdir(out)):
# Prefer release directories.
for pattern in ['elease', '']:
for o in os.listdir(out):
subdir = os.path.join(out, o)
if os.path.isdir(subdir) and pattern in o:
argsgn = os.path.join(subdir, "args.gn")
if os.path.isfile(argsgn):
return subdir
# If we reached this point, there was no build directory in the angle repo
raise Exception("Could not find GN out directory")
def get_linux_glslang_exe_path():
return '../../../../tools/glslang/glslang_validator'
def get_win_glslang_exe_path():
return get_linux_glslang_exe_path() + '.exe'
def get_glslang_exe_path():
glslang_exe = get_win_glslang_exe_path() if is_windows else get_linux_glslang_exe_path()
if not os.path.isfile(glslang_exe):
raise Exception('Could not find %s' % glslang_exe)
return glslang_exe
# Generates the code for a shader blob array entry.
def gen_shader_blob_entry(shader):
......@@ -466,29 +467,17 @@ def main():
for shader in os.listdir(shaders_dir)
if any([os.path.splitext(shader)[1] == ext for ext in valid_extensions])])
if print_inputs:
glslang_revision = '../../../../third_party/glslang/src/glslang/Include/revision.h'
print(",".join(input_shaders + [glslang_revision]))
sys.exit(0)
win_glslang_binary = get_win_glslang_exe_path() + '.sha1'
print(",".join(input_shaders + [win_glslang_binary]))
return 0
# STEP 1: Call glslang to generate the internal shaders into small .inc files.
# Iterates over the shaders and call glslang with the right arguments.
# a) Get the path to the glslang binary from the script directory.
glslang_path = None
if not print_outputs:
build_path = find_build_path()
print("Using glslang_validator from '" + build_path + "'")
result = subprocess.call(['ninja', '-C', build_path, 'glslang_validator'])
if result != 0:
raise Exception("Error building glslang_validator")
glslang_binary = 'glslang_validator'
if os.name == 'nt':
glslang_binary += '.exe'
glslang_path = os.path.join(build_path, glslang_binary)
if not os.path.isfile(glslang_path):
raise Exception("Could not find " + glslang_binary)
glslang_path = get_glslang_exe_path()
# b) Iterate over the shaders and call glslang with the right arguments.
output_shaders = []
input_shaders_and_variations = [ShaderAndVariations(shader_file) for shader_file in input_shaders]
......@@ -522,7 +511,7 @@ def main():
if print_outputs:
print(','.join(outputs))
sys.exit(0)
return 0
# STEP 2: Consolidate the .inc files into an auto-generated cpp/h library.
with open(out_file_cpp, 'w') as outfile:
......@@ -575,6 +564,8 @@ def main():
outfile.write(outcode)
outfile.close()
return 0
if __name__ == '__main__':
sys.exit(main())
An empty file to make git happy.
\ No newline at end of file
# Standalone glslang validator
This folder contains a standalone glslang validator binary. We use this binary
for offline compilation of internal Vulkan shaders. See [the internal shader
docs](../../src/libANGLE/renderer/vulkan/shaders/README.md) for more info on
offline shader compilation.
Use the script [`update_glslang_binary.py`](update_glslang_binary.py) to update
the versions of the validator in cloud storage. It must be run on Linux or
Windows. It will update the SHA for your platform. After running the script run
`git commit` and then `git cl upload` to code review using the normal review
process. Note that if the version of glslang has been updated you will also want
to run [`scripts/run_code_generation.py`](../../scripts/run_code_generation.py)
to update the compiled shader binaries.
Please update both Windows and Linux binaries at the same time. Use two CLs. One
for each platform. Note that we don't currently suport Mac on Vulkan. If we do
we should add a glslang download for Mac as well.
Contact jmadill or syouseffi for any help with the validator or updating the binaries.
1320cd7889b936808e6badd9e0c40d3c5db5b5f2
\ No newline at end of file
#!/usr/bin/python2
#
# Copyright 2019 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.
#
# update_glslang_binary.py:
# Helper script to update the version of glslang in cloud storage.
# This glslang is used to precompile Vulkan shaders. This script builds
# glslang and uploads it to the bucket for Windows or Linux. It
# currently only works on Windows and Linux. It also will update the
# hashes stored in the tree. For more info see README.md in this folder.
import os
import platform
import re
import shutil
import subprocess
import sys
gn_args = """is_clang = true
is_debug = false
angle_enable_vulkan = true"""
is_windows = platform.system() == 'Windows'
is_linux = platform.system() == 'Linux'
def find_file_in_path(filename):
""" Finds |filename| by searching the environment paths """
path_delimiter = ';' if is_windows else ':'
for env_path in os.environ['PATH'].split(path_delimiter):
full_path = os.path.join(env_path, filename)
if os.path.isfile(full_path):
return full_path
raise Exception('Cannot find %s in environment' % filename)
def main():
if not is_windows and not is_linux:
print('Script must be run on Linux or Windows.')
return 1
# Step 1: Generate an output directory
out_dir = os.path.join('out', 'glslang_release')
if not os.path.isdir(out_dir):
os.mkdir(out_dir)
args_gn = os.path.join(out_dir, 'args.gn')
if not os.path.isfile(args_gn):
with open(args_gn, 'w') as f:
f.write(gn_args)
f.close()
gn_exe = 'gn'
if is_windows:
gn_exe += '.bat'
# Step 2: Generate the ninja build files in the output directory
if subprocess.call([gn_exe, 'gen', out_dir]) != 0:
print('Error calling gn')
return 2
# Step 3: Compile glslang_validator
if subprocess.call(['ninja', '-C', out_dir, 'glslang_validator']) != 0:
print('Error calling ninja')
return 3
# Step 4: Copy glslang_validator to the tools/glslang directory
glslang_exe = 'glslang_validator'
if is_windows:
glslang_exe += '.exe'
glslang_src = os.path.join(out_dir, glslang_exe)
glslang_dst = os.path.join(sys.path[0], glslang_exe)
shutil.copyfile(glslang_src, glslang_dst)
# Step 5: Delete the build directory
shutil.rmtree(out_dir)
# Step 6: Upload to cloud storage
upload_script = find_file_in_path('upload_to_google_storage.py')
upload_args = ['python', upload_script, '-b', 'angle-glslang-validator', glslang_dst]
if subprocess.call(upload_args) != 0:
print('Error upload to cloud storage')
return 4
# Step 7: Stage new SHA to git
git_exe = 'git'
if is_windows:
git_exe += '.bat'
git_exe = find_file_in_path(git_exe)
if subprocess.call([git_exe, 'add', glslang_dst + '.sha1']) != 0:
print('Error running git add')
return 5
print('')
print('The updated SHA has been staged for commit. Please commit and upload.')
print('Suggested commit message:')
print('----------------------------')
print('')
print('Update glslang_validator binary for %s.' % platform.system())
print('')
print('This binary was updated using %s.' % os.path.basename(__file__))
print('Please see instructions in tools/glslang/README.md.')
print('')
print('Bug: None')
return 0
if __name__ == '__main__':
sys.exit(main())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment