Download tests/test_shader_graph.py from kimjunhan/vkgs-sim: direct link, hf CLI and curl.
- Browser
- Download file 3.65 kB
-
https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/tests/test_shader_graph.py
- Command line
-
hf download hf://kimjunhan/vkgs-sim/tests/test_shader_graph.py
-
curl -L -o test_shader_graph.py https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/tests/test_shader_graph.py
3.65 kB
| """scripts/shader_graph.py β λ Έλ λΌμ΄λΈλ¬λ¦¬ 리νλ μ , μμ μ λ ¬, νμ κ²μ¬, μμ±λ GLSL μ»΄νμΌ.""" | |
| import importlib.util | |
| import json | |
| import shutil | |
| import subprocess | |
| from pathlib import Path | |
| import pytest | |
| ROOT = Path(__file__).resolve().parents[1] | |
| SHADERS = ROOT / "src/vkgs/shaders" | |
| _spec = importlib.util.spec_from_file_location("shader_graph", ROOT / "scripts/shader_graph.py") | |
| sg = importlib.util.module_from_spec(_spec) | |
| _spec.loader.exec_module(sg) | |
| LIB = sg.parse_library((SHADERS / "nodes/isp.glsl").read_text()) | |
| def _gen(nodes): | |
| return sg.generate({"nodes": nodes, "target": {"params_resource": "p"}}, LIB, "t", ["nodes/isp.glsl"]) | |
| def test_library_signatures(): | |
| assert LIB["exposure"]["inputs"] == [("c", "vec3")] | |
| assert LIB["exposure"]["ctx"] and LIB["exposure"]["params"] == [("ev", 0.0, -3.0, 3.0)] | |
| assert LIB["mix"]["inputs"] == [("a", "vec3"), ("b", "vec3")] | |
| assert LIB["luma"]["ret"] == "float" and not LIB["luma"]["ctx"] | |
| assert "return" not in LIB # λ³Έλ¬Έ μμ νΈμΆμ λ Έλκ° μλλ€ | |
| def test_order_and_params(): | |
| # μ μΈ μμκ° λ€μμ¬λ μ λ ₯ β μΆλ ₯ μμλ‘ νΌμΉλ€ | |
| src, table, dot = _gen({ | |
| "out": {"op": "output", "in": ["e"]}, | |
| "e": {"op": "exposure", "in": ["i"], "params": {"ev": 0.5}}, | |
| "i": {"op": "input"}, | |
| }) | |
| body = src[src.index("void main"):] | |
| assert body.index("v_i =") < body.index("v_e =") < body.index("imageStore") | |
| assert table["params"] == [{"name": "e.ev", "node": "e", "op": "exposure", "index": 0, | |
| "default": 0.5, "min": -3.0, "max": 3.0}] | |
| assert table["resource"] == "p" and '"i" -> "e"' in dot | |
| def test_branches_and_types(): | |
| src, table, _ = _gen({ | |
| "i": {"op": "input"}, | |
| "y": {"op": "luma", "in": ["i"]}, | |
| "g": {"op": "gray", "in": ["y"]}, | |
| "m": {"op": "mix", "in": ["i", "g"], "params": {"amount": 0.25}}, | |
| "o": {"op": "output", "in": ["m"]}, | |
| }) | |
| assert "float v_y = n_luma(v_i);" in src and "n_mix(v_i, v_g, x, P(0))" in src | |
| def test_errors(nodes, msg): | |
| with pytest.raises(sg.GraphError, match=msg): | |
| _gen(nodes) | |
| def test_repo_graphs_compile(graph, tmp_path): | |
| comp = sg.build(graph, SHADERS, tmp_path) | |
| table = json.loads(comp.with_suffix(".params.json").read_text()) | |
| assert table["count"] == len(table["params"]) > 0 | |
| subprocess.run(["glslc", "--target-env=vulkan1.2", "-O", "-I", str(SHADERS), str(comp), | |
| "-o", str(tmp_path / "x.spv")], check=True) | |