🐛 Refuse HEVC decodes of sizes the host lacks at their create

An x86-64 guest's HEVC stream smaller than the host decoder's least size (64x64
and 128x96 on the RTX 3090's NVDEC, lane vhevcenc's leg m3-max-77366) got a
session, and the host refused each picture at its schedule: AppleGVA reports
that as kVTVideoDecoderMalfunctionErr for the frame and every frame after it,
so a client that allows software decoding got no frame at all. CreateContexts
names the coded size, so the driver now refuses HEVC there as it refuses
H.264 (cffc93097), and VideoToolbox decodes such a stream in software. The
per-picture check stays for a stream whose SPS changes its size.

For the guest: an HEVC VTDecompressionSessionCreate of a coded size the host
does not decode fails at create, so VideoToolbox falls back to its software
decoder where the client allows it; before, the session was made and every
frame failed with -12911. checkDecodeSizeAtCreate replaces
checkH264SizeAtCreate, which held that an HEVC create of any size is made.
This commit is contained in:
Anees Iqbal committed 2026-11-27 14:10:48 -08:00
1 parent bd2a54f3f0
commit 5dfe92be18
3 files changed
+52 -41

No files matched your search

+9 -8
View File
@@ -1450,18 +1450,19 @@ uint64_t answer(int entry, uint64_t a0, uint64_t a1, uint64_t a2)
std::lock_guard<std::mutex> hold(g_sessionLock);
g_sessions.push_back(context);
} else if (codec != 0) {
// An H.264 stream of a coded size the host does not decode is refused here, where
// A stream of a coded size the host does not decode is refused here, where
// VideoToolbox hears of it and turns to its software decoder: AppleGVA's H.264
// decoder hears of no failure later (RgfxVideoStatus.hpp).
if (codec == RGFX_VIDEO_CODEC_H264 &&
!rgfx::video::sizeTaken(rgfx::video::hostCodec(codec, RGFX_VIDEO_DECODE),
// decoder hears of no failure later, and its HEVC decoder hears of one only as
// a failed frame and every frame after it (RgfxVideoStatus.hpp).
if (!rgfx::video::sizeTaken(rgfx::video::hostCodec(codec, RGFX_VIDEO_DECODE),
fi->width, fi->height)) {
static std::atomic<bool> said;
if (!said.exchange(true))
static std::atomic<bool> said[2];
const bool hevc = codec == RGFX_VIDEO_CODEC_HEVC;
if (!said[hevc].exchange(true))
os_log_error(rgfxLog(),
"RGFX: video: an H.264 decode of %ux%u refused at its create: "
"RGFX: video: an %s decode of %ux%u refused at its create: "
"the host decodes no picture of its coded size",
fi->width, fi->height);
hevc ? "HEVC" : "H.264", fi->width, fi->height);
} else {
context->session = rgfx::video::openSession(codec, RGFX_VIDEO_DECODE);
}
+6 -3
View File
@@ -23,9 +23,12 @@
* host, 2026-11-07, every picture failed on the host). Its pipelines schedule their commands one
* at a time and keep no decode's result (read from AppleGVA's code on macOS 26.7.1). So an H.264
* schedule does not wait for the host, as waiting would only cost: its frames reach the guest as
* decoded, as AppleGVA leaves no way to say otherwise. What the driver can tell before the first
* picture, a coded size the host does not decode (sizeTaken), it refuses at the context's create,
* which fails the client's session create, so VideoToolbox decodes the stream in software.
* decoded, as AppleGVA leaves no way to say otherwise.
*
* What the driver can tell before the first picture, a coded size the host does not decode
* (sizeTaken), it refuses at the context's create, for both codecs: that fails the client's
* session create, so VideoToolbox decodes the stream in software for a client that allows it,
* where an HEVC picture refused at its schedule would end the session's frames in -12911.
*/
#ifndef RGFX_VIDEO_STATUS_HPP_
+37 -30
View File
@@ -563,52 +563,59 @@ void checkFailedCreate()
CHECK(g_opened[0]->forgotten == 0, "the closed session's outputs forgotten");
}
// An H.264 decode of a coded size outside the host's (144 to 8192 samples a side here) is refused
// at its create, with no session opened, as are the contexts made before it in the same create;
// one of the host's least and largest sizes is made. An HEVC decode of any size is made: its
// pictures are held to the host's sizes as they are scheduled, which AppleGVA reports.
void checkH264SizeAtCreate()
// A decode of a coded size outside the host's (144 to 8192 samples a side here) is refused at its
// create, H.264's and HEVC's alike, with no session opened, as are the contexts made before it in
// the same create; one of the host's least and largest sizes is made. HEVC's is refused there
// too, where a picture refused at its schedule would end the session's frames in -12911 and leave
// VideoToolbox no software decode to turn to.
void checkDecodeSizeAtCreate()
{
const struct {
uint32_t width, height;
uint64_t want;
} cases[] = {
{8193, 720, kUnsupported}, {1280, 8208, kUnsupported}, {128, 720, kUnsupported},
{1280, 128, kUnsupported}, {144, 144, kOk}, {8192, 8192, kOk},
{1280, 128, kUnsupported}, {64, 64, kUnsupported}, {144, 144, kOk},
{8192, 8192, kOk},
};
for (const auto &c : cases) {
g_opened.clear();
std::vector<void *> contexts;
CHECK(makeContexts(1, contexts, kCodecH264, c.width, c.height) == c.want,
"an H.264 create of %ux%u", c.width, c.height);
CHECK(g_opened.size() == (c.want == kOk ? 1u : 0u), "%zu sessions opened for %ux%u",
g_opened.size(), c.width, c.height);
CHECK((contexts[0] != nullptr) == (c.want == kOk), "the context of %ux%u", c.width, c.height);
if (contexts[0]) {
ContextDelete del = {1, 0, &contexts[0]};
CHECK(call(kDeleteContexts, &del) == kOk, "DeleteContexts");
const struct {
uint64_t sub;
const char *name;
} codecs[] = {{kCodecH264, "H.264"}, {kCodecHevc, "HEVC"}};
for (const auto &codec : codecs)
for (const auto &c : cases) {
g_opened.clear();
std::vector<void *> contexts;
CHECK(makeContexts(1, contexts, codec.sub, c.width, c.height) == c.want,
"an %s create of %ux%u", codec.name, c.width, c.height);
CHECK(g_opened.size() == (c.want == kOk ? 1u : 0u), "%zu %s sessions opened for %ux%u",
g_opened.size(), codec.name, c.width, c.height);
CHECK((contexts[0] != nullptr) == (c.want == kOk), "the %s context of %ux%u", codec.name,
c.width, c.height);
if (contexts[0]) {
ContextDelete del = {1, 0, &contexts[0]};
CHECK(call(kDeleteContexts, &del) == kOk, "DeleteContexts");
}
}
}
// A create of two H.264 decodes whose second is of a size the host does not decode: the
// first's session goes with it.
{
// A create of two decodes whose second is of a size the host does not decode: the first's
// session goes with it.
for (const auto &codec : codecs) {
static FunctionInfo infos[2];
infos[0] = infos[1] = decodeH264();
infos[0].sub_id = infos[1].sub_id = codec.sub;
infos[1].width = 8193;
const FunctionInfo *list[2] = {&infos[0], &infos[1]};
void *contexts[2] = {};
ContextInfo info = {2, 0, list, contexts};
ContextInit init = {&info, nullptr};
g_opened.clear();
CHECK(call(kCreateContexts, &init) == kUnsupported, "a create whose second decode is too wide");
CHECK(g_opened.size() == 1 && g_opened[0]->closed, "the first decode's session left open");
CHECK(contexts[0] == nullptr && contexts[1] == nullptr, "a context handed back");
CHECK(call(kCreateContexts, &init) == kUnsupported,
"an %s create whose second decode is too wide", codec.name);
CHECK(g_opened.size() == 1 && g_opened[0]->closed, "the first %s decode's session left open",
codec.name);
CHECK(contexts[0] == nullptr && contexts[1] == nullptr, "an %s context handed back",
codec.name);
}
g_opened.clear();
std::vector<void *> contexts;
CHECK(makeContexts(1, contexts, kCodecHevc, 8193, 720) == kOk, "an HEVC create of 8193x720");
ContextDelete del = {1, 0, &contexts[0]};
CHECK(call(kDeleteContexts, &del) == kOk, "DeleteContexts");
}
// DeleteContexts closes each context's session, which a later FreePixelBufferPool no longer
@@ -2017,7 +2024,7 @@ int main(int argc, char **argv)
g_driver = createDriver();
RUN(checkPoolsPerDriver);
RUN(checkFailedCreate);
RUN(checkH264SizeAtCreate);
RUN(checkDecodeSizeAtCreate);
RUN(checkDelete);
RUN(checkUnsentDecode);
RUN(checkTileLanding);