Skip to content

Commit

Permalink
platform/linux-dmabuf: Be more lenient with EGL implementations (#3279)
Browse files Browse the repository at this point in the history
Some EGL implementations (*cough* NVIDIA) return formats from
`eglQueryDmaBufFormatsEXT` that generate
`EGL_BAD_PARAMETER` errors when querying for the associated modifiers
with `eglQueryDmaBufModifiersEXT`.

This doesn't need to be fatal, as long as there are *some* formats for
which we can successfully query
the modifiers, so make it non-fatal.

Fixes: #3278
  • Loading branch information
AlanGriffiths authored Mar 15, 2024
2 parents e1a94e1 + cfb02d7 commit 722a108
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/platform/mir/graphics/drm_formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class DRMFormat
};

auto drm_modifier_to_string(uint64_t modifier) -> std::string;
auto drm_format_to_string(uint32_t format) -> char const*;
}

#endif //MIR_PLATFORM_GRAPHICS_DRM_FORMATS_H_
7 changes: 2 additions & 5 deletions src/platform/graphics/drm_formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@

namespace mg = mir::graphics;

namespace
{
constexpr auto drm_format_to_string(uint32_t format) -> char const*
auto mg::drm_format_to_string(uint32_t format) -> char const*
{
#define STRINGIFY(val) \
case val: \
Expand Down Expand Up @@ -65,7 +63,6 @@ constexpr auto drm_format_to_string(uint32_t format) -> char const*
#undef STRINGIFY_BIGENDIAN
}

}
struct mg::DRMFormat::FormatInfo
{
uint32_t format;
Expand Down Expand Up @@ -456,7 +453,7 @@ constexpr auto info_for_format(uint32_t fourcc_format) -> mg::DRMFormat::FormatI
}
BOOST_THROW_EXCEPTION((
std::runtime_error{
std::string{"Unsupported DRM format: "} + drm_format_to_string(fourcc_format)}));
std::string{"Unsupported DRM format: "} + mg::drm_format_to_string(fourcc_format)}));
}

}
Expand Down
24 changes: 22 additions & 2 deletions src/platform/graphics/linux_dmabuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class mg::DmaBufFormatDescriptors
resize(returned_formats);
}

for (auto i = 0u; i < formats.size(); ++i)
for (auto i = 0u; i < formats.size();)
{
auto [format, modifiers, external_only] = (*this)[i];

Expand All @@ -101,7 +101,17 @@ class mg::DmaBufFormatDescriptors
nullptr,
&num_modifiers) != EGL_TRUE)
{
BOOST_THROW_EXCEPTION((mg::egl_error("Failed to query number of modifiers")));
mir::log_warning("eglQueryDmaBufModifiers failed for format %s: %s",
mg::drm_format_to_string(static_cast<uint32_t>(format)),
mg::egl_category().message(eglGetError()).c_str());

// Remove that format and its modifiers from our list
formats.erase(formats.begin() + i);
modifiers_for_format.erase(modifiers_for_format.begin() + i);
external_only_for_format.erase(external_only_for_format.begin() + i);
// formats[i] is now the format *after* the one we've just removed,
// so we can can continue iterating through the formats from here.
continue;
}
modifiers.resize(num_modifiers);
external_only.resize(num_modifiers);
Expand Down Expand Up @@ -138,6 +148,16 @@ class mg::DmaBufFormatDescriptors
modifiers.push_back(DRM_FORMAT_MOD_INVALID);
external_only.push_back(false);
}

// We've processed this format; move on to the next one
++i;
}
if (this->num_formats() == 0)
{
/* We can get here if the EGL implementation *claimed* to support some formats,
* but querying the supported modifiers failed for *all* formats.
*/
BOOST_THROW_EXCEPTION((std::runtime_error{"EGL claimed support for DMA-Buf import modifiers, but all queries failed"}));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/platform/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ MIR_PLATFORM_2.17 {
mir::graphics::common::EGLContextExecutor::spawn*;
mir::graphics::contains_alpha*;
mir::graphics::drm_modifier_to_string*;
mir::graphics::drm_format_to_string*;
mir::graphics::egl_category*;
mir::graphics::gl::Program::?Program*;
mir::graphics::gl::ProgramFactory::?ProgramFactory*;
Expand Down

0 comments on commit 722a108

Please sign in to comment.