1# Copyright (C) 2022 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import os 16 17# This script compiles the image decompression shaders. 18# glslc must be in the path for this script to work 19 20# The list of shaders to compile, without the .comp extension 21shaders = [ 22 "Astc", 23 "AstcToRgb", 24 "AstcToBc3", 25 "EacR11Snorm", 26 "EacR11Unorm", 27 "EacRG11Snorm", 28 "EacRG11Unorm", 29 "Etc2RGB8", 30 "Etc2RGBA8", 31] 32 33# Template for the compilation command 34command = "glslc -DDIM={dim} --target-env=vulkan1.1 -mfmt=num {input} -o {output}" 35 36output_dir = "compiled" 37 38 39# Compiles a single shader 40# shader: shader name, without the .comp extension 41# dim: image dimension. Must be 1, 2 or 3 - for 1D, 2D and 3D respectively 42def compile(shader: str, dim: int): 43 input = "{}.comp".format(shader) 44 output = os.path.join(output_dir, "{}_{}D.inl".format(shader, dim)) 45 cmd = command.format(dim=dim, input=input, output=output) 46 print("Executing: {}".format(cmd)) 47 ret = os.system(cmd) 48 if ret != 0: 49 print("Compiling {} failed.".format(input)) 50 exit(ret) 51 52 53def main(): 54 # Set the current working directory where the script is located 55 os.chdir(os.path.dirname(os.path.realpath(__file__))) 56 print("Compiling shaders in", os.getcwd()) 57 58 # Make sure the shaders are all properly formatted 59 ret = os.system("clang-format -i *.comp *.glsl") 60 if ret != 0: 61 print("Running clang-format failed. Make sure it is available in your PATH.") 62 exit(ret) 63 64 os.makedirs(output_dir, exist_ok=True) 65 66 for shader in shaders: 67 for dim in range(1, 4): 68 compile(shader, dim) 69 70 71if __name__ == "__main__": 72 main() 73