gfx2hlsl: the SAMPLER_CLAMP table is defined but never read #1757

Closed
opened 2026-11-24 18:14:22 +00:00 by ChazY11 · 3 comments
ChazY11 commented 2026-11-24 18:14:22 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T18:14:22Z.


tools/startup/gfx2hlsl.py:128 defines a sampler clamp-mode table:

SAMPLER_CLAMP = {0: 'WRAP', 1: 'MIRROR', 2: 'CLAMP', 3: 'MIRROR_ONCE', 4: 'CLAMP', 5: 'MIRROR_ONCE', 6: 'BORDER', 7: 'BORDER'}

Nothing reads it. The whole repository has one occurrence of the name:

$ git grep -n 'SAMPLER_CLAMP' origin/main
origin/main:tools/startup/gfx2hlsl.py:128:SAMPLER_CLAMP = {0: 'WRAP', ... }

No SAMPLER_CLAMP[...] subscript and no getattr on it either, and no other place in tools/ or src/ produces those mode strings.

Why it is worth a decision rather than silence

It reads like the authority for how an inline sampler's clamp bits become a D3D12 static-sampler description. Changing an entry has no effect anywhere:

# entry 2: 'CLAMP' -> 'WRAP'
out/pe-env/Scripts/python.exe -B tests/startup_translator_check.py            # green
out/pe-env/Scripts/python.exe -B tests/startup_inline_sampler_check.py        # green
out/pe-env/Scripts/python.exe -B tests/startup_sampler_heap_check.py          # green
out/pe-env/Scripts/python.exe -B tests/startup_flat_param_check.py            # green
out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_capture_check.py      # green

(reverted afterwards; all five pass unmodified)

So a contributor who "corrects" the table — or adds a case that pins it — is working on something the translator never consults. The inline sampler check does pass the clamp bits through (smp 0 0x2 0 0x100000 0 for the clamp fixture), but as raw folded words, not through this table.

Question

Is the table meant to drive the emitted SamplerState description and simply not wired up yet, or is it a leftover from an earlier approach? If it is a leftover, deleting it removes a false trail; if it is intended, the wiring plus one check that pins mode 2 would make it real.

Either way this is a note, not a request for a change I should make myself — the answer decides whether the line is removed or used.

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588421240 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1764). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T18:14:22Z. --- `tools/startup/gfx2hlsl.py:128` defines a sampler clamp-mode table: ```python SAMPLER_CLAMP = {0: 'WRAP', 1: 'MIRROR', 2: 'CLAMP', 3: 'MIRROR_ONCE', 4: 'CLAMP', 5: 'MIRROR_ONCE', 6: 'BORDER', 7: 'BORDER'} ``` Nothing reads it. The whole repository has one occurrence of the name: ```text $ git grep -n 'SAMPLER_CLAMP' origin/main origin/main:tools/startup/gfx2hlsl.py:128:SAMPLER_CLAMP = {0: 'WRAP', ... } ``` No `SAMPLER_CLAMP[...]` subscript and no `getattr` on it either, and no other place in `tools/` or `src/` produces those mode strings. ## Why it is worth a decision rather than silence It reads like the authority for how an inline sampler's clamp bits become a D3D12 static-sampler description. Changing an entry has no effect anywhere: ```powershell # entry 2: 'CLAMP' -> 'WRAP' out/pe-env/Scripts/python.exe -B tests/startup_translator_check.py # green out/pe-env/Scripts/python.exe -B tests/startup_inline_sampler_check.py # green out/pe-env/Scripts/python.exe -B tests/startup_sampler_heap_check.py # green out/pe-env/Scripts/python.exe -B tests/startup_flat_param_check.py # green out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_capture_check.py # green ``` (reverted afterwards; all five pass unmodified) So a contributor who "corrects" the table — or adds a case that pins it — is working on something the translator never consults. The inline sampler check does pass the clamp bits through (`smp 0 0x2 0 0x100000 0` for the clamp fixture), but as raw folded words, not through this table. ## Question Is the table meant to drive the emitted `SamplerState` description and simply not wired up yet, or is it a leftover from an earlier approach? If it is a leftover, deleting it removes a false trail; if it is intended, the wiring plus one check that pins mode 2 would make it real. Either way this is a note, not a request for a change I should make myself — the answer decides whether the line is removed or used. - AI-assisted.
winne42 commented 2026-11-24 20:01:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by winne42 on 2026-11-24T19:32:47Z.


This looks like a leftover. The live table is in the runtime, not the translator.

  • SAMPLER_CLAMP came in with the first stand-ins commit (e658fe24), and git log -S SAMPLER_CLAMP shows no later commit that reads it.
  • The translator writes inline sampler words to the manifest unchanged (smp/smpc lines). decode_sampler() in src/startup_stubs/translated_sampler_bindings.h:26 turns them into the D3D12 static sampler. It has its own modes[8] with the same mapping and reads AddressU/V/W from WORD0 bits 2:0, 5:3 and 8:6. That is why changing the Python entry had no effect.

So a fix to the clamp mapping belongs on decode_sampler(), and so does a check that pins mode 2. startup_translated_sampler_bindings_check calls decode_sampler(), but it does not check AddressU/V/W today, so that pin would be new. #1849 deletes the Python copy. I ran the 53 pure-Python checks on Linux and all pass. The Windows ctests were not run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7142252341 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1764#issuecomment-7142252341). Originally posted by [winne42](https://github.com/winne42) on 2026-11-24T19:32:47Z. --- This looks like a leftover. The live table is in the runtime, not the translator. - `SAMPLER_CLAMP` came in with the first stand-ins commit (`e658fe24`), and `git log -S SAMPLER_CLAMP` shows no later commit that reads it. - The translator writes inline sampler words to the manifest unchanged (`smp`/`smpc` lines). `decode_sampler()` in `src/startup_stubs/translated_sampler_bindings.h:26` turns them into the D3D12 static sampler. It has its own `modes[8]` with the same mapping and reads `AddressU/V/W` from `WORD0` bits 2:0, 5:3 and 8:6. That is why changing the Python entry had no effect. So a fix to the clamp mapping belongs on `decode_sampler()`, and so does a check that pins mode 2. `startup_translated_sampler_bindings_check` calls `decode_sampler()`, but it does not check `AddressU/V/W` today, so that pin would be new. #1849 deletes the Python copy. I ran the 53 pure-Python checks on Linux and all pass. The Windows ctests were not run. AI-assisted (Claude Code).
ChazY11 commented 2026-11-24 20:01:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T19:49:24Z.


Resolved by #1849 (startup/drop-unused-sampler-clamp, merged as afddddbd), which deletes the table this issue asked about:

$ git show afddddbd --stat
 tools/startup/gfx2hlsl.py | 3 ---

$ grep -c SAMPLER_CLAMP tools/startup/gfx2hlsl.py
0

So the answer to the question in the description was "leftover": the table is gone rather than wired up, and nothing reads a
sampler mode string from it. The five checks I listed as staying green under a mutated entry were green because no code path
reads it, which is consistent with the removal.

Nothing left to do here; this can be closed. (Recording the merge so the next person searching for SAMPLER_CLAMP lands on
this issue and sees the outcome.)

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7142638541 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1764#issuecomment-7142638541). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T19:49:24Z. --- Resolved by #1849 (`startup/drop-unused-sampler-clamp`, merged as `afddddbd`), which deletes the table this issue asked about: ```text $ git show afddddbd --stat tools/startup/gfx2hlsl.py | 3 --- $ grep -c SAMPLER_CLAMP tools/startup/gfx2hlsl.py 0 ``` So the answer to the question in the description was "leftover": the table is gone rather than wired up, and nothing reads a sampler mode string from it. The five checks I listed as staying green under a mutated entry were green because no code path reads it, which is consistent with the removal. Nothing left to do here; this can be closed. (Recording the merge so the next person searching for `SAMPLER_CLAMP` lands on this issue and sees the outcome.) - AI-assisted.
R0Y00 commented 2026-11-24 20:01:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T19:49:49Z.


Resolved in #1849. The startup translator still publishes the raw words and the runtime decode_sampler remains the address-mode mapping. The five translator and sampler checks in the report passed on the merged candidate.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7142648602 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1764#issuecomment-7142648602). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T19:49:49Z. --- Resolved in #1849. The startup translator still publishes the raw words and the runtime decode_sampler remains the address-mode mapping. The five translator and sampler checks in the report passed on the merged candidate.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#1757
No description provided.