From e0a82d78d8b872e3eb3f474c611aea940d065f0e Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Wed, 31 Jul 2024 18:13:16 +0800 Subject: [PATCH] serialization simplified (#17463) --- cocos/rendering/custom/archive.ts | 12 +- cocos/rendering/custom/binary-archive.ts | 16 +- cocos/rendering/custom/layout-graph.ts | 460 +++++++++++------------ cocos/rendering/custom/serialization.ts | 68 ++-- cocos/rendering/custom/types.ts | 312 +++++++-------- 5 files changed, 434 insertions(+), 434 deletions(-) diff --git a/cocos/rendering/custom/archive.ts b/cocos/rendering/custom/archive.ts index 9ce7eeaf8d9..9f426e13d44 100644 --- a/cocos/rendering/custom/archive.ts +++ b/cocos/rendering/custom/archive.ts @@ -29,13 +29,13 @@ */ /* eslint-disable max-len */ export interface OutputArchive { - writeBool (value: boolean): void; - writeNumber (value: number): void; - writeString (value: string): void; + b (value: boolean): void; + n (value: number): void; + s (value: string): void; } export interface InputArchive { - readBool (): boolean; - readNumber (): number; - readString (): string; + b (): boolean; + n (): number; + s (): string; } diff --git a/cocos/rendering/custom/binary-archive.ts b/cocos/rendering/custom/binary-archive.ts index 5d79dd1374c..254af10fb2f 100644 --- a/cocos/rendering/custom/binary-archive.ts +++ b/cocos/rendering/custom/binary-archive.ts @@ -30,7 +30,7 @@ export class BinaryOutputArchive implements OutputArchive { this.buffer = new Uint8Array(this.capacity); this.dataView = new DataView(this.buffer.buffer); } - writeBool (value: boolean): void { + b (value: boolean): void { const newSize = this.size + 1; if (newSize > this.capacity) { this.reserve(newSize); @@ -38,7 +38,7 @@ export class BinaryOutputArchive implements OutputArchive { this.dataView.setUint8(this.size, value ? 1 : 0); this.size = newSize; } - writeNumber (value: number): void { + n (value: number): void { const newSize = this.size + 8; if (newSize > this.capacity) { this.reserve(newSize); @@ -46,8 +46,8 @@ export class BinaryOutputArchive implements OutputArchive { this.dataView.setFloat64(this.size, value, true); this.size = newSize; } - writeString (value: string): void { - this.writeNumber(value.length); + s (value: string): void { + this.n(value.length); const newSize = this.size + value.length; if (newSize > this.capacity) { this.reserve(newSize); @@ -78,16 +78,16 @@ export class BinaryInputArchive implements InputArchive { constructor (data: ArrayBuffer) { this.dataView = new DataView(data); } - readBool (): boolean { + b (): boolean { return this.dataView.getUint8(this.offset++) !== 0; } - readNumber (): number { + n (): number { const value = this.dataView.getFloat64(this.offset, true); this.offset += 8; return value; } - readString (): string { - const length = this.readNumber(); + s (): string { + const length = this.n(); // we only support ascii string now, so we can use String.fromCharCode // see https://stackoverflow.com/questions/67057689/typscript-type-uint8array-is-missing-the-following-properties-from-type-numb // answer on stackoverflow might be wrong. diff --git a/cocos/rendering/custom/layout-graph.ts b/cocos/rendering/custom/layout-graph.ts index 57c7780cd15..b9ea34b5494 100644 --- a/cocos/rendering/custom/layout-graph.ts +++ b/cocos/rendering/custom/layout-graph.ts @@ -1162,47 +1162,47 @@ export class LayoutGraphObjectPool { private readonly _layoutGraphData: RecyclePool; } -export function saveDescriptorDB (ar: OutputArchive, v: DescriptorDB): void { - ar.writeNumber(v.blocks.size); // Map +export function saveDescriptorDB (a: OutputArchive, v: DescriptorDB): void { + a.n(v.blocks.size); // Map for (const [k1, v1] of v.blocks) { - saveDescriptorBlockIndex(ar, JSON.parse(k1) as DescriptorBlockIndex); - saveDescriptorBlock(ar, v1); + saveDescriptorBlockIndex(a, JSON.parse(k1) as DescriptorBlockIndex); + saveDescriptorBlock(a, v1); } } -export function loadDescriptorDB (ar: InputArchive, v: DescriptorDB): void { +export function loadDescriptorDB (a: InputArchive, v: DescriptorDB): void { let sz = 0; - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { const k1 = new DescriptorBlockIndex(); - loadDescriptorBlockIndex(ar, k1); + loadDescriptorBlockIndex(a, k1); const v1 = new DescriptorBlock(); - loadDescriptorBlock(ar, v1); + loadDescriptorBlock(a, v1); v.blocks.set(JSON.stringify(k1), v1); } } -export function saveRenderPhase (ar: OutputArchive, v: RenderPhase): void { - ar.writeNumber(v.shaders.size); // Set +export function saveRenderPhase (a: OutputArchive, v: RenderPhase): void { + a.n(v.shaders.size); // Set for (const v1 of v.shaders) { - ar.writeString(v1); + a.s(v1); } } -export function loadRenderPhase (ar: InputArchive, v: RenderPhase): void { +export function loadRenderPhase (a: InputArchive, v: RenderPhase): void { let sz = 0; - sz = ar.readNumber(); // Set + sz = a.n(); // Set for (let i1 = 0; i1 !== sz; ++i1) { - const v1 = ar.readString(); + const v1 = a.s(); v.shaders.add(v1); } } -export function saveLayoutGraph (ar: OutputArchive, g: LayoutGraph): void { +export function saveLayoutGraph (a: OutputArchive, g: LayoutGraph): void { const numVertices = g.numVertices(); const numEdges = g.numEdges(); - ar.writeNumber(numVertices); - ar.writeNumber(numEdges); + a.n(numVertices); + a.n(numEdges); let numStages = 0; let numPhases = 0; for (const v of g.vertices()) { @@ -1217,19 +1217,19 @@ export function saveLayoutGraph (ar: OutputArchive, g: LayoutGraph): void { break; } } - ar.writeNumber(numStages); - ar.writeNumber(numPhases); + a.n(numStages); + a.n(numPhases); for (const v of g.vertices()) { - ar.writeNumber(g.id(v)); - ar.writeNumber(g.getParent(v)); - ar.writeString(g.getName(v)); - saveDescriptorDB(ar, g.getDescriptors(v)); + a.n(g.id(v)); + a.n(g.getParent(v)); + a.s(g.getName(v)); + saveDescriptorDB(a, g.getDescriptors(v)); switch (g.id(v)) { case LayoutGraphValue.RenderStage: - ar.writeNumber(g.getRenderStage(v)); + a.n(g.getRenderStage(v)); break; case LayoutGraphValue.RenderPhase: - saveRenderPhase(ar, g.getRenderPhase(v)); + saveRenderPhase(a, g.getRenderPhase(v)); break; default: break; @@ -1237,26 +1237,26 @@ export function saveLayoutGraph (ar: OutputArchive, g: LayoutGraph): void { } } -export function loadLayoutGraph (ar: InputArchive, g: LayoutGraph): void { - const numVertices = ar.readNumber(); - const numEdges = ar.readNumber(); - const numStages = ar.readNumber(); - const numPhases = ar.readNumber(); +export function loadLayoutGraph (a: InputArchive, g: LayoutGraph): void { + const numVertices = a.n(); + const numEdges = a.n(); + const numStages = a.n(); + const numPhases = a.n(); for (let v = 0; v !== numVertices; ++v) { - const id = ar.readNumber(); - const u = ar.readNumber(); - const name = ar.readString(); + const id = a.n(); + const u = a.n(); + const name = a.s(); const descriptors = new DescriptorDB(); - loadDescriptorDB(ar, descriptors); + loadDescriptorDB(a, descriptors); switch (id) { case LayoutGraphValue.RenderStage: { - const renderStage = ar.readNumber(); + const renderStage = a.n(); g.addVertex(LayoutGraphValue.RenderStage, renderStage, name, descriptors, u); break; } case LayoutGraphValue.RenderPhase: { const renderPhase = new RenderPhase(); - loadRenderPhase(ar, renderPhase); + loadRenderPhase(a, renderPhase); g.addVertex(LayoutGraphValue.RenderPhase, renderPhase, name, descriptors, u); break; } @@ -1266,312 +1266,312 @@ export function loadLayoutGraph (ar: InputArchive, g: LayoutGraph): void { } } -export function saveUniformData (ar: OutputArchive, v: UniformData): void { - ar.writeNumber(v.uniformID); - ar.writeNumber(v.uniformType); - ar.writeNumber(v.offset); - ar.writeNumber(v.size); +export function saveUniformData (a: OutputArchive, v: UniformData): void { + a.n(v.uniformID); + a.n(v.uniformType); + a.n(v.offset); + a.n(v.size); } -export function loadUniformData (ar: InputArchive, v: UniformData): void { - v.uniformID = ar.readNumber(); - v.uniformType = ar.readNumber(); - v.offset = ar.readNumber(); - v.size = ar.readNumber(); +export function loadUniformData (a: InputArchive, v: UniformData): void { + v.uniformID = a.n(); + v.uniformType = a.n(); + v.offset = a.n(); + v.size = a.n(); } -export function saveUniformBlockData (ar: OutputArchive, v: UniformBlockData): void { - ar.writeNumber(v.bufferSize); - ar.writeNumber(v.uniforms.length); // UniformData[] +export function saveUniformBlockData (a: OutputArchive, v: UniformBlockData): void { + a.n(v.bufferSize); + a.n(v.uniforms.length); // UniformData[] for (const v1 of v.uniforms) { - saveUniformData(ar, v1); + saveUniformData(a, v1); } } -export function loadUniformBlockData (ar: InputArchive, v: UniformBlockData): void { - v.bufferSize = ar.readNumber(); +export function loadUniformBlockData (a: InputArchive, v: UniformBlockData): void { + v.bufferSize = a.n(); let sz = 0; - sz = ar.readNumber(); // UniformData[] + sz = a.n(); // UniformData[] v.uniforms.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { const v1 = new UniformData(); - loadUniformData(ar, v1); + loadUniformData(a, v1); v.uniforms[i1] = v1; } } -export function saveDescriptorData (ar: OutputArchive, v: DescriptorData): void { - ar.writeNumber(v.descriptorID); - ar.writeNumber(v.type); - ar.writeNumber(v.count); +export function saveDescriptorData (a: OutputArchive, v: DescriptorData): void { + a.n(v.descriptorID); + a.n(v.type); + a.n(v.count); } -export function loadDescriptorData (ar: InputArchive, v: DescriptorData): void { - v.descriptorID = ar.readNumber(); - v.type = ar.readNumber(); - v.count = ar.readNumber(); +export function loadDescriptorData (a: InputArchive, v: DescriptorData): void { + v.descriptorID = a.n(); + v.type = a.n(); + v.count = a.n(); } -export function saveDescriptorBlockData (ar: OutputArchive, v: DescriptorBlockData): void { - ar.writeNumber(v.type); - ar.writeNumber(v.visibility); - ar.writeNumber(v.offset); - ar.writeNumber(v.capacity); - ar.writeNumber(v.descriptors.length); // DescriptorData[] +export function saveDescriptorBlockData (a: OutputArchive, v: DescriptorBlockData): void { + a.n(v.type); + a.n(v.visibility); + a.n(v.offset); + a.n(v.capacity); + a.n(v.descriptors.length); // DescriptorData[] for (const v1 of v.descriptors) { - saveDescriptorData(ar, v1); + saveDescriptorData(a, v1); } } -export function loadDescriptorBlockData (ar: InputArchive, v: DescriptorBlockData): void { - v.type = ar.readNumber(); - v.visibility = ar.readNumber(); - v.offset = ar.readNumber(); - v.capacity = ar.readNumber(); +export function loadDescriptorBlockData (a: InputArchive, v: DescriptorBlockData): void { + v.type = a.n(); + v.visibility = a.n(); + v.offset = a.n(); + v.capacity = a.n(); let sz = 0; - sz = ar.readNumber(); // DescriptorData[] + sz = a.n(); // DescriptorData[] v.descriptors.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { const v1 = new DescriptorData(); - loadDescriptorData(ar, v1); + loadDescriptorData(a, v1); v.descriptors[i1] = v1; } } -export function saveDescriptorSetLayoutData (ar: OutputArchive, v: DescriptorSetLayoutData): void { - ar.writeNumber(v.slot); - ar.writeNumber(v.capacity); - ar.writeNumber(v.uniformBlockCapacity); - ar.writeNumber(v.samplerTextureCapacity); - ar.writeNumber(v.descriptorBlocks.length); // DescriptorBlockData[] +export function saveDescriptorSetLayoutData (a: OutputArchive, v: DescriptorSetLayoutData): void { + a.n(v.slot); + a.n(v.capacity); + a.n(v.uniformBlockCapacity); + a.n(v.samplerTextureCapacity); + a.n(v.descriptorBlocks.length); // DescriptorBlockData[] for (const v1 of v.descriptorBlocks) { - saveDescriptorBlockData(ar, v1); + saveDescriptorBlockData(a, v1); } - ar.writeNumber(v.uniformBlocks.size); // Map + a.n(v.uniformBlocks.size); // Map for (const [k1, v1] of v.uniformBlocks) { - ar.writeNumber(k1); - saveUniformBlock(ar, v1); + a.n(k1); + saveUniformBlock(a, v1); } - ar.writeNumber(v.bindingMap.size); // Map + a.n(v.bindingMap.size); // Map for (const [k1, v1] of v.bindingMap) { - ar.writeNumber(k1); - ar.writeNumber(v1); + a.n(k1); + a.n(v1); } } -export function loadDescriptorSetLayoutData (ar: InputArchive, v: DescriptorSetLayoutData): void { - v.slot = ar.readNumber(); - v.capacity = ar.readNumber(); - v.uniformBlockCapacity = ar.readNumber(); - v.samplerTextureCapacity = ar.readNumber(); +export function loadDescriptorSetLayoutData (a: InputArchive, v: DescriptorSetLayoutData): void { + v.slot = a.n(); + v.capacity = a.n(); + v.uniformBlockCapacity = a.n(); + v.samplerTextureCapacity = a.n(); let sz = 0; - sz = ar.readNumber(); // DescriptorBlockData[] + sz = a.n(); // DescriptorBlockData[] v.descriptorBlocks.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { const v1 = new DescriptorBlockData(); - loadDescriptorBlockData(ar, v1); + loadDescriptorBlockData(a, v1); v.descriptorBlocks[i1] = v1; } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readNumber(); + const k1 = a.n(); const v1 = new UniformBlock(); - loadUniformBlock(ar, v1); + loadUniformBlock(a, v1); v.uniformBlocks.set(k1, v1); } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readNumber(); - const v1 = ar.readNumber(); + const k1 = a.n(); + const v1 = a.n(); v.bindingMap.set(k1, v1); } } -export function saveDescriptorSetData (ar: OutputArchive, v: DescriptorSetData): void { - saveDescriptorSetLayoutData(ar, v.descriptorSetLayoutData); - saveDescriptorSetLayoutInfo(ar, v.descriptorSetLayoutInfo); +export function saveDescriptorSetData (a: OutputArchive, v: DescriptorSetData): void { + saveDescriptorSetLayoutData(a, v.descriptorSetLayoutData); + saveDescriptorSetLayoutInfo(a, v.descriptorSetLayoutInfo); // skip, v.descriptorSetLayout: DescriptorSetLayout // skip, v.descriptorSet: DescriptorSet } -export function loadDescriptorSetData (ar: InputArchive, v: DescriptorSetData): void { - loadDescriptorSetLayoutData(ar, v.descriptorSetLayoutData); - loadDescriptorSetLayoutInfo(ar, v.descriptorSetLayoutInfo); +export function loadDescriptorSetData (a: InputArchive, v: DescriptorSetData): void { + loadDescriptorSetLayoutData(a, v.descriptorSetLayoutData); + loadDescriptorSetLayoutInfo(a, v.descriptorSetLayoutInfo); // skip, v.descriptorSetLayout: DescriptorSetLayout // skip, v.descriptorSet: DescriptorSet } -export function savePipelineLayoutData (ar: OutputArchive, v: PipelineLayoutData): void { - ar.writeNumber(v.descriptorSets.size); // Map +export function savePipelineLayoutData (a: OutputArchive, v: PipelineLayoutData): void { + a.n(v.descriptorSets.size); // Map for (const [k1, v1] of v.descriptorSets) { - ar.writeNumber(k1); - saveDescriptorSetData(ar, v1); + a.n(k1); + saveDescriptorSetData(a, v1); } } -export function loadPipelineLayoutData (ar: InputArchive, v: PipelineLayoutData): void { +export function loadPipelineLayoutData (a: InputArchive, v: PipelineLayoutData): void { let sz = 0; - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readNumber(); + const k1 = a.n(); const v1 = new DescriptorSetData(); - loadDescriptorSetData(ar, v1); + loadDescriptorSetData(a, v1); v.descriptorSets.set(k1, v1); } } -export function saveShaderBindingData (ar: OutputArchive, v: ShaderBindingData): void { - ar.writeNumber(v.descriptorBindings.size); // Map +export function saveShaderBindingData (a: OutputArchive, v: ShaderBindingData): void { + a.n(v.descriptorBindings.size); // Map for (const [k1, v1] of v.descriptorBindings) { - ar.writeNumber(k1); - ar.writeNumber(v1); + a.n(k1); + a.n(v1); } } -export function loadShaderBindingData (ar: InputArchive, v: ShaderBindingData): void { +export function loadShaderBindingData (a: InputArchive, v: ShaderBindingData): void { let sz = 0; - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readNumber(); - const v1 = ar.readNumber(); + const k1 = a.n(); + const v1 = a.n(); v.descriptorBindings.set(k1, v1); } } -export function saveShaderLayoutData (ar: OutputArchive, v: ShaderLayoutData): void { - ar.writeNumber(v.layoutData.size); // Map +export function saveShaderLayoutData (a: OutputArchive, v: ShaderLayoutData): void { + a.n(v.layoutData.size); // Map for (const [k1, v1] of v.layoutData) { - ar.writeNumber(k1); - saveDescriptorSetLayoutData(ar, v1); + a.n(k1); + saveDescriptorSetLayoutData(a, v1); } - ar.writeNumber(v.bindingData.size); // Map + a.n(v.bindingData.size); // Map for (const [k1, v1] of v.bindingData) { - ar.writeNumber(k1); - saveShaderBindingData(ar, v1); + a.n(k1); + saveShaderBindingData(a, v1); } } -export function loadShaderLayoutData (ar: InputArchive, v: ShaderLayoutData): void { +export function loadShaderLayoutData (a: InputArchive, v: ShaderLayoutData): void { let sz = 0; - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readNumber(); + const k1 = a.n(); const v1 = new DescriptorSetLayoutData(); - loadDescriptorSetLayoutData(ar, v1); + loadDescriptorSetLayoutData(a, v1); v.layoutData.set(k1, v1); } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readNumber(); + const k1 = a.n(); const v1 = new ShaderBindingData(); - loadShaderBindingData(ar, v1); + loadShaderBindingData(a, v1); v.bindingData.set(k1, v1); } } -export function saveTechniqueData (ar: OutputArchive, v: TechniqueData): void { - ar.writeNumber(v.passes.length); // ShaderLayoutData[] +export function saveTechniqueData (a: OutputArchive, v: TechniqueData): void { + a.n(v.passes.length); // ShaderLayoutData[] for (const v1 of v.passes) { - saveShaderLayoutData(ar, v1); + saveShaderLayoutData(a, v1); } } -export function loadTechniqueData (ar: InputArchive, v: TechniqueData): void { +export function loadTechniqueData (a: InputArchive, v: TechniqueData): void { let sz = 0; - sz = ar.readNumber(); // ShaderLayoutData[] + sz = a.n(); // ShaderLayoutData[] v.passes.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { const v1 = new ShaderLayoutData(); - loadShaderLayoutData(ar, v1); + loadShaderLayoutData(a, v1); v.passes[i1] = v1; } } -export function saveEffectData (ar: OutputArchive, v: EffectData): void { - ar.writeNumber(v.techniques.size); // Map +export function saveEffectData (a: OutputArchive, v: EffectData): void { + a.n(v.techniques.size); // Map for (const [k1, v1] of v.techniques) { - ar.writeString(k1); - saveTechniqueData(ar, v1); + a.s(k1); + saveTechniqueData(a, v1); } } -export function loadEffectData (ar: InputArchive, v: EffectData): void { +export function loadEffectData (a: InputArchive, v: EffectData): void { let sz = 0; - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readString(); + const k1 = a.s(); const v1 = new TechniqueData(); - loadTechniqueData(ar, v1); + loadTechniqueData(a, v1); v.techniques.set(k1, v1); } } -export function saveShaderProgramData (ar: OutputArchive, v: ShaderProgramData): void { - savePipelineLayoutData(ar, v.layout); +export function saveShaderProgramData (a: OutputArchive, v: ShaderProgramData): void { + savePipelineLayoutData(a, v.layout); // skip, v.pipelineLayout: PipelineLayout } -export function loadShaderProgramData (ar: InputArchive, v: ShaderProgramData): void { - loadPipelineLayoutData(ar, v.layout); +export function loadShaderProgramData (a: InputArchive, v: ShaderProgramData): void { + loadPipelineLayoutData(a, v.layout); // skip, v.pipelineLayout: PipelineLayout } -export function saveRenderStageData (ar: OutputArchive, v: RenderStageData): void { - ar.writeNumber(v.descriptorVisibility.size); // Map +export function saveRenderStageData (a: OutputArchive, v: RenderStageData): void { + a.n(v.descriptorVisibility.size); // Map for (const [k1, v1] of v.descriptorVisibility) { - ar.writeNumber(k1); - ar.writeNumber(v1); + a.n(k1); + a.n(v1); } } -export function loadRenderStageData (ar: InputArchive, v: RenderStageData): void { +export function loadRenderStageData (a: InputArchive, v: RenderStageData): void { let sz = 0; - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readNumber(); - const v1 = ar.readNumber(); + const k1 = a.n(); + const v1 = a.n(); v.descriptorVisibility.set(k1, v1); } } -export function saveRenderPhaseData (ar: OutputArchive, v: RenderPhaseData): void { - ar.writeString(v.rootSignature); - ar.writeNumber(v.shaderPrograms.length); // ShaderProgramData[] +export function saveRenderPhaseData (a: OutputArchive, v: RenderPhaseData): void { + a.s(v.rootSignature); + a.n(v.shaderPrograms.length); // ShaderProgramData[] for (const v1 of v.shaderPrograms) { - saveShaderProgramData(ar, v1); + saveShaderProgramData(a, v1); } - ar.writeNumber(v.shaderIndex.size); // Map + a.n(v.shaderIndex.size); // Map for (const [k1, v1] of v.shaderIndex) { - ar.writeString(k1); - ar.writeNumber(v1); + a.s(k1); + a.n(v1); } // skip, v.pipelineLayout: PipelineLayout } -export function loadRenderPhaseData (ar: InputArchive, v: RenderPhaseData): void { - v.rootSignature = ar.readString(); +export function loadRenderPhaseData (a: InputArchive, v: RenderPhaseData): void { + v.rootSignature = a.s(); let sz = 0; - sz = ar.readNumber(); // ShaderProgramData[] + sz = a.n(); // ShaderProgramData[] v.shaderPrograms.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { const v1 = new ShaderProgramData(); - loadShaderProgramData(ar, v1); + loadShaderProgramData(a, v1); v.shaderPrograms[i1] = v1; } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readString(); - const v1 = ar.readNumber(); + const k1 = a.s(); + const v1 = a.n(); v.shaderIndex.set(k1, v1); } // skip, v.pipelineLayout: PipelineLayout } -export function saveLayoutGraphData (ar: OutputArchive, g: LayoutGraphData): void { +export function saveLayoutGraphData (a: OutputArchive, g: LayoutGraphData): void { const numVertices = g.numVertices(); const numEdges = g.numEdges(); - ar.writeNumber(numVertices); - ar.writeNumber(numEdges); + a.n(numVertices); + a.n(numEdges); let numStages = 0; let numPhases = 0; for (const v of g.vertices()) { @@ -1586,73 +1586,73 @@ export function saveLayoutGraphData (ar: OutputArchive, g: LayoutGraphData): voi break; } } - ar.writeNumber(numStages); - ar.writeNumber(numPhases); + a.n(numStages); + a.n(numPhases); for (const v of g.vertices()) { - ar.writeNumber(g.id(v)); - ar.writeNumber(g.getParent(v)); - ar.writeString(g.getName(v)); - ar.writeNumber(g.getUpdate(v)); - savePipelineLayoutData(ar, g.getLayout(v)); + a.n(g.id(v)); + a.n(g.getParent(v)); + a.s(g.getName(v)); + a.n(g.getUpdate(v)); + savePipelineLayoutData(a, g.getLayout(v)); switch (g.id(v)) { case LayoutGraphDataValue.RenderStage: - saveRenderStageData(ar, g.getRenderStage(v)); + saveRenderStageData(a, g.getRenderStage(v)); break; case LayoutGraphDataValue.RenderPhase: - saveRenderPhaseData(ar, g.getRenderPhase(v)); + saveRenderPhaseData(a, g.getRenderPhase(v)); break; default: break; } } - ar.writeNumber(g.valueNames.length); // string[] + a.n(g.valueNames.length); // string[] for (const v1 of g.valueNames) { - ar.writeString(v1); + a.s(v1); } - ar.writeNumber(g.attributeIndex.size); // Map + a.n(g.attributeIndex.size); // Map for (const [k1, v1] of g.attributeIndex) { - ar.writeString(k1); - ar.writeNumber(v1); + a.s(k1); + a.n(v1); } - ar.writeNumber(g.constantIndex.size); // Map + a.n(g.constantIndex.size); // Map for (const [k1, v1] of g.constantIndex) { - ar.writeString(k1); - ar.writeNumber(v1); + a.s(k1); + a.n(v1); } - ar.writeNumber(g.shaderLayoutIndex.size); // Map + a.n(g.shaderLayoutIndex.size); // Map for (const [k1, v1] of g.shaderLayoutIndex) { - ar.writeString(k1); - ar.writeNumber(v1); + a.s(k1); + a.n(v1); } - ar.writeNumber(g.effects.size); // Map + a.n(g.effects.size); // Map for (const [k1, v1] of g.effects) { - ar.writeString(k1); - saveEffectData(ar, v1); + a.s(k1); + saveEffectData(a, v1); } } -export function loadLayoutGraphData (ar: InputArchive, g: LayoutGraphData): void { - const numVertices = ar.readNumber(); - const numEdges = ar.readNumber(); - const numStages = ar.readNumber(); - const numPhases = ar.readNumber(); +export function loadLayoutGraphData (a: InputArchive, g: LayoutGraphData): void { + const numVertices = a.n(); + const numEdges = a.n(); + const numStages = a.n(); + const numPhases = a.n(); for (let v = 0; v !== numVertices; ++v) { - const id = ar.readNumber(); - const u = ar.readNumber(); - const name = ar.readString(); - const update = ar.readNumber(); + const id = a.n(); + const u = a.n(); + const name = a.s(); + const update = a.n(); const layout = new PipelineLayoutData(); - loadPipelineLayoutData(ar, layout); + loadPipelineLayoutData(a, layout); switch (id) { case LayoutGraphDataValue.RenderStage: { const renderStage = new RenderStageData(); - loadRenderStageData(ar, renderStage); + loadRenderStageData(a, renderStage); g.addVertex(LayoutGraphDataValue.RenderStage, renderStage, name, update, layout, u); break; } case LayoutGraphDataValue.RenderPhase: { const renderPhase = new RenderPhaseData(); - loadRenderPhaseData(ar, renderPhase); + loadRenderPhaseData(a, renderPhase); g.addVertex(LayoutGraphDataValue.RenderPhase, renderPhase, name, update, layout, u); break; } @@ -1661,34 +1661,34 @@ export function loadLayoutGraphData (ar: InputArchive, g: LayoutGraphData): void } } let sz = 0; - sz = ar.readNumber(); // string[] + sz = a.n(); // string[] g.valueNames.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { - g.valueNames[i1] = ar.readString(); + g.valueNames[i1] = a.s(); } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readString(); - const v1 = ar.readNumber(); + const k1 = a.s(); + const v1 = a.n(); g.attributeIndex.set(k1, v1); } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readString(); - const v1 = ar.readNumber(); + const k1 = a.s(); + const v1 = a.n(); g.constantIndex.set(k1, v1); } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readString(); - const v1 = ar.readNumber(); + const k1 = a.s(); + const v1 = a.n(); g.shaderLayoutIndex.set(k1, v1); } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readString(); + const k1 = a.s(); const v1 = new EffectData(); - loadEffectData(ar, v1); + loadEffectData(a, v1); g.effects.set(k1, v1); } } diff --git a/cocos/rendering/custom/serialization.ts b/cocos/rendering/custom/serialization.ts index f9c61215bf6..8c9c8f22b01 100644 --- a/cocos/rendering/custom/serialization.ts +++ b/cocos/rendering/custom/serialization.ts @@ -26,82 +26,82 @@ import { OutputArchive, InputArchive } from './archive'; import { Color, DescriptorSetLayoutBinding, DescriptorSetLayoutInfo, Uniform, UniformBlock } from '../../gfx'; export function saveColor (ar: OutputArchive, v: Color): void { - ar.writeNumber(v.x); - ar.writeNumber(v.y); - ar.writeNumber(v.z); - ar.writeNumber(v.w); + ar.n(v.x); + ar.n(v.y); + ar.n(v.z); + ar.n(v.w); } export function loadColor (ar: InputArchive, v: Color): void { - v.x = ar.readNumber(); - v.y = ar.readNumber(); - v.z = ar.readNumber(); - v.w = ar.readNumber(); + v.x = ar.n(); + v.y = ar.n(); + v.z = ar.n(); + v.w = ar.n(); } export function saveUniform (ar: OutputArchive, v: Uniform): void { - ar.writeString(v.name); - ar.writeNumber(v.type); - ar.writeNumber(v.count); + ar.s(v.name); + ar.n(v.type); + ar.n(v.count); } export function loadUniform (ar: InputArchive, v: Uniform): void { - v.name = ar.readString(); - v.type = ar.readNumber(); - v.count = ar.readNumber(); + v.name = ar.s(); + v.type = ar.n(); + v.count = ar.n(); } export function saveUniformBlock (ar: OutputArchive, v: UniformBlock): void { - ar.writeNumber(v.set); - ar.writeNumber(v.binding); - ar.writeString(v.name); - ar.writeNumber(v.members.length); + ar.n(v.set); + ar.n(v.binding); + ar.s(v.name); + ar.n(v.members.length); for (const v1 of v.members) { saveUniform(ar, v1); } - ar.writeNumber(v.count); + ar.n(v.count); } export function loadUniformBlock (ar: InputArchive, v: UniformBlock): void { - v.set = ar.readNumber(); - v.binding = ar.readNumber(); - v.name = ar.readString(); + v.set = ar.n(); + v.binding = ar.n(); + v.name = ar.s(); let sz = 0; - sz = ar.readNumber(); + sz = ar.n(); v.members.length = sz; for (let i = 0; i !== sz; ++i) { const v1 = new Uniform(); loadUniform(ar, v1); v.members[i] = v1; } - v.count = ar.readNumber(); + v.count = ar.n(); } export function saveDescriptorSetLayoutBinding (ar: OutputArchive, v: DescriptorSetLayoutBinding): void { - ar.writeNumber(v.binding); - ar.writeNumber(v.descriptorType); - ar.writeNumber(v.count); - ar.writeNumber(v.stageFlags); + ar.n(v.binding); + ar.n(v.descriptorType); + ar.n(v.count); + ar.n(v.stageFlags); // skip immutableSamplers; } export function loadDescriptorSetLayoutBinding (ar: InputArchive, v: DescriptorSetLayoutBinding): void { - v.binding = ar.readNumber(); - v.descriptorType = ar.readNumber(); - v.count = ar.readNumber(); - v.stageFlags = ar.readNumber(); + v.binding = ar.n(); + v.descriptorType = ar.n(); + v.count = ar.n(); + v.stageFlags = ar.n(); // skip immutableSamplers; } export function saveDescriptorSetLayoutInfo (ar: OutputArchive, v: DescriptorSetLayoutInfo): void { - ar.writeNumber(v.bindings.length); + ar.n(v.bindings.length); for (const v1 of v.bindings) { saveDescriptorSetLayoutBinding(ar, v1); } } export function loadDescriptorSetLayoutInfo (ar: InputArchive, v: DescriptorSetLayoutInfo): void { - const sz = ar.readNumber(); + const sz = ar.n(); v.bindings.length = sz; for (let i = 0; i !== sz; ++i) { const v1 = new DescriptorSetLayoutBinding(); diff --git a/cocos/rendering/custom/types.ts b/cocos/rendering/custom/types.ts index 13d700827d0..2b07c25deba 100644 --- a/cocos/rendering/custom/types.ts +++ b/cocos/rendering/custom/types.ts @@ -603,216 +603,216 @@ export class RenderCommonObjectPool { private readonly _pipelineStatistics: RecyclePool; } -export function saveLightInfo (ar: OutputArchive, v: LightInfo): void { +export function saveLightInfo (a: OutputArchive, v: LightInfo): void { // skip, v.light: Light // skip, v.probe: ReflectionProbe - ar.writeNumber(v.level); - ar.writeBool(v.culledByLight); + a.n(v.level); + a.b(v.culledByLight); } -export function loadLightInfo (ar: InputArchive, v: LightInfo): void { +export function loadLightInfo (a: InputArchive, v: LightInfo): void { // skip, v.light: Light // skip, v.probe: ReflectionProbe - v.level = ar.readNumber(); - v.culledByLight = ar.readBool(); + v.level = a.n(); + v.culledByLight = a.b(); } -export function saveDescriptor (ar: OutputArchive, v: Descriptor): void { - ar.writeNumber(v.type); - ar.writeNumber(v.count); +export function saveDescriptor (a: OutputArchive, v: Descriptor): void { + a.n(v.type); + a.n(v.count); } -export function loadDescriptor (ar: InputArchive, v: Descriptor): void { - v.type = ar.readNumber(); - v.count = ar.readNumber(); +export function loadDescriptor (a: InputArchive, v: Descriptor): void { + v.type = a.n(); + v.count = a.n(); } -export function saveDescriptorBlock (ar: OutputArchive, v: DescriptorBlock): void { - ar.writeNumber(v.descriptors.size); // Map +export function saveDescriptorBlock (a: OutputArchive, v: DescriptorBlock): void { + a.n(v.descriptors.size); // Map for (const [k1, v1] of v.descriptors) { - ar.writeString(k1); - saveDescriptor(ar, v1); + a.s(k1); + saveDescriptor(a, v1); } - ar.writeNumber(v.uniformBlocks.size); // Map + a.n(v.uniformBlocks.size); // Map for (const [k1, v1] of v.uniformBlocks) { - ar.writeString(k1); - saveUniformBlock(ar, v1); + a.s(k1); + saveUniformBlock(a, v1); } - ar.writeNumber(v.capacity); - ar.writeNumber(v.count); + a.n(v.capacity); + a.n(v.count); } -export function loadDescriptorBlock (ar: InputArchive, v: DescriptorBlock): void { +export function loadDescriptorBlock (a: InputArchive, v: DescriptorBlock): void { let sz = 0; - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readString(); + const k1 = a.s(); const v1 = new Descriptor(); - loadDescriptor(ar, v1); + loadDescriptor(a, v1); v.descriptors.set(k1, v1); } - sz = ar.readNumber(); // Map + sz = a.n(); // Map for (let i1 = 0; i1 !== sz; ++i1) { - const k1 = ar.readString(); + const k1 = a.s(); const v1 = new UniformBlock(); - loadUniformBlock(ar, v1); + loadUniformBlock(a, v1); v.uniformBlocks.set(k1, v1); } - v.capacity = ar.readNumber(); - v.count = ar.readNumber(); + v.capacity = a.n(); + v.count = a.n(); } -export function saveDescriptorBlockFlattened (ar: OutputArchive, v: DescriptorBlockFlattened): void { - ar.writeNumber(v.descriptorNames.length); // string[] +export function saveDescriptorBlockFlattened (a: OutputArchive, v: DescriptorBlockFlattened): void { + a.n(v.descriptorNames.length); // string[] for (const v1 of v.descriptorNames) { - ar.writeString(v1); + a.s(v1); } - ar.writeNumber(v.uniformBlockNames.length); // string[] + a.n(v.uniformBlockNames.length); // string[] for (const v1 of v.uniformBlockNames) { - ar.writeString(v1); + a.s(v1); } - ar.writeNumber(v.descriptors.length); // Descriptor[] + a.n(v.descriptors.length); // Descriptor[] for (const v1 of v.descriptors) { - saveDescriptor(ar, v1); + saveDescriptor(a, v1); } - ar.writeNumber(v.uniformBlocks.length); // UniformBlock[] + a.n(v.uniformBlocks.length); // UniformBlock[] for (const v1 of v.uniformBlocks) { - saveUniformBlock(ar, v1); + saveUniformBlock(a, v1); } - ar.writeNumber(v.capacity); - ar.writeNumber(v.count); + a.n(v.capacity); + a.n(v.count); } -export function loadDescriptorBlockFlattened (ar: InputArchive, v: DescriptorBlockFlattened): void { +export function loadDescriptorBlockFlattened (a: InputArchive, v: DescriptorBlockFlattened): void { let sz = 0; - sz = ar.readNumber(); // string[] + sz = a.n(); // string[] v.descriptorNames.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { - v.descriptorNames[i1] = ar.readString(); + v.descriptorNames[i1] = a.s(); } - sz = ar.readNumber(); // string[] + sz = a.n(); // string[] v.uniformBlockNames.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { - v.uniformBlockNames[i1] = ar.readString(); + v.uniformBlockNames[i1] = a.s(); } - sz = ar.readNumber(); // Descriptor[] + sz = a.n(); // Descriptor[] v.descriptors.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { const v1 = new Descriptor(); - loadDescriptor(ar, v1); + loadDescriptor(a, v1); v.descriptors[i1] = v1; } - sz = ar.readNumber(); // UniformBlock[] + sz = a.n(); // UniformBlock[] v.uniformBlocks.length = sz; for (let i1 = 0; i1 !== sz; ++i1) { const v1 = new UniformBlock(); - loadUniformBlock(ar, v1); + loadUniformBlock(a, v1); v.uniformBlocks[i1] = v1; } - v.capacity = ar.readNumber(); - v.count = ar.readNumber(); -} - -export function saveDescriptorBlockIndex (ar: OutputArchive, v: DescriptorBlockIndex): void { - ar.writeNumber(v.updateFrequency); - ar.writeNumber(v.parameterType); - ar.writeNumber(v.descriptorType); - ar.writeNumber(v.visibility); -} - -export function loadDescriptorBlockIndex (ar: InputArchive, v: DescriptorBlockIndex): void { - v.updateFrequency = ar.readNumber(); - v.parameterType = ar.readNumber(); - v.descriptorType = ar.readNumber(); - v.visibility = ar.readNumber(); -} - -export function saveResolvePair (ar: OutputArchive, v: ResolvePair): void { - ar.writeString(v.source); - ar.writeString(v.target); - ar.writeNumber(v.resolveFlags); - ar.writeNumber(v.mode); - ar.writeNumber(v.mode1); -} - -export function loadResolvePair (ar: InputArchive, v: ResolvePair): void { - v.source = ar.readString(); - v.target = ar.readString(); - v.resolveFlags = ar.readNumber(); - v.mode = ar.readNumber(); - v.mode1 = ar.readNumber(); -} - -export function saveCopyPair (ar: OutputArchive, v: CopyPair): void { - ar.writeString(v.source); - ar.writeString(v.target); - ar.writeNumber(v.mipLevels); - ar.writeNumber(v.numSlices); - ar.writeNumber(v.sourceMostDetailedMip); - ar.writeNumber(v.sourceFirstSlice); - ar.writeNumber(v.sourcePlaneSlice); - ar.writeNumber(v.targetMostDetailedMip); - ar.writeNumber(v.targetFirstSlice); - ar.writeNumber(v.targetPlaneSlice); -} - -export function loadCopyPair (ar: InputArchive, v: CopyPair): void { - v.source = ar.readString(); - v.target = ar.readString(); - v.mipLevels = ar.readNumber(); - v.numSlices = ar.readNumber(); - v.sourceMostDetailedMip = ar.readNumber(); - v.sourceFirstSlice = ar.readNumber(); - v.sourcePlaneSlice = ar.readNumber(); - v.targetMostDetailedMip = ar.readNumber(); - v.targetFirstSlice = ar.readNumber(); - v.targetPlaneSlice = ar.readNumber(); -} - -export function saveMovePair (ar: OutputArchive, v: MovePair): void { - ar.writeString(v.source); - ar.writeString(v.target); - ar.writeNumber(v.mipLevels); - ar.writeNumber(v.numSlices); - ar.writeNumber(v.targetMostDetailedMip); - ar.writeNumber(v.targetFirstSlice); - ar.writeNumber(v.targetPlaneSlice); -} - -export function loadMovePair (ar: InputArchive, v: MovePair): void { - v.source = ar.readString(); - v.target = ar.readString(); - v.mipLevels = ar.readNumber(); - v.numSlices = ar.readNumber(); - v.targetMostDetailedMip = ar.readNumber(); - v.targetFirstSlice = ar.readNumber(); - v.targetPlaneSlice = ar.readNumber(); -} - -export function savePipelineStatistics (ar: OutputArchive, v: PipelineStatistics): void { - ar.writeNumber(v.numRenderPasses); - ar.writeNumber(v.numManagedTextures); - ar.writeNumber(v.totalManagedTextures); - ar.writeNumber(v.numUploadBuffers); - ar.writeNumber(v.numUploadBufferViews); - ar.writeNumber(v.numFreeUploadBuffers); - ar.writeNumber(v.numFreeUploadBufferViews); - ar.writeNumber(v.numDescriptorSets); - ar.writeNumber(v.numFreeDescriptorSets); - ar.writeNumber(v.numInstancingBuffers); - ar.writeNumber(v.numInstancingUniformBlocks); -} - -export function loadPipelineStatistics (ar: InputArchive, v: PipelineStatistics): void { - v.numRenderPasses = ar.readNumber(); - v.numManagedTextures = ar.readNumber(); - v.totalManagedTextures = ar.readNumber(); - v.numUploadBuffers = ar.readNumber(); - v.numUploadBufferViews = ar.readNumber(); - v.numFreeUploadBuffers = ar.readNumber(); - v.numFreeUploadBufferViews = ar.readNumber(); - v.numDescriptorSets = ar.readNumber(); - v.numFreeDescriptorSets = ar.readNumber(); - v.numInstancingBuffers = ar.readNumber(); - v.numInstancingUniformBlocks = ar.readNumber(); + v.capacity = a.n(); + v.count = a.n(); +} + +export function saveDescriptorBlockIndex (a: OutputArchive, v: DescriptorBlockIndex): void { + a.n(v.updateFrequency); + a.n(v.parameterType); + a.n(v.descriptorType); + a.n(v.visibility); +} + +export function loadDescriptorBlockIndex (a: InputArchive, v: DescriptorBlockIndex): void { + v.updateFrequency = a.n(); + v.parameterType = a.n(); + v.descriptorType = a.n(); + v.visibility = a.n(); +} + +export function saveResolvePair (a: OutputArchive, v: ResolvePair): void { + a.s(v.source); + a.s(v.target); + a.n(v.resolveFlags); + a.n(v.mode); + a.n(v.mode1); +} + +export function loadResolvePair (a: InputArchive, v: ResolvePair): void { + v.source = a.s(); + v.target = a.s(); + v.resolveFlags = a.n(); + v.mode = a.n(); + v.mode1 = a.n(); +} + +export function saveCopyPair (a: OutputArchive, v: CopyPair): void { + a.s(v.source); + a.s(v.target); + a.n(v.mipLevels); + a.n(v.numSlices); + a.n(v.sourceMostDetailedMip); + a.n(v.sourceFirstSlice); + a.n(v.sourcePlaneSlice); + a.n(v.targetMostDetailedMip); + a.n(v.targetFirstSlice); + a.n(v.targetPlaneSlice); +} + +export function loadCopyPair (a: InputArchive, v: CopyPair): void { + v.source = a.s(); + v.target = a.s(); + v.mipLevels = a.n(); + v.numSlices = a.n(); + v.sourceMostDetailedMip = a.n(); + v.sourceFirstSlice = a.n(); + v.sourcePlaneSlice = a.n(); + v.targetMostDetailedMip = a.n(); + v.targetFirstSlice = a.n(); + v.targetPlaneSlice = a.n(); +} + +export function saveMovePair (a: OutputArchive, v: MovePair): void { + a.s(v.source); + a.s(v.target); + a.n(v.mipLevels); + a.n(v.numSlices); + a.n(v.targetMostDetailedMip); + a.n(v.targetFirstSlice); + a.n(v.targetPlaneSlice); +} + +export function loadMovePair (a: InputArchive, v: MovePair): void { + v.source = a.s(); + v.target = a.s(); + v.mipLevels = a.n(); + v.numSlices = a.n(); + v.targetMostDetailedMip = a.n(); + v.targetFirstSlice = a.n(); + v.targetPlaneSlice = a.n(); +} + +export function savePipelineStatistics (a: OutputArchive, v: PipelineStatistics): void { + a.n(v.numRenderPasses); + a.n(v.numManagedTextures); + a.n(v.totalManagedTextures); + a.n(v.numUploadBuffers); + a.n(v.numUploadBufferViews); + a.n(v.numFreeUploadBuffers); + a.n(v.numFreeUploadBufferViews); + a.n(v.numDescriptorSets); + a.n(v.numFreeDescriptorSets); + a.n(v.numInstancingBuffers); + a.n(v.numInstancingUniformBlocks); +} + +export function loadPipelineStatistics (a: InputArchive, v: PipelineStatistics): void { + v.numRenderPasses = a.n(); + v.numManagedTextures = a.n(); + v.totalManagedTextures = a.n(); + v.numUploadBuffers = a.n(); + v.numUploadBufferViews = a.n(); + v.numFreeUploadBuffers = a.n(); + v.numFreeUploadBufferViews = a.n(); + v.numDescriptorSets = a.n(); + v.numFreeDescriptorSets = a.n(); + v.numInstancingBuffers = a.n(); + v.numInstancingUniformBlocks = a.n(); }