gpu+shader: encode sRGB UAV stores and fill unknown RTV format on typeless textures #3436
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3436"
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?
Imported from Marvisak/VIctory. Originally posted by Monard2033 on 2026-11-27T01:42:53Z.
Summary
Host D3D12 does not support sRGB unordered access views (
R8G8B8A8_UNORM_SRGB,B8G8R8A8_UNORM_SRGB,B8G8R8X8_UNORM_SRGB).victory-gpualready promotes sRGB+UAV textures toTYPELESS(resource.rs) and strips sRGB UAV formats to their linearUNORMtwins (descriptor/host.rs), butvictory-shader's floatimage_storestill wrote raw linear values without sRGB OETF encoding. Quantizing linear light directly into 8-bitUNORMcrushes dark tones (linear 0.0..0.05-> only ~13 discrete levels) and causes severe ~4-bit banding/posterization in shadows and skies.Separately,
RtvRecord::host_descleftwords[0] == 0(DXGI_FORMAT_UNKNOWN) when a title passed a non-null RTV/DSV descriptor withFormat = UNKNOWNon a resource promoted toTYPELESS, which host D3D12 rejects.Changes
victory-shader(emit/shader.rs,emit/mod.rs,emit/lower.rs,emit/host.rs):VIEW_STRIDE_BITSto(1 << 29) - 1and addVIEW_SRGB = 1 << 29in theVIEW_STRIDEStable (t255).stridewithVIEW_STRIDE_BITSinbuffer_guardso setting bit 29 on texture UAV slots never bypassesNULL_BUFFER_VIEWredirection.Shader::texture_uav_indexmap (separate fromview_indexandtexture_index).image_store, conditionally branch on(view_word & VIEW_SRGB) != 0to apply exact IEC 61966-2-1linear_to_srgb()to RGB channels (leaving alpha linear), with zero SFU overhead on linear UAVs.victory-gpu(descriptor/host.rs,descriptor.rs):29,91,93) withVIEW_SRGBinview_kind()while keepingview_stride() == 0.RtvRecord::host_desc, substituteresource::view_format(self.resource)whenself.described != 0 && words[0] == 0.emit/stride_tests.rs,descriptor/host.rs,descriptor.rs):texture_uav_image_store_encodes_srgb_when_marked(hardware + WARP)buffer_guard_redirects_slot_with_only_view_srgb_set(WARP + hardware heap-size check)srgb_texture_uavs_are_marked_in_the_stride_tabledescribed_rtv_with_unknown_format_fills_typeless_resource_formatVerification
cargo clippy --workspace --all-targets --locked -- -D warnings— passed (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings— passed (0 warnings)VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked— 248 passed, 0 failedcargo test -p xtask --locked(repository_passes_policy) — 6 passed, 0 failedRuntime Screenshots (RTX 5080 Laptop 16 GB, smooth gradients / clean shadows)
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T01:47:54Z.
Review: APPROVED
LGTM — verified on Windows (RTX 5090 + WARP):
cargo test -p victory-shader --lib srgbpassed (2/2:texture_uav_image_store_encodes_srgb_when_markedandbuffer_guard_redirects_slot_with_only_view_srgb_set) on RTX 5090 and underVICTORY_WARP=1cargo test -p victory-gpu --lib descriptor::(23/23, includingsrgb_texture_uavs_are_marked_in_the_stride_tableanddescribed_rtv_with_unknown_format_fills_typeless_resource_format, skipping the pre-existingorigin/mainRTX 5090 failure) anddraw::(20/20) passed on RTX 5090cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warningspassed with 0 warningscargo xtask policypassed (191 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:00:25Z.
Review: APPROVED
Looks good to me — both the typeless RTV format fill and the sRGB UAV store encoding are cleanly wired and properly isolated from buffer-view strides.
Review & Verification Notes
crates/victory-gpu/src/descriptor.rs:381-386: fillingDXGI_FORMAT_UNKNOWN(0) on described RTVs (and shared DSV handling) fromresource::view_format(self.resource)beforepc_formatallows D3D12 view creation to succeed on typeless host copies.crates/victory-gpu/src/descriptor/host.rs:1017-1046&crates/victory-shader/src/emit/lower.rs:4630-4648, 5582, 8650-8675:VIEW_SRGB(1 << 29) is set strictly for sRGB texture UAVs (View::UnorderedandView::Placed(true, ...)for formats29/91/93afterpc_format), leaving linear UAVs and sRGB SRVs untouched.VIEW_STRIDESconsumer inemit/lower.rsmasks withVIEW_STRIDE_BITS((1 << 29) - 1), so texture UAV slots withVIEW_SRGBstill resolve stride0and redirect toNULL_BUFFER_VIEWunderbuffer_guard.image_storeapplies IEC 61966-2-1 encoding to RGB only (clamped viasaturateand floored at1e-12beforelog2to avoid NaNs) while preserving linear alpha.7b87d312:cargo xtask policypasses (191 files ok;crates/victory-shader/src/emit/lower.rsstays under the 512 KiB limit at523,162bytes).cargo clippy(--lib,--tests, and--features diagnostics --tests,-D warnings) is clean acrossvictory-shaderandvictory-gpu.victory-gpudescriptor::tests+descriptor::host::testspass on discrete D3D12 (10/10,VICTORY_D3D12_DEBUG=1+VICTORY_D3D12_GBV=1) and WARP (24/24,--features diagnostics,VICTORY_D3D12_DEBUG=1+VICTORY_D3D12_WARP=1).victory-shaderstride_tests(texture_uav_image_store_encodes_srgb_when_markedandbuffer_guard_redirects_slot_with_only_view_srgb_set) pass on discrete D3D12 and WARP withdxil.dll.ID3D12Device::CreateRenderTargetViewon typeless sRGB+UAV host textures for bothDXGI_FORMAT_R8G8B8A8_UNORM_SRGB(29) andDXGI_FORMAT_B8G8R8A8_UNORM_SRGB(91) under the D3D12 Debug Layer with zero debug errors.Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-27T02:30:50Z.
Review: CHANGES_REQUESTED
Tested
7b87d31locally againstorigin/main(63bcca4, clean merge) on Windows 11, NVIDIA GeForce RTX 3060 Ti + Microsoft WARP, Rust 1.98.1 MSVC. All 4 PR tests pass (texture_uav_image_store_encodes_srgb_when_marked,buffer_guard_redirects_slot_with_only_view_srgb_set,srgb_texture_uavs_are_marked_in_the_stride_table,described_rtv_with_unknown_format_fills_typeless_resource_format), butimage_loadon sRGB texture UAVs is missing the matching decode.Blocking issue:
image_loadon sRGB texture UAVs causes double gamma on read-modify-writeBecause host D3D12 backs sRGB texture UAVs with their linear
UNORMtwins,image_storenow encodes linear RGB to sRGB (VIEW_SRGB), sotextureLoad.f32(image_loadwithop == 66 && uav) returns raw sRGB-encoded values instead of linear light unless decoded symmetrically withsrgb_to_linear. Any shader doing a read-modify-write (image_store->image_load->image_store, or loading an sRGB UAV to blend and store back) applies sRGB gamma a second time.Reproduced on
7b87d31with an identityimage_store->image_load->image_storedispatch onDXGI_FORMAT_R8G8B8A8_UNORM_SRGB(texture_uav_srgb_read_modify_write_preserves_encoded_texel):(For linear
0.01,iec_linear_to_srgb(0.01) * 255 ≈ 25; reading it back un-decoded and storing again encodes0.098to88.)Two smaller notes
lower.rsfile size vsxtask policy: On7b87d31,crates/victory-shader/src/emit/lower.rsis523,162bytes — only1,126bytes underxtask/src/policy.rs's512 KiB(524,288-byte)MAX_FILE_SIZE. Moving the IEC 61966-2-1 encode/decode helpers into a submodulecrates/victory-shader/src/emit/lower/srgb.rs(alongsidelower/bvh.rs) keepslower.rscomfortably under the limit (520,957bytes).resource::view_formatdoes not checkthis.is_null()before dereferencingresource(this); existing production callers checkhost_resource(this)first, so it is safe today, though a!this.is_null()check (matchingtitle_format) would guard direct callers.With the patch below applied on top of
7b87d31:cargo test -p victory-shader --lib --locked srgb -- --test-threads=1: 3 passed, 0 failed (RTX 3060 Ti hardware + WARP, including the new RMW regression).cargo clippy -p victory-shader --all-targets --locked -- -D warnings: 0 warnings.cargo xtask policy: 192 files ok (lower.rsat520,957bytes).Tested patch (emit/lower/srgb.rs + UAV image_load decode) and RMW regression against
7b87d31Synthetic tests only; AI-assisted review.
Imported from Marvisak/VIctory. Originally posted by Monard2033 on 2026-11-27T09:17:56Z.
Addressed all 3 review items in
13d205c: decoded image_load on sRGB texture UAVs (srgb_to_linear) + added the RMW test, moved sRGB helpers to lower/srgb.rs (keeping lower.rs under the policy limit), and added !this.is_null() in resource::view_format.View command line instructions
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.