Skip to content

dxgi: factory argument errors and the content-protection teardown event answer as the host does (D3D round 3a) - #4540

Open
kapitche wants to merge 2 commits into
ItsNotRexed:mainfrom
kapitche:d3dr3-dxgi-factory-args
Open

kapitche wants to merge 2 commits into
ItsNotRexed:mainfrom
kapitche:d3dr3-dxgi-factory-args

Conversation

@kapitche

Copy link
Copy Markdown
Contributor

What broke: IDXGIFactory::CreateSoftwareAdapter, IDXGIFactory2::GetSharedResourceAdapterLuid, CreateSwapChainForComposition and IDXGIAdapter3::RegisterHardwareContentProtectionTeardownStatusEvent returned E_NOTIMPL for every call. Repro: factory->CreateSoftwareAdapter(nullptr, &adapter) returned 0x80004001; the host dxgi.dll returns DXGI_ERROR_INVALID_CALL.

Fix, measured on the host dxgi.dll with a probe (RTX 4080 SUPER, Intel UHD 770, WARP):

Test: new dxgi_factory_args_test (ctest dxgi_factory_args) runs the checks on the layer's factory and on the host factory.

Tested on Windows 11, MSVC 14.51, worktree built from this commit (only that target): passes on the RTX 4080 SUPER and on the Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*), and the host-factory half of the run agrees. Negative control: with dxgi_com.cpp from upstream/main it fails (CreateSoftwareAdapter(nullptr, ...) = 0x80004001, expected 0x887A0001).

Claimed in #4421 (D3D round 3). Related, not overlapping: #3283 (stereo registration) and #4260 (matrix transform) touch other methods of dxgi_com.cpp.

AI-assisted.

…ChainForComposition and the teardown event answer as the host does

@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 dxgi_factory_args_test at 718f2326 on Windows 11, RTX 5070 Ti: exit 0, layer and host both report "factory and adapter argument answers match the host runtime". The factory/adapter refusals (CreateSoftwareAdapter, GetSharedResourceAdapterLuid, CreateSwapChainForComposition, teardown event) match. No blocking issue.

@Flyander Flyander 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.

[P2] Validate non-null invalid resource handles

When both arguments are non-null, an invalid handle such as 0x1234 falls through to E_NOTIMPL. Microsoft documents DXGI_ERROR_INVALID_CALL when hResource is invalid: https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_2/nf-dxgi1_2-idxgifactory2-getsharedresourceadapterluid. The test currently combines 0x1234 with a null LUID, so it does not cover this path. Please add a case with a valid LUID and preserve the host error for an invalid handle before returning E_NOTIMPL for unsupported valid resources.

[P2] Validate composition descriptor fields before E_NOTIMPL

Only pointer arguments are checked. A non-null descriptor with SwapEffect other than DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL or Scaling other than DXGI_SCALING_STRETCH currently returns E_NOTIMPL. The API requires both values and returns DXGI_ERROR_INVALID_CALL for invalid data: https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_2/nf-dxgi1_2-idxgifactory2-createswapchainforcomposition. Please add invalid-field probes with non-null arguments before the unsupported-operation fallback.

@MKmajster

Copy link
Copy Markdown

Tested 718f232 on Windows 11 24H2, MSVC 19.44, NVIDIA RTX 3070 / 617.42: dxgi_factory_args and dxgi_swapchain pass, full CTest 156/156. A probe of the host dxgi.dll on this machine (a fourth adapter/driver next to the three in the description) gives the answers the branch encodes:

CreateSoftwareAdapter(nullptr module, &a)                          0x887a0001
GetSharedResourceAdapterLuid(nullptr handle, &luid)                0x887a0001
CreateSwapChainForComposition(nullptr device, nullptr desc)        0x887a0001
RegisterHardwareContentProtectionTeardownStatusEvent(nullptr, &c)  0x887a0001
RegisterHardwareContentProtectionTeardownStatusEvent(ev, nullptr)  0x887a0001
RegisterHardwareContentProtectionTeardownStatusEvent(ev, &c)       S_OK

For reference only: GetSharedResourceAdapterLuid with a bogus non-null handle (0x1234) returns 0x88760873 on the host, where the branch deliberately answers E_NOTIMPL.

AI-assisted (Claude).

…handle; CreateSwapChainForComposition refuses non-flip SwapEffect and ASPECT_RATIO_STRETCH
@kapitche

Copy link
Copy Markdown
Contributor Author

Both points are right that the unsupported-operation fallback came too early, so I measured what the host does and changed the code to match (pushed as 9a748d3).

Probed host dxgi.dll with a real D3D12 queue on the RTX 4080 SUPER, Intel UHD 770, the third adapter and WARP (identical on all):

  • GetSharedResourceAdapterLuid(0x1234, &luid) is 0x88760873, not DXGI_ERROR_INVALID_CALL. INVALID_HANDLE_VALUE is E_INVALIDARG. A null handle or null LUID stays INVALID_CALL. The layer now returns these instead of E_NOTIMPL, and the test has the valid-LUID case you asked for.
  • CreateSwapChainForComposition with a non-null device: SwapEffect DISCARD and SEQUENTIAL give INVALID_CALL, but FLIP_DISCARD is accepted as well as FLIP_SEQUENTIAL. Scaling ASPECT_RATIO_STRETCH gives INVALID_CALL, but Scaling NONE is accepted as well as STRETCH. So the layer refuses a non-flip SwapEffect and ASPECT_RATIO_STRETCH, and still answers E_NOTIMPL for the accepted combinations. The test probes DISCARD, SEQUENTIAL, ASPECT_RATIO_STRETCH and DISCARD+NONE on both the layer and the host (host with a real command queue).

Tested on Windows 11 (MSVC, RelWithDebInfo): dxgi_factory_args_test passes on the RTX 4080 SUPER and on the Intel UHD 770, both the layer and host lines. Negative control: with the previous dxgi_com.cpp and the new test, it fails at GetSharedResourceAdapterLuid(0x1234, ...) = 0x80004001, expected 0x88760873.

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.

4 participants