[pr-performance][shaders] Shaders: a buffer view's start remainder is only added (DARNER_VIEW_START_FAST, on; 0 = the checked form) #303
Loading…
Reference in a new issue
No description provided.
Delete branch "cafe/view-start-fast"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Contributor role (optional)
Cafe#9189What it changes
DARNER_VIEW_START_REMAINDER, on: the dark neon signs fix). The checked lowering also asks each such view's size (oneGetDimensionsper view) and checks the extent with selects on every access. On an RTX 2080 Ti that costs about 2.6 ms of GPU time a frame.The host already widens such a view (
descriptor/host/viewstart.rs,window()), so it ends where the console's view ends, and the card's own bounds check keeps every access inside it. The extent check never cuts anything the host view would not, with one exception: an address within about 24 bytes below 2^32 wraps in the short form and can read up to 12 bytes before the view's start, inside the same buffer (no access we know of does that). With this change the remainder is only added: no size query, no extent check.emit/lower/viewstart.rs: the short form, the default.DARNER_VIEW_START_FAST=0gives the checked form as before.emit/shader.rs,emit/mod.rs: the switch,view_start_fast().shader_cache.rs: the switch is in the shader cache key, with a test that it changes the key.How it was tested
Tested revision: game runs on our branch from an older
main(de8d42006) with this commit; the picture check and the gates onmainf3840d73d+ this commit (72f50293a).viewstart.rsand the host'swindow()are the same on both.Changes a default: yes, for every card (the shaders are rebuilt once).
A/B result (RTX 2080 Ti, house save, the same 50 s after the world shows, pipelines warm, 2 runs each):
For comparison,
DARNER_VIEW_START_REMAINDER=0(before the signs fix): 50.6 ms, 19.21 fps. For context, latestmainf3840d73dat its defaults measures 53.7 ms / 18.11 fps in the same place (one run).Picture: a recorded frame of the house (1,551 unaligned views a frame there), translated again with
DARNER_VIEW_START_FAST=0and=1: 1,551 shaders differ, 0 pipelines refused, the replayed picture is the same to the pixel. The replay has no ray tracing.Gates run on
72f50293a:cargo build --locked --release -p darnerok;cargo clippy --locked --release -p darner-shader -p darner-gpu --all-targets -- -D warningsok;cargo test --locked --release -p darner-shader --lib -- --skip oracle64: 488 passed, 67 failed, the same 67 as onmainf3840d73don this PC (they need a Shader Model 6.6 device, which Windows 10's own D3D12 lacks, or DXIL validation). Not run this time: thedarner-gputests (they create a D3D12 device), including the new shader cache key test. Not run: the whole-workspace gates.Gameplay: RTX 2080 Ti, Windows 10 22H2, Series S profile, 2560x1440 output, DLSS Performance, hardware ray tracing, no frame generation.
Shader wave sizes tested: 32 lanes (NVIDIA).
Hardware dependence: likely general (fewer instructions); untested on AMD and Intel. On AMD the remainder fix is off by default, so nothing changes there unless it is turned on.
Coverage gaps: no check by eye of the night signs with this change (only the replayed daytime frame); only the house scene measured on its own.
Checklist
main.docs/asset-policy.md.Checked for overlap
emit/lower/viewstart.rs).Thanks for this, and for the A/B table. I read the change against the code on
72f50293a. The reasoning holds, with one small edge (3) and four questions.What I checked
window()widened the view (descriptor/host.rs:6022,make_twinnedgives the remainder only for a widened view,descriptor/host/viewstart.rs,window). A view that was not widened carries remainder 0, and then both forms leave the address alone (view_byte: the checked form'shas_biasselect returns the plain byte).start & !15and iscount * stride + remainderbytes long. So for one dword, the card's testaddr + remainder + 4 <= size + remainderis the same as the checked form'saddr + 4 <= logical.addr + delta + remaindercan wrap past 2^32 and land in the firstremainderbytes of the widened view, which are bytes before the console view's start but inside the buffer. That needs an address within about 24 bytes below 2^32 (the remainder is 4, 8 or 12, plus a delta of up to 12; for example a small negative offset). I doubt it matters, but it is not "outside either way".view_byte:view_dwordsand the stores and loads (lower.rs:7932, 8042, 8119, 13862, 13918and thebuffer_bytecalls from14000on), the scalar constant loads (lower.rs:8110, 8142) and the BVH node fetches (intersect.rs:306, 518). None of them uses the skipped size in fast mode:view_boundsonly hands it on toview_byte.Questions
view_dwordsup to 4 dwords, thebuffer_byte(..., 4 * count)stores and loads, BVH node fetches ofn * 4bytes): the checked form drops the whole access (thelong_enough/insidetest uses the full width). The fast form leaves it to the card's own out-of-bounds rule for raw buffer loads, which may return the in-range dwords and zero for the rest. Is that intended, and does it match what the console does for such an access?intersect.rs:518). Could you check once with ray tracing on: a replay that includes it, or the night signs and a ray-traced scene by eye? The PR says the night signs were not looked at with this change.cargo clippy --workspace --all-targets --locked -- -D warnings, the same with--all-features,cargo test --workspace --locked, and thedarner-gputests including the newview_start_fast_changes_the_shader_cache_key. The PR says these were not run, and I understand Windows 10 can't run some of them (the Shader Model 6.6 ones). We can run the full set on our PC (Windows 11, RTX 2070 SUPER) and report the result here on72f50293a.A/B offer
When our PC is free we can run the same A/B on an RTX 2070 SUPER (Turing, the same generation as the 2080 Ti),
DARNER_VIEW_START_FAST=0against the default, as launch pairs in ABBA order (the switch is in the shader cache key, so it can't change while the game runs), and post the numbers with the n and the spread here. Say if you'd rather we didn't.This comment was written with AI assistance (Claude Code); nothing here has been run yet.
Thanks for the careful read. Answers:
scalar_buffer_loads_read_the_same_dwords_one_call_or_fourexpects the same thing. So here the fast form is closer to the console than the checked form, which drops the whole access.72f50293awould help.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.