Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Babylon.js Platform committed Feb 8, 2025
2 parents 1f6b80a + 4d9cbe5 commit df8e0da
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/dev/core/src/Engines/Native/nativeInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export type NativeVertexArrayObject = NativeData;
export type NativeProgram = NativeData;
export type NativeUniform = NativeData;

/** @internal */
export type NativeFrameStats = {
/** @internal */
gpuTimeNs: number;
};

/** @internal */
export interface INativeEngine {
dispose(): void;
Expand Down Expand Up @@ -97,6 +103,8 @@ export interface INativeEngine {

setCommandDataStream(dataStream: NativeDataStream): void;
submitCommands(): void;

populateFrameStats?(stats: NativeFrameStats): void;
}

/** @internal */
Expand Down
31 changes: 29 additions & 2 deletions packages/dev/core/src/Engines/nativeEngine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { Nullable, IndicesArray, DataArray, FloatArray, DeepImmutable } from "../types";
import type { Nullable, IndicesArray, DataArray, FloatArray, DeepImmutable, int } from "../types";
import { Engine } from "../Engines/engine";
import type { VertexBuffer } from "../Buffers/buffer";
import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture";
Expand Down Expand Up @@ -33,7 +33,17 @@ import type { IStencilState } from "../States/IStencilState";
import type { RenderTargetWrapper } from "./renderTargetWrapper";
import type { NativeData } from "./Native/nativeDataStream";
import { NativeDataStream } from "./Native/nativeDataStream";
import type { INative, INativeCamera, INativeEngine, NativeFramebuffer, NativeProgram, NativeTexture, NativeUniform, NativeVertexArrayObject } from "./Native/nativeInterfaces";
import type {
INative,
INativeCamera,
INativeEngine,
NativeFramebuffer,
NativeFrameStats,
NativeProgram,
NativeTexture,
NativeUniform,
NativeVertexArrayObject,
} from "./Native/nativeInterfaces";
import { NativePipelineContext } from "./Native/nativePipelineContext";
import { NativeRenderTargetWrapper } from "./Native/nativeRenderTargetWrapper";
import { NativeHardwareTexture } from "./Native/nativeHardwareTexture";
Expand All @@ -57,6 +67,7 @@ import type { WebGLHardwareTexture } from "./WebGL/webGLHardwareTexture";

import "../Buffers/buffer.align";
import { _GetCompatibleTextureLoader } from "core/Materials/Textures/Loaders/textureLoaderManager";
import { _TimeToken } from "../Instrumentation/timeToken";

// REVIEW: add a flag to effect to prevent multiple compilations of the same shader.
declare module "../Materials/effect" {
Expand Down Expand Up @@ -219,6 +230,8 @@ export class NativeEngine extends Engine {

private readonly _commandBufferEncoder = new CommandBufferEncoder(this._engine);

private readonly _frameStats: NativeFrameStats = { gpuTimeNs: Number.NaN };

private _boundBuffersVertexArray: any = null;
private _currentDepthTest: number = _native.Engine.DEPTH_TEST_LEQUAL;
private _stencilTest = false;
Expand Down Expand Up @@ -2704,4 +2717,18 @@ export class NativeEngine extends Engine {
return buffer;
});
}

override startTimeQuery(): Nullable<_TimeToken> {
if (!this._gpuFrameTimeToken) {
this._gpuFrameTimeToken = new _TimeToken();
}

// Always return the same time token. For native, we don't need a start marker, we just query for native frame stats.
return this._gpuFrameTimeToken;
}

override endTimeQuery(token: _TimeToken): int {
this._engine.populateFrameStats?.(this._frameStats);
return this._frameStats.gpuTimeNs;
}
}

0 comments on commit df8e0da

Please sign in to comment.