From 6c75e45e693ecf051e999c9fe440bd3dbebd2126 Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Wed, 11 Oct 2023 16:15:20 +0800 Subject: [PATCH] add uniform buffer --- cocos/rendering/custom/web-pipeline.ts | 6 +++++- cocos/rendering/custom/web-program-library.ts | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index ab178ce705b..47ee4dff3ec 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -238,7 +238,11 @@ export class WebSetter { this._copyToBuffer(v, offset, Type.FLOAT); } public setBuffer (name: string, buffer: Buffer): void { - // TODO + if (this._getCurrDescriptorBlock(name) === -1) { + return; + } + const num = this._lg.attributeIndex.get(name)!; + this._data.buffers.set(num, buffer); } public setTexture (name: string, texture: Texture): void { if (this._getCurrDescriptorBlock(name) === -1) { diff --git a/cocos/rendering/custom/web-program-library.ts b/cocos/rendering/custom/web-program-library.ts index 5b03ca067a4..3eb627f8d33 100644 --- a/cocos/rendering/custom/web-program-library.ts +++ b/cocos/rendering/custom/web-program-library.ts @@ -101,7 +101,7 @@ function overwriteShaderSourceBinding (shaderInfo: ShaderInfo, source: string): code = code.replace(samplerIter[0], replaceStr); samplerIter = samplerExp.exec(code); } - const blockExp = /layout\s*\(([^\)]+)\)\s*(readonly|writeonly)?\s*\b((uniform\s+|buffer|image2D){1,2})\b\s+(\b\w+\b)\s*[{;]/g; + const blockExp = /layout\s*\(([^\)]+)\)\s*(readonly|writeonly)?\s*\b((uniform\s*|buffer\s*|image2D\s*){1,2})\b\s*(\b\w+\b)\s*[{;]/g; let blockIter = blockExp.exec(code); while (blockIter) { const name = blockIter[5]; @@ -114,7 +114,7 @@ function overwriteShaderSourceBinding (shaderInfo: ShaderInfo, source: string): let desc = blockIter[1]; desc = desc.replace(/set\s*=\s*\d+/g, `set = ${set}`); desc = desc.replace(/binding\s*=\s*\d+/g, `binding = ${binding}`); - const replaceStr = `layout(${desc}) ${accessStr} ${blockIter[3]} ${blockIter[5]}` + endStr; + const replaceStr = `layout(${desc}) ${accessStr} ${blockIter[3]} ${blockIter[5]}${endStr}`; code = code.replace(blockIter[0], replaceStr); blockIter = blockExp.exec(code); }