get_shader_list.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import argparse
  9. import os
  10. import pathlib
  11. import subprocess
  12. def error(msg):
  13. print(msg)
  14. exit(1)
  15. def is_windows():
  16. if os.name == 'nt':
  17. return True
  18. else:
  19. return False
  20. def get_shader_list(project_path, asset_platform, shader_type, shader_platform, shadergen_path):
  21. """
  22. Gets the shader list for a specific platform using ShaderCacheGen.
  23. Right now the shader list will always output at <project-path>/user/Cache/Shaders
  24. That will change when this is updated to take a destination path
  25. """
  26. shadergen_path = os.path.join(shadergen_path, 'ShaderCacheGen')
  27. if is_windows():
  28. shadergen_path += '.exe'
  29. command_args = [
  30. shadergen_path,
  31. f'--project-path={str(project_path)}'
  32. '--GetShaderList',
  33. '--ShadersPlatform={}'.format(shader_type),
  34. '--TargetPlatform={}'.format(asset_platform)
  35. ]
  36. if not os.path.isfile(shadergen_path):
  37. error("[ERROR] ShaderCacheGen could not be found at {}".format(shadergen_path))
  38. else:
  39. command = ' '.join(command_args)
  40. print('[INFO] get_shader_list: Running command - {}'.format(command))
  41. try:
  42. subprocess.check_call(command, shell=True)
  43. except subprocess.CalledProcessError:
  44. error('[ERROR] Failed to get the shader list for {}'.format(shader_type))
  45. parser = argparse.ArgumentParser(description='Gets the shader list for a specific platform from the current shader compiler server')
  46. parser.add_argument('-g', '--project-path', type=pathlib.Path, required=True, help="Path to the project")
  47. parser.add_argument('asset-platform', type=str, help="The asset cache sub folder to use for shader generation")
  48. parser.add_argument('shader-type', type=str, help="The shader type to use")
  49. parser.add_argument('-p', '--shader_platform', type=str, required=False, default='', help="The target platform to generate shaders for.")
  50. parser.add_argument('-s', '--shadergen_path', type=str, help="Path to where the the ShaderCacheGen executable lives")
  51. args = parser.parse_args()
  52. print('Getting shader list for {}'.format(args.asset_platform))
  53. get_shader_list(args.project_path, args.asset_platform, args.shader_type, args.shader_platform, args.shadergen_path)
  54. print('Finish getting shader list')