|
15 | 15 | import re
|
16 | 16 | import sys
|
17 | 17 | from itertools import product
|
| 18 | +from multiprocessing.pool import ThreadPool |
18 | 19 |
|
19 | 20 | sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
20 | 21 | import subprocess
|
@@ -620,9 +621,12 @@ def constructOutputMap(self) -> None:
|
620 | 621 |
|
621 | 622 | def generateSPV(self, output_dir: str) -> Dict[str, str]:
|
622 | 623 | output_file_map = {}
|
623 |
| - for shader_name in self.output_shader_map: |
624 |
| - source_glsl = self.output_shader_map[shader_name][0] |
625 |
| - shader_params = self.output_shader_map[shader_name][1] |
| 624 | + |
| 625 | + def process_shader(shader_paths_pair): |
| 626 | + shader_name = shader_paths_pair[0] |
| 627 | + |
| 628 | + source_glsl = shader_paths_pair[1][0] |
| 629 | + shader_params = shader_paths_pair[1][1] |
626 | 630 |
|
627 | 631 | with codecs.open(source_glsl, "r", encoding="utf-8") as input_file:
|
628 | 632 | input_text = input_file.read()
|
@@ -652,9 +656,15 @@ def generateSPV(self, output_dir: str) -> Dict[str, str]:
|
652 | 656 | ]
|
653 | 657 |
|
654 | 658 | print("glslc cmd:", cmd)
|
655 |
| - # pyre-ignore |
656 | 659 | subprocess.check_call(cmd)
|
657 | 660 |
|
| 661 | + return (spv_out_path, glsl_out_path) |
| 662 | + |
| 663 | + # Parallelize shader compilation as much as possible to optimize build time. |
| 664 | + with ThreadPool(os.cpu_count()) as pool: |
| 665 | + for spv_out_path, glsl_out_path in pool.map( |
| 666 | + process_shader, self.output_shader_map.items() |
| 667 | + ): |
658 | 668 | output_file_map[spv_out_path] = glsl_out_path
|
659 | 669 |
|
660 | 670 | return output_file_map
|
|
0 commit comments