diff options
| author | lumenpearson <139921639+lumenpearson@users.noreply.github.com> | 2026-11-22 23:25:25 +0300 |
|---|---|---|
| committer | lumenpearson <139921639+lumenpearson@users.noreply.github.com> | 2026-11-22 23:25:25 +0300 |
| commit | f324bfbc71f0eabf9515bcd7c8b7c9e4b89448bf (patch) | |
| tree | 2db4ae6fd5412abbbc3e1894f8bc7ed88c8ae514 /runtime/shims/xbox_present.cpp | |
| parent | 18380c6d2baf1422109b369860a6e8be5e185b05 (diff) | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
Merge upstream main into SHADER-537
Diffstat (limited to 'runtime/shims/xbox_present.cpp')
| -rw-r--r-- | runtime/shims/xbox_present.cpp | 96 |
1 files changed, 93 insertions, 3 deletions
diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp index 0190d029c..54c74b959 100644 --- a/runtime/shims/xbox_present.cpp +++ b/runtime/shims/xbox_present.cpp | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | #include "xbox_present.h" | 1 | #include "xbox_present.h" |
| 2 | 2 | ||
| 3 | #include "../src/vulkan_present.h" | ||
| 4 | |||
| 3 | #include <cstdio> | 5 | #include <cstdio> |
| 4 | 6 | ||
| 5 | namespace rt::d3d12 { | 7 | namespace rt::d3d12 { |
| @@ -79,6 +81,13 @@ HRESULT XboxPresentation::PresentX(UINT plane_count, const XboxPresentPlaneParam | |||
| 79 | const XboxPresentPlaneParameters& plane = planes[i]; | 81 | const XboxPresentPlaneParameters& plane = planes[i]; |
| 80 | if (plane.Token != token || plane.ResourceCount == 0 || !plane.ppResources || !plane.ppResources[0]) | 82 | if (plane.Token != token || plane.ResourceCount == 0 || !plane.ppResources || !plane.ppResources[0]) |
| 81 | return E_INVALIDARG; | 83 | return E_INVALIDARG; |
| 84 | // Both paths read ppResources[0] only: a plane with several resources would silently lose the others and could show | ||
| 85 | // the wrong frame, so it is refused (before anything is presented) until it is modelled. What the console does | ||
| 86 | // with ResourceCount above 1 (views? stereo?) is unmeasured. | ||
| 87 | if (plane.ResourceCount != 1) { | ||
| 88 | log_once(logged_resource_count_, "PresentX plane with ResourceCount other than 1: not implemented, refused"); | ||
| 89 | return DXGI_ERROR_UNSUPPORTED; | ||
| 90 | } | ||
| 82 | } | 91 | } |
| 83 | // Only a token that was never handed out is refused. Null, stale and repeated tokens are presented anyway (what the | 92 | // Only a token that was never handed out is refused. Null, stale and repeated tokens are presented anyway (what the |
| 84 | // console does with them is unmeasured, and a title that does it must not freeze); each kind is logged once. | 93 | // console does with them is unmeasured, and a title that does it must not freeze); each kind is logged once. |
| @@ -99,6 +108,90 @@ HRESULT XboxPresentation::PresentX(UINT plane_count, const XboxPresentPlaneParam | |||
| 99 | break; | 108 | break; |
| 100 | } | 109 | } |
| 101 | 110 | ||
| 111 | // What each plane asks for. Colour spaces other than HDR10 are composed as the SDR default (logged once). | ||
| 112 | const auto is_hdr10 = [&](const XboxPresentPlaneParameters& p) { | ||
| 113 | if (p.ColorSpace != xbox_color_space_g22_p709 && p.ColorSpace != xbox_color_space_g2084_p2020) | ||
| 114 | log_once(logged_color_space_, "a present plane's DXGI colour space is neither G22/P709 nor G2084/P2020: composed as SDR G22/P709"); | ||
| 115 | return p.ColorSpace == xbox_color_space_g2084_p2020; | ||
| 116 | }; | ||
| 117 | // The extra fields are unmeasured, so they are read defensively: a placement that is not a sane sub-rectangle of the output | ||
| 118 | // (also NaN) counts as none, an unknown filter as the default, unknown flag bits are ignored, extended descriptors are | ||
| 119 | // not read; each is logged once and the frame is shown anyway (a title must not freeze on a field we misread). | ||
| 120 | const auto placement = [&](const XboxPresentPlaneParameters& p) -> const XboxViewRect* { | ||
| 121 | const XboxViewRect* r = p.pDestPlacementBase; | ||
| 122 | if (!r) return nullptr; | ||
| 123 | if (!(r->left >= 0.0f && r->left < r->right && r->right <= 1.0f && r->top >= 0.0f && r->top < r->bottom && | ||
| 124 | r->bottom <= 1.0f)) { | ||
| 125 | log_once(logged_extras_, "a present plane's pDestPlacementBase is not a sub-rectangle of 0..1: ignored (whole output)"); | ||
| 126 | return nullptr; | ||
| 127 | } | ||
| 128 | return (r->left == 0.0f && r->top == 0.0f && r->right == 1.0f && r->bottom == 1.0f) ? nullptr : r; | ||
| 129 | }; | ||
| 130 | const auto filter_of = [&](const XboxPresentPlaneParameters& p) { | ||
| 131 | if (p.ScaleFilter == xbox_scale_filter_point || p.ScaleFilter == xbox_scale_filter_linear) return p.ScaleFilter; | ||
| 132 | if (p.ScaleFilter != xbox_scale_filter_default) | ||
| 133 | log_once(logged_extras_, "a present plane's ScaleFilter is not a known value: default filter"); | ||
| 134 | return int(xbox_scale_filter_default); | ||
| 135 | }; | ||
| 136 | for (UINT i = 0; i < plane_count; ++i) | ||
| 137 | if (planes[i].ExtendedDescCount) | ||
| 138 | log_once(logged_extras_, "a present plane has extended descriptors: ignored"); | ||
| 139 | const bool hdr0 = is_hdr10(planes[0]); | ||
| 140 | // Plane 1 is composed over plane 0 only when flagged an overlay (hypothesis). Otherwise it is not shown, as before: in | ||
| 141 | // the public HDR sample it is the GameDVR copy of the frame, and blending a plane we cannot tell apart from it risks | ||
| 142 | // drawing the frame twice with an alpha that was never meant to be blended. | ||
| 143 | const bool overlay = plane_count == 2 && (planes[1].Flags & xbox_plane_flag_overlay) != 0; | ||
| 144 | if (plane_count == 2 && !overlay) | ||
| 145 | log_once(logged_planes_, "PresentX with 2 planes and no overlay flag on plane 1: only plane 0 is shown (plane 1 is taken " | ||
| 146 | "as the GameDVR copy of the frame)"); | ||
| 147 | const bool compose = hdr0 || placement(planes[0]) || filter_of(planes[0]) != xbox_scale_filter_default || overlay; | ||
| 148 | |||
| 149 | if (compose) { | ||
| 150 | // Every shown plane: a 2D texture, a source rectangle inside it, a placement inside the output. | ||
| 151 | leonida::PresentPlanes composed; | ||
| 152 | composed.count = overlay ? 2 : 1; | ||
| 153 | composed.sdr_white_nits = sdr_white_nits_; | ||
| 154 | for (UINT i = 0; i < composed.count; ++i) { | ||
| 155 | const XboxPresentPlaneParameters& p = planes[i]; | ||
| 156 | ID3D12Resource* source = p.ppResources[0]; | ||
| 157 | const D3D12_RESOURCE_DESC source_desc = source->GetDesc(); | ||
| 158 | if (source_desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) return E_INVALIDARG; | ||
| 159 | const D3D12_RECT* source_rect = p.pSrcViewRects; | ||
| 160 | if (source_rect && (source_rect->left < 0 || source_rect->top < 0 || source_rect->left >= source_rect->right || | ||
| 161 | source_rect->top >= source_rect->bottom || UINT64(source_rect->right) > source_desc.Width || | ||
| 162 | UINT(source_rect->bottom) > source_desc.Height)) | ||
| 163 | return E_INVALIDARG; | ||
| 164 | const XboxViewRect* place = placement(p); | ||
| 165 | leonida::PresentPlane& out = composed.plane[i]; | ||
| 166 | out.source = resource_id(source); | ||
| 167 | if (source_rect) { | ||
| 168 | out.source_rect = {source_rect->left, source_rect->top, source_rect->right, source_rect->bottom}; | ||
| 169 | out.has_source_rect = true; | ||
| 170 | } | ||
| 171 | if (place) { | ||
| 172 | out.dest[0] = place->left; | ||
| 173 | out.dest[1] = place->top; | ||
| 174 | out.dest[2] = place->right; | ||
| 175 | out.dest[3] = place->bottom; | ||
| 176 | } | ||
| 177 | out.point_filter = filter_of(p) == xbox_scale_filter_point; | ||
| 178 | out.hdr10 = is_hdr10(p); | ||
| 179 | out.straight_alpha = (p.Flags & xbox_plane_flag_straight_alpha) != 0; | ||
| 180 | } | ||
| 181 | bool tear = false; | ||
| 182 | if (wants_tear && sync_interval > 0 && presenter_->tear_supported()) { | ||
| 183 | const FramePacer::PresentTiming timing = pacer_.present_timing(token); | ||
| 184 | tear = leonida::decide_present_sync(timing.late_us, timing.period_us, threshold) == leonida::PresentSync::immediate; | ||
| 185 | } | ||
| 186 | const HRESULT result = presenter_->present_planes(composed, sync_interval, tear); | ||
| 187 | if (FAILED(result)) return pacer_.suspended() ? from_pacer(hr::invalid_state) : result; | ||
| 188 | pacer_.commit_present_token(token, plane_count, | ||
| 189 | tear && presenter_->last_present_tore() ? leonida::PresentSync::immediate | ||
| 190 | : leonida::PresentSync::vblank); | ||
| 191 | ++presents_; | ||
| 192 | return S_OK; | ||
| 193 | } | ||
| 194 | |||
| 102 | const XboxPresentPlaneParameters& plane = planes[0]; | 195 | const XboxPresentPlaneParameters& plane = planes[0]; |
| 103 | ID3D12Resource* resource = plane.ppResources[0]; | 196 | ID3D12Resource* resource = plane.ppResources[0]; |
| 104 | const D3D12_RESOURCE_DESC desc = resource->GetDesc(); | 197 | const D3D12_RESOURCE_DESC desc = resource->GetDesc(); |
| @@ -113,9 +206,6 @@ HRESULT XboxPresentation::PresentX(UINT plane_count, const XboxPresentPlaneParam | |||
| 113 | UINT64(rect->right) > desc.Width || UINT(rect->bottom) > desc.Height)) | 206 | UINT64(rect->right) > desc.Width || UINT(rect->bottom) > desc.Height)) |
| 114 | return E_INVALIDARG; | 207 | return E_INVALIDARG; |
| 115 | 208 | ||
| 116 | if (plane_count == 2) | ||
| 117 | log_once(logged_planes_, "PresentX with 2 planes: only plane 0 is shown; HDR/GameDVR plane composition is not implemented"); | ||
| 118 | |||
| 119 | // How late the frame is, now that everything that can refuse it has: past the vblank it was due at, by what part of | 209 | // How late the frame is, now that everything that can refuse it has: past the vblank it was due at, by what part of |
| 120 | // the interval the scan has moved on. The presenter says whether it really queued it as a tear. | 210 | // the interval the scan has moved on. The presenter says whether it really queued it as a tear. |
| 121 | FramePacer::PresentTiming timing; | 211 | FramePacer::PresentTiming timing; |