Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jun 15, 2024
1 parent 88496f1 commit 9381daa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
8 changes: 4 additions & 4 deletions webgpu/webgl-optimization-none-uniform-buffers-4kplus.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@
format: gl.RGBA,
width: 2,
src: new Uint8Array([
255, 255, 255, 255,
128, 128, 128, 255,
192, 192, 192, 255,
64, 64, 64, 255,
...hslToRGBA8(0, 0, 1),
...hslToRGBA8(0, 0, 0.5),
...hslToRGBA8(0, 0, 0.75),
...hslToRGBA8(0, 0, 0.25),
]),
minMag: gl.NEAREST,
wrap: gl.CLAMP_TO_EDGE,
Expand Down
8 changes: 4 additions & 4 deletions webgpu/webgl-optimization-none-uniform-buffers-8k.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@
format: gl.RGBA,
width: 2,
src: new Uint8Array([
255, 255, 255, 255,
128, 128, 128, 255,
192, 192, 192, 255,
64, 64, 64, 255,
...hslToRGBA8(0, 0, 1),
...hslToRGBA8(0, 0, 0.5),
...hslToRGBA8(0, 0, 0.75),
...hslToRGBA8(0, 0, 0.25),
]),
minMag: gl.NEAREST,
wrap: gl.CLAMP_TO_EDGE,
Expand Down
8 changes: 4 additions & 4 deletions webgpu/webgl-optimization-none-uniform-buffers.html
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@
format: gl.RGBA,
width: 2,
src: new Uint8Array([
255, 255, 255, 255,
128, 128, 128, 255,
192, 192, 192, 255,
64, 64, 64, 255,
...hslToRGBA8(0, 0, 1),
...hslToRGBA8(0, 0, 0.5),
...hslToRGBA8(0, 0, 0.75),
...hslToRGBA8(0, 0, 0.25),
]),
minMag: gl.NEAREST,
wrap: gl.CLAMP_TO_EDGE,
Expand Down
8 changes: 4 additions & 4 deletions webgpu/webgl-optimization-none.html
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@
format: gl.RGBA,
width: 2,
src: new Uint8Array([
255, 255, 255, 255,
128, 128, 128, 255,
192, 192, 192, 255,
64, 64, 64, 255,
...hslToRGBA8(0, 0, 1),
...hslToRGBA8(0, 0, 0.5),
...hslToRGBA8(0, 0, 0.75),
...hslToRGBA8(0, 0, 0.25),
]),
minMag: gl.NEAREST,
wrap: gl.CLAMP_TO_EDGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
const gpuAverage = new RollingAverage();
const mathAverage = new RollingAverage();

/** Given a css color string, return an array of 4 values from 0 to 255 */
const cssColorToRGBA8 = (() => {
const canvas = new OffscreenCanvas(1, 1);
const ctx = canvas.getContext('2d', {willReadFrequently: true});
Expand All @@ -66,13 +67,31 @@
};
})();

const hsl = (h, s, l) => `hsl(${h * 360 | 0}, ${s * 100}%, ${l * 100 | 0}%)`;
/** Given a css color string, return an array of 4 values from 0 to 1 */
const cssColorToRGBA = cssColor => cssColorToRGBA8(cssColor).map(v => v / 255);
const hslToRGBA = (h, s, l) => cssColorToRGBA(hsl(h, s, l));

// Returns a random number between min and max.
// If min and max are not specified, returns 0 to 1
// If max is not specified, return 0 to min.
/**
* Given hue, saturation, and luminance values in the range of 0 to 1
* return the corresponding CSS hsl string
*/
const hsl = (h, s, l) => `hsl(${h * 360 | 0}, ${s * 100}%, ${l * 100 | 0}%)`;

/**
* Given hue, saturation, and luminance values in the range of 0 to 1
* returns an array of values from 0 to 1
*/
const hslToRGBA = (h, s, l) => cssColorToRGBA(hsl(h, s, l));
/**
* Given hue, saturation, and luminance values in the range of 0 to 1
* returns an array of values from 0 to 255
*/
const hslToRGBA8 = (h, s, l) => cssColorToRGBA8(hsl(h, s, l));

/**
* Returns a random number between min and max.
* If min and max are not specified, returns 0 to 1
* If max is not specified, return 0 to min.
*/
function rand(min, max) {
if (min === undefined) {
max = 1;
Expand All @@ -84,12 +103,12 @@
return Math.random() * (max - min) + min;
}

/** Selects a random array element */
const randomArrayElement = arr => arr[Math.random() * arr.length | 0];

/** Rounds up v to a multiple of alignment */
const roundUp = (v, alignment) => Math.ceil(v / alignment) * alignment;

// Selects a random array element
const randomArrayElement = arr => arr[Math.random() * arr.length | 0];

async function main() {
const adapter = await navigator.gpu?.requestAdapter();
const canTimestamp = adapter.features.has('timestamp-query');
Expand Down

0 comments on commit 9381daa

Please sign in to comment.