[Feat] (MG_Util, DirectGLES, DirectVulkan): normalize rectangle coordinates in the module

Neither target API has GL_TEXTURE_RECTANGLE: ESSL has no rectangle sampler, and
Vulkan's SPIR-V environment does not allow Dim::Rect. Both emulate it on a plain 2D
texture, and the two differ in exactly one way - a rectangle lookup addresses texels
where a 2D one addresses [0,1].

That one difference now lives in one SPIR-V pass, so neither backend has to know about
it: every lookup taking normalized coordinates gets its coordinate divided by the size
the texture reports, and the image type is then rewritten to 2D. Magma had no rectangle
handling at all - it fed Dim::Rect straight to Vulkan, which read the texel coordinates
as normalized and sampled the edge, so all fifteen KHR-GL40.texture_gather.*-2drect
cases came back holding the clear colour.

This replaces the ESSL text rewrite that did the same divide for DirectGLES only. Doing
it in the module instead is both shorter and stricter: the pass resolves an operation's
image type through the sampled-image and pointer wrappers rather than matching a
sampler name in generated source, so it cannot be fooled by an expression where it
expected an identifier, and it needs no help from the frontend reflection to know which
samplers were rectangles.

Still declined, as before: the Dref *sample* forms, whose coordinate carries the compare
value in its last component, and the projective ones, where the divide would have to
happen after the perspective divide. texelFetch is deliberately untouched - integer
texel coordinates mean the same thing on both targets.

KHR-GL40.texture_gather: Magma 66 failures -> 2, Espryt stays at 75/75.
This commit is contained in:
BZLZHH
2026-08-04 13:25:40 -04:00
parent 44ee6b66b3
commit 28d0af6f04
11 changed files with 263 additions and 192 deletions
-9
View File
@@ -129,15 +129,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
// all have a zero bias is therefore unaffected. Returns the source unchanged when
// there is nothing to rewrite.
String EmulateTextureLodBias(const String& glslCode);
// GL_TEXTURE_RECTANGLE is emulated on an ES 2D texture and LowerRectImagesForEssl
// rewrites the image type to match, but a rectangle lookup addresses texels
// directly while a 2D one addresses [0,1] - so every lookup that takes normalized
// coordinates has to divide by the texture's size. `rectSamplerNames` is the set of
// samplers the program declared as rectangle; texelFetch is left alone (its
// coordinates are unnormalized on both targets) and so is anything projective,
// which LowerRectImagesForEssl still declines outright.
String NormalizeRectSamplerCoordinates(const String& glslCode,
const Vector<String>& rectSamplerNames);
} // namespace PrgramImpl
namespace Utils {