Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,30 @@ target_compile_features(startup_null_texture_view_check PRIVATE cxx_std_17)
add_test(NAME startup_null_texture_view COMMAND startup_null_texture_view_check)
add_test(NAME startup_null_texture_view_unchecked_fallback_control COMMAND startup_null_texture_view_check --mutate unchecked-fallback)
set_tests_properties(startup_null_texture_view_unchecked_fallback_control PROPERTIES WILL_FAIL TRUE)
# Device views with ViewDimension 0 (UNKNOWN) or a dimension that does not fit the resource
# (src/startup_stubs/view_dimension.h). The control must FAIL.
add_executable(startup_view_dimension tests/startup_view_dimension_check.cpp)
target_include_directories(startup_view_dimension PRIVATE src)
target_compile_features(startup_view_dimension PRIVATE cxx_std_17)
add_test(NAME startup_view_dimension COMMAND startup_view_dimension)
add_test(NAME startup_view_dimension_control COMMAND startup_view_dimension --control)
set_tests_properties(startup_view_dimension_control PROPERTIES PASS_REGULAR_EXPRESSION "FAIL: ")
# The same through d3d12_xs.dll: an unknown-dimension SRV samples its texture's colour, an incompatible explicit SRV is
# refused without device removal, and a refused replacement leaves a null descriptor, not the slot's old view. The
# off control (X2W_D3D12_VIEW_DEFAULTS=off) must fail on the missing default view alone, with the device not removed.
add_executable(startup_view_dimension_device tests/startup_view_dimension_device.cpp)
target_compile_features(startup_view_dimension_device PRIVATE cxx_std_17)
target_link_libraries(startup_view_dimension_device PRIVATE d3d12_xs_shim d3d12 dxgi d3dcompiler)
foreach(backend IN ITEMS warp hardware)
add_test(NAME startup_view_dimension_${backend} COMMAND startup_view_dimension_device ${backend})
set_tests_properties(startup_view_dimension_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_DEBUG=0")
endforeach()
add_test(NAME startup_view_dimension_off_control_warp COMMAND startup_view_dimension_device warp off)
set_tests_properties(startup_view_dimension_off_control_warp PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_DEBUG=0;X2W_D3D12_VIEW_DEFAULTS=off"
PASS_REGULAR_EXPRESSION "FAIL: \\(a\\) default view reads 0\\.000 0\\.000 0\\.000 0\\.000, expected 0\\.200 0\\.600 0\\.800 1\\.000; device not removed.*cases complete"
FAIL_REGULAR_EXPRESSION "FAIL: setup|FAIL: \\(b\\)|FAIL: \\(c\\)|FAIL: \\(d\\)|DEVICE REMOVED|removed the device")
# The slot and label of the x2w-render totals line each null-binding cause is counted under
# (src/startup_stubs/null_binding_cause.h). The mutated run is the negative control.
add_executable(startup_null_cause_labels_check tests/startup_null_cause_labels_check.cpp)
Expand Down
47 changes: 47 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,52 @@ dimensions, formats, resources and counters that are left alone. A rewrite must
field of the description. `startup_null_texture_view_unchecked_fallback_control` rewrites without
asking about R8G8B8A8 and must fail.

## Unknown and mismatched view dimensions

A view description with `ViewDimension` 0 (UNKNOWN) makes desktop D3D12 remove the device instead of
failing the call, and so does a dimension that does not suit the resource (debug layer: "The
ViewDimension in the View Desc is incompatible with the type of the Resource"). Measured: a console
package module made such SRVs on 2D RGBA8 textures. Views of device slots 18 to 21 (shader resource,
unordered access, render target, depth stencil) are now checked before they are forwarded:

- an SRV (slot 18) with dimension 0 gets the resource's default view (a null description) where
desktop allows one: a texture with a typed format that is not a depth format. The default view
replaces the whole description, including its format and component mapping. Only this SRV case is
measured. With dimension 0 every other view is skipped;
- a dimension whose resource dimension differs from the resource's is skipped.

The default view for UAV, RTV and DSV descriptions with dimension 0 is an explicit experiment,
`X2W_D3D12_VIEW_DEFAULTS=all`: it is unmeasured, and it drops the requested format the same way.
`X2W_D3D12_VIEW_DEFAULTS=off` skips the SRV case too. Any other value, or none, keeps the SRV
default.

A refused SRV, for any reason, writes a null SRV (R8G8B8A8_UNORM, the requested dimension where it
is a texture dimension, else 2D) into its destination descriptor. Otherwise the slot would keep the
view it held before. That view would still be bindable and would be copied by `CopyDescriptors`,
although the slot's record no longer keeps its resource alive. Translated draws already resolve the
slot to nothing.

A refused UAV, RTV or DSV leaves the previous descriptor and its tracking record in place.

The first of each are logged (`x2w-d3d12 Device::slot<n> view dimension ...`), and when a view still
removes the device, its forwarded description and the resource's shape are logged
(`removing view desc`). Run
`ctest --preset dev --no-tests=error -R '^startup_view_dimension(_control)?$'`
(`src/startup_stubs/view_dimension.h`); the control swaps the resource dimension of the mismatched
cases for the matching one and must print `FAIL:`.

`startup_view_dimension_warp` goes through `d3d12_xs.dll` on WARP. A compute shader samples each
descriptor of a shader-visible heap through the wrapper's desktop heap. The fixture checks three
cases. An unknown-dimension SRV of a texture filled with one distinct colour must read back that
colour. An explicit TEXTURE3D SRV of a 2D texture must be refused with the device not removed.
A descriptor slot that held a valid view of a second colour, then receives a refused TEXTURE2D
SRV of a buffer, must read zero, and so must a `CopyDescriptorsSimple` copy of it. The slot gate
for UAV, RTV and DSV is checked without a device by `startup_view_dimension`.
`startup_view_dimension_off_control_warp` runs the same fixture with
`X2W_D3D12_VIEW_DEFAULTS=off`. It must print `FAIL: (a) default view` with `device not removed`,
so it fails on the missing default view and not on setup or a removed device. Both return 77
without WARP.

## 16-bit packed targets

A description that asks for a B5G5R5A1_UNORM, B4G4R4A4_UNORM or B5G6R5_UNORM render target is created as
Expand Down Expand Up @@ -1349,6 +1395,7 @@ ctest --preset dev --no-tests=error -R '^startup_trap_header(_prefix_control|_pr
| `X2W_D3D12_RELEASE_RETIRED=1` | opt-in, effective with `X2W_D3D12_RENDER=1` only (the list handlers that record holds exist only there): frees the desktop object of a released committed 2D texture of one narrow class once no recorded list, submission or release-time fence refers to it ([details](#d3d12-resource-budget)). Unset, nothing changes |
| `X2W_D3D12_RELEASE_RETIRED_VIEWS=1` | opt-in, effective only together with `X2W_D3D12_RELEASE_RETIRED=1`: a released class texture that only tracked slot-18 descriptor slots keep alive (the title never overwrites them) is freed once those slots are replaced by null descriptors ([details](#d3d12-resource-budget)). Unset, nothing changes |
| `X2W_D3D12_RETIRE_REASONS=1` | diagnostic only, effective with `X2W_D3D12_RELEASE_RETIRED=1` and `X2W_D3D12_BUDGET=1`: adds one `x2w-retire held:` line to the heartbeat that counts final-released resources whose desktop object is still alive, by reason ([details](#d3d12-resource-budget)). Unset, nothing is recorded |
| `X2W_D3D12_VIEW_DEFAULTS=all` or `=off` | `all` is experimental: UAV, RTV and DSV descriptions with `ViewDimension` 0 also get the resource's default view, which drops their requested format and component mapping. `off` skips the measured SRV case too. Unset, only SRVs of typed non-depth textures get the default view ([details](#unknown-and-mismatched-view-dimensions)) |
| `X2W_D3D12_VIEW_CENSUS=1` | diagnostic only: counts new distinct view records by device slot (a heartbeat line), and logs the record vector capacity and hash bucket count before either grows ([details](#d3d12-view-census)). Unset, nothing is counted or logged |
| `X2W_DRAW_NULL_IDENTITY=1` | null descriptors read as identity values instead of zero |
| `X2W_DEPTH_STATE=1` | translated draws of slot 57 pipelines take their depth-stencil state and stencil reference from state block A instead of the desktop default (depth and stencil off); a refused block keeps the default. Off by default, then nothing changes: see [Shortcuts that are known to be wrong](#shortcuts-that-are-known-to-be-wrong) |
Expand Down
Loading
Loading