mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-20 16:31:57 +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:
@@ -1140,10 +1140,16 @@ namespace MobileGL::MG_Pipe {
|
||||
MGP_ASSERT_POD(MGPProgramBindings, 32);
|
||||
|
||||
// Covers the DEFAULT UNIFORM BLOCK only (D6).
|
||||
//
|
||||
// Range (P14, was Pad0 and the size did not move): 0 means the bytes are the whole block.
|
||||
// Otherwise it is (offset << 16) | length, and the bytes are only that span of the block,
|
||||
// written over the image the program's record already holds - which the client sends only
|
||||
// while it knows the server holds its previous image for the same ShaderCso (the latch that
|
||||
// suppresses an unchanged block). A Minecraft chunk draw moves one vec3 of a ~230-byte block.
|
||||
struct MGPGlobalConstants {
|
||||
MGPipeHandle ShaderCso;
|
||||
Uint32 Version;
|
||||
Uint32 Pad0;
|
||||
Uint32 Range;
|
||||
MGPBlobRef Blob;
|
||||
};
|
||||
MGP_ASSERT_POD(MGPGlobalConstants, 40);
|
||||
|
||||
@@ -2951,6 +2951,10 @@ namespace MobileGL::MG_Pipe {
|
||||
record.AttributeCount = desc.AttributeCount;
|
||||
record.BindingPointCount = desc.BindingPointCount;
|
||||
record.Live = true;
|
||||
// A new configuration starts without kept bindings (see the record): the client drops
|
||||
// its mirror of them at the same create.
|
||||
record.StoredBuffersValid = false;
|
||||
record.StoredIndexValid = false;
|
||||
// Serial 0 means "never created", so the first create of an identity lands on 1 and a
|
||||
// backend twin that has synced nothing can never accidentally match a live record.
|
||||
++record.ContentSerial;
|
||||
@@ -2973,6 +2977,14 @@ namespace MobileGL::MG_Pipe {
|
||||
const MGPipeVertexElementsRecord* record = ResolveVertexElements("bind_vertex_elements", handle.Handle);
|
||||
if (record == nullptr) return;
|
||||
MGPipeApplier().BoundVertexElements = handle.Handle;
|
||||
// The array's kept bindings come back with it, through the same two applies their
|
||||
// records take, so every serial and field moves exactly as it would for the records.
|
||||
// (The apply writes the same entries back over themselves: harmless, and no copy.)
|
||||
if (record->StoredBuffersValid) {
|
||||
const MGPVertexBuffers header = record->StoredBuffersHeader;
|
||||
MGPipeApplySetVertexBuffers(header, record->StoredBuffers.data());
|
||||
}
|
||||
if (record->StoredIndexValid) MGPipeApplySetIndexBuffer(record->StoredIndex);
|
||||
}
|
||||
|
||||
void MGPipeApplyDeleteVertexElements(const MGPHandleOnly& handle) {
|
||||
@@ -3043,6 +3055,15 @@ namespace MobileGL::MG_Pipe {
|
||||
// would keep the previous shift.
|
||||
MGPipeApplier().VertexFetchBaseInstance = hdr.BaseInstance;
|
||||
++MGPipeApplier().VertexBuffersSerial;
|
||||
// Kept by the bound array (MGPipeVertexElementsRecord's P14 note). A re-apply from the
|
||||
// bind writes back what it read, which is harmless.
|
||||
if (MGPipeVertexElementsRecord* bound = FindVertexElements(MGPipeApplier().BoundVertexElements)) {
|
||||
bound->StoredBuffersValid = hdr.Start == 0 && hdr.Count <= kMGPipeVaoStoredVertexBuffers;
|
||||
if (bound->StoredBuffersValid) {
|
||||
bound->StoredBuffersHeader = hdr;
|
||||
for (Uint32 i = 0; i < hdr.Count; ++i) bound->StoredBuffers[i] = tail[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MGPipeApplySetIndexBuffer(const MGPIndexBuffer& record) {
|
||||
@@ -3058,6 +3079,11 @@ namespace MobileGL::MG_Pipe {
|
||||
// configuration's, which is exactly what the backend's two separate compares need.
|
||||
MGPipeApplier().IndexBuffer = record;
|
||||
++MGPipeApplier().IndexBufferSerial;
|
||||
// Kept by the bound array (MGPipeVertexElementsRecord's P14 note).
|
||||
if (MGPipeVertexElementsRecord* bound = FindVertexElements(MGPipeApplier().BoundVertexElements)) {
|
||||
bound->StoredIndex = record;
|
||||
bound->StoredIndexValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
void MGPipeDeriveRenderStateFields(PipeInputs& inputs) {
|
||||
@@ -3949,10 +3975,21 @@ namespace MobileGL::MG_Pipe {
|
||||
// bounded there - so this call can only ever allocate what the create already declared,
|
||||
// and the blob rule has a real field to cross-check against for once.
|
||||
const Uint32 size = stored->Desc.GlobalUboSize;
|
||||
// A span (MGPGlobalConstants::Range) lands on the block the record already holds.
|
||||
const Uint32 spanOffset = record.Range >> 16;
|
||||
const Uint32 spanLength = record.Range & 0xffffu;
|
||||
const char* fault = nullptr;
|
||||
if (record.Version == ~Uint32{0}) {
|
||||
fault = "the version is the backends' never-uploaded sentinel, which no record may carry";
|
||||
} else if (record.Blob.Size != 0 && record.Blob.Size != size) {
|
||||
} else if (record.Range != 0 && (spanLength == 0 || spanOffset + spanLength > size)) {
|
||||
fault = "the span runs outside the program's default uniform block";
|
||||
} else if (record.Range != 0 && stored->GlobalConstants.size() != size) {
|
||||
fault = "a span arrived for a block the record does not hold";
|
||||
} else if (record.Range != 0 && record.Blob.Size != 0 && record.Blob.Size != spanLength) {
|
||||
fault = "the declared blob length is not the span's length";
|
||||
} else if (record.Range != 0 && bytes == nullptr) {
|
||||
fault = "a span carries no bytes";
|
||||
} else if (record.Range == 0 && record.Blob.Size != 0 && record.Blob.Size != size) {
|
||||
fault = "the declared blob length is not the program's own default uniform block size";
|
||||
} else if (size > kMGPipeMaxGlobalConstantsBytes) {
|
||||
fault = "the program's default uniform block is larger than any program may declare";
|
||||
@@ -3968,7 +4005,9 @@ namespace MobileGL::MG_Pipe {
|
||||
return;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
if (record.Range != 0) {
|
||||
std::memcpy(stored->GlobalConstants.data() + spanOffset, bytes, spanLength);
|
||||
} else if (size == 0) {
|
||||
stored->GlobalConstants.clear();
|
||||
} else {
|
||||
const Uint8* image = static_cast<const Uint8*>(bytes);
|
||||
|
||||
@@ -500,6 +500,11 @@ namespace MobileGL::MG_Pipe {
|
||||
// The 32 is GL's MAX_VERTEX_ATTRIBS as MobileGL advertises it (kMGPipeMaxVertexAttribs,
|
||||
// MGPipeTypes.h), which is also the bound the record's two declared counts are checked
|
||||
// against before the blob is unpacked.
|
||||
// The widest vertex-buffer set a vertex-elements record keeps as its own (see below). A
|
||||
// wider set is not kept, and the client, which mirrors this rule, then re-sends it after
|
||||
// every bind of that array.
|
||||
inline constexpr Uint32 kMGPipeVaoStoredVertexBuffers = 16;
|
||||
|
||||
struct MGPipeVertexElementsRecord {
|
||||
Uint32 Gen = 0;
|
||||
Bool Live = false;
|
||||
@@ -511,6 +516,25 @@ namespace MobileGL::MG_Pipe {
|
||||
// including a RE-create on the same handle, which is how a configuration change
|
||||
// travels (the handle is minted per frontend VAO and Gen moves only on slot reuse).
|
||||
Uint64 ContentSerial = 0;
|
||||
// P14: THE ARRAY'S OWN BUFFER AND ELEMENT BINDINGS, as GL keeps them on the vertex array
|
||||
// object. The last set_vertex_buffers (window starting at 0, at most
|
||||
// kMGPipeVaoStoredVertexBuffers entries) and the last set_index_buffer applied while this
|
||||
// record was bound are kept here, and bind_vertex_elements re-applies them, exactly as if
|
||||
// the two records had arrived again - so a client switching between arrays whose
|
||||
// bindings did not move sends the bind alone. create_vertex_elements on the handle drops
|
||||
// both (the client drops its mirror at the same create), so a kept set never outlives the
|
||||
// configuration it was sent for. The client's mirror (VertexInputEmit.h) only ever
|
||||
// believes a kept set the server also keeps; where it is unsure it re-sends.
|
||||
Bool StoredBuffersValid = false;
|
||||
Bool StoredIndexValid = false;
|
||||
MGPVertexBuffers StoredBuffersHeader{};
|
||||
Array<MGPVertexBuffer, kMGPipeVaoStoredVertexBuffers> StoredBuffers{};
|
||||
MGPIndexBuffer StoredIndex{};
|
||||
// P14: a backend's own derivation from this record (Magma's resolved vertex input
|
||||
// layout), opaque here. It lives and dies with the record - a re-created or recycled
|
||||
// record starts without it - and the backend keys it on ContentSerial plus the inputs it
|
||||
// read, so it is never believed for a configuration it was not built from.
|
||||
mutable SharedPtr<void> BackendMemo;
|
||||
};
|
||||
|
||||
// set_framebuffer_state's record, HELD PER FRAMEBUFFER OBJECT and indexed by the handle's
|
||||
|
||||
@@ -159,7 +159,7 @@
|
||||
F(Name) F(Binding)
|
||||
|
||||
#define MGP_FIELDS_MGPGlobalConstants(F) \
|
||||
F(ShaderCso) F(Version) F(Blob)
|
||||
F(ShaderCso) F(Version) F(Range) F(Blob)
|
||||
|
||||
#define MGP_FIELDS_MGPAttribValue(F) \
|
||||
F(Location) F(ValueClass) F(FloatView) F(IntView) F(UintView)
|
||||
|
||||
@@ -35,7 +35,9 @@ namespace MobileGL::MG_Pipe {
|
||||
kMGPipeWireLayoutMembers, sizeof(kMGPipeWireLayoutMembers) / sizeof(WireLayoutMember));
|
||||
// Bump when a fixed-layout pipe carrier keeps its bytes but changes their meaning. The
|
||||
// mutable-level extent carrier reuses BufOffset/BufSize only on named image respecifies.
|
||||
inline constexpr Uint32 kMGPipeResourceRespecifyExtentCarrierRevision = 1;
|
||||
// 2 (P14): bind_vertex_elements re-applies the array's kept vertex-buffer and index
|
||||
// bindings (PipeApply.h, MGPipeVertexElementsRecord), which a revision-1 peer would not.
|
||||
inline constexpr Uint32 kMGPipeResourceRespecifyExtentCarrierRevision = 2;
|
||||
|
||||
constexpr Uint64 WireCatalogueDigest() {
|
||||
Uint64 hash = 1469598103934665603ull;
|
||||
|
||||
@@ -221,6 +221,7 @@ inline constexpr WireLayoutMember kMGPipeWireLayoutMembers[] = {
|
||||
{"MGPGlobalConstants", 0, sizeof(MGPGlobalConstants)},
|
||||
{"MGPGlobalConstants.ShaderCso", offsetof(MGPGlobalConstants, ShaderCso), sizeof(((MGPGlobalConstants*)nullptr)->ShaderCso)},
|
||||
{"MGPGlobalConstants.Version", offsetof(MGPGlobalConstants, Version), sizeof(((MGPGlobalConstants*)nullptr)->Version)},
|
||||
{"MGPGlobalConstants.Range", offsetof(MGPGlobalConstants, Range), sizeof(((MGPGlobalConstants*)nullptr)->Range)},
|
||||
{"MGPGlobalConstants.Blob", offsetof(MGPGlobalConstants, Blob), sizeof(((MGPGlobalConstants*)nullptr)->Blob)},
|
||||
{"MGPAttribValue", 0, sizeof(MGPAttribValue)},
|
||||
{"MGPAttribValue.Location", offsetof(MGPAttribValue, Location), sizeof(((MGPAttribValue*)nullptr)->Location)},
|
||||
|
||||
Reference in New Issue
Block a user