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 pipeline #15875

Merged
merged 9 commits into from
Aug 9, 2023
54 changes: 36 additions & 18 deletions cocos/core/geometry/intersect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
* @param plane @zh 要测试的平面。 @en The plane to test.
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
*/
const rayPlane = (function () {

Check warning on line 52 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return function (ray: Ray, plane: Plane): number {

Check warning on line 53 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
const denom = Vec3.dot(ray.d, plane.n);
if (Math.abs(denom) < Number.EPSILON) { return 0; }
const d = distance.point_plane(ray.o, plane);
Expand All @@ -71,14 +71,14 @@
* @param doubleSided @zh 要测试的三角形是否为双面。 @en Indicates whether the triangle to test is double sided.
* @returns @zh 0 或 非 0,0 表示没有相交。@en 0 or not 0, 0 indicates there is no intersection.
*/
const rayTriangle = (function (): (ray: Ray, triangle: Triangle, doubleSided?: boolean) => number {

Check warning on line 74 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
const ab = new Vec3(0, 0, 0);
const ac = new Vec3(0, 0, 0);
const pvec = new Vec3(0, 0, 0);
const tvec = new Vec3(0, 0, 0);
const qvec = new Vec3(0, 0, 0);

return function (ray: Ray, triangle: Triangle, doubleSided?: boolean): number {

Check warning on line 81 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
Vec3.subtract(ab, triangle.b, triangle.a);
Vec3.subtract(ac, triangle.c, triangle.a);

Expand Down Expand Up @@ -116,9 +116,9 @@
* @param sphere @zh 要测试的球。 @en The sphere to test.
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
*/
const raySphere = (function (): (ray: Ray, sphere: Sphere) => number {

Check warning on line 119 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
const e = new Vec3(0, 0, 0);
return function (ray: Ray, sphere: Sphere): number {

Check warning on line 121 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
const r = sphere.radius;
const c = sphere.center;
const o = ray.o;
Expand Down Expand Up @@ -147,10 +147,10 @@
* @param aabb @zh 要测试的 AABB。 @en The aabb to test.
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
*/
const rayAABB = (function (): (ray: Ray, aabb: AABB) => number {

Check warning on line 150 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
const min = new Vec3();
const max = new Vec3();
return function (ray: Ray, aabb: AABB): number {

Check warning on line 153 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
Vec3.subtract(min, aabb.center, aabb.halfExtents);
Vec3.add(max, aabb.center, aabb.halfExtents);
return rayAABB2(ray, min, max);
Expand Down Expand Up @@ -181,7 +181,7 @@
* @param obb @zh 要测试的 OBB。 @en The OBB to test.
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
*/
const rayOBB = (function (): (ray: Ray, obb: OBB) => number {

Check warning on line 184 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
let center = new Vec3();
let o = new Vec3();
let d = new Vec3();
Expand All @@ -194,7 +194,7 @@
const e = new Array<number>(3);
const t = new Array<number>(6);

return function (ray: Ray, obb: OBB): number {

Check warning on line 197 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
size[0] = obb.halfExtents.x;
size[1] = obb.halfExtents.y;
size[2] = obb.halfExtents.z;
Expand Down Expand Up @@ -413,10 +413,12 @@
const u = 1.0 - v - w;

// outPt = u*a + v*d + w*c;
Vec3.set(outPt,
Vec3.set(
outPt,
triangle.a.x * u + triangle.b.x * v + triangle.c.x * w,
triangle.a.y * u + triangle.b.y * v + triangle.c.y * w,
triangle.a.z * u + triangle.b.z * v + triangle.c.z * w);
triangle.a.z * u + triangle.b.z * v + triangle.c.z * w,
);
}

return 1;
Expand Down Expand Up @@ -527,44 +529,60 @@
}

function getOBBVertices (c: Vec3, e: Vec3, a1: Vec3, a2: Vec3, a3: Vec3, out: Vec3[]): void {
Vec3.set(out[0],
Vec3.set(
out[0],
c.x + a1.x * e.x + a2.x * e.y + a3.x * e.z,
c.y + a1.y * e.x + a2.y * e.y + a3.y * e.z,
c.z + a1.z * e.x + a2.z * e.y + a3.z * e.z);
Vec3.set(out[1],
c.z + a1.z * e.x + a2.z * e.y + a3.z * e.z,
);
Vec3.set(
out[1],
c.x - a1.x * e.x + a2.x * e.y + a3.x * e.z,
c.y - a1.y * e.x + a2.y * e.y + a3.y * e.z,
c.z - a1.z * e.x + a2.z * e.y + a3.z * e.z);
Vec3.set(out[2],
c.z - a1.z * e.x + a2.z * e.y + a3.z * e.z,
);
Vec3.set(
out[2],
c.x + a1.x * e.x - a2.x * e.y + a3.x * e.z,
c.y + a1.y * e.x - a2.y * e.y + a3.y * e.z,
c.z + a1.z * e.x - a2.z * e.y + a3.z * e.z);
Vec3.set(out[3],
c.z + a1.z * e.x - a2.z * e.y + a3.z * e.z,
);
Vec3.set(
out[3],
c.x + a1.x * e.x + a2.x * e.y - a3.x * e.z,
c.y + a1.y * e.x + a2.y * e.y - a3.y * e.z,
c.z + a1.z * e.x + a2.z * e.y - a3.z * e.z);
Vec3.set(out[4],
c.z + a1.z * e.x + a2.z * e.y - a3.z * e.z,
);
Vec3.set(
out[4],
c.x - a1.x * e.x - a2.x * e.y - a3.x * e.z,
c.y - a1.y * e.x - a2.y * e.y - a3.y * e.z,
c.z - a1.z * e.x - a2.z * e.y - a3.z * e.z);
Vec3.set(out[5],
c.z - a1.z * e.x - a2.z * e.y - a3.z * e.z,
);
Vec3.set(
out[5],
c.x + a1.x * e.x - a2.x * e.y - a3.x * e.z,
c.y + a1.y * e.x - a2.y * e.y - a3.y * e.z,
c.z + a1.z * e.x - a2.z * e.y - a3.z * e.z);
Vec3.set(out[6],
c.z + a1.z * e.x - a2.z * e.y - a3.z * e.z,
);
Vec3.set(
out[6],
c.x - a1.x * e.x + a2.x * e.y - a3.x * e.z,
c.y - a1.y * e.x + a2.y * e.y - a3.y * e.z,
c.z - a1.z * e.x + a2.z * e.y - a3.z * e.z);
Vec3.set(out[7],
c.z - a1.z * e.x + a2.z * e.y - a3.z * e.z,
);
Vec3.set(
out[7],
c.x - a1.x * e.x - a2.x * e.y + a3.x * e.z,
c.y - a1.y * e.x - a2.y * e.y + a3.y * e.z,
c.z - a1.z * e.x - a2.z * e.y + a3.z * e.z);
c.z - a1.z * e.x - a2.z * e.y + a3.z * e.z,
);
}

function getInterval (vertices: any[] | Vec3[], axis: Vec3): number[] {
let min = Vec3.dot(axis, vertices[0]); let max = min;

Check failure on line 583 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`
for (let i = 1; i < 8; ++i) {
const projection = Vec3.dot(axis, vertices[i]);

Check failure on line 585 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`
min = (projection < min) ? projection : min;
max = (projection > max) ? projection : max;
}
Expand Down Expand Up @@ -602,15 +620,15 @@
Vec3.set(test[5], obb.orientation.m06, obb.orientation.m07, obb.orientation.m08);

for (let i = 0; i < 3; ++i) { // Fill out rest of axis
Vec3.cross(test[6 + i * 3 + 0], test[i], test[3]);

Check failure on line 623 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`

Check failure on line 623 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`
Vec3.cross(test[6 + i * 3 + 1], test[i], test[4]);

Check failure on line 624 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`

Check failure on line 624 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`
Vec3.cross(test[6 + i * 3 + 1], test[i], test[5]);

Check failure on line 625 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`

Check failure on line 625 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `IVec3Like`
}

Vec3.subtract(min, aabb.center, aabb.halfExtents);
Vec3.add(max, aabb.center, aabb.halfExtents);
getAABBVertices(min, max, vertices);

Check failure on line 630 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any[]` assigned to a parameter of type `Vec3[]`
getOBBVertices(obb.center, obb.halfExtents, test[3], test[4], test[5], vertices2);

Check failure on line 631 in cocos/core/geometry/intersect.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Vec3`

for (let j = 0; j < 15; ++j) {
const a = getInterval(vertices, test[j]);
Expand Down
3 changes: 2 additions & 1 deletion 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.
LAZILY_ALLOCATED = 0x10, // Try lazily allocated mode.
MUTABLE_VIEW_FORMAT = 0x40, // texture view as different format
}

export enum FormatFeatureBit {
Expand Down
39 changes: 31 additions & 8 deletions cocos/render-scene/scene/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,14 +1032,33 @@ export class Camera {
const wndXREye = xr.webXRWindowMap.get(this._window);
this._matProj.set(xr.webXRMatProjs[wndXREye]);
} else {
Mat4.perspective(this._matProj, this._fov, this._aspect, this._nearClip, this._farClip,
this._fovAxis === CameraFOVAxis.VERTICAL, this._device.capabilities.clipSpaceMinZ, projectionSignY, orientation);
Mat4.perspective(
this._matProj,
this._fov,
this._aspect,
this._nearClip,
this._farClip,
this._fovAxis === CameraFOVAxis.VERTICAL,
this._device.capabilities.clipSpaceMinZ,
projectionSignY,
orientation,
);
}
} else {
const x = this._orthoHeight * this._aspect;
const y = this._orthoHeight;
Mat4.ortho(this._matProj, -x, x, -y, y, this._nearClip, this._farClip,
this._device.capabilities.clipSpaceMinZ, projectionSignY, orientation);
Mat4.ortho(
this._matProj,
-x,
x,
-y,
y,
this._nearClip,
this._farClip,
this._device.capabilities.clipSpaceMinZ,
projectionSignY,
orientation,
);
}
Mat4.invert(this._matProjInv, this._matProj);
viewProjDirty = true;
Expand Down Expand Up @@ -1240,10 +1259,12 @@ export class Camera {

if (this._proj === CameraProjection.PERSPECTIVE) {
// calculate screen pos in far clip plane
Vec3.set(out,
Vec3.set(
out,
(screenPos.x - cx) / cw * 2 - 1,
(screenPos.y - cy) / ch * 2 - 1,
1.0);
1.0,
);

// transform to world
const { x, y } = out;
Expand All @@ -1256,10 +1277,12 @@ export class Camera {

Vec3.lerp(out, v_a, out, lerp(this._nearClip / this._farClip, 1, screenPos.z));
} else {
Vec3.set(out,
Vec3.set(
out,
(screenPos.x - cx) / cw * 2 - 1,
(screenPos.y - cy) / ch * 2 - 1,
screenPos.z * 2 - 1);
screenPos.z * 2 - 1,
);

// transform to world
const { x, y } = out;
Expand Down
118 changes: 54 additions & 64 deletions cocos/rendering/custom/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,68 +32,50 @@ import { Blit, ClearView, ComputePass, ComputeSubpass, CopyPass, Dispatch, Forma
RasterPass, RasterSubpass, RaytracePass, RenderGraph, RenderGraphVisitor, RasterView, ComputeView,
RenderQueue, RenderSwapchain, ResolvePass, ResourceGraph, ResourceGraphVisitor, SceneData, SubresourceView } from './render-graph';
import { AccessType, ResourceResidency, SceneFlags } from './types';
import { hashCombineNum, hashCombineStr } from './define';

let hashCode = 0;

function hashCombine (hash): void {
hashCode ^= (hash >>> 0) + 0x9e3779b9 + (hashCode << 6) + (hashCode >> 2);
}

function hashCombineNum (val: number): void {
const hash = 5381;
hashCombine((hash * 33) ^ val);
}

function hashCombineStr (str: string): void {
// DJB2 HASH
let hash = 5381;
for (let i = 0; i < str.length; i++) {
hash = (hash * 33) ^ str.charCodeAt(i);
}
hashCombine(hash);
}
function genHashValue (pass: RasterPass): void {
hashCode = 0;
let hashCode = 0;
for (const [name, raster] of pass.rasterViews) {
hashCombineStr('raster');
hashCombineStr(name);
hashCombineStr(raster.slotName);
hashCombineNum(raster.accessType);
hashCombineNum(raster.attachmentType);
hashCombineNum(raster.loadOp);
hashCombineNum(raster.storeOp);
hashCombineNum(raster.clearFlags);
hashCombineNum(raster.clearColor.x);
hashCombineNum(raster.clearColor.y);
hashCombineNum(raster.clearColor.z);
hashCombineNum(raster.clearColor.w);
hashCombineNum(raster.slotID);
hashCombineNum(raster.shaderStageFlags);
hashCode = hashCombineStr('raster', hashCode);
hashCode = hashCombineStr(name, hashCode);
hashCode = hashCombineStr(raster.slotName, hashCode);
hashCode = hashCombineNum(raster.accessType, hashCode);
hashCode = hashCombineNum(raster.attachmentType, hashCode);
hashCode = hashCombineNum(raster.loadOp, hashCode);
hashCode = hashCombineNum(raster.storeOp, hashCode);
hashCode = hashCombineNum(raster.clearFlags, hashCode);
hashCode = hashCombineNum(raster.clearColor.x, hashCode);
hashCode = hashCombineNum(raster.clearColor.y, hashCode);
hashCode = hashCombineNum(raster.clearColor.z, hashCode);
hashCode = hashCombineNum(raster.clearColor.w, hashCode);
hashCode = hashCombineNum(raster.slotID, hashCode);
hashCode = hashCombineNum(raster.shaderStageFlags, hashCode);
}
for (const [name, computes] of pass.computeViews) {
hashCombineStr(name);
hashCode = hashCombineStr(name, hashCode);
for (const compute of computes) {
hashCombineStr('compute');
hashCombineStr(compute.name);
hashCombineNum(compute.accessType);
hashCombineNum(compute.clearFlags);
hashCombineNum(compute.clearValueType);
hashCombineNum(compute.clearValue.x);
hashCombineNum(compute.clearValue.y);
hashCombineNum(compute.clearValue.z);
hashCombineNum(compute.clearValue.w);
hashCombineNum(compute.shaderStageFlags);
hashCode = hashCombineStr('compute', hashCode);
hashCode = hashCombineStr(compute.name, hashCode);
hashCode = hashCombineNum(compute.accessType, hashCode);
hashCode = hashCombineNum(compute.clearFlags, hashCode);
hashCode = hashCombineNum(compute.clearValueType, hashCode);
hashCode = hashCombineNum(compute.clearValue.x, hashCode);
hashCode = hashCombineNum(compute.clearValue.y, hashCode);
hashCode = hashCombineNum(compute.clearValue.z, hashCode);
hashCode = hashCombineNum(compute.clearValue.w, hashCode);
hashCode = hashCombineNum(compute.shaderStageFlags, hashCode);
}
}
hashCombineNum(pass.width);
hashCombineNum(pass.height);
hashCombineNum(pass.viewport.left);
hashCombineNum(pass.viewport.top);
hashCombineNum(pass.viewport.width);
hashCombineNum(pass.viewport.height);
hashCombineNum(pass.viewport.minDepth);
hashCombineNum(pass.viewport.maxDepth);
hashCombineNum(pass.showStatistics ? 1 : 0);
hashCode = hashCombineNum(pass.width, hashCode);
hashCode = hashCombineNum(pass.height, hashCode);
hashCode = hashCombineNum(pass.viewport.left, hashCode);
hashCode = hashCombineNum(pass.viewport.top, hashCode);
hashCode = hashCombineNum(pass.viewport.width, hashCode);
hashCode = hashCombineNum(pass.viewport.height, hashCode);
hashCode = hashCombineNum(pass.viewport.minDepth, hashCode);
hashCode = hashCombineNum(pass.viewport.maxDepth, hashCode);
hashCode = hashCombineNum(pass.showStatistics ? 1 : 0, hashCode);
pass.hashValue = hashCode;
}

Expand Down Expand Up @@ -157,8 +139,10 @@ class PassVisitor implements RenderGraphVisitor {
isPreRaster = true;
// TODO: Shadow map is rather special, as it will be merged into one pass later, and then this determination can be removed.
if (!this._isShadowMap(this.sceneID)) {
assert(currRaster.loadOp === LoadOp.LOAD,
`The resource with name ${input} is being used, and the pass that uses this resource must have loadOp set to 'load'`);
assert(
currRaster.loadOp === LoadOp.LOAD,
`The resource with name ${input} is being used, and the pass that uses this resource must have loadOp set to 'load'`,
);
}
}
}
Expand Down Expand Up @@ -287,7 +271,7 @@ class PassVisitor implements RenderGraphVisitor {
this._currPass = value;
const outputId = this.resID;
const outputName = resourceGraph.vertexName(outputId);
let vertID;
let vertID: number;
for (const pair of value.copyPairs) {
if (pair.target === outputName) {
rg.setValid(this.passID, true);
Expand Down Expand Up @@ -345,7 +329,7 @@ class PassManagerVisitor extends DefaultVisitor {
class ResourceVisitor implements ResourceGraphVisitor {
private readonly _context: CompilerContext;
public resID = 0xFFFFFFFF;
private _passManagerVis;
private _passManagerVis!: PassManagerVisitor;
constructor (context: CompilerContext) {
this._context = context;
}
Expand Down Expand Up @@ -392,10 +376,12 @@ class ResourceUseContext {
computes: Map<number, [ComputeView[]]> = new Map<number, [ComputeView[]]>();
}
class CompilerContext {
set (pipeline: BasicPipeline,
set (
pipeline: BasicPipeline,
resGraph: ResourceGraph,
renderGraph: RenderGraph,
layoutGraph: LayoutGraphData): void {
layoutGraph: LayoutGraphData,
): void {
this.pipeline = pipeline;
this.resourceGraph = resGraph;
this.renderGraph = renderGraph;
Expand All @@ -417,10 +403,12 @@ export class Compiler {
private _pipeline: BasicPipeline;
private _layoutGraph: LayoutGraphData;
private _visitor: ResourceManagerVisitor;
constructor (pipeline: BasicPipeline,
constructor (
pipeline: BasicPipeline,
renderGraph: RenderGraph,
resGraph: ResourceGraph,
layoutGraph: LayoutGraphData) {
layoutGraph: LayoutGraphData,
) {
this._pipeline = pipeline;
this._resourceGraph = resGraph;
this._layoutGraph = layoutGraph;
Expand All @@ -447,8 +435,10 @@ export class Compiler {
const firstRaster = use.rasters.get(min)!;
switch (trait.residency) {
case ResourceResidency.PERSISTENT:
assert(firstRaster.loadOp !== LoadOp.DISCARD,
`The loadOp for persistent resources in the top-level pass cannot be set to 'discard'.`);
assert(
firstRaster.loadOp !== LoadOp.DISCARD,
`The loadOp for persistent resources in the top-level pass cannot be set to 'discard'.`,
);
break;
case ResourceResidency.MANAGED:
assert(firstRaster.loadOp === LoadOp.CLEAR, `The loadOp for Managed resources in the top-level pass can only be set to 'clear'.`);
Expand Down
Loading
Loading