diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index c2e36319e2..9b7f32f6db 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -3575,6 +3575,9 @@ will forward to. The queue-side calls ignore which queue they came on (one `VkQu types and sizes are ours. The compose target follows the swapchain when it is recreated (resize, out-of-date acquire); `xbox_present_test` resizes the window between composed presents. + A B8G8R8X8 overlay is opaque within its destination rectangle because the sampled view supplies alpha 1. The + compositor leaves plane 0 visible outside that rectangle. + Colour. Only `RGB_FULL_G22_NONE_P709` (0, SDR, also the default for a zeroed struct) and `RGB_FULL_G2084_NONE_P2020` (12, HDR10) are composed; any other value is composed as SDR and logged once. The swapchain is UNORM. If a plane is HDR10 and the surface lists an ST.2084 format (`VK_COLOR_SPACE_HDR10_ST2084_EXT`, `A2B10G10R10` or `A2R10G10B10`; needs diff --git a/runtime/shims/d3d12_com.h b/runtime/shims/d3d12_com.h index 849791a262..68fb819d7a 100644 --- a/runtime/shims/d3d12_com.h +++ b/runtime/shims/d3d12_com.h @@ -40,6 +40,13 @@ namespace leonida::label { struct Write; } namespace rt::d3d12 { bool record_gpu_label(ID3D12GraphicsCommandList* list, const leonida::label::Write& write); +// B8G8R8X8 uses a BGRA8 Vulkan format with an unused alpha byte. Its DXGI typeless family is distinct from B8G8R8A8, +// so a view crossing between them needs a castable-format list. +constexpr bool alpha_unused(DXGI_FORMAT format) { + return format == DXGI_FORMAT_B8G8R8X8_TYPELESS || format == DXGI_FORMAT_B8G8R8X8_UNORM || + format == DXGI_FORMAT_B8G8R8X8_UNORM_SRGB; +} + // How a queue answers GetClockCalibration. With `calibrated` (vkGetCalibratedTimestampsKHR or its EXT alias, on a // device whose time domains include DEVICE and QUERY_PERFORMANCE_COUNTER) both clocks are read in one call. Without // it, the queue writes a timestamp query and reads QueryPerformanceCounter around it; that needs `get_device_proc` diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index d2681ad6c4..dbad68e47a 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -1727,13 +1727,6 @@ bool rgb96_refused(const D3D12_RESOURCE_DESC& desc) { D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)); } -// B8G8R8X8: the BGRA8 Vulkan formats with the alpha byte unused. Its typeless family is a family of its own, so -// only a castable-format list lets a view cross between it and B8G8R8A8, although both land on the same VkFormat. -bool alpha_unused(DXGI_FORMAT format) { - return format == DXGI_FORMAT_B8G8R8X8_TYPELESS || format == DXGI_FORMAT_B8G8R8X8_UNORM || - format == DXGI_FORMAT_B8G8R8X8_UNORM_SRGB; -} - // The 8-bit four-channel UNORM and SRGB formats in either channel order, B8G8R8X8 included. A texture in one of them // takes an RTV in another when its castable-format list names it: WARP and AMD's D3D12 driver store the clear or the // draw in the view's channel order and encoding. diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp index 77c2c9c53e..bddad797db 100644 --- a/runtime/shims/xbox_present.cpp +++ b/runtime/shims/xbox_present.cpp @@ -312,6 +312,7 @@ HRESULT XboxPresentation::present_x(UINT plane_count, const XboxPresentPlanePara out.point_filter = filter_of(p) == xbox_scale_filter_point; out.hdr10 = is_hdr10(p); out.straight_alpha = (p.Flags & xbox_plane_flag_straight_alpha) != 0; + out.opaque_alpha = i == 1 && alpha_unused(source_desc.Format); } bool tear = false; if (wants_tear && sync_interval > 0 && presenter_->tear_supported()) { diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h index d494233d3a..80a344335f 100644 --- a/runtime/src/vulkan_present.h +++ b/runtime/src/vulkan_present.h @@ -74,6 +74,7 @@ struct PresentPlane { bool point_filter = false; // nearest texel; otherwise bilinear inside the source rectangle bool hdr10 = false; // the texture holds ST.2084 (PQ) Rec.2020 values; otherwise sRGB or G2.2 (PresentPlanes::sdr_eotf) Rec.709 ones bool straight_alpha = false; // plane 1 only: alpha is not premultiplied into the colour + bool opaque_alpha = false; // the source format has no alpha, even if its Vulkan image does }; struct PresentPlanes { PresentPlane plane[2]; @@ -1178,6 +1179,7 @@ class VulkanPresenter { view_info.image = current[i].image; view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; view_info.format = current[i].format; + if (planes.plane[i].opaque_alpha) view_info.components.a = VK_COMPONENT_SWIZZLE_ONE; view_info.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; if (vk.vkCreateImageView(context_.device(), &view_info, nullptr, &frame.views[i]) != VK_SUCCESS) { drop_views(frame); diff --git a/runtime/test/xbox_present_test.cpp b/runtime/test/xbox_present_test.cpp index bc311a87e2..b4635470d8 100644 --- a/runtime/test/xbox_present_test.cpp +++ b/runtime/test/xbox_present_test.cpp @@ -935,6 +935,33 @@ int main() { refs[1] = model(ui, &middle_half, false); EXPECT(frame_matches(frame, refs, 2, false, 203.0, 1)); std::printf("compose: 2 planes, bilinear overlay: within 1 level of the model\n"); + { + const Px underlay{51, 153, 230}, opaque_green{0, 255, 0}; + const auto check_overlay = [&](Source& source, float stored_alpha, bool straight, const Px& centre) { + const FLOAT green_with_alpha[4] = {0.0f, 1.0f, 0.0f, stored_alpha}; + if (!fill(source, green_with_alpha)) return false; + const UINT flags = rt::d3d12::xbox_plane_flag_overlay | + (straight ? rt::d3d12::xbox_plane_flag_straight_alpha : 0u); + pair[1] = parameters(source, &middle_half, xbox_scale_filter_point, 0, flags); + return present_planes(pair, 2) && composed_ok() && + region_is(frame, width / 4, height / 4, 3 * width / 4, 3 * height / 4, centre, 0) && + region_is(frame, 0, 0, width, height / 4, underlay, 0) && + region_is(frame, 0, 3 * height / 4, width, height, underlay, 0) && + region_is(frame, 0, height / 4, width / 4, 3 * height / 4, underlay, 0) && + region_is(frame, 3 * width / 4, height / 4, width, 3 * height / 4, underlay, 0); + }; + EXPECT(check_overlay(bgra, 0.0f, false, underlay) && check_overlay(bgra, 1.0f, false, opaque_green)); + std::puts("compose: BGRA overlay still uses its alpha"); + for (DXGI_FORMAT format : {DXGI_FORMAT_B8G8R8X8_UNORM, DXGI_FORMAT_B8G8R8X8_UNORM_SRGB}) { + Source bgrx; + EXPECT(make_source(format, bgrx, 80, 60)); + for (bool straight : {false, true}) { + EXPECT(check_overlay(bgrx, 1.0f, straight, opaque_green)); + EXPECT(check_overlay(bgrx, 0.0f, straight, opaque_green)); + } + } + std::puts("compose: BGRX UNORM and sRGB overlays are opaque inside their placement for both alpha modes"); + } // Straight alpha with bilinear filtering across a transparent edge: opaque white on the left, transparent black on the // right. Colour is filtered premultiplied, so the edge is white at partial alpha, not grey (filtering the // unassociated colour would also quarter the colour and quarter it again by the alpha). At output x=160 the sample