🐎 Hold textures, views and Managed creates with the destroys

A texture's create (TEXTURE_CREATE), a view's (TEXTURE_VIEW), a Managed
texture's and buffer's (MANAGED_TEXTURE_CREATE, MANAGED_BUFFER_CREATE) and a
Managed buffer's modified range (BUFFER_DID_MODIFY_RANGE) are messages no one
waits for, each its own Submit call: on the RX 7900 XTX host 8 to 13 us each,
812 of them and 8.8 ms a Vision process. SubmitBatch now takes them too, each
of its one size, checked as Submit checks it, a create for a context closed
since its check destroyed behind it (rgfxSubmitBatchSize). None names a block,
which spans_test keeps. The bundle holds them with the destroys and the
heap-placed buffers (RgfxSerializer::postUnwaited), in their order, posted
before anything else the process posts or asks of the kext and before any
command buffer it commits. A texture over an IOSurface still goes at once, as
a present of the surface waits for it, and so do the creates that name a block.

This changes what the guest sees under transport exhaustion only (the control
ring full for 5 s, or the device stopped), as 628b03fb3 did for heap-placed
buffers: such an object made then is answered as made, held, where its refused
post answered nil. Its refusal reaches the app where Metal's caller sees a
lost GPU's: the next post retries what is held and is refused in that same
call where the held are refused again; a create that needs the held gone to
make room is refused at once; and a commit that finds anything but destroys
held fails its command buffer, unposted, with MTLCommandBufferErrorInternal.
postHeldCreates already answered so for every held type; serializer_tests'
test_held_creates checks each kind on its own, and protocol_tests'
test_commit_behind_an_untaken_buffer_fails a texture through a commit. A
create the host refuses was answered by no one before, and is not now.
This commit is contained in:
Anees Iqbal committed 2026-11-13 09:01:40 -08:00
1 parent 7daceaff19
commit 8430562098
11 files changed
+306 -81

No files matched your search

+29 -15
View File
@@ -1909,16 +1909,22 @@ library the app let go names a library the host still holds. The host makes the
pipeline from the library before the library's destroy, and the pipeline needs
it no more.
**Destroys and heap-placed buffers go together.** Each call into the kext
costs the guest its trip through the kernel, and a post that finds the host's
control thread asleep a doorbell's exit too: 14 us a destroy in a Vision
**Destroys and creates no one waits for go together.** Each call into the
kext costs the guest its trip through the kernel, and a post that finds the
host's control thread asleep a doorbell's exit too: 14 us a destroy in a Vision
request on the RTX 3090 host (9 to 10 us without the doorbell), 3415 destroys
and 68 to 70 ms a process, in runs of about 70 an app lets go back to back,
and 12 to 15 us a `BUFFER_AT_OFFSET`, the buffer a heap places (each small
buffer of a slab), 3079 and 40 to 48 ms a process, between them. So where the
kext carries `SubmitBatch` (selector 5), the bundle holds each of the two
(`RgfxRingWriter::postLater`) and posts what it holds in one call, at most
4096 bytes (170 destroys, 73 buffers), before anything else the process posts
buffer of a slab), 3079 and 40 to 48 ms a process, between them; and on the
RX 7900 XTX host 8 to 13 us each of a Vision process's 276
`TEXTURE_CREATE`s, 82 `TEXTURE_VIEW`s, 46 `MANAGED_TEXTURE_CREATE`s, 204
`MANAGED_BUFFER_CREATE`s and 204 `BUFFER_DID_MODIFY_RANGE`s, 8.8 ms a
process. So where the kext
carries `SubmitBatch` (selector 5), the bundle holds each of these messages,
none of which anyone waits for or which names a block
(`RgfxSerializer::postUnwaited`, `RgfxRingWriter::postLater`), and posts what
it holds in one call, at most 4096 bytes (170 destroys, 73 buffers, 39
textures), before anything else the process posts
or asks of the kext (every `IOConnectCall` of the device's goes through
`rgfxKextConn`, which posts the held first) and before any command buffer it
commits (the host reads a command buffer after the control ring's messages
@@ -1932,21 +1938,29 @@ went back once its destroy was posted: whatever takes it again, a create over
the bytes or with the id, or a block's free, is posted after the destroy, so
the host has dropped the object first, and every answer the guest reads (a
heap's `usedSize`, a new object's GPU address and resource id) is the one it
read before. A texture over an IOSurface goes at once: a present of the surface
shows the newest live texture the host names it by, and waits for its destroy.
read before. A texture over an IOSurface goes at once, made and destroyed: a
present of the surface, by any process, shows the newest live texture the
host names it by, and waits for its create and its destroy. So do the creates
that name a block (`BUFFER_OVER_PAGES`, `BUFFER_OVER_SURFACE_PAGES`), which the
block's lane orders.
Where the kext stops taking them (its ring stayed full 5 s, or the device
stopped), the rest stay held, first: the process's next post retries them,
under its own post's bound, and is refused only where they are refused again,
as the full ring refuses it; a commit that finds a buffer still held fails the
command buffer, unposted, with `MTLCommandBufferErrorInternal`, as a GPU
recovery's victim fails, as the buffer may name it. Two answers differ from
an unbatched post's then, and only then: a buffer held when the kext stopped
taking them was answered as made, where its refused post answered nil (as
Metal makes objects on a GPU that is gone, and fails the work at commit); and
recovery's victim fails, as the buffer may name it; so does any message held
but a destroy, each of the kinds above (a create the buffer may name, a
Managed range it may read). Two answers differ from an unbatched post's
then, and only then: an object held when the kext stopped taking them was
answered as made, where its refused post answered nil (as Metal makes
objects on a GPU that is gone, and fails the work at commit), and its
refusal reaches the app at the next post, refused in that call, or the next
commit, failed, never later; and
what the held destroys lay over has gone back, which a guest reading a heap's
`usedSize` through a 5 s stall of the control ring sees lower than it did.
Tested by `serializer_tests`' `test_held_destroys` and
`test_held_buffers`, `shell_tests`' `test_held_destroys_change_nothing_seen`,
`test_held_buffers` and `test_held_creates`, `shell_tests`'
`test_held_destroys_change_nothing_seen`,
`test_surface_texture_destroys_go_at_once` and
`test_commit_behind_an_untaken_buffer_fails`, and the kext's by
`submit_gate_test`, `spans_test` and `user_client_words_test`.
@@ -4015,7 +4029,7 @@ Map 1:
| 2 | | | given to none: the IOGPU base's device-info call on its own client type, so a trace names one call per number |
| 3 | `Features` | | the device's feature word, the kext's and the selector map; at 3 in every map |
| 4 | `PagesBlock` | 1 << 0 `PagesBlock` | a block of the runs of a process's own pages, wired, for its no-copy buffers |
| 5 | `SubmitBatch` | 1 << 1 `SubmitBatch` | a process's destroys and heap-placed buffers onto ring 0 in one call ("Destroys and heap-placed buffers go together") |
| 5 | `SubmitBatch` | 1 << 1 `SubmitBatch` | a process's destroys, and its creates and writes no one waits for that name no block, onto ring 0 in one call ("Destroys and creates no one waits for go together") |
| 6 | `WakeCompletions` | 1 << 2 `WakeCompletions` | reserved: wakes the client's completion waiters |
| 7 | `TakeAnswers` | 1 << 4 `DeferredAnswers` | hands a process its held pipeline-create answers ("Known pipeline creates") |
| 8 | `SurfaceBlockRelease` | | lets go of a shared block |
+5 -4
View File
@@ -78,7 +78,8 @@ typedef bool (*RgfxAwaitAnswer)(void *context, uint64_t seqno);
/// Hands `bytes` bytes of whole messages back to back (each header's `type` and `size` stamped),
/// which no one waits for, to the kext in one call (the accelerator's SubmitBatch, which takes
/// destroys alone): how many of them it posted, from the first, in their order. Fewer than all
/// the types the kext's rgfxSubmitBatchSize names): how many of them it posted, from the first,
/// in their order. Fewer than all
/// only where the kext refused them, as it does where its control ring stays full.
typedef uint32_t (*RgfxForwardBatch)(void *context, const void *messages, uint32_t bytes);
@@ -147,9 +148,9 @@ public:
/// Whether postLater() holds messages to go together (setBatch).
bool batches() const { return m_later != nullptr; }
/// Posts a message no one waits for (a destroy, a heap-placed buffer) together with others
/// where the writer batches (setBatch): held, to go in the order held before anything the
/// writer posts after it (each tryPost, tryPostKnown and tryPostShared posts the held first),
/// Posts a message no one waits for (a destroy, a create that names no block) together with
/// others where the writer batches (setBatch): held, to go in the order held before anything
/// the writer posts after it (each tryPost, tryPostKnown and tryPostShared posts the held first),
/// at flushLater(), once the held reach the batch's bytes, or setBatch's time after the first
/// held. Else, or for a message larger than a batch, posted as tryPost() posts it. True once
/// held or posted; false, holding nothing more, where the held had to go first to make room
+13 -9
View File
@@ -404,7 +404,7 @@ RgfxCreated RgfxSerializer::createManagedBuffer(RgfxObjId cpu_buffer, uint64_t l
msg.cpu_buffer_obj_id = cpu_buffer;
msg.length = length;
msg.options = RgfxHostResourceOptions(options);
out.posted = m_control.tryPost(RGFX_CMD_MANAGED_BUFFER_CREATE, &msg, sizeof(msg), &out.seqno);
out.posted = postUnwaited(RGFX_CMD_MANAGED_BUFFER_CREATE, &msg, sizeof(msg), &out.seqno);
return out;
}
@@ -448,12 +448,17 @@ RgfxCreated RgfxSerializer::createBufferAtOffset(RgfxObjId heap, uint64_t offset
msg.offset = offset;
msg.length = length;
msg.options = RgfxHostResourceOptions(options);
out.posted = m_control.batches()
? m_control.postLater(RGFX_CMD_BUFFER_AT_OFFSET, &msg, sizeof(msg))
: m_control.tryPost(RGFX_CMD_BUFFER_AT_OFFSET, &msg, sizeof(msg), &out.seqno);
out.posted = postUnwaited(RGFX_CMD_BUFFER_AT_OFFSET, &msg, sizeof(msg), &out.seqno);
return out;
}
bool RgfxSerializer::postUnwaited(uint32_t type, const void *message, uint32_t size,
uint64_t *out_seqno)
{
return m_control.batches() ? m_control.postLater(type, message, size)
: m_control.tryPost(type, message, size, out_seqno);
}
void RgfxSerializer::releaseResourceId(uint64_t resource_id)
{
m_ids.freeResourceId(resource_id);
@@ -500,7 +505,7 @@ RgfxCreated RgfxSerializer::createTexture(const RgfxTextureDescriptor &desc, Rgf
msg.heap_obj_id = heap;
msg.heap_offset = heap_offset;
}
out.posted = m_control.tryPost(RGFX_CMD_TEXTURE_CREATE, &msg, sizeof(msg), &out.seqno);
out.posted = postUnwaited(RGFX_CMD_TEXTURE_CREATE, &msg, sizeof(msg), &out.seqno);
return out;
}
@@ -511,7 +516,7 @@ bool RgfxSerializer::bufferDidModifyRange(RgfxObjId buffer, uint64_t location, u
msg.location = location;
msg.length = length;
uint64_t seqno = 0;
return m_control.tryPost(RGFX_CMD_BUFFER_DID_MODIFY_RANGE, &msg, sizeof(msg), &seqno);
return postUnwaited(RGFX_CMD_BUFFER_DID_MODIFY_RANGE, &msg, sizeof(msg), &seqno);
}
bool RgfxSerializer::textureDidModifyData(RgfxObjId texture)
@@ -551,8 +556,7 @@ RgfxCreated RgfxSerializer::createManagedTexture(const RgfxTextureDescriptor &de
msg.block_height = block_height;
msg.flags = flags;
msg.desc = desc;
out.posted =
m_control.tryPost(RGFX_CMD_MANAGED_TEXTURE_CREATE, &msg, sizeof(msg), &out.seqno);
out.posted = postUnwaited(RGFX_CMD_MANAGED_TEXTURE_CREATE, &msg, sizeof(msg), &out.seqno);
return out;
}
@@ -629,7 +633,7 @@ RgfxCreated RgfxSerializer::createTextureView(const RgfxTextureView &view)
msg.header = {};
msg.obj_id = out.obj_id;
msg.resource_id = out.resource_id;
out.posted = m_control.tryPost(RGFX_CMD_TEXTURE_VIEW, &msg, sizeof(msg), &out.seqno);
out.posted = postUnwaited(RGFX_CMD_TEXTURE_VIEW, &msg, sizeof(msg), &out.seqno);
return out;
}
+21 -8
View File
@@ -451,13 +451,15 @@ public:
/// where the device took RGFX_FEATURE_MANAGED_BUFFER_SLABS). The pick holds `offset` bytes
/// more, and the buffer's address is the pick plus `offset`, as a no-copy buffer's over the
/// app's pages keeps its pointer's offset in its page (createBufferOverPages). The answer's
/// `gpu_address` is the address picked, given back through releaseAddress.
/// `gpu_address` is the address picked, given back through releaseAddress. No one waits for
/// it: held where the control ring batches, as createBufferAtOffset's buffer is.
RgfxCreated createManagedBuffer(RgfxObjId cpu_buffer, uint64_t length, uint32_t options,
uint64_t align = kDefaultAddressAlign, uint64_t offset = 0);
/// The process wrote `length` bytes at `location` of Managed buffer `buffer`'s CPU copy
/// (`didModifyRange:`): every command buffer committed after it sees them. False where the
/// message was not posted.
/// (`didModifyRange:`): every command buffer committed after it sees them. Held where the
/// control ring batches, as createBufferAtOffset's buffer is, so a commit posts it first.
/// False where the message was neither held nor posted.
bool bufferDidModifyRange(RgfxObjId buffer, uint64_t location, uint64_t length);
/// The process changed the bytes texture `texture` lies over (`didModifyData`, SPI): a
@@ -484,7 +486,8 @@ public:
/// A texture of shape `desc`. When `heap` is RGFX_OBJ_NONE the texture is
/// device-placed at a picked GPU address, whose range holds `span` bytes (its
/// allocatedSize), as a buffer's holds its length; otherwise it lies at
/// `heap_offset` in `heap`. A resource id is picked either way.
/// `heap_offset` in `heap`. A resource id is picked either way. No one waits for it: held
/// where the control ring batches, as createBufferAtOffset's buffer is.
RgfxCreated createTexture(const RgfxTextureDescriptor &desc, RgfxObjId heap = RGFX_OBJ_NONE,
uint64_t heap_offset = 0, uint64_t align = kDefaultAddressAlign,
uint64_t span = 1);
@@ -492,7 +495,8 @@ public:
/// A Managed texture of shape `desc` at a picked GPU address, whose CPU copy is the Shared
/// buffer `cpu_buffer` over a block, of blocks `bytes_per_block` bytes and `block_width` by
/// `block_height` texels (RgfxManagedLayout.hpp), `flags` RGFX_MANAGED_TEXTURE_LINEAR or 0,
/// the address's range `span` bytes (its allocatedSize). A resource id is picked.
/// the address's range `span` bytes (its allocatedSize). A resource id is picked. No one waits
/// for it: held where the control ring batches, as createBufferAtOffset's buffer is.
RgfxCreated createManagedTexture(const RgfxTextureDescriptor &desc, RgfxObjId cpu_buffer,
uint32_t bytes_per_block, uint32_t block_width,
uint32_t block_height, uint32_t flags,
@@ -505,7 +509,8 @@ public:
const uint32_t origin[3], const uint32_t size[3]);
/// A view of a texture (RGFX_CMD_TEXTURE_VIEW): `view`'s parent, format, flags, type, levels,
/// slices and swizzle, with its id and resource id picked; `view`'s own are not read.
/// slices and swizzle, with its id and resource id picked; `view`'s own are not read. No one
/// waits for it: held where the control ring batches, as createBufferAtOffset's buffer is.
RgfxCreated createTextureView(const RgfxTextureView &view);
/// A texture of shape `desc` over the buffer `buffer` from `offset`, each row
@@ -739,8 +744,9 @@ public:
/// Posts what the control ring holds to go together (RgfxRingWriter::postLater), as a command
/// buffer's commit does before the buffer goes on its ring, which the host reads after the
/// control ring's messages posted before it: whether no create stays held, which the buffer
/// may name. Destroys left held wait for a later post, as refused ones do.
/// control ring's messages posted before it: whether nothing but destroys stays held, so no
/// create the buffer may name, nor a Managed buffer's range it may read. Destroys left held
/// wait for a later post, as refused ones do.
bool postHeldCreates();
/// The default alignment for a picked GPU address when the caller names none.
@@ -800,6 +806,13 @@ private:
// Posts OBJECT_DESTROY of `obj_id`: whether it reached the ring.
bool postDestroy(RgfxObjId obj_id);
// Posts a message no one waits for that names no block (a create of one, a Managed buffer's
// modified range): where the route batches (RgfxRingWriter::postLater), held to go with the
// messages around it, before anything posted after it and before any command buffer
// committed after it (postHeldCreates), `*out_seqno` left as it is; else at once, as tryPost
// posts it. Whether it is held or posted.
bool postUnwaited(uint32_t type, const void *message, uint32_t size, uint64_t *out_seqno);
// The ICB records waiting for flushIcbWrites(), under m_icbLock: one ICB_WRITE message for
// each buffer's run of records, in the order the runs began. m_icbPending is set as a record
// is added, and cleared only once a flush has posted them all, so a flush that finds it
+43 -1
View File
@@ -516,7 +516,8 @@ struct RefusingKext {
// holds it to go with others) fails the next command buffer committed, unposted, with
// MTLCommandBufferErrorInternal, as the buffer may name it, and the next post is refused, as a
// full control ring refuses it; once the kext takes them again, the buffer goes before the next
// command buffer, which goes on its ring.
// command buffer, which goes on its ring. A texture held so does the same (serializer_tests'
// test_held_creates checks each kind held).
void test_commit_behind_an_untaken_buffer_fails()
{
TestRing control(0x8000);
@@ -599,6 +600,47 @@ void test_commit_behind_an_untaken_buffer_fails()
CHECK(completion.postFromHost(&done, sizeof(done)));
[next waitUntilCompleted];
CHECK(next.status == MTLCommandBufferStatusCompleted);
// A texture held so fails the next commit too, as it may name it, and goes before the
// command buffer after it once the kext takes it again.
kext.refuse = true;
MTLTextureDescriptor *td =
[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm
width:4
height:4
mipmapped:NO];
td.storageMode = MTLStorageModePrivate;
RgfxTexture *texture = [RgfxTexture textureWithDescriptor:td
heap:RGFX_OBJ_NONE
heapOffset:0
device:nil
serializer:&ser];
CHECK(texture != nil);
id<MTLCommandBuffer> third = [queue commandBuffer];
id<MTLBlitCommandEncoder> blit3 = [third blitCommandEncoder];
[blit3 fillBuffer:buffer range:NSMakeRange(0, 256) value:2];
[blit3 endEncoding];
[third commit];
[third waitUntilCompleted];
CHECK(third.status == MTLCommandBufferStatusError);
CHECK(third.error != nil && third.error.code == MTLCommandBufferErrorInternal);
CHECK(!submit.next(&h, &bytes));
CHECK(!control.next(&h, &bytes));
kext.refuse = false;
id<MTLCommandBuffer> fourth = [queue commandBuffer];
id<MTLBlitCommandEncoder> blit4 = [fourth blitCommandEncoder];
[blit4 fillBuffer:buffer range:NSMakeRange(0, 256) value:3];
[blit4 endEncoding];
[fourth commit];
CHECK(control.next(&h, &bytes) && h.type == RGFX_CMD_TEXTURE_CREATE);
std::memcpy(&obj, bytes.data() + sizeof(h), sizeof(obj));
CHECK(obj == [texture rgfxObjId]);
CHECK(submit.next(&h, &bytes) && h.type == RGFX_CMD_COMMAND_BUFFER);
done.header.seqno = h.seqno;
done.cb_obj_id = ((RgfxResource *)fourth).rgfxObjId;
CHECK(completion.postFromHost(&done, sizeof(done)));
[fourth waitUntilCompleted];
CHECK(fourth.status == MTLCommandBufferStatusCompleted);
}
}
+10 -6
View File
@@ -37,6 +37,7 @@
#include "RgfxRingWriter.hpp"
#include "RgfxSerializer.hpp"
#include "reims_graphics_wire.h"
#include "../../kext/src/RgfxSubmitGate.hpp"
#include "rgfx_test_ring.hpp" // CHECK, g_checks, TestRing, expectMessage
void rgfxResourceTests();
@@ -1497,7 +1498,7 @@ struct KextRing {
for (uint32_t at = 0; at < bytes; posted++) {
RgfxMsgHeader header;
std::memcpy(&header, m + at, sizeof(header));
CHECK(header.type == RGFX_CMD_OBJECT_DESTROY || header.type == RGFX_CMD_BUFFER_AT_OFFSET);
CHECK(header.size != 0 && header.size == rgfxSubmitBatchSize(header.type));
if (!kext->direct.tryPost(header.type, m + at, header.size, nullptr))
break;
at += header.size;
@@ -1604,17 +1605,20 @@ HeldRun heldDestroysRun(bool batches)
heapAnswers();
run.answers.push_back(b.gpuAddress);
run.answers.push_back(u.gpuResourceID._impl);
// What is still held goes, as a commit posts it (the buffer and the texture are held
// too).
CHECK(fx.ser.postHeldCreates());
const auto made = wire(fx.ring);
run.sent.insert(run.sent.end(), made.begin(), made.end());
}
return run;
}
// Destroys held to go together (RgfxRingWriter::postLater) change nothing the guest reads or the
// host is sent: a heap's usedSize, currentAllocatedSize and maxAvailableSize drop at the release,
// and a buffer and a texture made after it take the same bytes and resource id, created after the
// destroys on the ring, as where each destroy is posted at its release. A residency set keeps its
// allocations, so no destroy is held while it counts them.
// Destroys held to go together (RgfxRingWriter::postLater), with the buffers and textures held
// too, change nothing the guest reads or the host is sent: a heap's usedSize, currentAllocatedSize
// and maxAvailableSize drop at the release, and a buffer and a texture made after it take the
// same bytes and resource id, created after the destroys on the ring, as where each is posted at
// once. A residency set keeps its allocations, so no destroy is held while it counts them.
void test_held_destroys_change_nothing_seen()
{
const HeldRun posted = heldDestroysRun(false);
+117 -3
View File
@@ -26,6 +26,7 @@
#include "RgfxBinaryArchiveFile.hpp"
#include "RgfxCaps.hpp"
#include "../../kext/src/RgfxUserClientABI.hpp"
#include "../../kext/src/RgfxSubmitGate.hpp"
#include <utility>
#include "RgfxEncoder.hpp"
#include "RgfxFeatureProfile.hpp"
@@ -2458,9 +2459,8 @@ uint32_t kextSubmitBatch(void *context, const void *messages, uint32_t bytes)
RgfxMsgHeader header;
std::memcpy(&header, m + at, sizeof(header));
CHECK(header.seqno == 0);
CHECK(header.type == RGFX_CMD_OBJECT_DESTROY ? header.size == sizeof(RgfxObjectDestroy)
: header.type == RGFX_CMD_BUFFER_AT_OFFSET &&
header.size == sizeof(RgfxBufferAtOffset));
// Each of a type and size the kext's SubmitBatch takes.
CHECK(header.size != 0 && header.size == rgfxSubmitBatchSize(header.type));
call.objs.push_back(KextLog::objOf(m + at));
call.types.push_back(header.type);
at += header.size;
@@ -2655,6 +2655,119 @@ void test_held_buffers()
CHECK(pser.postHeldCreates());
}
// The other creates no one waits for that name no block, and a Managed buffer's modified range,
// held as a heap-placed buffer is (RgfxSerializer::postUnwaited): each answered as made and held,
// in their order with the destroys, before anything posted after them; a commit's
// postHeldCreates() answers false while any of them stays held, each on its own; a texture over
// an IOSurface, which a present waits for, goes at once, behind the held; a writer that does not
// batch posts each at once, as before.
void test_held_creates()
{
constexpr uint64_t kNever = 600ull * 1000000000;
KextLog log;
RgfxRingWriter writer(&kextSubmit, &log, 4096);
writer.setBatch(&kextSubmitBatch, 4096, kNever);
RgfxIdSpace ids;
RgfxSerializer ser(writer, ids);
RgfxTextureDescriptor desc = {};
desc.texture_type = 2;
desc.pixel_format = 70;
desc.width = 4;
desc.height = 4;
desc.depth = 1;
desc.mipmap_level_count = 1;
desc.sample_count = 1;
desc.array_length = 1;
RgfxTextureView view = {};
view.parent_obj_id = 0x77;
view.pixel_format = 70;
// Each kind, made one at a time with the kext taking none: answered as made, held, and the
// commit's answer false until the kext takes it, which posts it alone.
auto heldAlone = [&](const char *what, uint32_t type, const std::function<RgfxObjId()> &make) {
log.calls.clear();
log.batchTakes = 0;
const RgfxObjId obj = make();
CHECK(log.calls.empty());
CHECK(!ser.postHeldCreates());
log.batchTakes = UINT32_MAX;
CHECK(ser.postHeldCreates());
const bool alone = log.calls.size() == 1 && log.calls[0].batch &&
log.calls[0].objs == std::vector<RgfxObjId>({obj}) &&
log.calls[0].types == std::vector<uint32_t>({type});
if (!alone)
std::fprintf(stderr, "held alone: %s\n", what);
CHECK(alone);
};
heldAlone("texture", RGFX_CMD_TEXTURE_CREATE, [&] {
RgfxCreated c = ser.createTexture(desc, RGFX_OBJ_NONE, 0, 256, 1024);
CHECK(c.posted && c.obj_id != 0 && c.resource_id != 0 && c.gpu_address != 0 && c.seqno == 0);
return c.obj_id;
});
heldAlone("view", RGFX_CMD_TEXTURE_VIEW, [&] {
RgfxCreated c = ser.createTextureView(view);
CHECK(c.posted && c.obj_id != 0 && c.resource_id != 0 && c.seqno == 0);
return c.obj_id;
});
heldAlone("managed texture", RGFX_CMD_MANAGED_TEXTURE_CREATE, [&] {
RgfxCreated c = ser.createManagedTexture(desc, 0x78, 4, 1, 1, 0, 256, 1024);
CHECK(c.posted && c.obj_id != 0 && c.resource_id != 0 && c.gpu_address != 0 && c.seqno == 0);
return c.obj_id;
});
heldAlone("managed buffer", RGFX_CMD_MANAGED_BUFFER_CREATE, [&] {
RgfxCreated c = ser.createManagedBuffer(0x79, 256, 0x10);
CHECK(c.posted && c.obj_id != 0 && c.gpu_address != 0 && c.seqno == 0);
return c.obj_id;
});
heldAlone("modified range", RGFX_CMD_BUFFER_DID_MODIFY_RANGE, [&] {
CHECK(ser.bufferDidModifyRange(0x7a, 16, 32));
return RgfxObjId{0x7a};
});
// Together with destroys and heap-placed buffers, in the order made, in one call.
log.calls.clear();
CHECK(ser.destroy(0x101));
RgfxCreated t = ser.createTexture(desc, 0x10, 4096);
RgfxCreated a = ser.createBufferAtOffset(0x10, 0, 256, 0);
RgfxCreated v = ser.createTextureView(view);
CHECK(ser.bufferDidModifyRange(0x7a, 0, 16));
RgfxCreated m = ser.createManagedBuffer(a.obj_id, 256, 0x10);
CHECK(t.posted && t.gpu_address == 0 && a.posted && v.posted && m.posted);
CHECK(log.calls.empty());
CHECK(ser.postHeldCreates());
CHECK(log.calls.size() == 1 && log.calls[0].batch);
CHECK(log.calls[0].objs ==
std::vector<RgfxObjId>({0x101, t.obj_id, a.obj_id, v.obj_id, 0x7a, m.obj_id}));
CHECK(log.calls[0].types == std::vector<uint32_t>({RGFX_CMD_OBJECT_DESTROY,
RGFX_CMD_TEXTURE_CREATE,
RGFX_CMD_BUFFER_AT_OFFSET,
RGFX_CMD_TEXTURE_VIEW,
RGFX_CMD_BUFFER_DID_MODIFY_RANGE,
RGFX_CMD_MANAGED_BUFFER_CREATE}));
// A texture over an IOSurface goes at once, behind what is held.
log.calls.clear();
RgfxCreated before = ser.createTexture(desc);
RgfxCreated surface = ser.createTextureFromIOSurface(0x7b, 0, 16, 0x55, 0, desc, 0,
RgfxSurfaceFacts{});
CHECK(before.posted && surface.posted && surface.seqno != 0);
CHECK(log.calls.size() == 2 && log.calls[0].batch && !log.calls[1].batch);
CHECK(log.ring() == std::vector<RgfxObjId>({before.obj_id, surface.obj_id}));
CHECK(log.calls[1].types == std::vector<uint32_t>({RGFX_CMD_TEXTURE_FROM_IOSURFACE}));
// A writer that does not batch posts each at once.
KextLog plain;
RgfxRingWriter direct(&kextSubmit, &plain, 4096);
RgfxSerializer pser(direct, ids);
RgfxCreated pt = pser.createTexture(desc);
RgfxCreated pv = pser.createTextureView(view);
CHECK(pt.posted && pt.seqno != 0 && pv.posted && pv.seqno != 0);
CHECK(pser.bufferDidModifyRange(0x7a, 0, 16));
CHECK(plain.calls.size() == 3 && !plain.calls[0].batch && !plain.calls[1].batch &&
!plain.calls[2].batch);
CHECK(pser.postHeldCreates());
}
// A synthetic .metallib: its header (the bitcode section at 0x60, 16 bytes), a stand-in for the
// function list, the bitcode, and a tail.
std::vector<uint8_t> syntheticMetallib()
@@ -3999,6 +4112,7 @@ int main()
test_forwarded_lifecycle();
test_held_destroys();
test_held_buffers();
test_held_creates();
test_library_key();
test_library_key_pieces();
test_library_key_of_file();
@@ -636,12 +636,13 @@ IOReturn RgfxAcceleratorUserClient::submitMethod(IOExternalMethodArguments *a)
return kIOReturnSuccess;
}
// kRgfxAccelMethodSubmitBatch (RgfxUserClientABI.hpp): the client's destroys and heap-placed
// buffers of its own objects onto the control ring in one call, each checked as submitMethod
// checks one, all before any is posted, then posted in their order: the runs between its queues'
// destroys under one hold of the ring each (RgfxAccelerator::postRun), and each queue's destroy
// routed as submitMethod routes it (destroyQueueIfTracked) after the run before it. A buffer
// made for a context that closed since the check is destroyed behind it, as submitMethod does
// kRgfxAccelMethodSubmitBatch (RgfxUserClientABI.hpp): the client's messages no one waits for
// that name no block (rgfxSubmitBatchSize), of its own objects, onto the control ring in one
// call, each checked as submitMethod checks one, all before any is posted, then posted in their
// order: the runs between its queues' destroys under one hold of the ring each
// (RgfxAccelerator::postRun), and each queue's destroy routed as submitMethod routes it
// (destroyQueueIfTracked) after the run before it. An object made for a context that closed
// since the check is destroyed behind it, as submitMethod does
// (rgfxSubmitDestroysBehind). The count out says how many went: all of them, but where a run met
// a ring that stayed full or a device that stopped.
IOReturn RgfxAcceleratorUserClient::submitBatchMethod(IOExternalMethodArguments *a)
+19 -5
View File
@@ -57,11 +57,15 @@ inline bool rgfxSubmitRoutesQueueDestroy(uint32_t type)
}
// The size of a message of `type` kRgfxAccelMethodSubmitBatch takes, 0 for a type it does not
// take: an OBJECT_DESTROY, and a BUFFER_AT_OFFSET, the buffer a heap places at an offset. Neither
// is waited for nor names a block (rgfxRegionSpans), and each is of one size, which its header
// must name. The caller also checks each obj_id lies in the sender's context, routes a queue's
// destroy as rgfxSubmitRoutesQueueDestroy says, and follows a create with its destroy as
// rgfxSubmitDestroysBehind says.
// take: an OBJECT_DESTROY; the creates no one waits for that name no block, a BUFFER_AT_OFFSET
// (the buffer a heap places at an offset), a TEXTURE_CREATE, a TEXTURE_VIEW, a
// MANAGED_TEXTURE_CREATE and a MANAGED_BUFFER_CREATE; and a BUFFER_DID_MODIFY_RANGE, a write into
// a Managed buffer the host carries out before any command buffer after it. None is waited for
// nor names a block (rgfxRegionSpans), and each is of one size, which its header must name. A
// TEXTURE_FROM_IOSURFACE is not taken: a present of the surface by any process waits for it on
// the host, so it goes on the ring as it is made. The caller also checks each obj_id lies in the
// sender's context, routes a queue's destroy as rgfxSubmitRoutesQueueDestroy says, and follows a
// create with its destroy as rgfxSubmitDestroysBehind says.
inline uint32_t rgfxSubmitBatchSize(uint32_t type)
{
switch (type) {
@@ -69,6 +73,16 @@ inline uint32_t rgfxSubmitBatchSize(uint32_t type)
return sizeof(RgfxObjectDestroy);
case RGFX_CMD_BUFFER_AT_OFFSET:
return sizeof(RgfxBufferAtOffset);
case RGFX_CMD_TEXTURE_CREATE:
return sizeof(RgfxTextureCreate);
case RGFX_CMD_TEXTURE_VIEW:
return sizeof(RgfxTextureView);
case RGFX_CMD_MANAGED_TEXTURE_CREATE:
return sizeof(RgfxManagedTextureCreate);
case RGFX_CMD_MANAGED_BUFFER_CREATE:
return sizeof(RgfxManagedBufferCreate);
case RGFX_CMD_BUFFER_DID_MODIFY_RANGE:
return sizeof(RgfxBufferDidModifyRange);
default:
return 0;
}
+11 -9
View File
@@ -71,14 +71,16 @@ enum {
// kIOReturnNoSpace or kIOReturnNoResources where the region or the kext's table has no room
// for the block.
kRgfxAccelMethodPagesBlock = 4,
// Posts the client's destroys and heap-placed buffers of its own objects on the control ring
// in one call (kRgfxKextFeatureSubmitBatch): struct in, inline, OBJECT_DESTROY and
// BUFFER_AT_OFFSET messages back to back, each whole (its header's type and size set, the
// size its type's; the kext stamps its seqno) and of an object in the client's context, at
// most kRgfxSubmitBatchBytes in all; out: how many were posted, in their order, each as
// kRgfxAccelMethodSubmit posts it (a destroy of one of the client's command queues ends the
// queue as Submit's does, after the messages before it; a buffer of a context closed since is
// destroyed behind it). None is posted where any is not such a message
// Posts the client's messages no one waits for that name no block, of its own objects, on
// the control ring in one call (kRgfxKextFeatureSubmitBatch): struct in, inline, messages
// back to back of the types RgfxSubmitGate's rgfxSubmitBatchSize names (OBJECT_DESTROY,
// BUFFER_AT_OFFSET, TEXTURE_CREATE, TEXTURE_VIEW, MANAGED_TEXTURE_CREATE,
// MANAGED_BUFFER_CREATE and BUFFER_DID_MODIFY_RANGE), each whole (its header's type and size
// set, the size its type's; the kext stamps its seqno) and of an object in the client's
// context, at most kRgfxSubmitBatchBytes in all; out: how many were posted, in their order,
// each as kRgfxAccelMethodSubmit posts it (a destroy of one of the client's command queues
// ends the queue as Submit's does, after the messages before it; an object made for a context
// closed since is destroyed behind it). None is posted where any is not such a message
// (kIOReturnBadArgument). Succeeds with fewer than all only where the control ring stayed full
// or the device stopped: the rest were not posted, and go in a later call, before anything
// else of the client's.
@@ -290,7 +292,7 @@ enum {
};
// The most bytes of messages one kRgfxAccelMethodSubmitBatch takes: an inline struct in, 170
// destroys or 73 heap-placed buffers.
// destroys, 73 heap-placed buffers or 39 textures.
enum {
kRgfxSubmitBatchBytes = 4096,
};
+31 -15
View File
@@ -60,22 +60,38 @@ int main()
check(!rgfxSubmitRoutesQueueDestroy(RGFX_CMD_QUEUE_CREATE), "QUEUE_CREATE does not route");
check(!rgfxSubmitRoutesQueueDestroy(RGFX_CMD_BLOCK_RELEASE), "BLOCK_RELEASE does not route");
// SubmitBatch takes destroys and heap-placed buffers, each of its one size: messages no one
// waits for, which name no block (spans_test), so the batch needs neither answers nor pins;
// the buffer is a create, which a close since the check follows with its destroy. Every
// other type, accepted by Submit or not, goes one call at a time.
check(rgfxSubmitBatchSize(RGFX_CMD_OBJECT_DESTROY) == sizeof(RgfxObjectDestroy),
"SubmitBatch takes OBJECT_DESTROY, of its size");
check(rgfxSubmitBatchSize(RGFX_CMD_BUFFER_AT_OFFSET) == sizeof(RgfxBufferAtOffset),
"SubmitBatch takes BUFFER_AT_OFFSET, of its size");
check(rgfxSubmitAdmitted(RGFX_CMD_OBJECT_DESTROY) && !rgfxSubmitMakes(RGFX_CMD_OBJECT_DESTROY),
"a batched destroy is one Submit takes, and makes nothing");
check(rgfxSubmitAdmitted(RGFX_CMD_BUFFER_AT_OFFSET) && rgfxSubmitMakes(RGFX_CMD_BUFFER_AT_OFFSET),
"a batched heap-placed buffer is one Submit takes, and makes one");
// SubmitBatch takes destroys, the creates no one waits for that name no block, and a Managed
// buffer's modified range, each of its one size: messages no one waits for, which name no
// block (spans_test), so the batch needs neither answers nor pins; a create is followed by
// its destroy where a close came since the check. A texture over an IOSurface, which a
// present waits for, and every other type, accepted by Submit or not, go one call at a time.
struct Taken {
uint32_t type;
uint32_t size;
bool makes;
};
const Taken taken[] = {
{RGFX_CMD_OBJECT_DESTROY, sizeof(RgfxObjectDestroy), false},
{RGFX_CMD_BUFFER_AT_OFFSET, sizeof(RgfxBufferAtOffset), true},
{RGFX_CMD_TEXTURE_CREATE, sizeof(RgfxTextureCreate), true},
{RGFX_CMD_TEXTURE_VIEW, sizeof(RgfxTextureView), true},
{RGFX_CMD_MANAGED_TEXTURE_CREATE, sizeof(RgfxManagedTextureCreate), true},
{RGFX_CMD_MANAGED_BUFFER_CREATE, sizeof(RgfxManagedBufferCreate), true},
{RGFX_CMD_BUFFER_DID_MODIFY_RANGE, sizeof(RgfxBufferDidModifyRange), false},
};
for (const Taken &t : taken) {
check(rgfxSubmitBatchSize(t.type) == t.size, "SubmitBatch takes the type, of its size");
check(rgfxSubmitAdmitted(t.type) && rgfxSubmitMakes(t.type) == t.makes,
"a batched message is one Submit takes, making an object where a create");
}
check(rgfxSubmitBatchSize(RGFX_CMD_TEXTURE_FROM_IOSURFACE) == 0,
"SubmitBatch does not take a texture over an IOSurface");
for (uint32_t type = 0; type <= RGFX_CMD_CONTEXT_CLOSE + 64; type++) {
if (type == RGFX_CMD_OBJECT_DESTROY || type == RGFX_CMD_BUFFER_AT_OFFSET)
continue;
check(rgfxSubmitBatchSize(type) == 0, "SubmitBatch takes no other type");
bool listed = false;
for (const Taken &t : taken)
listed = listed || t.type == type;
if (!listed)
check(rgfxSubmitBatchSize(type) == 0, "SubmitBatch takes no other type");
}
// Which accepted types make an object a destroy then drops: every type of the accepted