Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.8.1 gpu-driven #15760

Closed
wants to merge 83 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
20c50a0
add comment
star-e Jun 8, 2023
38b7e2c
fixing csm
star-e Jun 8, 2023
1b3dfa5
add shadow
star-e Jun 8, 2023
0e7255b
adding sampler
star-e Jun 9, 2023
4c036fa
samplers added
star-e Jun 9, 2023
a911731
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 9, 2023
ac03ee3
fix csm crash
star-e Jun 9, 2023
bc5a821
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 12, 2023
b9f6fba
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 12, 2023
1af5c4c
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 12, 2023
76399f5
remove addRasterView, addComputeView
star-e Jun 12, 2023
e51c4ba
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 14, 2023
6aabfb7
fix typo
star-e Jun 15, 2023
aeba1ff
fix typo
star-e Jun 15, 2023
5bf68ae
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 15, 2023
7e7342d
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 16, 2023
a0bb559
deferred-pipeline (#141)
bluesky013 Jun 16, 2023
ec2b849
fix vk csm
star-e Jun 16, 2023
0b2710c
Merge branch 'v3.8.0-pipeline' of https://github.com/star-e/cocos-eng…
star-e Jun 16, 2023
365d127
update custom pipeline effect import error log
star-e Jun 16, 2023
69d90a1
update error map
star-e Jun 16, 2023
dc2f864
fix typo
star-e Jun 16, 2023
bdf18f4
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 16, 2023
49fc0e1
Forward defaulted to PostProcessBuilder
star-e Jun 16, 2023
e20a7c0
fix lint
star-e Jun 19, 2023
19554ff
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 19, 2023
57d76c3
[Fixed] Fix the issue of transparent objects not being rendered in th…
GengineJS Jun 20, 2023
0ceb7ec
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 20, 2023
4449b83
[Add] Add logic to make the post-processing pipeline effective in the…
GengineJS Jun 20, 2023
c99ec12
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 20, 2023
af68340
Revert "[Add] Add logic to make the post-processing pipeline effectiv…
star-e Jun 20, 2023
d164666
sync with 3.8.1
star-e Jun 20, 2023
1799f5f
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 20, 2023
80ea215
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 21, 2023
eccbbe1
adding comment
star-e Jun 25, 2023
98e4af5
add PipelineRuntime document
star-e Jun 25, 2023
890e006
update comment
star-e Jun 25, 2023
24149c8
adding enum comments
star-e Jun 25, 2023
e53d130
change beta and experimental
star-e Jun 25, 2023
e6b2a5b
PipelineType added
star-e Jun 25, 2023
420da77
update PipelineType
star-e Jun 25, 2023
74e32f5
add doc
star-e Jun 27, 2023
dbdce57
QueueHint updated
star-e Jun 27, 2023
1da0544
Basic Pipeline added
star-e Jun 28, 2023
9193c55
api documents added
star-e Jun 28, 2023
4665983
fix wording
star-e Jun 28, 2023
a632a47
update doc
star-e Jun 29, 2023
cd03b67
Merge branch 'v3.8.0' into v3.8.0-pipeline
star-e Jun 29, 2023
9be4bd7
add multisample render pass builder
star-e Jun 29, 2023
704bfb7
add MultisampleRenderPassBuilder
star-e Jun 29, 2023
474828b
refactor interface, adding gpu-driven
star-e Jun 30, 2023
85f239b
cleanup
star-e Jun 30, 2023
53619fc
Merge branch 'v3.8.0' into v3.8.0-msaa
star-e Jun 30, 2023
d79394d
format
star-e Jun 30, 2023
6dabe6f
add resource added
star-e Jul 5, 2023
10f8639
add sortedVertices for GPU driven
star-e Jul 5, 2023
36f6570
use depth first visit on sorted vertices
star-e Jul 5, 2023
50c34d5
go through msaa on metal & vk (#148)
hana-alice Jul 7, 2023
9a7591b
Merge branch 'v3.8.0' into v3.8.0-msaa
star-e Jul 7, 2023
4b94796
Merge branch 'v3.8.0-msaa' of https://github.com/star-e/cocos-engine …
star-e Jul 7, 2023
a6784ee
Merge branch 'v3.8.0' into v3.8.0-msaa
star-e Jul 7, 2023
242cc4e
3.8.0 msaa update (#149)
hana-alice Jul 7, 2023
72041a9
gfx msaa && memoryless (#147)
bluesky013 Jul 11, 2023
14a4ded
adding gpu driven
star-e Jul 11, 2023
03f4209
Merge branch 'v3.8.0' into v3.8.0-msaa
star-e Jul 12, 2023
6a63d93
fix gles3 msaa with hardware buffer. (#150)
bluesky013 Jul 12, 2023
ca53e38
Merge branch 'v3.8.0' into v3.8.0-msaa
star-e Jul 12, 2023
6f4b2a4
Merge branch 'v3.8.0-msaa' of https://github.com/star-e/cocos-engine …
star-e Jul 12, 2023
2b75f0f
Merge branch 'v3.8.1' into v3.8.0-msaa
star-e Jul 12, 2023
551d0c5
fix various problems
star-e Jul 14, 2023
0796c7e
Merge branch 'v3.8.1' into v3.8.0-msaa
star-e Jul 14, 2023
275fe8f
update gles3 framebuffer attachent binding && add comment. (#151)
bluesky013 Jul 14, 2023
8d635a5
Merge branch 'v3.8.1' into v3.8.0-msaa
star-e Jul 17, 2023
46e8e8f
remove Scene from interface
star-e Jul 17, 2023
e77671b
fix lint
star-e Jul 17, 2023
c7438ae
fix lint
star-e Jul 17, 2023
0a5d7b9
[Fixed] eslint (#152)
GengineJS Jul 17, 2023
46387df
fix lint
star-e Jul 18, 2023
69037fc
Merge branch 'v3.8.1' into v3.8.0-msaa
star-e Jul 18, 2023
56d6339
add gpu driven
star-e Jul 18, 2023
5f6ac06
Sync develop indirect draw. (#153)
bluesky013 Jul 18, 2023
9a3b379
fix eslint
star-e Jul 19, 2023
6b42ad2
fix def
star-e Jul 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions cocos/asset/assets/rendering-sub-mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,19 @@ export class RenderingSubMesh {
* @param indirectBuffer @en indirect buffer. @zh 间接缓冲区。
*/
constructor (
vertexBuffers: Buffer[], attributes: Attribute[], primitiveMode: PrimitiveMode,
indexBuffer: Buffer | null = null, indirectBuffer: Buffer | null = null,
vertexBuffers: Buffer[],
attributes: Attribute[],
primitiveMode: PrimitiveMode,
indexBuffer: Buffer | null = null,
indirectBuffer: Buffer | null = null,
isOwnerOfIndexBuffer = true,
) {
this._attributes = attributes;
this._vertexBuffers = vertexBuffers;
this._indexBuffer = indexBuffer;
this._indirectBuffer = indirectBuffer;
this._primitiveMode = primitiveMode;
this._iaInfo = new InputAssemblerInfo(attributes, vertexBuffers, indexBuffer, indirectBuffer);
this._iaInfo = new InputAssemblerInfo(attributes, vertexBuffers, indexBuffer);
this._isOwnerOfIndexBuffer = isOwnerOfIndexBuffer;
}

Expand Down Expand Up @@ -197,7 +200,7 @@ export class RenderingSubMesh {
const indices = mesh.readIndices(index) as Uint16Array;
const max = new Vec3();
const min = new Vec3();
const pAttri = this.attributes.find((element): boolean => element.name === AttributeName.ATTR_POSITION);
const pAttri = this.attributes.find((element): boolean => element.name === AttributeName.ATTR_POSITION as string);
if (pAttri) {
const conut = FormatInfos[pAttri.format].count;
if (conut === 2) {
Expand Down Expand Up @@ -307,14 +310,14 @@ export class RenderingSubMesh {
}
let jointFormat: Format;
let jointOffset: number;
const { device } = cclegacy.director.root;
const device = cclegacy.director.root.device as Device;
for (let i = 0; i < prim.vertexBundelIndices.length; i++) {
const bundle = struct.vertexBundles[prim.vertexBundelIndices[i]];
jointOffset = 0;
jointFormat = Format.UNKNOWN;
for (let j = 0; j < bundle.attributes.length; j++) {
const attr = bundle.attributes[j];
if (attr.name === AttributeName.ATTR_JOINTS) {
if (attr.name === AttributeName.ATTR_JOINTS as string) {
jointFormat = attr.format;
break;
}
Expand All @@ -324,8 +327,15 @@ export class RenderingSubMesh {
const data = new Uint8Array(this.mesh.data.buffer, bundle.view.offset, bundle.view.length);
const dataView = new DataView(data.slice().buffer);
const idxMap = struct.jointMaps[prim.jointMapIndex];
mapBuffer(dataView, (cur): number => idxMap.indexOf(cur), jointFormat, jointOffset,
bundle.view.length, bundle.view.stride, dataView);
mapBuffer(
dataView,
(cur): number => idxMap.indexOf(cur),
jointFormat,
jointOffset,
bundle.view.length,
bundle.view.stride,
dataView,
);
const buffer = device.createBuffer(new BufferInfo(
BufferUsageBit.VERTEX | BufferUsageBit.TRANSFER_DST,
MemoryUsageBit.DEVICE,
Expand Down
5 changes: 2 additions & 3 deletions cocos/gfx/base/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ export enum TextureFlagBit {
GENERAL_LAYOUT = 0x2, // For inout framebuffer attachments
EXTERNAL_OES = 0x4, // External oes texture
EXTERNAL_NORMAL = 0x8, // External normal texture
LAZILY_ALLOCATED = 0x10 // Try lazily allocated mode.
MUTABLE_STORAGE = 0x10, // Texture is mutable or not, default is immutable(only for webgl2)
LAZILY_ALLOCATED = 0x20, // Try lazily allocated mode.
}

export enum FormatFeatureBit {
Expand Down Expand Up @@ -1502,14 +1503,12 @@ export class InputAssemblerInfo {
public attributes: Attribute[] = [],
public vertexBuffers: Buffer[] = [],
public indexBuffer: Buffer | null = null,
public indirectBuffer: Buffer | null = null,
) {}

public copy (info: Readonly<InputAssemblerInfo>): InputAssemblerInfo {
deepCopy(this.attributes, info.attributes, Attribute);
this.vertexBuffers = info.vertexBuffers.slice();
this.indexBuffer = info.indexBuffer;
this.indirectBuffer = info.indirectBuffer;
return this;
}
}
Expand Down
9 changes: 0 additions & 9 deletions cocos/gfx/base/input-assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ export abstract class InputAssembler extends GFXObject {
return this._indexBuffer;
}

/**
* @en Get the indirect buffer, if present.
* @zh 间接绘制缓冲。
*/
get indirectBuffer (): Buffer | null {
return this._indirectBuffer;
}

/**
* @en Get hash of current attributes.
* @zh 获取顶点属性数组的哈希值。
Expand Down Expand Up @@ -169,7 +161,6 @@ export abstract class InputAssembler extends GFXObject {

protected _vertexBuffers: Buffer[] = [];
protected _indexBuffer: Buffer | null = null;
protected _indirectBuffer: Buffer | null = null;

protected _drawInfo = new DrawInfo();

Expand Down
6 changes: 3 additions & 3 deletions cocos/gfx/webgl/webgl-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from './webgl-commands';
import { IWebGLGPUBuffer, IWebGLGPUBufferView, WebGLIndirectDrawInfos } from './webgl-gpu-objects';
import { WebGLDeviceManager } from './webgl-define';
import { warn } from '../../core/platform';

export class WebGLBuffer extends Buffer {
get gpuBuffer (): IWebGLGPUBuffer {
Expand Down Expand Up @@ -83,7 +84,6 @@ export class WebGLBuffer extends Buffer {
stride: this._stride,
buffer: null,
vf32: null,
indirects: new WebGLIndirectDrawInfos(),
glTarget: 0,
glBuffer: null,
};
Expand Down Expand Up @@ -112,7 +112,7 @@ export class WebGLBuffer extends Buffer {

public resize (size: number): void {
if (this._isBufferView) {
console.warn('cannot resize buffer views!');
warn('cannot resize buffer views!');
return;
}

Expand Down Expand Up @@ -142,7 +142,7 @@ export class WebGLBuffer extends Buffer {

public update (buffer: Readonly<BufferSource>, size?: number): void {
if (this._isBufferView) {
console.warn('cannot update through buffer views!');
warn('cannot update through buffer views!');
return;
}

Expand Down
84 changes: 1 addition & 83 deletions cocos/gfx/webgl/webgl-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,12 +782,6 @@ export function WebGLCmdFuncUpdateBuffer (
} else {
gpuBuffer.vf32!.set(new Float32Array(buffer as ArrayBuffer), offset / Float32Array.BYTES_PER_ELEMENT);
}
} else if (gpuBuffer.usage & BufferUsageBit.INDIRECT) {
gpuBuffer.indirects.clearDraws();
const drawInfos = (buffer as IndirectBuffer).drawInfos;
for (let i = 0; i < drawInfos.length; ++i) {
gpuBuffer.indirects.setDrawInfo(offset + i, drawInfos[i]);
}
} else {
const buff = buffer as ArrayBuffer;
const { gl } = device;
Expand Down Expand Up @@ -2590,83 +2584,7 @@ export function WebGLCmdFuncDraw (device: WebGLDevice, drawInfo: Readonly<DrawIn

if (gpuInputAssembler) {
const indexBuffer = gpuInputAssembler.gpuIndexBuffer;
if (gpuInputAssembler.gpuIndirectBuffer) {
const indirects = gpuInputAssembler.gpuIndirectBuffer.indirects;
if (indirects.drawByIndex) {
for (let j = 0; j < indirects.drawCount; j++) {
indirects.byteOffsets[j] = indirects.offsets[j] * indexBuffer!.stride;
}
if (md) {
if (indirects.instancedDraw) {
md.multiDrawElementsInstancedWEBGL(
glPrimitive,
indirects.counts,
0,
gpuInputAssembler.glIndexType,
indirects.byteOffsets,
0,
indirects.instances,
0,
indirects.drawCount,
);
} else {
md.multiDrawElementsWEBGL(
glPrimitive,
indirects.counts,
0,
gpuInputAssembler.glIndexType,
indirects.byteOffsets,
0,
indirects.drawCount,
);
}
} else {
for (let j = 0; j < indirects.drawCount; j++) {
if (indirects.instances[j] && ia) {
ia.drawElementsInstancedANGLE(
glPrimitive,
indirects.counts[j],
gpuInputAssembler.glIndexType,
indirects.byteOffsets[j],
indirects.instances[j],
);
} else {
gl.drawElements(glPrimitive, indirects.counts[j], gpuInputAssembler.glIndexType, indirects.byteOffsets[j]);
}
}
}
} else if (md) {
if (indirects.instancedDraw) {
md.multiDrawArraysInstancedWEBGL(
glPrimitive,
indirects.offsets,
0,
indirects.counts,
0,
indirects.instances,
0,
indirects.drawCount,
);
} else {
md.multiDrawArraysWEBGL(
glPrimitive,
indirects.offsets,
0,
indirects.counts,
0,
indirects.drawCount,
);
}
} else {
for (let j = 0; j < indirects.drawCount; j++) {
if (indirects.instances[j] && ia) {
ia.drawArraysInstancedANGLE(glPrimitive, indirects.offsets[j], indirects.counts[j], indirects.instances[j]);
} else {
gl.drawArrays(glPrimitive, indirects.offsets[j], indirects.counts[j]);
}
}
}
} else if (drawInfo.instanceCount && ia) {
if (drawInfo.instanceCount && ia) {
if (indexBuffer) {
if (drawInfo.indexCount > 0) {
const offset = drawInfo.firstIndex * indexBuffer.stride;
Expand Down
24 changes: 14 additions & 10 deletions cocos/gfx/webgl/webgl-gpu-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export interface IWebGLGPUBuffer {

buffer: ArrayBufferView | null;
vf32: Float32Array | null;
indirects: WebGLIndirectDrawInfos;
}

export interface IWebGLGPUTexture {
Expand Down Expand Up @@ -309,7 +308,6 @@ export interface IWebGLGPUInputAssembler {
attributes: Attribute[];
gpuVertexBuffers: IWebGLGPUBuffer[];
gpuIndexBuffer: IWebGLGPUBuffer | null;
gpuIndirectBuffer: IWebGLGPUBuffer | null;

glAttribs: IWebGLAttrib[];
glIndexType: GLenum;
Expand Down Expand Up @@ -341,12 +339,16 @@ export class IWebGLBlitManager {
this._gpuShader = {
name: 'Blit Pass',
blocks: [
new UniformBlock(0, 0, `BlitParams`,
new UniformBlock(
0,
0,
`BlitParams`,
[
new Uniform(`tilingOffsetSrc`, Type.FLOAT4, 1),
new Uniform(`tilingOffsetDst`, Type.FLOAT4, 1),
],
1),
1,
),
],
samplerTextures: [new UniformSamplerTexture(0, samplerOffset, 'textureSrc', Type.SAMPLER2D, 1)],
subpassInputs: [],
Expand Down Expand Up @@ -430,7 +432,6 @@ export class IWebGLBlitManager {
stride: 4 * Float32Array.BYTES_PER_ELEMENT,
buffer: null,
vf32: null,
indirects: new WebGLIndirectDrawInfos(),
glTarget: 0,
glBuffer: null,
};
Expand All @@ -448,7 +449,6 @@ export class IWebGLBlitManager {
attributes: [new Attribute(`a_position`, Format.RG32F), new Attribute(`a_texCoord`, Format.RG32F)],
gpuVertexBuffers: [this._gpuVertexBuffer],
gpuIndexBuffer: null,
gpuIndirectBuffer: null,

glAttribs: [],
glIndexType: 0,
Expand Down Expand Up @@ -480,7 +480,6 @@ export class IWebGLBlitManager {
stride: 8 * Float32Array.BYTES_PER_ELEMENT,
buffer: this._uniformBuffer,
vf32: null,
indirects: new WebGLIndirectDrawInfos(),
glTarget: 0,
glBuffer: null,
};
Expand Down Expand Up @@ -538,7 +537,7 @@ export class IWebGLBlitManager {
descriptor.gpuSampler = filter === Filter.POINT ? this._gpuPointSampler : this._gpuLinearSampler;

const formatInfo = FormatInfos[gpuTextureDst.format];
let attachment = gl.COLOR_ATTACHMENT0;
let attachment: number = gl.COLOR_ATTACHMENT0;
if (formatInfo.hasStencil) {
attachment = gl.DEPTH_STENCIL_ATTACHMENT;
} else if (formatInfo.hasDepth) {
Expand Down Expand Up @@ -582,8 +581,13 @@ export class IWebGLBlitManager {
this._uniformBuffer[6] = region.dstOffset.x / dstWidth;
this._uniformBuffer[7] = region.dstOffset.y / dstHeight;

WebGLCmdFuncUpdateBuffer(device, this._gpuUniformBuffer, this._uniformBuffer, 0,
this._uniformBuffer.length * Float32Array.BYTES_PER_ELEMENT);
WebGLCmdFuncUpdateBuffer(
device,
this._gpuUniformBuffer,
this._uniformBuffer,
0,
this._uniformBuffer.length * Float32Array.BYTES_PER_ELEMENT,
);
WebGLCmdFuncBindStates(device, this._gpuPipelineState, this._gpuInputAssembler, [this._gpuDescriptorSet], [], null!);
WebGLCmdFuncDraw(device, this._drawInfo);
}
Expand Down
13 changes: 3 additions & 10 deletions cocos/gfx/webgl/webgl-input-assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
THE SOFTWARE.
*/

import { error } from '../../core/platform';
import { InputAssemblerInfo } from '../base/define';
import { InputAssembler } from '../base/input-assembler';
import { WebGLBuffer } from './webgl-buffer';
Expand All @@ -38,7 +39,7 @@ export class WebGLInputAssembler extends InputAssembler {

public initialize (info: Readonly<InputAssemblerInfo>): void {
if (info.vertexBuffers.length === 0) {
console.error('InputAssemblerInfo.vertexBuffers is null.');
error('InputAssemblerInfo.vertexBuffers is null.');
return;
}

Expand All @@ -59,8 +60,6 @@ export class WebGLInputAssembler extends InputAssembler {
this._drawInfo.instanceCount = 0;
this._drawInfo.firstInstance = 0;

this._indirectBuffer = info.indirectBuffer || null;

const gpuVertexBuffers: IWebGLGPUBuffer[] = new Array<IWebGLGPUBuffer>(info.vertexBuffers.length);
for (let i = 0; i < info.vertexBuffers.length; ++i) {
const vb = info.vertexBuffers[i] as WebGLBuffer;
Expand All @@ -79,22 +78,16 @@ export class WebGLInputAssembler extends InputAssembler {
case 2: glIndexType = 0x1403; break; // WebGLRenderingContext.UNSIGNED_SHORT
case 4: glIndexType = 0x1405; break; // WebGLRenderingContext.UNSIGNED_INT
default: {
console.error('Error index buffer stride.');
error('Error index buffer stride.');
}
}
}
}

let gpuIndirectBuffer: IWebGLGPUBuffer | null = null;
if (info.indirectBuffer) {
gpuIndirectBuffer = (info.indirectBuffer as WebGLBuffer).gpuBuffer;
}

this._gpuInputAssembler = {
attributes: info.attributes,
gpuVertexBuffers,
gpuIndexBuffer,
gpuIndirectBuffer,

glAttribs: [],
glIndexType,
Expand Down
Loading
Loading