Skip to content

openOMSI's OpenGL shaders on the bound tier; textureLoad from depth in GLSL; DX shader cache on disk - #14

Merged
turbo-devv merged 10 commits into
mainfrom
feat/openomsi-gl-shaders
Nov 23, 2026
Merged

turbo-devv merged 10 commits into
mainfrom
feat/openomsi-gl-shaders

Conversation

@turbo-devv

@turbo-devv turbo-devv commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

openOMSI assembles its shader modules differently on OpenGL (gl_backend()): the scene's arrays and lamps read from textures, the roof map read as a float texture, the basic set for weak drivers. Until now openomsi_shaders skipped the bound tier. This PR adds those GL variants and tests them on GL.

  • crates/mx/tests/openomsi_gl: openOMSI's 17 OpenGL modules (from openOMSI fc59155ad, see the README there). openomsi_shaders uses them on a GL device. Other bound tiers (Metal 2, Direct3D 11) take the native set, as openOMSI does on them.
  • naga (MX_PATCHES.md): naga's GLSL writer refused textureLoad from a depth texture. That broke the sky module: the screen-space clouds read the scene's depth (cloud_covered), so on OpenGL the cloud pipelines would fail with Enhanced graphics on. Now a depth texture that is only loaded from, never sampled, is declared as sampler2D and read with texelFetch(..).x. A multisampled one is read from its sampler2DMS. A depth texture that is also sampled with a comparison still gets the error. Unit test in mx-shader (validated with glslangValidator, GLSL ES 3.10 and GL 4.30, plus ES 3.00).
  • CI: the Linux job runs conformance and openOMSI's GL shaders on Mesa llvmpipe through EGL under Xvfb, on OpenGL ES and on desktop GL.

Checked on an M4:

  • ANGLE over Metal (OpenGL ES 3.0, MX_EGL_LIBRARY=VS Code's libEGL): 17/17 openOMSI GL modules compile (before the naga fix: 16, the sky failed). Conformance 29/29.
  • Metal 2 bound tier (MX_METAL_BOUND=1): the native set compiles (ray tracing skipped).

Compiled shaders on disk (Direct3D 12 and 11)

DXC took about 15 s over openOMSI's scene module on WARP, and every start of the game paid that again. mx_shader::disk_cache keeps the bytecode keyed by the HLSL, entry point, profile, flags and the compiler's build: DXC's version, the DLL's size, and whether dxil.dll signs the output. The cache lives in %LOCALAPPDATA%\mX\shaders, or wherever MX_SHADER_CACHE points (0 turns it off).

  • Each entry stores the key's length, a second hash of the key, and a checksum of the code. A damaged file, or one written for another key, is ignored.
  • Writes go to a temporary file that is then renamed into place.
  • The folder stays under 512 MB; the oldest entries go first.
  • Direct3D 12 uses it behind its in-memory cache. Direct3D 11's FXC path uses it too.
  • Unit tests in mx-shader run on every platform. On Windows, CI runs openOMSI's shaders twice: once into an empty cache, then again from it.
  • Checked: cargo clippy -p mx-dx12 -p mx-dx11 --target x86_64-pc-windows-msvc -- -D warnings. Not yet run on Windows hardware; CI on WARP is the first run.

mx-gl: depth-only pipelines on OpenGL ES

I ran openOMSI's own renderer GPU tests on this branch over ANGLE (--config patch.… pointing openOMSI at the local mX; nothing changed in openOMSI). The renderer could not be created: the "shadow clear" pipeline has no fragment stage, and OpenGL ES won't link a program without one. mx-gl now attaches an empty fragment shader, which is what wgpu-hal does. New conformance test depth_only_pipelines_draw_without_a_fragment_stage: it fails on ANGLE without the fix and passes on Metal and GL with it. After the fix, enhanced_respects_material_ambient passes on mX GL. That test builds the whole renderer with Enhanced, including the cloud pass that relies on the naga fix above.

CI on WARP, shader cache: the scene module goes from 14.0 s in DXC to 0.15 s read from the cache, and openOMSI's whole set from 40.6 s to 0.7 s.

mx-gl: what Mesa (llvmpipe, OpenGL ES 3.2) found in CI

  • Indirect draws with a first instance drew at instance 0. OpenGL ES's indirect commands have no first-instance field (it's reservedMustBeZero). Without draw parameters, the shader adds the first instance from a uniform, and a GPU-side draw can't set that uniform. Without draw parameters, indirect draws now take the same route as on ES 3.0: the arguments are read back and the draw is issued directly. openOMSI makes no indirect draws.
  • copy_texture_to_buffer of a compressed texture panicked. Now each layer's blocks are copied with glCopyImageSubData (GL 4.3 / ES 3.2) into an RG32UI/RGBA32UI texture, one texel per block, and read back from there.
  • Draws starting past instance 0 were drawn as instance 0 on desktop GL with draw parameters: the shader reads gl_BaseInstance, and plain glDraw*Instanced calls leave it at 0. They now use the base-instance draws (GL 4.2). This broke render bundles and occlusion queries on GL 4.5.
  • Compressed uploads into a mip smaller than a block, like WebGPU's 4×4 into a 2×2 mip, were refused by GL. The small mips of every BC texture were never written, so on GL the mip chain was incomplete. The upload now uses the mip's real size.

CI now runs green on Mesa llvmpipe both as OpenGL ES 3.2 and as desktop GL 4.5 core: 30/30 conformance, and 17/17 of openOMSI's GL modules.

Not done: openOMSI's renderer GPU tests on mX GL (ANGLE ES 3.0) give 48 passed and 42 failed, all on picture checks. Some of those features are absent on GL anyway (puddles, ray tracing, MetalFX, lamp sight, GPU timers). The rest haven't been sorted yet into GL-path differences versus mX bugs; that needs a wgpu-GL baseline of the same tests.

…L shaders on the bound tier

openOMSI's OpenGL variants of its modules (gl_backend(): arrays and lamps in
textures, roof map as float, the basic set) are in tests/openomsi_gl, and
openomsi_shaders takes them on a GL device. On ANGLE over Metal (OpenGL ES 3.0)
16 of 17 compiled; the sky failed: naga's GLSL writer refused textureLoad from
the scene's depth (the screen-space clouds' cloud_covered), so the cloud
pipelines would fail on OpenGL with Enhanced graphics.

naga (MX_PATCHES.md): a depth texture loaded from and never sampled is a
sampler2D read with texelFetch(..).x; a multisampled one is fetched from its
sampler2DMS. Now all 17 compile on ANGLE, conformance 29/29 there.

CI: conformance and openOMSI's GL shaders on Mesa llvmpipe (EGL under Xvfb),
OpenGL ES and desktop.
DXC took some 15 s over openOMSI's scene module on WARP, and every start of
the game paid it again. mx_shader::disk_cache keeps the bytecode keyed by the
HLSL, entry point, profile, flags and the compiler's build (DXC's version,
DLL size and whether dxil.dll signs; FXC's DLL), in %LOCALAPPDATA%\mX\shaders
or MX_SHADER_CACHE (0: off). Entries carry the key's length and a second hash
and a checksum of the code, are written through a temporary file renamed into
place, and the folder is kept under 512 MB, oldest first.

Direct3D 12 compiles through it (behind the in-memory cache), Direct3D 11's
FXC too. CI on Windows runs openOMSI's shaders into an empty cache and again
from it.
@turbo-devv turbo-devv changed the title openOMSI's OpenGL shaders on the bound tier; textureLoad from depth in GLSL openOMSI's OpenGL shaders on the bound tier; textureLoad from depth in GLSL; DX shader cache on disk Nov 23, 2026
…oltenVK under sync validation, lavapipe and WARP in CI)
…fragment shader

OpenGL ES links no program without a fragment shader, so every depth-only
pipeline (shadow maps, openOMSI's "shadow clear") failed there: openOMSI's
renderer could not be made on ANGLE. wgpu-hal adds an empty one too.
Conformance: depth_only_pipelines_draw_without_a_fragment_stage (fails
without the fix on ANGLE, passes on Metal and GL).
…ures read back

Mesa (llvmpipe, OpenGL ES 3.2) in CI found two more:
- An indirect draw with a first instance drew at instance 0: OpenGL ES's
  indirect commands have no first instance (reservedMustBeZero), and without
  draw parameters the shader adds it from a uniform a GPU-side draw cannot
  set. Without draw parameters indirect draws now go the way of ES 3.0's:
  the arguments read back and drawn directly.
- copy_texture_to_buffer of a compressed texture panicked. The blocks are
  now copied with glCopyImageSubData (GL 4.3, ES 3.2) into an RG32UI /
  RGBA32UI texture, a texel a block, and read back from it.
… the mip's real size

WebGPU's copy size is whole blocks (4x4 into a 2x2 or 1x1 mip); GL refuses a
region past the mip's edge, and the small mips of compressed textures were
never written (Mesa in CI: compressed_small_mips_take_whole_blocks).
…where shaders read gl_BaseInstance

With draw parameters (GL 4.6, ARB_shader_draw_parameters) the shader's
instance index is gl_InstanceID + gl_BaseInstance, but draws went through
glDrawArraysInstanced / glDrawElementsInstanced, which leave the base
instance 0: every draw with instances starting past 0 drew as instance 0
(Mesa desktop GL in CI: render bundles, occlusion queries). They now use the
base-instance draws (GL 4.2) there.
@turbo-devv
turbo-devv merged commit 650b244 into main Nov 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant