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

Additional performance markers & small code cleanup #4251

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions examples/src/examples/graphics/render-to-texture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class RenderToTextureExample {
addressV: pc.ADDRESS_CLAMP_TO_EDGE
});
const renderTarget = new pc.RenderTarget({
name: `RT`,
colorBuffer: texture,
depth: true,
flipY: true,
Expand Down
9 changes: 9 additions & 0 deletions src/graphics/webgl/webgl-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
* {@link GraphicsDevice#updateEnd} must not be nested.
*/
updateBegin() {
DebugGraphics.pushGpuMarker(this, `UPDATE-BEGIN`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to shout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah .. I've decided to use capital letters for engine commands (BLIT, RESOLVE, PICKER) and similar. And use whatever user provides for Camera / Entity names as currently (usually camel syntax), to make them more distinct and cleaner in SpectorJS capture.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻


this.boundVao = null;

// clear texture units once a frame on desktop safari
Expand All @@ -1266,6 +1268,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
} else {
this.setFramebuffer(this.defaultFramebuffer);
}

DebugGraphics.popGpuMarker(this);
}

/**
Expand All @@ -1274,6 +1278,9 @@ class WebglGraphicsDevice extends GraphicsDevice {
* {@link GraphicsDevice#updateEnd} must not be nested.
*/
updateEnd() {

DebugGraphics.pushGpuMarker(this, `UPDATE-END`);

const gl = this.gl;

// unbind VAO from device to protect it from being changed
Expand All @@ -1300,6 +1307,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
target.resolve();
}
}

DebugGraphics.popGpuMarker(this);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export { SortedLoopArray } from './core/sorted-loop-array.js';
export { Tags } from './core/tags.js';
export { Timer, now } from './core/time.js';
export { URI, createURI } from './core/uri.js';
export { Debug } from './core/debug.js';

// NET
export { http, Http } from './net/http.js';
Expand Down
8 changes: 4 additions & 4 deletions src/scene/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Material } from './materials/material.js';

/** @typedef {import('../framework/components/camera/component.js').CameraComponent} CameraComponent */
/** @typedef {import('../framework/components/light/component.js').LightComponent} LightComponent */
/** @typedef {import('../graphics/render-target.js').RenderTarget} RenderTarget */
/** @typedef {import('./graph-node.js').GraphNode} GraphNode */
/** @typedef {import('./light.js').Light} Light */
/** @typedef {import('./mesh-instance.js').MeshInstance} MeshInstance */
Expand Down Expand Up @@ -175,7 +174,9 @@ class Layer {
*/
this.transparentSortMode = options.transparentSortMode === undefined ? SORTMODE_BACK2FRONT : options.transparentSortMode;

this.renderTarget = options.renderTarget;
if (options.renderTarget) {
this.renderTarget = options.renderTarget;
}

/**
* A type of shader to use during rendering. Possible values are:
Expand Down Expand Up @@ -269,8 +270,7 @@ class Layer {
this.onPostCull = options.onPostCull;
/**
* Custom function that is called after this layer is rendered. Useful to revert changes
* made in {@link Layer#onPreRender} or performing some processing on
* {@link Layer#renderTarget}. This function is called after the last occurrence of this
* made in {@link Layer#onPreRender}. This function is called after the last occurrence of this
* layer in {@link LayerComposition}. It will receive camera index as the only argument.
* You can get the actual camera being used by looking up {@link LayerComposition#cameras}
* with this index.
Expand Down
5 changes: 5 additions & 0 deletions src/scene/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ADDRESS_CLAMP_TO_EDGE, CLEARFLAG_DEPTH, FILTER_NEAREST, PIXELFORMAT_R8_
import { GraphicsDevice } from '../graphics/graphics-device.js';
import { RenderTarget } from '../graphics/render-target.js';
import { Texture } from '../graphics/texture.js';
import { DebugGraphics } from '../graphics/debug-graphics.js';

import { SHADER_PICK, SORTMODE_NONE } from './constants.js';
import { Camera } from './camera.js';
Expand Down Expand Up @@ -119,6 +120,8 @@ class Picker {
// backup active render target
const origRenderTarget = device.renderTarget;

DebugGraphics.pushGpuMarker(device, 'PICKER');

// Ready the device for rendering to the pick buffer
device.setRenderTarget(this.renderTarget);
device.updateBegin();
Expand All @@ -131,6 +134,8 @@ class Picker {
// Restore render target
device.setRenderTarget(origRenderTarget);

DebugGraphics.popGpuMarker(device);

const mapping = this.mapping;
for (let i = 0; i < width * height; i++) {
const r = pixels[4 * i + 0];
Expand Down
5 changes: 5 additions & 0 deletions src/scene/renderer/forward-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,10 @@ class ForwardRenderer {
}

clearView(camera, target, clear, forceWrite, options) {

const device = this.device;
DebugGraphics.pushGpuMarker(device, 'CLEAR-VIEW');

device.setRenderTarget(target);
device.updateBegin();

Expand Down Expand Up @@ -424,6 +427,8 @@ class ForwardRenderer {
stencil: camera._clearStencil
});
}

DebugGraphics.popGpuMarker(device);
}

dispatchGlobalLights(scene) {
Expand Down