FindPermutationInBlob misses permutations when one define name is a prefix of another (A / A1)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- cpp
- Domain
- build-system
Research direction
The mismatch is between combinedDefines in ProcessConfigLine in ShaderMake.cpp, which sorts full NAME=value strings, and FindPermutationInBlob in ShaderBlob.cpp, which sorts only names. Start by reading both sort sites and reproducing the A / A1 case from the report with a small reader. Done means the reader finds all four permutations in that blob, and blobs already written by the writer still load.
Written by the indexing model from the issue text.
Description
FindPermutationInBlob fails to find permutations whose define names are prefixes of each other, such as A and A1. Every permutation of such a shader comes back as not found, even though the blob contains them.
The executable and the blob library build the permutation key in different orders:
ShaderMake.cpp(thecombinedDefinesconstruction inProcessConfigLine) sorts the fullNAME=valuestrings from the config line and joins them with spaces. That key is what goes into the blob.FindPermutationInBlobinShaderBlob.cppsorts by the constant names only, then joinsname=value.
The two orders are the same for most names. They differ when one name is a prefix of another and the next character sorts below = (0x3D), which covers digits, so TEXCOORD/TEXCOORD1 or LAYER/LAYER2 would both hit it. For A and A1:
- writer:
"A1=0" < "A=0"because'1' < '=', so the key isA1=0 A=0 - reader:
"A" < "A1", so it looks forA=0 A1=0
The comment above the writer's sort says the values do not matter as long as keys differ. With these names the = and the value take part in the comparison, so that does not hold.
Repro
ShaderMake main (4f1ffd5), built on macOS arm64 with Apple clang 21. I used a stand-in compiler script that writes a few bytes to the -Fo path, since only the blob layout matters here. Config line:
a.hlsl -T ps -D A={0,1} -D A1={0,1}
Run with --platform DXIL --binaryBlob. A small reader linked against ShaderBlob.cpp loads the blob and calls FindPermutationInBlob with {"A", a}, {"A1", a1}:
in blob: 'A1=0 A=0'
in blob: 'A1=1 A=0'
in blob: 'A1=0 A=1'
in blob: 'A1=1 A=1'
FindPermutationInBlob(A=0, A1=0) -> NOT FOUND
FindPermutationInBlob(A=0, A1=1) -> NOT FOUND
FindPermutationInBlob(A=1, A1=0) -> NOT FOUND
FindPermutationInBlob(A=1, A1=1) -> NOT FOUND
Passing the constants in a different order does not help, because the reader re-sorts them by name.
Possible fix
In FindPermutationInBlob, sort the name=value strings instead of the names, so the reader uses the same key as the writer. This keeps existing blobs readable. Changing the writer would invalidate blobs that were already built. I can send a PR for this.
- Dominant language
- C++
- Stars
- 119
- Forks
- 42
- Avg merge
- 13d 13h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA-RTX/ShaderMake
-
Difficulty 3/5 Half a day Newbie friendliness 62/100
NVIDIA-RTX/ShaderMake#31 ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
NVIDIA-RTX/ShaderMake#22 · 1 comment · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
NVIDIA-RTX/ShaderMake#13 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
NVIDIA-RTX/ShaderMake#11 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
NVIDIA-RTX/ShaderMake#8 ·
All issues in NVIDIA-RTX/ShaderMake
Similar issues
-
launcher: settings are never saved on macOS — QSettings SystemScope points to /Library/PreferencesOpen
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 82/100
supercollider/supercollider#7872 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
yetanotherbrowser/yab#1062 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days