Skip to content

Commit

Permalink
Merge branch 'v3.8.4' into v3.8.4-pipeline-reflection-probe
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Sep 4, 2024
2 parents ef5ea7f + 3a5898d commit 282ac50
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 85 deletions.
82 changes: 38 additions & 44 deletions cocos/rendering/custom/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,24 +448,17 @@ export function getDescBindingFromName (bindingName: string): number {
return -1;
}

const uniformMap: Map<string, Float32Array> = new Map();
const buffHashMap: Map<Buffer, number> = new Map();
function numsHash (arr: number[]): number {
let hash = 0;
for (let i = 0; i < arr.length; i++) {
hash = hashCombineNum(arr[i], hash);
}
return hash;
}

class DescBuffManager {
private buffers: Buffer[] = [];
private currBuffIdx: number = 0;
private device: Device;
public currUniform: Float32Array;
private _root;
constructor (bufferSize: number, numBuffers: number = 2) {
const root = cclegacy.director.root;
const root = this._root = cclegacy.director.root;
const device = root.device;
this.device = device;
this.currUniform = new Float32Array(bufferSize / 4);
for (let i = 0; i < numBuffers; i++) {
const bufferInfo: BufferInfo = new BufferInfo(
BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST,
Expand All @@ -477,42 +470,33 @@ class DescBuffManager {
}
}
getCurrentBuffer (): Buffer {
const root = cclegacy.director.root;
this.currBuffIdx = root.frameCount % this.buffers.length;
this.currBuffIdx = this._root.frameCount % this.buffers.length;
return this.buffers[this.currBuffIdx];
}
updateBuffer (bindId: number, vals: number[], layout: string, setData: DescriptorSetData): void {
updateData (vals: number[]): void {
this.currUniform.set(vals);
}
updateBuffer (bindId: number, setData: DescriptorSetData): void {
const descriptorSet = setData.descriptorSet!;
const buffer = this.getCurrentBuffer();
const uniformKey = `${layout}${bindId}${this.currBuffIdx}`;
let currUniform = uniformMap.get(uniformKey);
const currHash = numsHash(vals);
if (!currUniform) {
currUniform = new Float32Array(vals);
uniformMap.set(uniformKey, currUniform);
}
const destHash = buffHashMap.get(buffer);
if (destHash !== currHash) {
currUniform.set(vals);
buffer.update(currUniform);
bindGlobalDesc(descriptorSet, bindId, buffer);
buffHashMap.set(buffer, currHash);
}
buffer.update(this.currUniform);
bindGlobalDesc(descriptorSet, bindId, buffer);
}
}

const buffsMap: Map<string, DescBuffManager> = new Map();

function updateGlobalDescBuffer (blockId: number, sceneId: number, vals: number[], layout: string, setData: DescriptorSetData): void {
const currBindBuffs: Map<string, number> = new Map();
function updateGlobalDescBuffer (blockId: number, sceneId: number, idxRD: number, vals: number[], setData: DescriptorSetData): void {
const bindId = getDescBinding(blockId, setData);
if (bindId === -1) { return; }
const descKey = `${blockId}${bindId}${sceneId}`;
const descKey = `${blockId}${bindId}${idxRD}${sceneId}`;
currBindBuffs.set(descKey, bindId);
let currDescBuff = buffsMap.get(descKey);
if (!currDescBuff) {
buffsMap.set(descKey, new DescBuffManager(vals.length * 4));
buffsMap.set(descKey, new DescBuffManager(vals.length * 4, 2));
currDescBuff = buffsMap.get(descKey);
}
currDescBuff!.updateBuffer(bindId, vals, layout, setData);
currDescBuff!.updateData(vals);
}

const layouts: Map<string, DescriptorSetData> = new Map();
Expand All @@ -537,8 +521,8 @@ export function getDescriptorSetDataFromLayoutId (id: number): DescriptorSetData
return layoutData;
}

export function updateGlobalDescBinding (data: RenderData, sceneId: number, layoutName = 'default'): void {
updatePerPassUBO(layoutName, sceneId, data);
export function updateGlobalDescBinding (data: RenderData, sceneId: number, idxRD: number, layoutName = 'default'): void {
updatePerPassUBO(layoutName, sceneId, idxRD, data);
}

function getUniformBlock (block: string, layoutName: string): UniformBlock | undefined {
Expand Down Expand Up @@ -572,15 +556,20 @@ class ConstantBlockInfo {
blockId: number = -1;
}
const constantBlockMap: Map<number, ConstantBlockInfo> = new Map();
function copyToConstantBuffer (target: number[], val: number[], offset: number): void {
function copyToConstantBuffer (target: number[], val: number[], offset: number): boolean {
let isImparity = false;
if (offset < 0 || offset > target.length) {
throw new Error('Offset is out of the bounds of the target array.');
return isImparity;
}
const length = Math.min(val.length, target.length - offset);

for (let i = 0; i < length; i++) {
target[offset + i] = val[i];
if (target[offset + i] !== val[i]) {
target[offset + i] = val[i];
isImparity = true;
}
}
return isImparity;
}

function addConstantBuffer (block: string, layout: string): number[] | null {
Expand All @@ -602,14 +591,15 @@ function addConstantBuffer (block: string, layout: string): number[] | null {
uniformBlockMap.set(block, buffers);
return buffers;
}
export function updatePerPassUBO (layout: string, sceneId: number, user: RenderData): void {
export function updatePerPassUBO (layout: string, sceneId: number, idxRD: number, user: RenderData): void {
const constantMap = user.constants;
const samplers = user.samplers;
const textures = user.textures;
const buffers = user.buffers;
const webPip = cclegacy.director.root.pipeline as WebPipeline;
const lg = webPip.layoutGraph;
const descriptorSetData = getDescriptorSetDataFromLayout(layout)!;
currBindBuffs.clear();
for (const [key, data] of constantMap) {
let constantBlock = constantBlockMap.get(key);
if (!constantBlock) {
Expand All @@ -622,20 +612,20 @@ export function updatePerPassUBO (layout: string, sceneId: number, user: RenderD
if (offset === -1) {
// Although the current uniformMem does not belong to the current uniform block,
// it does not mean that it should not be bound to the corresponding descriptor.
updateGlobalDescBuffer(blockId, sceneId, constantBuff, layout, descriptorSetData);
updateGlobalDescBuffer(blockId, sceneId, idxRD, constantBuff, descriptorSetData);
continue;
}
constantBlockMap.set(key, new ConstantBlockInfo());
constantBlock = constantBlockMap.get(key)!;
constantBlock.buffer = constantBuff;
constantBlock.blockId = blockId;
constantBlock.offset = offset;
copyToConstantBuffer(constantBuff, data, offset);
updateGlobalDescBuffer(blockId, sceneId, constantBuff, layout, descriptorSetData);
const isImparity = copyToConstantBuffer(constantBuff, data, offset);
if (isImparity) updateGlobalDescBuffer(blockId, sceneId, idxRD, constantBuff, descriptorSetData);
}
} else {
copyToConstantBuffer(constantBlock.buffer, data, constantBlock.offset);
updateGlobalDescBuffer(constantBlock.blockId, sceneId, constantBlock.buffer, layout, descriptorSetData);
const isImparity = copyToConstantBuffer(constantBlock.buffer, data, constantBlock.offset);
if (isImparity) updateGlobalDescBuffer(constantBlock.blockId, sceneId, idxRD, constantBlock.buffer, descriptorSetData);
}
}

Expand All @@ -658,6 +648,10 @@ export function updatePerPassUBO (layout: string, sceneId: number, user: RenderD
bindGlobalDesc(descriptorSet, bindId, value);
}
}
for (const [key, value] of currBindBuffs) {
const buffManager = buffsMap.get(key)!;
buffManager.updateBuffer(value, descriptorSetData);
}
for (const [key, value] of buffers) {
const bindId = getDescBinding(key, descriptorSetData);
if (bindId === -1) { continue; }
Expand Down
13 changes: 10 additions & 3 deletions cocos/rendering/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ class DeviceRenderPass implements RecordingInterface {
protected _viewport: Viewport | null = null;
private _rasterInfo: RasterPassInfo;
private _layout: RenderPassLayoutInfo | null = null;
private _idxOfRenderData: number = 0;
constructor (passInfo: RasterPassInfo) {
this._rasterInfo = passInfo;
const device = context.device;
Expand Down Expand Up @@ -909,6 +910,7 @@ class DeviceRenderPass implements RecordingInterface {
swapchain ? swapchain.depthStencilTexture : depthTex,
));
}
get indexOfRD (): number { return this._idxOfRenderData; }
get layoutName (): string { return this._layoutName; }
get passID (): number { return this._passID; }
get renderLayout (): RenderPassLayoutInfo | null { return this._layout; }
Expand All @@ -920,6 +922,9 @@ class DeviceRenderPass implements RecordingInterface {
get deviceQueues (): Map<number, DeviceRenderQueue> { return this._deviceQueues; }
get rasterPassInfo (): RasterPassInfo { return this._rasterInfo; }
get viewport (): Viewport | null { return this._viewport; }
addIdxOfRD (): void {
this._idxOfRenderData++;
}
visitResource (resName: string): void {
const resourceGraph = context.resourceGraph;
const vertId = resourceGraph.vertex(resName);
Expand Down Expand Up @@ -1040,6 +1045,7 @@ class DeviceRenderPass implements RecordingInterface {
this._layoutName = context.renderGraph.getLayout(id);
this._passID = cclegacy.rendering.getPassID(this._layoutName);
this._deviceQueues.clear();
this._idxOfRenderData = 0;
let framebuffer: Framebuffer | null = null;
const colTextures: Texture[] = [];
const currFramebuffer = this._framebuffer;
Expand Down Expand Up @@ -1234,7 +1240,7 @@ class DeviceComputePass implements RecordingInterface {
queue.record();
}
const renderData = context.renderGraph.getData(this._computeInfo.id);
updateGlobalDescBinding(renderData, -1, context.renderGraph.getLayout(this._computeInfo.id));
updateGlobalDescBinding(renderData, -1, 0, context.renderGraph.getLayout(this._computeInfo.id));
}

resetResource (id: number, pass: ComputePass): void {
Expand Down Expand Up @@ -1392,7 +1398,8 @@ class DeviceRenderScene implements RecordingInterface {

protected _updateGlobal (data: RenderData, sceneId: number): void {
const devicePass = this._currentQueue.devicePass;
updateGlobalDescBinding(data, sceneId, context.renderGraph.getLayout(devicePass.rasterPassInfo.id));
devicePass.addIdxOfRD();
updateGlobalDescBinding(data, sceneId, devicePass.indexOfRD, context.renderGraph.getLayout(devicePass.rasterPassInfo.id));
}

protected _updateRenderData (): void {
Expand Down Expand Up @@ -1996,7 +2003,7 @@ class PreRenderVisitor extends BaseRenderVisitor implements RenderGraphVisitor {
if (!this.rg.getValid(this.sceneID)) return;
const renderQueue = this.currQueue as DeviceRenderQueue;
const graphScene = context.pools.addGraphScene();
graphScene.init(null, value, -1);
graphScene.init(null, value, this.sceneID);
const renderScene = renderQueue.addScene(graphScene);
renderScene.preRecord();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,6 @@ export class BuiltinPipelineSettings extends Component {
return this._settings.bloom.threshold;
}

@property({
tooltip: 'i18n:bloom.intensity',
group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
type: CCFloat,
min: 0,
visible: false,
})
set bloomIntensity(value: number) {
this._settings.bloom.intensity = value;
}
Expand Down
30 changes: 11 additions & 19 deletions editor/assets/effects/pipeline/post-process/color-grading.effect
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ CCEffect %{
pass: color-grading-nx1
rasterizerState: &rasterizerState
cullMode: none
blendState: &blendState
targets:
- blend: false
blendSrc: one
blendDst: zero
depthStencilState: &depthStencilState
depthTest: false
depthWrite: false
Expand All @@ -16,6 +21,7 @@ CCEffect %{
pass: color-grading-8x8
rasterizerState: *rasterizerState
depthStencilState: *depthStencilState
blendState: *blendState
}%

CCProgram ubo %{
Expand All @@ -35,8 +41,6 @@ CCProgram color-grading-vs %{

CCProgram color-grading-nx1-fs %{
precision highp float;
#include <common/color/gamma>
#include <common/color/tone-mapping>
#include <ubo>
in vec2 v_uv;

Expand All @@ -58,44 +62,32 @@ CCProgram color-grading-nx1-fs %{
layout(location = 0) out vec4 fragColor;
void main () {
vec4 sceneColor = texture(sceneColorMap, v_uv);
// (Tone mapping + gamma correction) + Color grading
#if CC_USE_FLOAT_OUTPUT
sceneColor.rgb = HDRToLDR(sceneColor.rgb);
sceneColor.rgb = LinearToSRGB(sceneColor.rgb);
#endif
vec3 gradeColor = ColorGrading(colorGradingMap, sceneColor.rgb);
fragColor = mix(sceneColor, vec4(gradeColor, sceneColor.a), contribute);
fragColor = mix(sceneColor, vec4(gradeColor, 1.0), contribute);
}
}%

CCProgram color-grading-8x8-fs %{
precision highp float;
#include <common/color/gamma>
#include <common/color/tone-mapping>
#include <ubo>
in vec2 v_uv;
#define EPS 0.000001
#define TOTAL 64.0
#define SIZE 512.0
layout(location = 0) out vec4 fragColor;
void main () {
vec4 origColor = texture(sceneColorMap, v_uv);
// (Tone mapping + gamma correction) + Color grading
#if CC_USE_FLOAT_OUTPUT
origColor.rgb = HDRToLDR(origColor.rgb);
origColor.rgb = LinearToSRGB(origColor.rgb);
#endif
float bValue = (origColor.b * 255.0) / 4.0;
vec3 orgColor = texture(sceneColorMap, v_uv).rgb;
float bValue = (orgColor.b * 255.0) / 4.0;
vec2 mulB = clamp(floor(bValue) + vec2(0.0, 1.0), 0.0, 63.0);
vec2 row = floor(mulB / 8.0 + EPS);
vec4 row_col = vec4(row, mulB - row * 8.0);
vec4 lookup = origColor.ggrr * (63.0 / SIZE) + row_col * (TOTAL / SIZE) + (0.5 / SIZE);
vec4 lookup = orgColor.ggrr * (63.0 / SIZE) + row_col * (TOTAL / SIZE) + (0.5 / SIZE);

float b1w = bValue - mulB.x;

vec3 sampled1 = texture(colorGradingMap, lookup.zx).rgb;
vec3 sampled2 = texture(colorGradingMap, lookup.wy).rgb;

fragColor = vec4(mix(origColor.rgb, mix(sampled1, sampled2, b1w), contribute), origColor.a);
fragColor = vec4(mix(orgColor, mix(sampled1, sampled2, b1w), contribute), 1.0);
}
}%
10 changes: 10 additions & 0 deletions editor/assets/effects/pipeline/post-process/fsr.effect
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ CCEffect %{
depthStencilState:
depthTest: false
depthWrite: false
blendState:
targets:
- blend: true
blendSrc: one
blendDst: zero
- vert: vs
frag: fs-rcas
pass: post-process
Expand All @@ -19,6 +24,11 @@ CCEffect %{
depthStencilState:
depthTest: false
depthWrite: false
blendState:
targets:
- blend: true
blendSrc: one
blendDst: zero
}%


Expand Down
12 changes: 6 additions & 6 deletions editor/i18n/en/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,16 +1105,16 @@ module.exports = link(mixin({
description: "Enable the XR function system",
},
custom_pipeline: {
label: "Custom Render Pipeline (Beta)",
description: "Enable custom render pipeline",
label: "Render Pipeline (New)",
description: "The new render pipeline is based on data-oriented render graph. Users can write cross platform render pipelines and optimize for the specific platform.",
},
custom_pipeline_post_process: {
label: "Custom Render Pipeline Post Process (Deprecated)",
description: "Enable custom render pipeline post process",
label: "Post Process Module (Deprecated)",
description: "The render pipeline used in previous versions. This pipeline will be deprecated in future versions.",
},
legacy_pipeline: {
label: "Legacy Render Pipeline (Deprecated)",
description: "Enable legacy render pipeline",
label: "Render Pipeline (Legacy)",
description: "The render pipeline used in previous versions. This pipeline will be deprecated in future versions.",
},
websocket: {
label: "WebSocket",
Expand Down
12 changes: 6 additions & 6 deletions editor/i18n/zh/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,16 +1080,16 @@ module.exports = link(mixin({
description: "启用 XR 功能系统。",
},
custom_pipeline: {
label: "自定义渲染管线 (Beta)",
description: "启用自定义渲染管线。",
label: "新渲染管线",
description: "面向数据的Render Graph渲染管线,可以自由构建跨平台的渲染算法,并针对目标平台优化。",
},
custom_pipeline_post_process: {
label: "自定义渲染管线的后处理模块 (Deprecated)",
description: "启用自定义渲染管线的后处理模块",
label: "后处理模块(已废弃)",
description: "此选项用于兼容旧项目(Custom管线),新项目请使用 Builtin 自带的后处理流程。",
},
legacy_pipeline: {
label: "废弃渲染管线 (Deprecated)",
description: "启用废弃渲染管线。",
label: "原渲染管线",
description: "原有的渲染管线,在后续的版本中会被移除。",
},
websocket: {
label: "WebSocket",
Expand Down

0 comments on commit 282ac50

Please sign in to comment.