mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-20 00:11:56 +09:00
[Perf] (MG_Pipe): a vertex array keeps its buffer and index bindings on the server, a small uniform change crosses as a span, and unchanged context values skip their record (rd12 split arms +5-10%).
This commit is contained in:
@@ -852,6 +852,59 @@ namespace {
|
||||
EXPECT_TRUE(MGPipeHandleIsNull(MGPipeApplier().BoundVertexElements));
|
||||
}
|
||||
|
||||
// P14: a vertex-elements record keeps the last vertex-buffer set and index binding applied
|
||||
// while it was bound, and bind_vertex_elements re-applies them through the same two applies
|
||||
// - every field and both serials move as if the records had arrived again. A re-create of
|
||||
// the handle drops what it kept (the client drops its mirror at the same create).
|
||||
TEST(ResourceEmit, AVertexElementsRecordKeepsItsBindingsAndABindReappliesThem) {
|
||||
ApplierGuard guard;
|
||||
const MGPipeHandle resA{7, 3};
|
||||
const MGPipeHandle resB{8, 1};
|
||||
const MGPipeHandle csoA{2, 1};
|
||||
const MGPipeHandle csoB{3, 1};
|
||||
const ElementsBlob elementsA = MakeElements(csoA, 2, 1, true);
|
||||
const ElementsBlob elementsB = MakeElements(csoB, 2, 1, true);
|
||||
MGPipeApplyCreateVertexElements(elementsA.Desc, elementsA.Data());
|
||||
MGPipeApplyCreateVertexElements(elementsB.Desc, elementsB.Data());
|
||||
|
||||
const auto setBuffers = [](MGPipeHandle res, Uint32 stride, Uint32 baseInstance) {
|
||||
MGPVertexBuffers hdr{};
|
||||
hdr.Count = 1;
|
||||
hdr.BaseInstance = baseInstance;
|
||||
MGPVertexBuffer entry{};
|
||||
entry.Res = res;
|
||||
entry.Stride = stride;
|
||||
MGPipeApplySetVertexBuffers(hdr, &entry);
|
||||
};
|
||||
MGPipeApplyBindVertexElements(ElementsHandle(csoA));
|
||||
setBuffers(resA, 12, 0);
|
||||
MGPipeApplySetIndexBuffer(MGPIndexBuffer{resA, 0, 0, 0});
|
||||
MGPipeApplyBindVertexElements(ElementsHandle(csoB));
|
||||
setBuffers(resB, 20, 0);
|
||||
MGPipeApplySetIndexBuffer(MGPIndexBuffer{resB, 0, 0, 0});
|
||||
|
||||
// Back to A with nothing sent but the bind: A's own bindings come back.
|
||||
const Uint64 vertexSerial = MGPipeApplier().VertexBuffersSerial;
|
||||
const Uint64 indexSerial = MGPipeApplier().IndexBufferSerial;
|
||||
MGPipeApplyBindVertexElements(ElementsHandle(csoA));
|
||||
EXPECT_EQ(MGPipeApplier().VertexBufferCount, 1u);
|
||||
EXPECT_EQ(MGPipeApplier().VertexBuffers[0].Res, resA);
|
||||
EXPECT_EQ(MGPipeApplier().VertexBuffers[0].Stride, 12u);
|
||||
EXPECT_EQ(MGPipeApplier().IndexBuffer.Res, resA);
|
||||
EXPECT_GT(MGPipeApplier().VertexBuffersSerial, vertexSerial) << "a re-applied set must move its serial";
|
||||
EXPECT_GT(MGPipeApplier().IndexBufferSerial, indexSerial);
|
||||
MGPipeApplyBindVertexElements(ElementsHandle(csoB));
|
||||
EXPECT_EQ(MGPipeApplier().VertexBuffers[0].Res, resB);
|
||||
EXPECT_EQ(MGPipeApplier().IndexBuffer.Res, resB);
|
||||
|
||||
// A re-create drops what A kept: binding it again leaves B's bindings in place.
|
||||
MGPipeApplyCreateVertexElements(elementsA.Desc, elementsA.Data());
|
||||
MGPipeApplyBindVertexElements(ElementsHandle(csoA));
|
||||
EXPECT_EQ(MGPipeApplier().VertexBuffers[0].Res, resB);
|
||||
EXPECT_EQ(MGPipeApplier().IndexBuffer.Res, resB);
|
||||
EXPECT_EQ(MGPipeApplier().RefusedVertexInputCalls, 0u);
|
||||
}
|
||||
|
||||
// C1's observable. A call that names a record this applier does not have is a DEFINED
|
||||
// no-op - nothing stored, nothing dispatched, no serial moved - because the teardown order
|
||||
// makes exactly one such sequence legal (release the records, then every ~BufferObject
|
||||
|
||||
@@ -557,6 +557,60 @@ namespace {
|
||||
EXPECT_EQ(Emitter().CreateCount(), 3u);
|
||||
}
|
||||
|
||||
// P14: GL keeps a vertex array's buffer and element bindings ON THE ARRAY, and so does the
|
||||
// applier's record (MGPipeVertexElementsRecord): a switch back to an array whose bindings did
|
||||
// not move sends the bind alone - no set_vertex_buffers, no set_index_buffer. A binding that
|
||||
// did move still goes out after the bind.
|
||||
TEST(VertexInputEmit, ASwitchBetweenArraysWithUnchangedBindingsSendsOnlyTheBind) {
|
||||
EmitterScope scope;
|
||||
const SharedPtr<BufferObject> vertices = Ctx().CreateBufferObject(1);
|
||||
vertices->Respecify(256, nullptr);
|
||||
const SharedPtr<BufferObject> elements = Ctx().CreateBufferObject(2);
|
||||
elements->Respecify(64, nullptr);
|
||||
const SharedPtr<BufferObject> other = Ctx().CreateBufferObject(3);
|
||||
other->Respecify(256, nullptr);
|
||||
const auto configure = [&](Uint name, const SharedPtr<BufferObject>& buffer) {
|
||||
const SharedPtr<VertexArrayObject> vao = MakeVao(name);
|
||||
vao->SetAttributeFormat(0, 4, DataType::Float32, false, 16, 0, false);
|
||||
vao->BindAttributeBuffer(0, buffer);
|
||||
vao->EnableAttribute(0);
|
||||
vao->GetIndexBufferBindingSlot().Bind(elements);
|
||||
return vao;
|
||||
};
|
||||
const auto validate = [&] {
|
||||
Uint64 bytes = Emitter().EmitVertexElements(Ctx());
|
||||
bytes += Emitter().EmitVertexBuffers(Ctx(), 0);
|
||||
bytes += Emitter().EmitIndexBuffer(Ctx());
|
||||
return bytes;
|
||||
};
|
||||
const SharedPtr<VertexArrayObject> a = configure(1, vertices);
|
||||
ASSERT_GT(validate(), 0u);
|
||||
const SharedPtr<VertexArrayObject> b = configure(2, other);
|
||||
ASSERT_GT(validate(), 0u);
|
||||
const Uint64 sets = Emitter().VertexBufferSetCount();
|
||||
const Uint64 indexSets = Emitter().IndexBufferSetCount();
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
Ctx().BindVertexArray(1);
|
||||
EXPECT_EQ(validate(), sizeof(MGPHandleOnly)) << "a switch to an unchanged array sent more than its bind";
|
||||
Ctx().BindVertexArray(2);
|
||||
EXPECT_EQ(validate(), sizeof(MGPHandleOnly));
|
||||
}
|
||||
EXPECT_EQ(Emitter().VertexBufferSetCount(), sets);
|
||||
EXPECT_EQ(Emitter().IndexBufferSetCount(), indexSets);
|
||||
|
||||
// A moved binding is sent after the bind, and kept from then on.
|
||||
Ctx().BindVertexArray(1);
|
||||
a->BindAttributeBuffer(0, other);
|
||||
EXPECT_GT(validate(), sizeof(MGPHandleOnly));
|
||||
EXPECT_EQ(Emitter().VertexBufferSetCount(), sets + 1);
|
||||
Ctx().BindVertexArray(2);
|
||||
EXPECT_EQ(validate(), sizeof(MGPHandleOnly));
|
||||
Ctx().BindVertexArray(1);
|
||||
EXPECT_EQ(validate(), sizeof(MGPHandleOnly));
|
||||
EXPECT_EQ(Emitter().VertexBufferSetCount(), sets + 1);
|
||||
}
|
||||
|
||||
// ============================ C-1: the death path ============================
|
||||
//
|
||||
// THE LEAK THIS RULES OUT, and why it is a client case rather than a backend one. Every
|
||||
|
||||
Reference in New Issue
Block a user