mirror of
https://github.com/seedds/nxnative.git
synced 2026-11-23 11:39:42 -10:00
gl/shaders: a GLSL ES 1.00 name that later GLSL takes is renamed for the compile and given back in the table rows (#2818, PR #2819)
Fate/hollow ataraxia REMASTERED's ES 1.00 shaders declare `uniform sampler2D texture;`. They go through glslang as ES 3.10, where texture is a built-in function: 16 of its 78 captured fragment shaders failed with `'texture' : redefinition`, and the scenes they draw were black. es100() now renames the name (dm_texture; a texture( call stays), as it renamed `sample`, and every table row (a:, o:, u:, t:, n:) gives the renamed names (dm_texture, gm_sample, dm_sampler) back as the game wrote them, since the host finds attributes, uniforms and samplers by the game's names. PR #2819 renamed the sampler before the version check, so a versioned shader lost the rename, and gave back only t: rows. Fate: 62 shaders translate → 75 (the other 3 need a sampler slot above 15). The tables of Well Dweller (93) and Balatro (35) are the same row for row. Checked: test_gl_shaders.py. Fixes #2818 Co-authored-by: Beeven <[email protected]>
This commit is contained in:
1 parent
58ab54a5b3
commit
ba9ce21258
4 files changed
+48
-1
No files matched your search
@@ -175,8 +175,21 @@ def es100(t, stage):
|
||||
if stage == 'frag' and 'gl_FragColor' in t:
|
||||
t = 'out vec4 gm_FragColor;\n' + t.replace('gl_FragColor', 'gm_FragColor')
|
||||
t = re.sub(r'\bsample\b', 'gm_sample', t) # `sample` became a reserved word after ES 1.00 (GameMaker's sprite shaders use it as a variable)
|
||||
# `texture` became a built-in function after ES 1.00, and a name declared `texture` redefines it (Fate/hollow ataraxia REMASTERED: `uniform sampler2D texture;`); a call stays
|
||||
t = re.sub(r'\btexture\b(?!\s*\()', 'dm_texture', t)
|
||||
return '#version 310 es\nprecision highp float;\nprecision highp int;\n' + t
|
||||
|
||||
# The game's names that the rewrite renames (es100, fixups): the table rows give them back as the game wrote them, since the host finds attributes, uniforms and samplers by the
|
||||
# game's name (glGetAttribLocation, glGetUniformLocation); the key is the hash of the game's own source
|
||||
RENAMED = {'gm_sample': 'sample', 'dm_texture': 'texture', 'dm_sampler': 'sampler'}
|
||||
|
||||
def game_names(f):
|
||||
"""table fields with the renamed names in their name part (a:, o:, u:, t:, n: up to the '=') given back"""
|
||||
def back(x):
|
||||
k, sep, rest = x.partition('=')
|
||||
return re.sub(r'\b(' + '|'.join(RENAMED) + r')\b', lambda m: RENAMED[m.group(1)], k) + sep + rest
|
||||
return [back(x) for x in f]
|
||||
|
||||
def translate(src, stage, key, tmp):
|
||||
"""GLSL → MSL; returns (msl path, table fields) or an error string"""
|
||||
t = src.decode('latin1')
|
||||
@@ -225,7 +238,7 @@ def translate(src, stage, key, tmp):
|
||||
for k in ('separate_images', 'separate_samplers', 'images', 'ssbos', 'push_constants'):
|
||||
if refl.get(k): return f'{k} are not implemented'
|
||||
if any(int(x) > 15 for x in re.findall(r'\[\[(?:sampler|buffer)\((\d+)\)\]\]', m)): return 'a buffer or sampler slot above 15'
|
||||
return msl, f
|
||||
return msl, game_names(f)
|
||||
|
||||
def one(item, tmp):
|
||||
"""[(key, stage, fields, msl, where)], or [(key, None, errors, None, where)] when no stage translates"""
|
||||
|
||||
@@ -56,6 +56,23 @@ class Fixups(unittest.TestCase):
|
||||
self.assertEqual(gl_shaders.function_semicolons(g), g)
|
||||
|
||||
|
||||
# GLSL ES 1.00 as Fate/hollow ataraxia REMASTERED's built shaders write it: a sampler named `texture` (a built-in function from ES 3.00 on) and, as GameMaker's, a variable `sample`
|
||||
ES100_FRAG = (b'precision mediump float;\nvarying vec2 v_uv;\nuniform sampler2D texture;\nuniform float sample;\n'
|
||||
b'void main() { gl_FragColor = texture2D(texture, v_uv) * sample; }\n')
|
||||
|
||||
|
||||
class GameNames(unittest.TestCase):
|
||||
def test_es100_renames_texture_names_not_calls(self):
|
||||
t = gl_shaders.es100(ES100_FRAG.decode(), 'frag')
|
||||
self.assertIn('uniform sampler2D dm_texture;', t); self.assertIn('texture2D(dm_texture, v_uv)', t)
|
||||
self.assertIn('vec4 c = texture (s, v);', gl_shaders.es100('vec4 c = texture (s, v);', 'frag')) # a call (NVIDIA takes one in ES 1.00 too) stays
|
||||
|
||||
def test_table_rows_give_the_names_back(self):
|
||||
rows = ['t:dm_texture=0:sampler2D', 'u:L.gm_sample=16:float:0:0', 'a:dm_sampler=1:vec4', 'b:0:32', 'o:gm_FragColor=0', 'u:dm_texture_scale=0:float:0:0']
|
||||
self.assertEqual(gl_shaders.game_names(rows), ['t:texture=0:sampler2D', 'u:L.sample=16:float:0:0', 'a:sampler=1:vec4', 'b:0:32', 'o:gm_FragColor=0',
|
||||
'u:dm_texture_scale=0:float:0:0'])
|
||||
|
||||
|
||||
class Sources(unittest.TestCase):
|
||||
def test_glsl_files_are_read_with_no_stage(self): # Mega Man Legacy Collection: shaders/nx/*.glsl, whose names say nothing of the stage
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
@@ -89,6 +106,14 @@ class Translate(unittest.TestCase):
|
||||
self.assertEqual([x for x in r[1] if x.startswith('t:')], ['t:T0=0:sampler2D'])
|
||||
|
||||
|
||||
def test_es100_sampler_named_texture(self): # Fate/hollow ataraxia REMASTERED: 16 of its 78 fragment shaders failed with `'texture' : redefinition`
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
r = gl_shaders.translate(ES100_FRAG, 'frag', 'e' * 16, tmp)
|
||||
self.assertIsInstance(r, tuple, r)
|
||||
self.assertIn('t:texture=0:sampler2D', r[1])
|
||||
self.assertTrue(any(x.startswith('u:sample=') for x in r[1]), r[1])
|
||||
|
||||
|
||||
class MainStrings(unittest.TestCase):
|
||||
def test_a_prefix_is_not_a_shader(self):
|
||||
self.assertIsNone(gl_shaders.GL_ENTRY.search(PREFIX.encode()))
|
||||
|
||||
@@ -1054,6 +1054,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
|
||||
- every draw is skipped: `[RED] … shader <key> (<n> bytes of GLSL) is not in the library (DM_GL_CAPTURE collects it)`, `program <n>: a shader is missing from the library, its draws are skipped`, `draw with no usable program`, and frame records of `draws 0`. The NSP script translated only `main`'s strings and planned no capture, since those count as the game's GLSL. → [GLSL source files named `.glsl`](../reference/rendering.md#glsl-source-files-named-glsl)
|
||||
- `gl_shaders.py` reports `does not translate: vert: glslang: ERROR: …: 'extraneous semicolon' : not supported with this profile: es`, and the host skips that program's draws. → [A function body closed with `};`](../reference/rendering.md#a-function-body-closed-with-)
|
||||
- every sprite of a program samples black, while the textures are there; the shader's table row lists two samplers at one slot, such as `t:T0=0:sampler2D t:T1=0:sampler2D`. → [A sampler the shader never reads](../reference/rendering.md#a-sampler-the-shader-never-reads)
|
||||
- `gl_shaders.py` reports `does not translate: frag: glslang: ERROR: …: 'texture' : redefinition`, and the scenes those shaders draw are black. → [A GLSL ES 1.00 name that later GLSL takes](../reference/rendering.md#a-glsl-es-100-name-that-later-glsl-takes)
|
||||
- in a capture run every program links with no uniforms; the game's first `Shader:send` raises a Lua error and, on the Switch, its error handler quits (Any Lua error quits a LÖVE game). → [GL shaders put together at run time and captured](../reference/rendering.md#gl-shaders-put-together-at-run-time-and-captured)
|
||||
- a capture run that only boots or plays the game misses shaders: `[RED] … shader … is not in the library (DM_GL_CAPTURE collects it)` once play reaches something the capture never drew. → [GLSL an id Tech 4 renderer makes on first use](../reference/rendering.md#glsl-an-id-tech-4-renderer-makes-on-first-use)
|
||||
- `UNIMPL glGenSamplers`, `glSamplerParameteri`, `glSamplerParameterf`, `glSamplerParameterfv` at boot and `UNIMPL glBindSampler` at the first draw; textures sample with their own parameters, not the game's. → [GL sampler objects](../reference/rendering.md#gl-sampler-objects)
|
||||
|
||||
@@ -2149,6 +2149,14 @@ Digimon Story Cyber Sleuth: Complete Edition (Media.Vision's MVGL engine, SDK 6.
|
||||
- GLSL 1.50 as DOOM 3's renderer writes it: built-ins redeclared as plain varyings (`out vec4 gl_Position;`, `in vec4 gl_FragCoord;`, `out float gl_FragDepth;`) lose the declaration and keep the built-in; `out vec4 gl_FragColor;` becomes a plain output of the shader's own, `dm_FragColor` (Vulkan GLSL has no `gl_FragColor`); the compatibility colour declared as a varying, `out vec4 gl_FrontColor;` in the vertex shader and `in vec4 gl_Color;` in the fragment shader, which NVIDIA links as GL's fixed pipeline does, becomes one varying, `dm_Color`, matched by name; `sampler` as a name (its helpers take `sampler2D sampler`), a reserved word in Vulkan GLSL, becomes `dm_sampler`. A compatibility built-in the shader does not declare is left alone.
|
||||
- **Found on:** [DOOM 3](../../dm/games/010029D00E740000/README.md): all 62 shaders of its title and first level (`test_gl_shaders.py` has a pair written in their form).
|
||||
|
||||
### A GLSL ES 1.00 name that later GLSL takes
|
||||
|
||||
- **Symptom:** `gl_shaders.py` reports `does not translate: frag: glslang: ERROR: …: 'texture' : redefinition`, and the scenes those shaders draw are black.
|
||||
- **Cause:** GLSL ES 1.00 shaders go through glslang as ES 3.10, where `texture` is a built-in function and `sample` a reserved word; ES 1.00 leaves both free as names (`uniform sampler2D texture;`).
|
||||
- **Fix:** `es100()` renames them (`dm_texture`, `gm_sample`; a `texture(` call stays, since NVIDIA's compiler takes one in ES 1.00 too), and the table rows give every name the rewrite renamed (`dm_texture`, `gm_sample`, `dm_sampler`) back as the game wrote it: the host finds attributes, uniforms and samplers by the game's names, and the shader's key is the hash of the game's own source.
|
||||
- **Check:** `test_gl_shaders.py`.
|
||||
- **Found on:** Fate/hollow ataraxia REMASTERED, [issue #2818](https://github.com/seedds/nxnative/issues/2818): 16 of its 78 captured fragment shaders; 13 of them translate now (62 shaders → 75), and the other 3 need a sampler slot above 15, which the table cannot name. The tables of Well Dweller (93 shaders) and Balatro (35) are the same row for row.
|
||||
|
||||
### GL shaders put together at run time and captured
|
||||
|
||||
- **Symptom:** in a capture run every program links with no uniforms; the game's first `Shader:send` raises a Lua error and, on the Switch, its error handler quits ([Any Lua error quits a LÖVE game](game-state.md#any-lua-error-quits-a-löve-game)).
|
||||
|
||||
Reference in new issue
Block a user