mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Improve YAML loading performance using libyaml
This adds optional support for loading the YAML reflection data using `libyaml`, which is faster than PyYAML's pure Python implementation.
This commit is contained in:
parent
92df50f36c
commit
b2cdb1e6b4
2 changed files with 14 additions and 1 deletions
|
|
@ -7,6 +7,7 @@
|
|||
```
|
||||
|
||||
- Install `glslc` and spirv-tools 2023+ (the easiest way is to install Vulkan SDK)
|
||||
- For improved performance you may also install [libyaml](https://github.com/yaml/libyaml)
|
||||
|
||||
- Run the compile.py script
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import hashlib
|
|||
import itertools
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
|
@ -36,6 +37,11 @@ from pathlib import Path
|
|||
import yaml
|
||||
|
||||
|
||||
try:
|
||||
from yaml import CSafeLoader as SafeLoader
|
||||
except ImportError:
|
||||
from yaml import SafeLoader
|
||||
|
||||
STAGE_EXTENSIONS = {
|
||||
"vertex": ".vs",
|
||||
"fragment": ".fs",
|
||||
|
|
@ -43,6 +49,8 @@ STAGE_EXTENSIONS = {
|
|||
"compute": ".cs",
|
||||
}
|
||||
|
||||
YAML_DIRECTIVE_PATTERN = re.compile(b"^%YAML 1.0\n")
|
||||
|
||||
|
||||
def execute(command):
|
||||
try:
|
||||
|
|
@ -158,8 +166,12 @@ def compile_and_reflect(input_mod_path, dependencies, stage, path, out_path, def
|
|||
"Error: {}\n".format(ret, " ".join(command), input_path, output_path, err)
|
||||
)
|
||||
raise ValueError(err)
|
||||
|
||||
# Reflect the result SPIRV.
|
||||
data = yaml.safe_load(out)
|
||||
|
||||
# libyaml doesn't support files with a YAML 1.0 directive, so
|
||||
# let's strip the directive out before loading the data.
|
||||
data = yaml.load(YAML_DIRECTIVE_PATTERN.sub(b"", out), Loader=SafeLoader)
|
||||
module = data["module"]
|
||||
interface_variables = []
|
||||
if data.get("all_interface_variables"):
|
||||
|
|
|
|||
Loading…
Reference in a new issue