Skip to content

Always declare random texture samplers used by a preset shader - #1071

Open
Coastrnaut wants to merge 1 commit into
projectM-visualizer:masterfrom
Coastrnaut:fix/random-texture-samplers
Open

Coastrnaut wants to merge 1 commit into
projectM-visualizer:masterfrom
Coastrnaut:fix/random-texture-samplers

Conversation

@Coastrnaut

@Coastrnaut Coastrnaut commented Nov 9, 2026 •

Copy link
Copy Markdown

Two cases left a sampler_randNN sampler used by a preset shader undeclared, so HLSL parsing failed and the default shader was used:

  • No matching texture. If no texture file was available, or none matched the prefix of a name like rand00_smalltiled, GetRandomTexture() returned an empty descriptor, which declares nothing. A missing regular texture uses the placeholder texture instead, so the shader still compiles. This does the same for random textures. It matters most for apps that don't ship a texture pack.
  • Same slot, different names. The texture of a random slot is shared between the warp and composite shader, but the second shader reused the first one's descriptor including its sampler name. If the shaders use different names for the same slot, e.g. sampler_rand00 and sampler_rand00_smalltiled, the second name was never declared. The texture is still shared, but the descriptor now uses the current shader's sampler name.

Results

  • Without any texture files, presets falling back to the default shader dropped from 253 to 146 with this PR alone; most of the remaining ones are fixed by the other open shader PRs.
  • With the preset folders as texture search path, 5 more presets compile both of their shaders, e.g. amandio c, flexi - Op illusions - random1 and Flexi - mindblob [where it's at now] gno sth air fetch.
  • For all other presets, shader compile/link results and rendered frames are identical to master.
  • All unit tests pass. TextureManager needs a GL context, so this is covered by the preset run.

Note: #1042 changes the same lines in MilkdropShader::LoadTexturesAndCompile() where the slot descriptor is reused, so whichever is merged second needs a small manual merge: create the descriptor with the current shader's sampler name, then apply PrefixSampler().

How I tested it

I loaded all 14,536 presets from cream-of-the-crop, en-d, milkdrop-original and projectm-classic one after another (Windows, RTX A6000, GL 3.3 core and GLES contexts), both with the preset folders as texture search path and without any textures, rendered frames with fixed audio and frame times, and recorded shader compile/link results, failed loads, logged shader fallbacks and frame hashes. For the pixel comparison both builds had their random seeds fixed (a local patch only, identical on both sides). The presets this PR fixes are excluded from the pixel comparison, since loading them changes shared state (e.g. the expression evaluator's random generator) for every preset after them.

Retested on current master (2026-11-12)

Two cases left a "sampler_randNN" sampler used by a preset shader without
a declaration, so HLSL parsing failed and the default shader was used:

- If no texture file was available, or none matched the prefix of a name
  like "rand00_smalltiled", GetRandomTexture() returned an empty
  descriptor, which declares nothing. A missing regular texture uses the
  placeholder texture instead, so the shader still compiles. Do the same
  for random textures.
- The texture of a random slot is shared between the warp and composite
  shader, but the second shader reused the first one's descriptor
  including its sampler name. If the shaders used different names for
  the same slot, e.g. "sampler_rand00" and "sampler_rand00_smalltiled",
  the second name was never declared. Keep the texture, but use the
  sampler name of the current shader.

This branch has not been deployed

No deployments
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