Skip to content

ps_interp_modes: refuse a --limit below 1 - #1647

Closed
bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:fix/ps-interp-modes-limit
Closed

bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:fix/ps-interp-modes-limit

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: claim.

What and why

--limit is tested after the row has been appended, so any count at or below zero keeps exactly one shader:

$ python -I tools/ps_interp_modes.py work/shaders --limit 0
... one shader's rows ...
$ echo $?
0
$ python -I tools/ps_interp_modes.py work/shaders --limit -1     # same one shader

A --limit 0 that reports one row is the opposite of what its help says ("stop after this many pixel shaders"), and it is the same false answer #1397 and #1452 fixed in the other tools: a count below one is a usage error, not a silent clamp.

The change

+def positive_int(text: str) -> int:
+    try:
+        value = int(text)
+    except ValueError:
+        raise argparse.ArgumentTypeError(f"invalid int value: {text!r}") from None
+    if value < 1:
+        raise argparse.ArgumentTypeError("must be at least 1")
+    return value
...
-    ap.add_argument("--limit", type=int, default=None, help="stop after this many pixel shaders")
+    ap.add_argument("--limit", type=positive_int, default=None, help="stop after this many pixel shaders")

Nothing else moves: no --limit still scans every shader, --limit 1 still stops after one, and --json is untouched.

Tested

CPU only, no GPU, no game data; Windows 11, CPython 3.12.13. The container is synthetic, built with the file's own psv0() / dxbc_container() helpers (PSV0 layout from dxc's DxilPipelineStateValidation).

  • python -m pytest tests/test_ps_interp_modes.py -q -> 24 passed (23 before).
  • New test: the CLI on one synthetic .dxbc gives 1 file with --limit 1 and 1 file with no --limit, then --limit 0, -1 and -5 each exit 2, print must be at least 1, and write nothing to stdout.
  • Negative control, tools/ps_interp_modes.py reverted to main (99f99890) with the new test kept -> 1 failed, 23 passed: exactly test_a_limit_below_one_is_refused (line 304, the --limit 0 case).
  • python -m compileall -q tools tests -> clean.

Not covered: a real corpus of pixel shaders (--limit 0 over 12,101 files was not run).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A, tool CLI only.)

`--limit 0` and `--limit -1` kept exactly one shader and exited 0: the limit
is tested after the row it has just appended, so any count below one passed on
the first shader. A count that cannot mean what its help says is now a usage
error, as in the other tools (ItsNotRexed#1397, ItsNotRexed#1452).

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@bobcatchris

Copy link
Copy Markdown
Contributor Author

Closing as redundant: main (41f44826) already refuses a --limit below 1 in this tool via _at_least_one (with the same reasoning), so the change here would only be a second name for it. My branch was cut from 99f99890c5 before that merge, which is why it now conflicts. No code from this PR is needed; the test idea it carried is covered by the merged guard.

@bobcatchris

Copy link
Copy Markdown
Contributor Author

Closed as superseded: main already has this fix.

1fdae256 ("ps_interp_modes: refuse --limit below 1 and skip directory .dxbc entries", from #1501) added the same _at_least_one argparse type and the same refusal of --limit below 1, plus a directory-entry fix this branch did not carry. The conflict came from that commit landing after this branch was opened, and git log origin/main -- tools/ps_interp_modes.py confirms nothing here is missing on main.

Reasons the two changes are equivalent, checked against 1fdae256:

  • --limit 0, -1, -5 exit 2 through argparse.ArgumentTypeError before any shader is read, exactly as this branch's positive_int did.
  • no --limit and --limit 1 behave as before.

Nothing to rebase; closing so it does not sit in the queue. AI-assisted.

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