Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8558e2e..3d1166b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -167,6 +167,15 @@ add_test(
COMMAND commitThread "commitThread")
add_dependencies(tests commitThread)

+add_executable(scanoutAlias "tests/ScanoutAlias.cpp")
+target_include_directories(scanoutAlias PRIVATE "./src/include" "./include")
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
+target_link_libraries(scanoutAlias PRIVATE PkgConfig::deps)
+add_test(
+ NAME "scanoutAlias"
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
+ COMMAND scanoutAlias)
+add_dependencies(tests scanoutAlias)
+
# Installation
install(TARGETS aquamarine)
install(DIRECTORY "include/aquamarine" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
diff --git a/src/allocator/GBM.cpp b/src/allocator/GBM.cpp
index 6f596b7..b5a724e 100644
--- a/src/allocator/GBM.cpp
+++ b/src/allocator/GBM.cpp
@@ -4,6 +4,7 @@
#include <aquamarine/backend/DRM.hpp>
#include <aquamarine/allocator/Swapchain.hpp>
#include "FormatUtils.hpp"
+#include "ScanoutAlias.hpp"
#include "Shared.hpp"
#include <xf86drm.h>
#include <gbm.h>
@@ -101,6 +102,13 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
return;
}

+ // Scanout planes that offer only the alpha variant of an 8 bpc format (Apple M5 internal panel):
+ // allocate the A variant when the X variant is requested but not offered.
+ if (const uint32_t alt = scanoutAlphaAlias(FORMATS, attrs.format, params.scanout, CURSOR); alt != DRM_FORMAT_INVALID) {
+ allocator->backend->log(AQ_LOG_DEBUG, std::format("GBM: {} not offered by the scanout plane, using {}", fourccToName(attrs.format), fourccToName(alt)));
+ attrs.format = alt;
+ }
+
bool foundFormat = false;
// check if we can use modifiers. If the requested support has any explicit modifier
// supported by the primary backend, we can.
@@ -145,12 +153,9 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
if (MULTIGPU && !forceLinearBlit) {
// Try to use the linear format if available for cross-GPU compatibility.
// However, Nvidia doesn't support linear, so this is a best-effort basis.
- for (auto const& f : FORMATS) {
- if (f.drmFormat == DRM_FORMAT_MOD_LINEAR) {
- allocator->backend->log(AQ_LOG_DEBUG, "GBM: Buffer is marked as multigpu, using linear format");
- explicitModifiers = {DRM_FORMAT_MOD_LINEAR};
- break;
- }
+ if (std::ranges::find(explicitModifiers, DRM_FORMAT_MOD_LINEAR) != explicitModifiers.end()) {
+ allocator->backend->log(AQ_LOG_DEBUG, "GBM: Buffer is marked as multigpu, using linear format");
+ explicitModifiers = {DRM_FORMAT_MOD_LINEAR};
}
} else if (MULTIGPU && forceLinearBlit) {
// FIXME: Nvidia cannot render to linear buffers. What do?
@@ -200,21 +205,19 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
}
}

- if (MULTIGPU && forceLinearBlit) {
- // FIXME: most likely nvidia main gpu on multigpu
- if (!bo) {
- if (oldMods.empty())
- bo = gbm_bo_create(allocator->gbmDevice, attrs.size.x, attrs.size.y, attrs.format, GBM_BO_USE_RENDERING);
- else
- bo = gbm_bo_create_with_modifiers(allocator->gbmDevice, attrs.size.x, attrs.size.y, attrs.format, oldMods.data(), oldMods.size());
-
- if (!bo) {
- allocator->backend->log(AQ_LOG_ERROR, "GBM: Failed to allocate a GBM buffer: bo null");
- return;
- }
+ // FIXME: most likely nvidia main gpu on multigpu
+ if (MULTIGPU && !bo) {
+ if (oldMods.empty())
+ bo = gbm_bo_create(allocator->gbmDevice, attrs.size.x, attrs.size.y, attrs.format, GBM_BO_USE_RENDERING);
+ else
+ bo = gbm_bo_create_with_modifiers(allocator->gbmDevice, attrs.size.x, attrs.size.y, attrs.format, oldMods.data(), oldMods.size());

- modifier = gbm_bo_get_modifier(bo);
+ if (!bo) {
+ allocator->backend->log(AQ_LOG_ERROR, "GBM: Failed to allocate a GBM buffer: bo null");
+ return;
}
+
+ modifier = gbm_bo_get_modifier(bo);
}

if (!bo) {
@@ -284,7 +287,7 @@ bool Aquamarine::CGBMBuffer::isSynchronous() {
}

bool Aquamarine::CGBMBuffer::good() {
- return bo;
+ return bo && attrs.success;
}

SDMABUFAttrs Aquamarine::CGBMBuffer::dmabuf() {
diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp
index 688ed97..d313e33 100644
--- a/src/backend/drm/DRM.cpp
+++ b/src/backend/drm/DRM.cpp
@@ -35,6 +35,7 @@ extern "C" {

#include "Props.hpp"
#include "FormatUtils.hpp"
+#include "ScanoutAlias.hpp"
#include "Shared.hpp"
#include "hwdata.hpp"
#include "Renderer.hpp"
@@ -1949,7 +1950,7 @@ IOutput::SParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> d
TRACE(backend->backend->log(AQ_LOG_TRACE,
std::format("EDID: chromaticity coords {},{} {},{} {},{} {},{}", parsed.chromaticityCoords->red.x, parsed.chromaticityCoords->red.y,
parsed.chromaticityCoords->green.x, parsed.chromaticityCoords->green.y, parsed.chromaticityCoords->blue.x,
- parsed.chromaticityCoords->blue.y, parsed.chromaticityCoords->white.y, parsed.chromaticityCoords->white.y)));
+ parsed.chromaticityCoords->blue.y, parsed.chromaticityCoords->white.x, parsed.chromaticityCoords->white.y)));
}

const auto* hdr_static_metadata = di_info_get_hdr_static_metadata(info);
@@ -2255,6 +2256,7 @@ void Aquamarine::SDRMConnector::applyCommit(SDRMConnectorCommitData& data) {
auto bk = backend.lock();
if (bk) {
bk->backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} enabledState changed {} -> {}", szName, wasEnabled, output->enabledState));
+ bk->recheckCRTCs();
auto weak = bk->self;
bk->backend->addIdleEvent(makeShared<std::function<void(void)>>([weak] {
auto b = weak.lock();
@@ -2374,8 +2376,6 @@ bool Aquamarine::CDRMOutput::test() {
const auto QUEUE_KEY = connector->crtc->id;
if (pendingAsyncCommit)
backend->cancelAsyncOutput(this, true);
- if (pendingAsyncCommit)
- return false;
if (!backend->pauseCommitQueue(QUEUE_KEY))
return false;
CScopeGuard resume([this, QUEUE_KEY] { backend->resumeCommitQueue(QUEUE_KEY); });
@@ -2546,9 +2546,11 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) {

if (COMMITTED & COutputState::eOutputStateProperties::AQ_OUTPUT_STATE_FORMAT) {
// verify the format is valid for the primary plane
- bool ok = false;
- for (auto const& f : getRenderFormats()) {
- if (f.drmFormat == STATE.drmFormat) {
+ const auto FORMATS = getRenderFormats();
+ const auto ALIAS = scanoutAlphaAlias(FORMATS, STATE.drmFormat, true, false);
+ bool ok = false;
+ for (auto const& f : FORMATS) {
+ if (f.drmFormat == STATE.drmFormat || f.drmFormat == ALIAS) {
ok = true;
break;
}
@@ -2768,7 +2770,8 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) {
// sometimes, our consumer could f up the swapchain format and change it without the state changing
bool formatMismatch = false;
if (data.mainFB) {
- if (const auto params = data.mainFB->buffer->dmabuf(); params.success && params.format != STATE.drmFormat) {
+ if (const auto params = data.mainFB->buffer->dmabuf(); params.success && params.format != STATE.drmFormat &&
+ !scanoutAlphaAliasAccepted(getRenderFormats(), STATE.drmFormat, params.format, true, false)) {
// formats mismatch. Update the state format and roll with it
backend->backend->log(AQ_LOG_WARNING,
std::format("drm: Formats mismatch in commit, buffer is {} but output is set to {}. Modesetting to {}", fourccToName(params.format),
@@ -3168,7 +3171,7 @@ Aquamarine::IOutput::SCommitSubmission Aquamarine::CDRMOutput::commitAsync(const

const auto MAIN_BUFFER = data.mainFB ? data.mainFB->buffer.lock() : nullptr;
const auto ATTRS = MAIN_BUFFER ? MAIN_BUFFER->dmabuf() : SDMABUFAttrs{};
- if (ATTRS.success && ATTRS.format != STATE.drmFormat)
+ if (ATTRS.success && ATTRS.format != STATE.drmFormat && !scanoutAlphaAliasAccepted(getRenderFormats(), STATE.drmFormat, ATTRS.format, true, false))
return {.error = ENOTSUP};

if (options.lateCursor && cursorVisible && connector->crtc->cursor)
diff --git a/src/include/FormatUtils.hpp b/src/include/FormatUtils.hpp
index 75c8733..33f0e6a 100644
--- a/src/include/FormatUtils.hpp
+++ b/src/include/FormatUtils.hpp
@@ -5,3 +5,4 @@

std::string fourccToName(uint32_t drmFormat);
std::string drmModifierToName(uint64_t drmModifier);
+
17 changes: 12 additions & 5 deletions pkgbuilds/aquamarine/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
# restarting the compositor (Apple Silicon);
# - reconnect an output whose connector gained modes after it connected, so a
# monitor behind a USB4 dock that wakes slowly is not left without a mode
# (NVIDIA N1x).
# (NVIDIA N1x);
# - allocate the alpha variant of an 8 bpc format when the scanout plane
# offers only the alpha variant, so compositors that ask for XRGB8888
# start on panels without the opaque formats (M5 Max internal panel;
# hyprwm/aquamarine#496).
# hyprwm's fixes fc77bd58 and 04bfb7db, carried with 0.15.1, ship in 0.16.0.
# Drop the carry once hyprwm releases the fixes.
# Drop each carry once hyprwm releases the fix.

pkgname=aquamarine
pkgver=0.16.0
pkgrel=1.1
pkgrel=1.2
pkgdesc='a very light linux rendering backend library'
arch=(aarch64)
url="https://github.com/hyprwm/$pkgname"
Expand All @@ -39,15 +43,18 @@ provides=("lib$pkgname.so")
_archive="$pkgname-$pkgver"
source=("$url/archive/v$pkgver/$_archive.tar.gz"
0001-drm-re-read-possible-CRTCs-when-rescanning-connectors.patch
0004-drm-reconnect-an-output-whose-connector-gained-modes.patch)
0004-drm-reconnect-an-output-whose-connector-gained-modes.patch
0005-drm-use-the-alpha-variant-when-the-scanout-plane-lacks-it.patch)
sha256sums=('42339c3096c9de6582c0d71bc86b7e63334a3faf6a2b917d385ad093caf66c3c'
'50e9e38ff915b18074dc9b5dd1d07d7f24e340e99f254476d6abe578eece7864'
'7fe7620c222d9f323b6a424301b98176f798f41a97945282ec71b361e742511a')
'7fe7620c222d9f323b6a424301b98176f798f41a97945282ec71b361e742511a'
'21948dde6ff91580aeb3d3218a297dccd687b216d8b8afd5d0fc147ec131a180')

prepare() {
cd "$_archive"
patch -Np1 -i ../0001-drm-re-read-possible-CRTCs-when-rescanning-connectors.patch
patch -Np1 -i ../0004-drm-reconnect-an-output-whose-connector-gained-modes.patch
patch -Np1 -i ../0005-drm-use-the-alpha-variant-when-the-scanout-plane-lacks-it.patch
}

build() {
Expand Down
Loading