allocator: allow format-less allocations

will pick a format
This commit is contained in:
Vaxry 2024-06-26 19:42:39 +02:00
parent 41b1b28ce1
commit 3dbff4025c
3 changed files with 17 additions and 13 deletions

View file

@ -9,7 +9,7 @@ namespace Aquamarine {
struct SSwapchainOptions { struct SSwapchainOptions {
size_t length = 0; size_t length = 0;
Hyprutils::Math::Vector2D size; Hyprutils::Math::Vector2D size;
uint32_t format = DRM_FORMAT_INVALID; uint32_t format = DRM_FORMAT_INVALID; // if you leave this on invalid, the swapchain will choose an appropriate format (and modifier) for you.
bool scanout = false, cursor = false /* requires scanout = true */; bool scanout = false, cursor = false /* requires scanout = true */;
}; };

View file

@ -21,9 +21,6 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
const bool CURSOR = params.cursor && params.scanout; const bool CURSOR = params.cursor && params.scanout;
if (CURSOR)
allocator->backend->log(AQ_LOG_WARNING, "GBM: Allocating a cursor buffer");
const auto FORMATS = CURSOR ? swapchain->backendImpl->getCursorFormats() : swapchain->backendImpl->getRenderFormats(); const auto FORMATS = CURSOR ? swapchain->backendImpl->getCursorFormats() : swapchain->backendImpl->getRenderFormats();
std::vector<uint64_t> explicitModifiers; std::vector<uint64_t> explicitModifiers;
@ -31,15 +28,25 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
// check if we can use modifiers. If the requested support has any explicit modifier // check if we can use modifiers. If the requested support has any explicit modifier
// supported by the primary backend, we can. // supported by the primary backend, we can.
for (auto& f : FORMATS) { for (auto& f : FORMATS) {
if (f.drmFormat != params.format) if (f.drmFormat != attrs.format && attrs.format != DRM_FORMAT_INVALID)
continue; continue;
for (auto& m : f.modifiers) { for (auto& m : f.modifiers) {
if (m == DRM_FORMAT_MOD_LINEAR || m == DRM_FORMAT_MOD_INVALID) if (m == DRM_FORMAT_MOD_INVALID)
continue; continue;
explicitModifiers.push_back(m); explicitModifiers.push_back(m);
} }
if (attrs.format == DRM_FORMAT_INVALID) {
allocator->backend->log(AQ_LOG_WARNING, std::format("GBM: Automatically selected format {} for new GBM buffer", fourccToName(f.drmFormat)));
attrs.format = f.drmFormat;
}
}
if (attrs.format == DRM_FORMAT_INVALID) {
allocator->backend->log(AQ_LOG_ERROR, "GBM: Failed to allocate a GBM buffer: no format found");
return;
} }
if (explicitModifiers.empty()) { if (explicitModifiers.empty()) {
@ -163,11 +170,6 @@ SP<IBuffer> Aquamarine::CGBMAllocator::acquire(const SAllocatorBufferParams& par
return nullptr; return nullptr;
} }
if (params.format == DRM_FORMAT_INVALID) {
backend->log(AQ_LOG_ERROR, "Couldn't allocate a gbm buffer with invalid format");
return nullptr;
}
auto newBuffer = SP<CGBMBuffer>(new CGBMBuffer(params, self, swapchain_)); auto newBuffer = SP<CGBMBuffer>(new CGBMBuffer(params, self, swapchain_));
if (!newBuffer->good()) { if (!newBuffer->good()) {

View file

@ -30,10 +30,10 @@ bool Aquamarine::CSwapchain::reconfigure(const SSwapchainOptions& options_) {
return true; return true;
} }
if (options_.format == options.format && options_.size == options.size && options_.length == options.length) if ((options_.format == options.format || options_.format == DRM_FORMAT_INVALID) && options_.size == options.size && options_.length == options.length)
return true; // no need to reconfigure return true; // no need to reconfigure
if (options_.format == options.format && options_.size == options.size) { if ((options_.format == options.format || options_.format == DRM_FORMAT_INVALID) && options_.size == options.size) {
bool ok = resize(options_.length); bool ok = resize(options_.length);
if (!ok) if (!ok)
return false; return false;
@ -49,6 +49,8 @@ bool Aquamarine::CSwapchain::reconfigure(const SSwapchainOptions& options_) {
return false; return false;
options = options_; options = options_;
if (options.format == DRM_FORMAT_INVALID)
options.format = buffers.at(0)->dmabuf().format;
allocator->getBackend()->log(AQ_LOG_DEBUG, allocator->getBackend()->log(AQ_LOG_DEBUG,
std::format("Swapchain: Reconfigured a swapchain to {} {} of length {}", options.size, fourccToName(options.format), options.length)); std::format("Swapchain: Reconfigured a swapchain to {} {} of length {}", options.size, fourccToName(options.format), options.length));