Skip to content

d3d12: log the pipeline state stream refusal reason for E_INVALIDARG - #1740

Closed
imShangLi wants to merge 1 commit into
ProjectLeonida:mainfrom
imShangLi:feat/pso-stream-refusal-reason
Closed

imShangLi wants to merge 1 commit into
ProjectLeonida:mainfrom
imShangLi:feat/pso-stream-refusal-reason

Conversation

@imShangLi

@imShangLi imShangLi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-PSO-STREAM-REFUSAL-REASON
(#2570 (comment))

Depends on: none

What and why

ID3D12Device2::CreatePipelineState refuses a pipeline state stream with E_INVALIDARG without saying why, so a pipeline that is skipped cannot be seen in the log.

Two places make the refusal silent, both on main:

  • runtime/shims/d3d12_vulkan_device.cpp: the finish lambda of the PC CreatePipelineState records a PipelineStream::Refused trace for E_NOTIMPL only, and every E_INVALIDARG from parse_pipeline_stream returns a bare HRESULT, so d3d12_trace::stream_refusal stays null;
  • runtime/shims/d3d12_xs_device.cpp: the console proxy's LEONIDA_PSO_STREAM_AUDIT gate fires for E_NOTIMPL and E_FAIL only, and audit_pso_stream is called from that console proxy path only, so the PC path prints no audit line either.

Each refusal now names its case and is logged once, next to stream_unsupported: the stream has no subobjects, ends inside a subobject type or payload, an unknown subobject type, two subobjects of one family, too many render targets, a compute stage with graphics stages, no shader stage, a mesh pipeline with a vertex, tessellation or geometry stage, a graphics pipeline with no vertex stage, and no description. The PC path records the E_INVALIDARG refusals in the trace, LEONIDA_PSO_STREAM_AUDIT=1 prints them, and the remaining graphics-state refusals keep one generic reason. docs/d3d12_vulkan.md follows.

No HRESULT changes.

What is new since the first review

  • the reason the log, the trace and the console audit read is now the same one: the generic reason is left in d3d12_trace::stream_refusal for the audit to print (it used to print -), the console re-read of a stream keeps its own reason out of the log (that reading may be discarded, and a stream that was built must not show a refusal), and the classic CreateGraphicsPipelineState / CreateComputePipelineState paths clear the field so that no reason of one call is left behind for another;
  • docs/d3d12_vulkan.md names the cases the stream's own refusals give, and says that the refusals of the graphics state itself keep one generic reason (there are more than a dozen of those, and they are not named here).

The classic path now logs the reason of a refusal it used to pass over in silence (a graphics pipeline with no vertex stage). That is deliberate: the refusal is the caller's mistake and it is worth seeing. It does not change any HRESULT.

Tested

  • MoonEyes built and ran the first commit with MSVC 19.44 on an RTX 4060 (Windows 11, NVIDIA 610.88, RelWithDebInfo): ten test targets, ctest green, and the reasons printed once each.
  • python3 -I -m unittest discover -s tests -p "test_docs_*.py" → 57 tests, OK.
  • python3 -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/shims/d3d12_xs_device.cpp docs/d3d12_vulkan.md → exit 0.
  • An independent read-only reviewer agent read the whole diff; its findings are the consistency fixes above.

What was not tested here

  • runtime/ is Windows-only and runtime.yml no longer runs on push or on a pull request (the legacy C++ runtime is deprecated in favour of the Rust runtimes), so no CI job compiles this diff. The Windows build and the ctest run above are the evidence.
  • No Vulkan device and no mesh shader here: the d3d12_mesh_test cases (the E_INVALIDARG set this change touches) were not run.

No game files: a stream is read from the caller's own description.

AI-assisted.

…(RT-PSO-STREAM-EINVALIDARG-REASON)

The PC CreatePipelineState refuses a pipeline state stream with E_INVALIDARG
without saying why: the finish lambda records a PipelineStream::Refused trace for
E_NOTIMPL only, and every E_INVALIDARG from parse_pipeline_stream returns a bare
HRESULT, so d3d12_trace::stream_refusal stays null. The console audit gate fires
for E_NOTIMPL and E_FAIL only, and audit_pso_stream is called from that console
proxy path only, so the PC path prints no audit line either.

Each refusal now names its case and is logged once, next to stream_unsupported:
the stream has no subobjects, ends inside a subobject type or payload, an unknown
subobject type, two subobjects of one family, a compute stage with graphics stages,
no shader stage, a mesh pipeline with a vertex, tessellation or geometry stage, a
graphics pipeline with no vertex stage. The PC path records the E_INVALIDARG
refusals in the trace, LEONIDA_PSO_STREAM_AUDIT=1 prints them, and the remaining
graphics-state refusals keep one generic reason. docs/d3d12_vulkan.md follows.

No game files: a stream is read from the caller's own description.

@abnalstlll-byte abnalstlll-byte 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.

Clean-Room & Technical Verification

  • Mergeability: 3-way merge against upstream main (bcaa13dad) is 100% clean with zero merge conflicts.
  • Clean-Room Compliance: 100% clean-room. D3D12 pipeline stream diagnostic logging and parser hardening only; zero retail code, game data, or keys (check_no_game_data.py clean).
  • Technical Rigor & Diagnostic Visibility:
    • Previously, parse_pipeline_stream returned bare E_INVALIDARG without recording a refusal reason into d3d12_trace::stream_refusal or logging reasons, leaving pipeline refusals completely silent.
    • Implements stream_invalid() logging each distinct refusal once via log_once (e.g. stream has no subobjects, ends inside type or payload, duplicate subobject family, invalid stage mixtures, or missing vertex stage) and setting d3d12_trace::stream_refusal.
    • Extends PipelineStream::Refused recording to capture both E_NOTIMPL and E_INVALIDARG, and widens the console proxy audit gate (LEONIDA_PSO_STREAM_AUDIT) to audit E_INVALIDARG refusals.
    • Updates documentation in docs/d3d12_vulkan.md.

LGTM! Approved.

@MoonEyes

Copy link
Copy Markdown
Collaborator

Built and ran #1740 at head 28f9123cc with MSVC and a GPU, since the PR was syntax-checked only.

Config: Windows 11 (26300), RTX 4060 desktop, NVIDIA 610.88, MSVC 19.44, RelWithDebInfo, Vulkan SDK 1.4.363.0. Test targets only, no game files.

  • Builds with MSVC /W4 /permissive-: 10 test targets. Six link both changed files (d3d12_mesh_test, d3d12_pso_validation_test, d3d12_vulkan_device_test, d3d12_com_test, d3d12_draw_test, d3d12_pipeline_library_test); device_proxy_test, root_sig_test and xs_proxy_mock_test link d3d12_xs_device.cpp only; pso_stream_test links neither. 0 errors, no warning on the lines the PR changes.
  • ctest on those 10: all pass.
  • The reasons are printed. d3d12_mesh_test (9 streams refused as invalid) now logs, once each: two subobjects of one family in the pipeline state stream <type> (types 0, 2, 11, 21, 28), unknown pipeline state stream subobject type 23, the pipeline state stream ends inside a subobject payload, a compute stage with graphics stages, no shader stage in the pipeline state stream, a mesh pipeline with a vertex, tessellation or geometry stage, and the generic a pipeline state stream this layer refuses.

Not covered: the full runtime build (gta6rt.exe) and full ctest, the PipelineStream::Refused trace record, and the LEONIDA_PSO_STREAM_AUDIT=1 console path.

AI-assisted: yes (Claude Code ran the tests)

@imShangLi

Copy link
Copy Markdown
Contributor Author

Five of the six failing checks below come from a test that fails the same way on a tree that does not contain this change; the sixth (windows) is a test the runner skipped for lack of a Vulkan device and still counted as failed.

The diff is 3 files: docs/d3d12_vulkan.md (+7/-4), runtime/shims/d3d12_vulkan_device.cpp (+34/-14), runtime/shims/d3d12_xs_device.cpp (+1/-1). It adds a reason to the refusals that used to return a bare E_INVALIDARG: a new stream_invalid(reason, type) helper stores the reason in d3d12_trace::stream_refusal, prints it once with log_once and returns E_INVALIDARG; the PC CreatePipelineState finish lambda now records PipelineStream::Refused for E_INVALIDARG as well as E_NOTIMPL; and the console proxy's LEONIDA_PSO_STREAM_AUDIT gate also fires for E_INVALIDARG. No HRESULT changes.

Per check, with the failing test named:

  • macos-python — tests/test_mod_pack_output_alias.py, PackAliasTest::test_alias_preflight_precedes_output_truncation, two subtests, ModsError not raised. The same test fails the same way on docs/gpu_test_results: refresh the AMD Radeon 780M record on main bcaa13dad #431, which changes only docs/gpu_test_results.md and gpu-test-results/780M.txt.
  • macos and linux-gpu-tools — cs_imgatomic_ext (6 of 64 sint words differ; first word 32: got 0x0badf00d, expected 0x00000101). In the macos leg ps_ssharp and cs_fma_fused fail as well, but those are the two failures that leg declares as expected; cs_imgatomic_ext is the one that turns it red. This is the fixture whose 3D volume T# does not carry the tag vk_store_test expects, which is what open PR cs_imgatomic_ext: use the volume T# key vk_store_test now expects (GPU-IMG-ATOMIC-EXT-VOLUME-TAG) #1518 changes. We measured the same failure on a main tree without this change, at fe1553456, and runtime/test/shaders/cs_imgatomic_ext.asm has not changed since. This diff does not touch tools/rdna2spirv.py, the fixtures, or the Vulkan compute path.
  • stdlib-tests-linux — tests/test_runner_calls_all_tests.py::test_every_stdlib_runner_calls_its_test_functions, reporting tests/test_feature_scan.py: test_out_named_like_the_optional_spirv_index() is defined but its __main__ runner never calls it. Reproduced here on this PR's base 57ba40bd6 and on docs/gpu_test_results: refresh the AMD Radeon 780M record on main bcaa13dad #431's base bcaa13dad; it passes on current main a73a57e1339b.
  • translator-tests — both tests/test_translate.py cases on cs_dpp_cmp.asm: llvm-mc answers error: dpp variant of this instruction is not supported for the two v_cmp_gt_f32_dpp in that fixture. Reproduced here on current main as well, with the same llvm-mc command (-triple=amdgcn--amdpal -mcpu=gfx1013).
  • windows — the CTest list has one failure, vk_xdxr_postbuild_readback, which printed skipped (no Vulkan device with bufferDeviceAddress) and was still counted as failed. It is a Vulkan-backend acceleration-structure readback test; this diff does not touch the Vulkan backend.

The check job was cancelled.

Local reproductions ran on Windows 11 10.0.29712 with CPython 3.13.17, llvm-mc 23.1.6 and SPIRV-Tools on PATH. We did not build this branch here (no MSVC and no Windows SDK on this machine), so this is attribution of the CI results, not a build.

@imShangLi

Copy link
Copy Markdown
Contributor Author

Temporarily closed to rotate this account's single open pull request slot: this repository limits users without write access to one open pull request each, and this one has held the slot since 26 November.

The change is not withdrawn and the branch is kept. It will be reopened once the other pull request merges.

@imShangLi

Copy link
Copy Markdown
Contributor Author

Continued in #2918: this pull request's head branch was rebased onto the current main while it was closed, and GitHub does not reopen a pull request whose head branch was force-pushed. The change is the same, with the review's findings fixed; #2918 says what is new.

The claim is in the coordination issue: #2570 (comment)

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.

3 participants