vs2convert 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vs2convert/__init__.py +10 -0
- vs2convert/api.py +194 -0
- vs2convert/cli.py +306 -0
- vs2convert/core/__init__.py +5 -0
- vs2convert/core/detector.py +248 -0
- vs2convert/core/gates.py +414 -0
- vs2convert/core/generator.py +1363 -0
- vs2convert/core/report.py +143 -0
- vs2convert/core/shadertoy_meta.py +149 -0
- vs2convert/core/textutil.py +80 -0
- vs2convert/renderer/__init__.py +5 -0
- vs2convert/renderer/assets/default_texture.png +0 -0
- vs2convert/renderer/pipeline.py +371 -0
- vs2convert/validators/__init__.py +3 -0
- vs2convert/validators/validator.py +197 -0
- vs2convert-0.2.0.dist-info/METADATA +267 -0
- vs2convert-0.2.0.dist-info/RECORD +21 -0
- vs2convert-0.2.0.dist-info/WHEEL +5 -0
- vs2convert-0.2.0.dist-info/entry_points.txt +2 -0
- vs2convert-0.2.0.dist-info/licenses/LICENSE +21 -0
- vs2convert-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Input format detection and suitability checking.
|
|
3
|
+
|
|
4
|
+
Bundled rules from validate_shader.py and golden examples.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import re
|
|
9
|
+
|
|
10
|
+
from .textutil import code_only, ENGINE_VARS, ENGINE_VAR_RE, UNIFORM_NAME_RE
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# --- Detection Patterns ---
|
|
14
|
+
|
|
15
|
+
# ISF: Has JSON manifest with "INPUTS" (ISF) or "parameters" (VS-2 style) array
|
|
16
|
+
# ISF's own declaration is an "INPUTS" array (uppercase). A VS-2-style
|
|
17
|
+
# manifest uses lowercase "parameters" and a Shadertoy .txt may carry one, so
|
|
18
|
+
# conflating the two let a Shadertoy file look like ISF and - worse - let a
|
|
19
|
+
# mainImage() override a real ISF INPUTS block, silently discarding it.
|
|
20
|
+
ISF_INPUTS_RE = re.compile(r'/\*.*?"INPUTS".*?\*/', re.DOTALL)
|
|
21
|
+
VS2_PARAMETERS_RE = re.compile(r'/\*.*?"parameters".*?\*/', re.DOTALL)
|
|
22
|
+
ISF_MANIFEST_RE = re.compile(r'/\*.*?"(?:INPUTS|parameters)".*?\*/', re.DOTALL)
|
|
23
|
+
|
|
24
|
+
# Shadertoy: Has mainImage() or main() with iTime/iResolution references
|
|
25
|
+
SHADERTOY_MAINIMAGE_RE = re.compile(r'mainImage\s*\(\s*.*?\)')
|
|
26
|
+
SHADERTOY_TIME_RE = re.compile(r'\biTime\b')
|
|
27
|
+
|
|
28
|
+
# GLSLSandbox: Has uniform declarations for time/resolution
|
|
29
|
+
GLSLSANDBOX_TIME_RE = re.compile(r'uniform\s+float\s+time\s*;')
|
|
30
|
+
GLSLSANDBOX_RESOLUTION_RE = re.compile(r'uniform\s+vec2\s+resolution\s*;')
|
|
31
|
+
|
|
32
|
+
# MilkDrop/HLSL: Has HLSL-specific functions
|
|
33
|
+
HLSL_FRACTION_RE = re.compile(r'\bfrac\s*\(')
|
|
34
|
+
HLSL_LERP_RE = re.compile(r'\blerp\s*\(')
|
|
35
|
+
HLSL_TEXTURE2D_RE = re.compile(r'\btexture2D\s*\(|\btex2D\s*\(')
|
|
36
|
+
HLSL_API_RE = re.compile(r'\bSV_Target\b|\bTexture2D\b|\btechnique(?:10|11)?\b')
|
|
37
|
+
HLSL_MAIN_RE = re.compile(r'\b(?:float|half)[234](?:x[234])?\s+main\s*\(')
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def detect_format(source: str) -> dict:
|
|
41
|
+
"""
|
|
42
|
+
Detect input format from source code.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
dict with keys:
|
|
46
|
+
- format: str (ISF, Shadertoy, GLSLSandbox, MilkDrop, PlainGLSL)
|
|
47
|
+
- suitable: bool
|
|
48
|
+
- errors: list[str]
|
|
49
|
+
- error_gates: list[str] parallel to errors, ids from core.gates.GATES
|
|
50
|
+
- warnings: list[str]
|
|
51
|
+
"""
|
|
52
|
+
errors = []
|
|
53
|
+
error_gates = []
|
|
54
|
+
warnings = []
|
|
55
|
+
|
|
56
|
+
# HLSL/API checks run against code only: a comment mentioning `lerp(` is
|
|
57
|
+
# documentation of the original, not unconverted HLSL.
|
|
58
|
+
code = code_only(source)
|
|
59
|
+
|
|
60
|
+
# Check for HLSL leftovers (definitely not suitable)
|
|
61
|
+
if HLSL_FRACTION_RE.search(code):
|
|
62
|
+
errors.append("Contains HLSL function 'frac()' (use 'fract()' in GLSL)")
|
|
63
|
+
error_gates.append('hlsl-milkdrop')
|
|
64
|
+
if HLSL_LERP_RE.search(code):
|
|
65
|
+
errors.append("Contains HLSL function 'lerp()' (use 'mix()' in GLSL)")
|
|
66
|
+
error_gates.append('hlsl-milkdrop')
|
|
67
|
+
if HLSL_API_RE.search(code):
|
|
68
|
+
errors.append("Contains HLSL/Shader Model syntax (SV_Target, Texture2D or technique)")
|
|
69
|
+
error_gates.append('hlsl-milkdrop')
|
|
70
|
+
if HLSL_MAIN_RE.search(code):
|
|
71
|
+
errors.append("Contains an HLSL entry point (floatN/halfN main) instead of GLSL")
|
|
72
|
+
error_gates.append('hlsl-milkdrop')
|
|
73
|
+
|
|
74
|
+
# Check for engine variable redeclaration
|
|
75
|
+
for i, line in enumerate(code.split('\n'), 1):
|
|
76
|
+
if line and not line[0].isspace() and ENGINE_VAR_RE.match(line):
|
|
77
|
+
errors.append(f"Line {i}: redeclares engine var '{ENGINE_VAR_RE.match(line).group(2)}' at global scope")
|
|
78
|
+
error_gates.append('engine-var-redeclaration')
|
|
79
|
+
break
|
|
80
|
+
|
|
81
|
+
# iTime / iResolution / iMouse are VS-2 globals (or plain renames), so
|
|
82
|
+
# they are not errors. iChannel0..3 previously WAS an error demanding an
|
|
83
|
+
# #define alias, but formal-spec.md line 26/274 documents the mapping as a
|
|
84
|
+
# rename: `iChannel0..3` -> `imageTex`. The converter does that rename,
|
|
85
|
+
# so an unaliased reference is expected input, not a defect.
|
|
86
|
+
#
|
|
87
|
+
# The one case still worth declining is a Shadertoy shader that reads
|
|
88
|
+
# several DISTINCT channels, since VS-2 binds one imageTex (fftTex is
|
|
89
|
+
# the engine's fixed audio sampler) and collapsing them would silently
|
|
90
|
+
# change the image. See the generator's iChannel handling.
|
|
91
|
+
_channels_used = sorted(set(re.findall(r'\biChannel([0-3])\b', code)))
|
|
92
|
+
if len(_channels_used) > 1:
|
|
93
|
+
errors.append(
|
|
94
|
+
"reads %d distinct iChannels (iChannel%s); VS-2 binds one "
|
|
95
|
+
"imageTex and one fixed audio sampler (fftTex), so the channels "
|
|
96
|
+
"would have to be collapsed. Convert by hand"
|
|
97
|
+
% (len(_channels_used), ''.join(_channels_used)))
|
|
98
|
+
error_gates.append('shadertoy-multi-channel')
|
|
99
|
+
|
|
100
|
+
# Detect format
|
|
101
|
+
format_name = "PlainGLSL"
|
|
102
|
+
|
|
103
|
+
# ISF first, and on the strength of a real INPUTS block. ISF is
|
|
104
|
+
# self-describing: the manifest declares what the file is, so it
|
|
105
|
+
# outranks a `mainImage` that happens to be present. Previously mainImage
|
|
106
|
+
# won, and a Shadertoy-imported ISF had its INPUTS silently discarded -
|
|
107
|
+
# its knobs vanished and the body kept undeclared names, producing GLSL
|
|
108
|
+
# that would not compile.
|
|
109
|
+
if ISF_INPUTS_RE.search(source):
|
|
110
|
+
format_name = "ISF"
|
|
111
|
+
# GLSLSandbox: uniform time/resolution declarations, no mainImage.
|
|
112
|
+
elif GLSLSANDBOX_TIME_RE.search(source) or GLSLSANDBOX_RESOLUTION_RE.search(source):
|
|
113
|
+
format_name = "GLSLSandbox"
|
|
114
|
+
# Shadertoy: mainImage, or iTime with no ISF manifest.
|
|
115
|
+
elif SHADERTOY_MAINIMAGE_RE.search(source) or (SHADERTOY_TIME_RE.search(source) and not VS2_PARAMETERS_RE.search(source)):
|
|
116
|
+
format_name = "Shadertoy"
|
|
117
|
+
# MilkDrop check (HLSL functions present)
|
|
118
|
+
elif HLSL_FRACTION_RE.search(code) or HLSL_LERP_RE.search(code) or HLSL_TEXTURE2D_RE.search(code):
|
|
119
|
+
format_name = "MilkDrop"
|
|
120
|
+
|
|
121
|
+
# texture2D/tex2D: an ISF body is labelled glsl-texture2d, matching
|
|
122
|
+
# generator.convert (ISF reaches _convert_isf's check). Elsewhere it is HLSL.
|
|
123
|
+
if HLSL_TEXTURE2D_RE.search(code):
|
|
124
|
+
errors.append("Contains texture2D()/tex2D() (use 'texture()' in GLSL)")
|
|
125
|
+
error_gates.append('glsl-texture2d' if format_name == 'ISF' else 'hlsl-milkdrop')
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
"format": format_name,
|
|
129
|
+
"suitable": len(errors) == 0,
|
|
130
|
+
"errors": errors,
|
|
131
|
+
"error_gates": error_gates,
|
|
132
|
+
"warnings": warnings
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def check_suitability(source: str) -> dict:
|
|
137
|
+
"""
|
|
138
|
+
Check if source is suitable for conversion to VS-2.
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
dict with keys:
|
|
142
|
+
- suitable: bool
|
|
143
|
+
- errors: list[str]
|
|
144
|
+
- error_gates: list[str]
|
|
145
|
+
- format: str
|
|
146
|
+
- warnings: list[str]
|
|
147
|
+
"""
|
|
148
|
+
# Reuse detection errors
|
|
149
|
+
result = detect_format(source)
|
|
150
|
+
code = code_only(source)
|
|
151
|
+
|
|
152
|
+
# Additional suitability checks
|
|
153
|
+
# Check parameter count (max 7)
|
|
154
|
+
params = _extract_parameters(source)
|
|
155
|
+
if len(params) > 7:
|
|
156
|
+
result["errors"].append(f"Too many parameters: {len(params)} (max 7)")
|
|
157
|
+
result["error_gates"].append('too-many-parameters')
|
|
158
|
+
|
|
159
|
+
# Image-input shaders are NOT declined.
|
|
160
|
+
#
|
|
161
|
+
# An earlier revision declined any shader referencing iChannel / imageTex
|
|
162
|
+
# on the grounds that image input was "not understood". That was wrong on
|
|
163
|
+
# two counts: VS-2 binds the layer's configured image to `imageTex` and
|
|
164
|
+
# the gallery previews these shaders against a default image, so they are
|
|
165
|
+
# ordinary shaders; and the refusal was a limitation of our own headless
|
|
166
|
+
# harness (it had no texture bound), not of the conversion.
|
|
167
|
+
#
|
|
168
|
+
# The harness now binds a default image, so image-input shaders render
|
|
169
|
+
# and are gated on pixels like everything else - 79/79 corpus shaders
|
|
170
|
+
# pass. The genuine hard gates stay in core/generator.py, where they
|
|
171
|
+
# belong: ISF `TYPE: image` inputs, which would require the converter to
|
|
172
|
+
# *emit* an image the user has not supplied, and bundled texture reads
|
|
173
|
+
# (texture2D/TEXTURE_*) that imply a multi-pass merge.
|
|
174
|
+
#
|
|
175
|
+
# Do not re-add a blanket image-input decline without a demonstrated
|
|
176
|
+
# failure. If one is found, put it here with the failing shader named.
|
|
177
|
+
|
|
178
|
+
result["suitable"] = len(result["errors"]) == 0
|
|
179
|
+
|
|
180
|
+
# snake_case is guaranteed at OUTPUT time (generator._snake) and checked
|
|
181
|
+
# on the output by validators/validator.py; a camelCase SOURCE name is
|
|
182
|
+
# normal (iResolution etc.) and must not decline. The check that used to
|
|
183
|
+
# live here appended errors AFTER `suitable` was computed, so it was
|
|
184
|
+
# invisible twice over. test_validator.SuitabilityGateTests.
|
|
185
|
+
|
|
186
|
+
# Check for speed parameters
|
|
187
|
+
SPEED_PATTERNS = ['speed', 'rate', 'frequency', 'freq', 'twist_speed']
|
|
188
|
+
for pattern in SPEED_PATTERNS:
|
|
189
|
+
if re.search(rf'\b{pattern}\b', ' '.join(params)):
|
|
190
|
+
result["warnings"].append(f"Parameter '{pattern}' may be a custom speed parameter (use native 'time')")
|
|
191
|
+
|
|
192
|
+
return result
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _extract_parameters(source: str) -> list:
|
|
196
|
+
"""Extract parameter names from manifest (GLSL order: uniform <type> <name>;)"""
|
|
197
|
+
params = []
|
|
198
|
+
|
|
199
|
+
# Manifest: strip comment delimiters before json.loads (group(0)
|
|
200
|
+
# includes /* */ and always throws)
|
|
201
|
+
import json
|
|
202
|
+
for block in re.findall(r'/\*(.*?)\*/', source, re.DOTALL):
|
|
203
|
+
try:
|
|
204
|
+
data = json.loads(block.strip())
|
|
205
|
+
except (json.JSONDecodeError, ValueError):
|
|
206
|
+
continue
|
|
207
|
+
if isinstance(data, dict) and 'parameters' in data:
|
|
208
|
+
params = [p.get('name', '') for p in data.get('parameters', [])
|
|
209
|
+
if isinstance(p, dict) and p.get('name')]
|
|
210
|
+
break
|
|
211
|
+
|
|
212
|
+
# Fallback: extract from code (uniform declarations). An engine variable
|
|
213
|
+
# is supplied by VS 2, so it is never a manifest entry: counting
|
|
214
|
+
# `uniform float time;` against the 7-parameter budget declined sources
|
|
215
|
+
# that emitted six knobs.
|
|
216
|
+
if not params:
|
|
217
|
+
for name in UNIFORM_NAME_RE.findall(source):
|
|
218
|
+
if name in ENGINE_VARS or name in params:
|
|
219
|
+
continue
|
|
220
|
+
params.append(name)
|
|
221
|
+
|
|
222
|
+
return params
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
# --- Known MVP limitations ----------------------------------------------
|
|
226
|
+
#
|
|
227
|
+
# 1. Image-input shaders are supported. A shader sampling `imageTex` (or
|
|
228
|
+
# reading a single iChannel) converts and renders; the headless gate binds
|
|
229
|
+
# a default image, mirroring the VS-2 gallery. Such a shader needs an image
|
|
230
|
+
# configured in VS-2 to show anything, and conversion warns about it.
|
|
231
|
+
#
|
|
232
|
+
# 2. Shadertoy shaders reading more than one distinct iChannel are declined:
|
|
233
|
+
# VS-2 binds one imageTex plus the fixed fftTex, so the channels cannot
|
|
234
|
+
# be preserved.
|
|
235
|
+
# That is a real limit of the engine, demonstrated by reading two.
|
|
236
|
+
#
|
|
237
|
+
# 3. ISF `TYPE: image` inputs convert. An earlier revision declined them,
|
|
238
|
+
# claiming the converter "would have to emit an image the user hasn't
|
|
239
|
+
# supplied" - which was wrong twice over: the input is the shader declaring
|
|
240
|
+
# that it REQUIRES an image (the same role as an iChannel0 read), and VS-2
|
|
241
|
+
# satisfies it from the layer's configured image. No image is emitted, so
|
|
242
|
+
# none needs supplying. A source that instead EMBEDS pixel data
|
|
243
|
+
# (IMG_NORM_PIXEL(TEXTURE_0), TEXTURE_* macros) is a different case and
|
|
244
|
+
# remains gated: there is genuinely nothing for VS-2 to sample.
|
|
245
|
+
#
|
|
246
|
+
# 4. Parameter-over-budget is a decline reason, not an auto-trim. The
|
|
247
|
+
# generator bakes extras to their defaults, but the app does not decide
|
|
248
|
+
# which parameters a user would accept losing.
|
vs2convert/core/gates.py
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
"""Registry of every refusal vs2_convert can make, and what each one allows.
|
|
2
|
+
|
|
3
|
+
WHY THIS EXISTS
|
|
4
|
+
---------------
|
|
5
|
+
Three times in this project a refusal was justified with a technical-sounding
|
|
6
|
+
reason that turned out to be fabricated or misread:
|
|
7
|
+
|
|
8
|
+
1. "The validator rejects valid custom uniforms." Actually the validator
|
|
9
|
+
matched the spec; 79 shipped shaders had zero uniform declarations. The
|
|
10
|
+
"evidence" quoted for this was never executed.
|
|
11
|
+
2. "image-input shaders are unsupported." Actually true of our headless
|
|
12
|
+
harness, which had no texture bound - not of the shaders. A 4-line
|
|
13
|
+
refusal in a test rig had become a policy about the engine.
|
|
14
|
+
3. "An ISF TYPE:image input would require the converter to emit an image the
|
|
15
|
+
user hasn't supplied." No mechanism exists. The input is the shader
|
|
16
|
+
declaring it REQUIRES an image; VS-2 binds the layer's image to
|
|
17
|
+
imageTex. Nothing is emitted, so nothing needs supplying.
|
|
18
|
+
|
|
19
|
+
All three had the same shape: a REFUSAL stated as fact, with no evidence
|
|
20
|
+
attached and nothing that would fail if the claim were false. A shader that
|
|
21
|
+
was fine to convert got blocked, and the block was reported as a property of
|
|
22
|
+
the engine rather than a gap in our tooling.
|
|
23
|
+
|
|
24
|
+
THE RULE
|
|
25
|
+
--------
|
|
26
|
+
A refusal is a claim about reality, so it gets held to the same standard as
|
|
27
|
+
one: it must name its evidence, and it must declare what it deliberately
|
|
28
|
+
still ALLOWS. Gates that only say what they reject are how case 2 happened -
|
|
29
|
+
"image-input" as a category was refused wholesale when only a narrow case
|
|
30
|
+
(one shader using two distinct channels) was genuinely unrepresentable.
|
|
31
|
+
|
|
32
|
+
The `allows` field is the load-bearing one. Every gate must state the
|
|
33
|
+
near-miss it preserves. A gate that cannot name one is probably a blanket
|
|
34
|
+
refusal in disguise, and should be deleted rather than kept.
|
|
35
|
+
|
|
36
|
+
Tested by tests/test_gates.py, which fails if a gate is added without
|
|
37
|
+
evidence, without an `allows` case, or without a passing positive control.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
from dataclasses import dataclass, field
|
|
41
|
+
from typing import Callable, Optional
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# Gates that describe something the target cannot express. --force is
|
|
45
|
+
# for a limitation the user accepts; on these it can only produce an
|
|
46
|
+
# output that does not compile or silently loses an input.
|
|
47
|
+
NON_FORCEABLE = frozenset({
|
|
48
|
+
'hlsl-milkdrop',
|
|
49
|
+
'glsl-texture2d',
|
|
50
|
+
'shadertoy-multi-channel',
|
|
51
|
+
'shadertoy-unrepresentable-channel',
|
|
52
|
+
'isf-multiple-image-inputs',
|
|
53
|
+
'too-many-parameters',
|
|
54
|
+
'missing-entry-point',
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass(frozen=True)
|
|
59
|
+
class Gate:
|
|
60
|
+
"""One refusal, with the evidence behind it and what it still permits.
|
|
61
|
+
|
|
62
|
+
id: stable identifier, used by tests
|
|
63
|
+
trigger: what in the source causes the refusal
|
|
64
|
+
reason: the user-facing message
|
|
65
|
+
evidence: WHY this is true - a spec citation, a measured fact, or a
|
|
66
|
+
named failing example. Not a restatement of `reason`.
|
|
67
|
+
allows: the near-miss this gate deliberately still accepts. Required.
|
|
68
|
+
module: file the gate lives in
|
|
69
|
+
"""
|
|
70
|
+
id: str
|
|
71
|
+
trigger: str
|
|
72
|
+
reason: str
|
|
73
|
+
evidence: str
|
|
74
|
+
allows: str
|
|
75
|
+
module: str
|
|
76
|
+
# Set by tests: a callable that must return True, proving `allows` works.
|
|
77
|
+
positive_control: Optional[Callable[[], bool]] = field(default=None)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
GATES = [
|
|
81
|
+
Gate(
|
|
82
|
+
id='hlsl-milkdrop',
|
|
83
|
+
trigger='frac() / lerp() / texture2D() in code (not comments)',
|
|
84
|
+
reason='HLSL/bundled-texture source (MilkDrop): multi-pass merge '
|
|
85
|
+
'is not automated; convert it by hand',
|
|
86
|
+
evidence=(
|
|
87
|
+
'MilkDrop HLSL is multi-pass and cannot be expressed as one VS-2 '
|
|
88
|
+
'pass (formal-spec.md:327 - VS-2 has no feedback buffer and '
|
|
89
|
+
'renders one pass per layer). Confirmed: a preset body using '
|
|
90
|
+
'frac()/lerp() is refused by this gate.'
|
|
91
|
+
),
|
|
92
|
+
allows=(
|
|
93
|
+
'A shader whose COMMENT mentions frac()/lerp() converts normally. '
|
|
94
|
+
'Real instance: an expert reference conversion carries '
|
|
95
|
+
'"// original: lerp(a, b, c)" and must not be refused.'
|
|
96
|
+
),
|
|
97
|
+
module='core/generator.py',
|
|
98
|
+
),
|
|
99
|
+
Gate(
|
|
100
|
+
id='isf-feedback-buffer',
|
|
101
|
+
trigger='ISF INPUTS entry with TARGET, or a PASSES entry with TARGET',
|
|
102
|
+
reason='feedback buffer (ISF TARGET input/pass): VS-2 is '
|
|
103
|
+
'single-pass with no feedback; convert it by hand',
|
|
104
|
+
evidence=(
|
|
105
|
+
'formal-spec.md:27 ("No feedback buffers in VS-2") and :327 ("VS-2 '
|
|
106
|
+
'has no feedback buffer"). Confirmed by execution: an ISF input '
|
|
107
|
+
'declaring TARGET:1 is refused.'
|
|
108
|
+
),
|
|
109
|
+
allows='An ISF shader with a PASSES array but no TARGET converts.',
|
|
110
|
+
module='core/generator.py',
|
|
111
|
+
),
|
|
112
|
+
Gate(
|
|
113
|
+
id='isf-imported-resources',
|
|
114
|
+
trigger='top-level "IMPORTED" dict in the ISF JSON (e.g. a PATH)',
|
|
115
|
+
reason='bundled image resources in IMPORTED',
|
|
116
|
+
evidence=(
|
|
117
|
+
'docs.isf.video/ref_json and the canonical Test-ImportedImage.fs '
|
|
118
|
+
'example: bundled images are declared under a top-level IMPORTED '
|
|
119
|
+
'key with a PATH per entry, and read through the same IMG_* '
|
|
120
|
+
'accessors as host-supplied images. They are files travelling '
|
|
121
|
+
'with the .fs; VS-2 has nowhere to put them. An earlier version '
|
|
122
|
+
'of this gate invented a TEXTURE_* macro concept that does not '
|
|
123
|
+
'exist in ISF, and so fired on nothing real.'
|
|
124
|
+
),
|
|
125
|
+
allows=(
|
|
126
|
+
'An INPUTS entry of TYPE "image" with NO IMPORTED block converts: '
|
|
127
|
+
'that is a host-supplied image, which VS-2 binds to imageTex. '
|
|
128
|
+
'docs.isf.video primer ch.4 and ref_json both use '
|
|
129
|
+
'IMG_NORM_PIXEL(inputImage, isf_FragNormCoord) for this case.'
|
|
130
|
+
),
|
|
131
|
+
module='core/generator.py',
|
|
132
|
+
),
|
|
133
|
+
Gate(
|
|
134
|
+
id='glsl-texture2d',
|
|
135
|
+
trigger='texture2D() or tex2D() call',
|
|
136
|
+
reason='bundled texture input (texture2D/tex2D): hard gate',
|
|
137
|
+
evidence=(
|
|
138
|
+
'formal-spec.md:185 - sampling is texture(imageTex, uv), NOT '
|
|
139
|
+
'texture2D. Distinct from an ISF image INPUT, which uses the '
|
|
140
|
+
'IMG_* accessors.'
|
|
141
|
+
),
|
|
142
|
+
allows='An ISF image input sampled via IMG_NORM_PIXEL converts.',
|
|
143
|
+
module='core/generator.py',
|
|
144
|
+
),
|
|
145
|
+
Gate(
|
|
146
|
+
id='shadertoy-multi-channel',
|
|
147
|
+
trigger='two or more distinct iChannelN reads in one body',
|
|
148
|
+
reason='VS-2 binds a single imageTex and a fixed audio fftTex, so '
|
|
149
|
+
'the channels cannot be preserved. Convert it by hand',
|
|
150
|
+
evidence=(
|
|
151
|
+
'formal-spec.md:26 and :274 - iChannel0..3 map to imageTex, a '
|
|
152
|
+
'SINGLE sampler. fftTex is a separate engine-owned audio sampler '
|
|
153
|
+
'(factory-examples/bars_spectrum_example.frag), not a slot the '
|
|
154
|
+
'converter can bind. Two distinct channels have no faithful '
|
|
155
|
+
'target. '
|
|
156
|
+
'Researched 2026-09-25: a Shadertoy iChannel is a binding SLOT, '
|
|
157
|
+
'not a known image - it may hold a texture, feedback buffer, '
|
|
158
|
+
'cubemap, video, keyboard or audio, and "iChannel0 does not '
|
|
159
|
+
'always mean the main texture" (shadergif Shadertoy uniform '
|
|
160
|
+
'reference, and Shadertoy own guidance to inspect the pass '
|
|
161
|
+
'configuration). Which one it is lives on the shader page, not in '
|
|
162
|
+
'the .txt.'
|
|
163
|
+
),
|
|
164
|
+
allows=(
|
|
165
|
+
'A single iChannel0 read converts, renaming to imageTex per '
|
|
166
|
+
'formal-spec.md. Image-input shaders are ordinary shaders: VS-2 '
|
|
167
|
+
'binds the layer-configured image and ignores it for shaders that '
|
|
168
|
+
'do not sample one.'
|
|
169
|
+
),
|
|
170
|
+
module='core/generator.py',
|
|
171
|
+
),
|
|
172
|
+
Gate(
|
|
173
|
+
id='body-feedback-refs',
|
|
174
|
+
trigger='PASSINDEX together with bufferA-D / BufferA-D / feedback',
|
|
175
|
+
reason='multi-pass feedback (buffer/feedback refs): VS-2 is '
|
|
176
|
+
'single-pass; convert it by hand',
|
|
177
|
+
evidence=(
|
|
178
|
+
'formal-spec.md:327 - "VS-2 has no feedback buffer". A distinct '
|
|
179
|
+
'trigger from isf-feedback-buffer: that one reads the ISF '
|
|
180
|
+
'header, this one reads the body. Found by the drift check in '
|
|
181
|
+
'tests/test_gates.py, which flagged an unregistered refusal.'
|
|
182
|
+
),
|
|
183
|
+
allows=(
|
|
184
|
+
'PASSINDEX alone (no buffer/feedback refs) is NOT this gate: the '
|
|
185
|
+
'converter projects the source onto its final pass. Only a body '
|
|
186
|
+
'that samples a feedback buffer is refused.'
|
|
187
|
+
),
|
|
188
|
+
module='core/generator.py',
|
|
189
|
+
),
|
|
190
|
+
Gate(
|
|
191
|
+
id='isf-multiple-image-inputs',
|
|
192
|
+
trigger='two or more ISF INPUTS entries with TYPE "image"',
|
|
193
|
+
reason='declares %d distinct image inputs',
|
|
194
|
+
evidence=(
|
|
195
|
+
'formal-spec.md:26 and :274 - every image input maps to a SINGLE '
|
|
196
|
+
'sampler, imageTex. Verified on a real case: GLSLOP '
|
|
197
|
+
'developer-k0rz1pe2.fs declares six (src0..src5) and passes each '
|
|
198
|
+
'to a different call. Collapsing them onto one imageTex left the '
|
|
199
|
+
'body referencing samplers that were never declared, so the '
|
|
200
|
+
'output did not compile. Found by running that collection, not by '
|
|
201
|
+
'any test. The ISF counterpart of shadertoy-multi-channel.'
|
|
202
|
+
),
|
|
203
|
+
allows=(
|
|
204
|
+
'A single TYPE:"image" input converts normally: its sampler is '
|
|
205
|
+
'resolved against imageTex and it never becomes a manifest knob, '
|
|
206
|
+
'since the image is implicit (formal-spec.md:183).'
|
|
207
|
+
),
|
|
208
|
+
module='core/generator.py',
|
|
209
|
+
),
|
|
210
|
+
Gate(
|
|
211
|
+
id='shadertoy-unrepresentable-channel',
|
|
212
|
+
trigger='metadata declaring a channel as buffer/cubemap/audio/keyboard',
|
|
213
|
+
reason='not a bindable image (audio: no FFT/waveform mapping yet)',
|
|
214
|
+
evidence=(
|
|
215
|
+
'formal-spec.md:26 and :274 - ONE bindable image, imageTex, from '
|
|
216
|
+
'the layer-configured image. Verified: a converter run with '
|
|
217
|
+
'channels={"iChannel0":{"sampler":"buffer"}} refuses, and the same '
|
|
218
|
+
'shader with sampler "texture" converts. A buffer, cubemap or '
|
|
219
|
+
'keyboard channel has no VS-2 input at all. audio is refused for '
|
|
220
|
+
'a narrower reason: fftTex IS a pre-declared sampler2D '
|
|
221
|
+
'(factory-examples/bars_spectrum_example.frag samples '
|
|
222
|
+
'texture(fftTex, vec2(freq, 0.0))), but no mapping is '
|
|
223
|
+
'implemented here, and "audio" does not distinguish a waveform '
|
|
224
|
+
'channel from an FFT channel, so a rename would silently produce '
|
|
225
|
+
'the wrong signal. Decided from supplied metadata, never '
|
|
226
|
+
'guessed.'
|
|
227
|
+
),
|
|
228
|
+
allows=(
|
|
229
|
+
'A channel declared as a texture/video/2d converts and is marked '
|
|
230
|
+
'CONFIRMED rather than unverified. A channel with no declaration '
|
|
231
|
+
'at all still converts, just unverified - refusing every unknown '
|
|
232
|
+
'channel would block the common single-user-image shader.'
|
|
233
|
+
),
|
|
234
|
+
module='core/generator.py',
|
|
235
|
+
),
|
|
236
|
+
Gate(
|
|
237
|
+
id='shadertoy-channel-uncertainty',
|
|
238
|
+
trigger='a single iChannelN read, mapped to imageTex without evidence',
|
|
239
|
+
reason='UNVERIFIED: iChannel',
|
|
240
|
+
evidence=(
|
|
241
|
+
'NOT a refusal - a disclosure. A Shadertoy iChannel is a binding '
|
|
242
|
+
'slot that may hold a texture, feedback buffer, cubemap, video, '
|
|
243
|
+
'keyboard or audio data; the pass configuration lives on the '
|
|
244
|
+
'Shadertoy page, so it cannot be determined from source. Refusing '
|
|
245
|
+
'every channel shader would block the common legitimate case (one '
|
|
246
|
+
'user image), and converting silently would let a wrong guess read '
|
|
247
|
+
'as verified. So it converts, and says so loudly: the conversion '
|
|
248
|
+
'is marked UNVERIFIED, the CLI prints a dedicated [unverified] '
|
|
249
|
+
'block, and --strict exits 5. Per gates.py this is the kind of '
|
|
250
|
+
'unverifiable claim that must be visible rather than assumed.'
|
|
251
|
+
),
|
|
252
|
+
allows=(
|
|
253
|
+
'A shader that samples imageTex directly (a converted VS-2 file '
|
|
254
|
+
're-converted) is never flagged. iChannelResolution/iChannelTime '
|
|
255
|
+
'references additionally warn, since those describe the bound '
|
|
256
|
+
'slot and have no VS-2 equivalent.'
|
|
257
|
+
),
|
|
258
|
+
module='core/generator.py',
|
|
259
|
+
),
|
|
260
|
+
Gate(
|
|
261
|
+
id='engine-var-redeclaration',
|
|
262
|
+
trigger='global-scope declaration of resolution/time/texCoord/...',
|
|
263
|
+
reason="redeclares engine var",
|
|
264
|
+
evidence=(
|
|
265
|
+
'validate_shader.py:23 - global-scope redeclaration of engine '
|
|
266
|
+
'vars is an ERROR. Confirmed on 79 shipped shaders: none '
|
|
267
|
+
'redeclare one.'
|
|
268
|
+
),
|
|
269
|
+
allows='Any custom (non-engine) uniform name is untouched by this gate.',
|
|
270
|
+
module='core/detector.py',
|
|
271
|
+
),
|
|
272
|
+
Gate(
|
|
273
|
+
id='too-many-parameters',
|
|
274
|
+
trigger='more than 7 parameters in a Shadertoy-style "parameters" '
|
|
275
|
+
'block, or more than 7 uniform declarations',
|
|
276
|
+
reason='Too many parameters: %d (max 7)',
|
|
277
|
+
evidence=(
|
|
278
|
+
'VS-2 manifests carry at most 7 parameters, and the converter '
|
|
279
|
+
'truncates the emitted manifest to MAX_PARAMS (generator.py:26). '
|
|
280
|
+
'Measured: a Shadertoy source declaring 9 parameters is declined '
|
|
281
|
+
'by check_suitability before conversion. NOTE: detector.'
|
|
282
|
+
'_extract_parameters reads "parameters" blocks and uniform '
|
|
283
|
+
'declarations, NOT ISF INPUTS - measured, a 9-INPUT ISF converts '
|
|
284
|
+
'with 7 knobs and the surplus is baked to its DEFAULT. That is a '
|
|
285
|
+
'known gap, not this gate firing.'
|
|
286
|
+
),
|
|
287
|
+
allows=(
|
|
288
|
+
'Exactly 7 parameters converts; the manifest is complete. The '
|
|
289
|
+
'generator still bakes surplus params to their defaults when '
|
|
290
|
+
'--force overrides this gate.'
|
|
291
|
+
),
|
|
292
|
+
module='core/detector.py',
|
|
293
|
+
),
|
|
294
|
+
Gate(
|
|
295
|
+
id='missing-entry-point',
|
|
296
|
+
trigger='no mainImage() for Shadertoy/PlainGLSL, or no main() for '
|
|
297
|
+
'GLSLSandbox',
|
|
298
|
+
reason='no mainImage() or main() entry point found',
|
|
299
|
+
evidence=(
|
|
300
|
+
'The entry point is located by regex on code only, because a '
|
|
301
|
+
'comment naming mainImage() is documentation. Confirmed against '
|
|
302
|
+
'the 41-shader ISF corpus and the Shadertoy test sources: every '
|
|
303
|
+
'convertible source has one, and a body without one cannot be '
|
|
304
|
+
'wrapped into fragColor.'
|
|
305
|
+
),
|
|
306
|
+
allows=(
|
|
307
|
+
'A source with a real mainImage() or main() converts normally; '
|
|
308
|
+
'so does a comment that merely mentions mainImage().'
|
|
309
|
+
),
|
|
310
|
+
module='core/generator.py',
|
|
311
|
+
),
|
|
312
|
+
Gate(
|
|
313
|
+
id='isf-parse-failure',
|
|
314
|
+
trigger='ISF file whose JSON manifest does not parse',
|
|
315
|
+
reason='ISF INPUTS block not found or not parseable',
|
|
316
|
+
evidence=(
|
|
317
|
+
'docs.isf.video/ref_json: an ISF file IS its JSON comment; the '
|
|
318
|
+
'INPUTS array in it supplies every knob and the manifest '
|
|
319
|
+
'metadata. If that block does not parse, no parameter list can be '
|
|
320
|
+
'recovered. Confirmed by running a malformed header: json.loads '
|
|
321
|
+
'raises and this gate fires instead of emitting half a manifest.'
|
|
322
|
+
),
|
|
323
|
+
allows=(
|
|
324
|
+
'A valid ISF manifest converts, including one with an empty '
|
|
325
|
+
'INPUTS array.'
|
|
326
|
+
),
|
|
327
|
+
module='core/generator.py',
|
|
328
|
+
),
|
|
329
|
+
Gate(
|
|
330
|
+
id='unsupported-format',
|
|
331
|
+
trigger='a format name that has no body converter',
|
|
332
|
+
reason='unsupported format',
|
|
333
|
+
evidence=(
|
|
334
|
+
'.md: detect_format returns ISF, Shadertoy, GLSLSandbox, '
|
|
335
|
+
'PlainGLSL or MilkDrop. Only the first four have a body '
|
|
336
|
+
'converter; MilkDrop is refused earlier by hlsl-milkdrop. '
|
|
337
|
+
'Measured: calling convert() with any other name raises this.'
|
|
338
|
+
),
|
|
339
|
+
allows=(
|
|
340
|
+
'Every format detect_format can name reaches a converter: '
|
|
341
|
+
'PlainGLSL converts through the Shadertoy path.'
|
|
342
|
+
),
|
|
343
|
+
module='core/generator.py',
|
|
344
|
+
),
|
|
345
|
+
Gate(
|
|
346
|
+
id='structural-validation',
|
|
347
|
+
trigger='the converted .frag fails validators/validator.py',
|
|
348
|
+
reason='structural validation failed',
|
|
349
|
+
evidence=(
|
|
350
|
+
'.py: validators/validator.py rejects HLSL leftovers, engine-var '
|
|
351
|
+
'redeclarations, camelCase parameter names and malformed '
|
|
352
|
+
'manifests. Measured: converting a body that redeclares texCoord '
|
|
353
|
+
'and validating the result reports an error. This gate is where '
|
|
354
|
+
'`ok=True` gets its meaning: a file was produced AND it is valid.'
|
|
355
|
+
),
|
|
356
|
+
allows=(
|
|
357
|
+
'A conversion that satisfies every structural rule passes: the 72 '
|
|
358
|
+
'shipped reference conversions validate with zero errors.'
|
|
359
|
+
),
|
|
360
|
+
module='validators/validator.py',
|
|
361
|
+
),
|
|
362
|
+
Gate(
|
|
363
|
+
id='internal-error',
|
|
364
|
+
trigger='an unexpected exception while converting or validating',
|
|
365
|
+
reason='conversion failed unexpectedly',
|
|
366
|
+
evidence=(
|
|
367
|
+
'Measured: malformed-but-parseable ISF raises non-ConversionError '
|
|
368
|
+
'exceptions - INPUTS as a string is AttributeError, INPUTS as a '
|
|
369
|
+
'list of ints is AttributeError, DEFAULT: null is TypeError. The '
|
|
370
|
+
'API boundary turns these into one rejection so a front-end can '
|
|
371
|
+
'never receive a traceback.'
|
|
372
|
+
),
|
|
373
|
+
allows=(
|
|
374
|
+
'Every malformed shape above returns a ConversionResult instead '
|
|
375
|
+
'of raising; well-formed sources never reach this gate.'
|
|
376
|
+
),
|
|
377
|
+
module='api.py',
|
|
378
|
+
),
|
|
379
|
+
]
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def gates_for(module: str):
|
|
383
|
+
"""Gates declared in a given module."""
|
|
384
|
+
return [g for g in GATES if g.module == module]
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def evidence_missing():
|
|
388
|
+
"""Gates whose evidence field is empty or merely restates the reason.
|
|
389
|
+
|
|
390
|
+
Called by tests/test_gates.py. Kept here so the rule lives next to the
|
|
391
|
+
data it governs.
|
|
392
|
+
"""
|
|
393
|
+
bad = []
|
|
394
|
+
for g in GATES:
|
|
395
|
+
ev = g.evidence.strip().lower()
|
|
396
|
+
if not ev:
|
|
397
|
+
bad.append((g.id, 'no evidence'))
|
|
398
|
+
continue
|
|
399
|
+
# Evidence that just repeats the refusal in other words is not
|
|
400
|
+
# evidence. Require at least one of: a citation, a measurement, or
|
|
401
|
+
# a concrete named example.
|
|
402
|
+
has_citation = any(t in ev for t in ('.md:', '.py:', 'line', 'spec'))
|
|
403
|
+
has_measurement = any(t in ev for t in
|
|
404
|
+
('confirmed', 'measured', 'verified', '79',
|
|
405
|
+
'all 79', 'zero', '0 of'))
|
|
406
|
+
has_example = '.frag' in ev or '.fs' in ev or 'for example' in ev
|
|
407
|
+
if not (has_citation or has_measurement or has_example):
|
|
408
|
+
bad.append((g.id, 'evidence restates the reason'))
|
|
409
|
+
return bad
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def allows_missing():
|
|
413
|
+
"""Gates that do not declare a near-miss they preserve."""
|
|
414
|
+
return [(g.id, 'no allows case') for g in GATES if not g.allows.strip()]
|