Skip to content

Commit

Permalink
Try to make optimization comparisons as far as possible
Browse files Browse the repository at this point in the history
by requesting high-performance on both and turning on antialiasing
and alpha on WebGL.
  • Loading branch information
greggman committed Jun 27, 2024
1 parent 4d63b55 commit 7128d8d
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 16 deletions.
8 changes: 6 additions & 2 deletions webgpu/lessons/webgpu-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ in general.

```js
async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
powerPreference: 'high-performance',
});
const device = await adapter?.requestDevice();
if (!device) {
fail('need a browser that supports WebGPU');
Expand Down Expand Up @@ -800,7 +802,9 @@ And we'll time our render pass
```js
async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({
powerPreference: 'high-performance',
});
- const device = await adapter?.requestDevice();
+ const canTimestamp = adapter.features.has('timestamp-query');
+ const device = await adapter?.requestDevice({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@

// Get a WebGPU context from the canvas and configure it
const canvas = document.querySelector('canvas');
const gl = canvas.getContext('webgl2');
const gl = canvas.getContext('webgl2', {
alpha: false,
antialias: false,
powerPreference: 'high-performance',
});
const timingHelper = new TimingHelper(gl);

const uniformBlock = `
Expand Down
6 changes: 5 additions & 1 deletion webgpu/webgl-optimization-none-uniform-buffers.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@

// Get a WebGPU context from the canvas and configure it
const canvas = document.querySelector('canvas');
const gl = canvas.getContext('webgl2');
const gl = canvas.getContext('webgl2', {
alpha: false,
antialias: false,
powerPreference: 'high-performance',
});
const timingHelper = new TimingHelper(gl);

const uniformBlock = `
Expand Down
6 changes: 5 additions & 1 deletion webgpu/webgl-optimization-none.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@

// Get a WebGPU context from the canvas and configure it
const canvas = document.querySelector('canvas');
const gl = canvas.getContext('webgl2');
const gl = canvas.getContext('webgl2', {
alpha: false,
antialias: false,
powerPreference: 'high-performance',
});
const timingHelper = new TimingHelper(gl);

const vs = `#version 300 es
Expand Down
6 changes: 5 additions & 1 deletion webgpu/webgl-optimization-uniform-buffers-one-large.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@

// Get a WebGPU context from the canvas and configure it
const canvas = document.querySelector('canvas');
const gl = canvas.getContext('webgl2');
const gl = canvas.getContext('webgl2', {
alpha: false,
antialias: false,
powerPreference: 'high-performance',
});
const timingHelper = new TimingHelper(gl);

const uniformBlock = `
Expand Down
2 changes: 1 addition & 1 deletion webgpu/webgpu-optimization-none.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
const randomArrayElement = arr => arr[Math.random() * arr.length | 0];

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
const randomArrayElement = arr => arr[Math.random() * arr.length | 0];

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
2 changes: 1 addition & 1 deletion webgpu/webgpu-optimization-step4-material-uniforms.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
const randomArrayElement = arr => arr[Math.random() * arr.length | 0];

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
2 changes: 1 addition & 1 deletion webgpu/webgpu-optimization-step5-use-buffer-offsets.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
const roundUp = (v, alignment) => Math.ceil(v / alignment) * alignment;

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
const roundUp = (v, alignment) => Math.ceil(v / alignment) * alignment;

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@
const roundUp = (v, alignment) => Math.ceil(v / alignment) * alignment;

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
2 changes: 1 addition & 1 deletion webgpu/webgpu-optimization-step6-use-mapped-buffers.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
const roundUp = (v, alignment) => Math.ceil(v / alignment) * alignment;

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
const roundUp = (v, alignment) => Math.ceil(v / alignment) * alignment;

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
const roundUp = (v, alignment) => Math.ceil(v / alignment) * alignment;

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down
2 changes: 1 addition & 1 deletion webgpu/webgpu-optimization-step7-double-buffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
const roundUp = (v, alignment) => Math.ceil(v / alignment) * alignment;

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const adapter = await navigator.gpu?.requestAdapter({powerPreference: 'high-performance'});
const canTimestamp = adapter.features.has('timestamp-query');
const device = await adapter?.requestDevice({
requiredFeatures: [
Expand Down

0 comments on commit 7128d8d

Please sign in to comment.