Skip to content

runtime: map a PSO-cache graphics user-data record to a root signature - #4732

Open
YaBulochka wants to merge 1 commit into
ItsNotRexed:mainfrom
YaBulochka:feat/gfx-pso-synthetic
Open

YaBulochka wants to merge 1 commit into
ItsNotRexed:mainfrom
YaBulochka:feat/gfx-pso-synthetic

Conversation

@YaBulochka

Copy link
Copy Markdown
Contributor

Starts the graphics side of the PSO-cache work: a portable reduction from one decoded graphics-stage user-data record (PS\0\x09 cache, #4358) to the layer's rt::rootsig::RootSignature, packed with the existing rt::rootsig::pack. No d3d12.h, no Vulkan, no cache file.

The mapping is deliberately conservative:

  • one distinct 0x42 table index (SS) becomes one descriptor-table parameter; each (SS, II) pair becomes one range (II is the D3D12 range type order), with the entry's base register/space/count;
  • each 0x401 entry becomes a 32-bit-constants parameter of a dwords;
  • 0x2 (sampler) and 0x100 consume no user-data dword and are reported as notes;
  • a descriptor without a slot, a slot without a descriptor, a kind/range-type mismatch, a zero count, an unknown kind, or a layout that spills the 32 user SGPRs is refused with a reason, never partially mapped.

What the record does not carry is not invented: the root-parameter order (Order::Record or Order::Table, both marked as hypotheses), the 0x401 base shader register (0 with a note), and the stage visibility (caller-supplied) are explicit options/notes. One record is one stage's block, so it produces its own signature; the current layer packs a single block for all graphics stages (#4312), which is why the synthetic pipeline will use the record of the stage it exercises.

runtime/test/pso_user_signature_test.cpp has 63 checks: the measured shape (SRV table + 0x401 constants, CBV table), both orders, interleaved tables, the console-dword diagnostic (27 vs 32), every refusal, and the canonical encode/decode round-trip. Linux build and ctest: 51/51, including pso_user_signature.

Dependency: docs/pso_cache.md and the decoder this consumes are in #4358; the header refers to that PR until it lands. Next step is the Windows/Wine synthetic draw test (root signature from such a record, one triangle, readback), which needs the cross build and is not in this PR.

Claim: D3D-479, #4683.

Add a portable mapper for one decoded graphics-stage record from the
PS\0\x09 PSO cache (D3D-479; format in docs/pso_cache.md, ItsNotRexed#4358): one
descriptor table per distinct 0x42 SS, one D3D12_DESCRIPTOR_RANGE per
(SS, II) slot pair, one 32-bit-constants parameter per 0x401 entry, then
rt::rootsig::pack into the 32 user-data dwords. What the record does not
carry is not invented: the parameter order is Record or ascending SS
(both labelled hypotheses), the 0x401 base register is 0 with a note, the
visibility comes from the caller, and an undecoded extra 0x42 slot
refuses the record instead of producing a partial mapping.

One record is one stage's user-data block, so it maps to its own root
signature; a graphics PSO carries 3-5 distinct records and concatenating
them would double-count parameters.

CPU test runtime/test/pso_user_signature_test.cpp (ctest
pso_user_signature, no GPU or game data) covers the measured shape, both
orders, interleaved tables, the extra-slot and slot-pair refusals, the
spill rule, and the canonical codec round-trip.

Depends on: ItsNotRexed#4358 (cache decoder and docs/pso_cache.md).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built and ran pso_user_signature_test at 02f734242 on Windows 11: all checks passed, exit 0.

The new portable mapping (runtime/src/pso_user_signature.{h,cpp}) reduces one PSO-cache graphics user-data record to RootSignature parameters: distinct 0x42 SS -> one descriptor table, each (SS, II) -> one range, each 0x401 -> 32-bit constants, samplers/0x100 -> no dword, and records with unpaired slots are refused rather than silently dropping user data. The tests cover the 32-dword packing rule, the one-dword-per-table case, the spill refusal and the mapping order. The header documents what the record does not carry (parameter order, base register, visibility) instead of guessing. No blocking issue.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

At 02f73424, two constant entries produce a root signature that Windows rejects. The mapper returns ok=true. Both parameters use register b0 in space 0 with visibility ALL. The Windows serializer returns 0x80070057 and reports an overlapping CBV range. Changing only the second register to b1 makes the serializer return 0x00000000.

Please reject this ambiguous binding with a reason when the record does not supply a distinct register. This keeps the caller from using an invalid signature.

To reproduce on Windows 11, save these two files in a new folder next to the PR checkout. Name the checkout head. Run cmake -S . -B build -A x64, then cmake --build build --config Release, then build\Release\probe.exe. The probe uses two hand-built entries.

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(probe LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(src ../head/runtime/src)
add_executable(probe main.cpp ${src}/pso_user_signature.cpp ${src}/root_signature.cpp)
target_include_directories(probe PRIVATE ${src})
target_link_libraries(probe PRIVATE d3d12)

main.cpp

#include "pso_user_signature.h"
#include <windows.h>
#include <d3d12.h>
#include <cstdio>
int main() {
    rt::pso::UserRecord record{{{0x401,1,1},{0x401,1,1}}, {}};
    auto r = rt::pso::map_user_record(record);
    if (!r.ok || r.signature.params.size()!=2) return 1;
    D3D12_ROOT_PARAMETER p[2]{};
    for (int i=0;i<2;i++) {
        auto &v=r.signature.params[i];
        p[i].ParameterType=D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
        p[i].Constants={v.shader_register,v.register_space,v.num_values};
        p[i].ShaderVisibility=(D3D12_SHADER_VISIBILITY)v.visibility;
    }
    D3D12_ROOT_SIGNATURE_DESC d{2,p,0,nullptr,D3D12_ROOT_SIGNATURE_FLAG_NONE};
    for (int n=0;n<=1;n++) {
        p[1].Constants.ShaderRegister+=n;
        ID3DBlob *blob=nullptr,*err=nullptr;
        auto hr=D3D12SerializeRootSignature(&d,D3D_ROOT_SIGNATURE_VERSION_1,&blob,&err);
        std::printf("map_ok=%d registers=%u,%u serialize=0x%08lx %s\n",r.ok,p[0].Constants.ShaderRegister,p[1].Constants.ShaderRegister,hr,err?(char*)err->GetBufferPointer():"");
        if (blob) blob->Release();
        if (err) err->Release();
    }
}

AI-assisted.

@Atomic258

Copy link
Copy Markdown

Re-ran at head 02f73424 on Windows 11, NVIDIA GeForce RTX 5090 (driver 617.42) — this test is CPU-only (no Vulkan), built with MSVC 14.44 / Ninja / RelWithDebInfo.

cmake --build runtime\build --target pso_user_signature_test
.\runtime\build\pso_user_signature_test.exe

Result: all checks passed (63 checks), exit 0. Confirms the earlier Windows 11 run at the same SHA on this machine class. No game data.

AI-assisted (Devin).

@memorypressure

Copy link
Copy Markdown

Reviewed on Linux: the mapping module is careful — every unplaceable record shape is refused with a specific error rather than guessed, notes are phrased for tests, and all fixtures are hand-built records (no cache file, no game data); API use matches the existing root_signature.h. It could not be compiled on this verifier host (no cmake builds), so correctness rests on the CI build legs, which were still queued. Note the header comments reference PR #4358's decoder and docs/pso_cache.md, which are not in this tree yet — comments only, so nothing breaks, but the constants land ahead of their documentation. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

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.

5 participants