Skip to content

Commit 49e0c39

Browse files
committed
oxfmt
1 parent a4aaf98 commit 49e0c39

6 files changed

Lines changed: 36 additions & 64 deletions

File tree

apps/typegpu-docs/src/examples/algorithms/probability/executor.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
randf,
3-
randomGeneratorSlot,
4-
type StatefulGenerator,
5-
} from '@typegpu/noise';
1+
import { randf, randomGeneratorSlot, type StatefulGenerator } from '@typegpu/noise';
62
import type {
73
StorageFlag,
84
TgpuBindGroup,
@@ -28,16 +24,10 @@ export class Executor {
2824
readonly #bindGroupLayout: TgpuBindGroupLayout;
2925
readonly #bufferCache: Map<
3026
number,
31-
[
32-
TgpuBuffer<d.WgslArray<d.Vec3f>> & StorageFlag,
33-
TgpuBuffer<d.WgslArray<d.F32>> & StorageFlag,
34-
]
27+
[TgpuBuffer<d.WgslArray<d.Vec3f>> & StorageFlag, TgpuBuffer<d.WgslArray<d.F32>> & StorageFlag]
3528
>;
3629
// they can be WeakMaps, because we always have reference to distribution and PRNG
37-
readonly #pipelineCache: WeakMap<
38-
TgpuFn,
39-
WeakMap<StatefulGenerator, TgpuComputePipeline>
40-
>;
30+
readonly #pipelineCache: WeakMap<TgpuFn, WeakMap<StatefulGenerator, TgpuComputePipeline>>;
4131

4232
constructor(root: TgpuRoot) {
4333
this.#root = root;
@@ -60,15 +50,12 @@ export class Executor {
6050
const id = input.gid.x;
6151
if (id >= bindGroupLayoutTempAlias.$.samplesBuffer.length) return;
6252
randf.seed(bindGroupLayoutTempAlias.$.seedBuffer[id]);
63-
bindGroupLayoutTempAlias.$.samplesBuffer[id] = distributionSlotTempAlias
64-
.$();
53+
bindGroupLayoutTempAlias.$.samplesBuffer[id] = distributionSlotTempAlias.$();
6554
});
6655
}
6756

6857
reseed() {
69-
this.#seedBuffer.write(
70-
Array.from({ length: this.#count }, () => Math.random()),
71-
);
58+
this.#seedBuffer.write(Array.from({ length: this.#count }, () => Math.random()));
7259
}
7360

7461
set count(value: number) {
@@ -77,8 +64,7 @@ export class Executor {
7764
if (cacheEntry) {
7865
[this.#samplesBuffer, this.#seedBuffer] = cacheEntry;
7966
} else {
80-
this.#samplesBuffer = this.#root.createBuffer(d.arrayOf(d.vec3f, value))
81-
.$usage('storage');
67+
this.#samplesBuffer = this.#root.createBuffer(d.arrayOf(d.vec3f, value)).$usage('storage');
8268
this.#seedBuffer = this.#root
8369
.createBuffer(
8470
d.arrayOf(d.f32, value),
@@ -130,9 +116,7 @@ export class Executor {
130116
): Promise<d.v3f[]> {
131117
const pipeline = this.pipelineCacheGet(distribution, generator);
132118

133-
pipeline.with(this.#bindGroup).dispatchWorkgroups(
134-
Math.ceil(this.#count / 64),
135-
);
119+
pipeline.with(this.#bindGroup).dispatchWorkgroups(Math.ceil(this.#count / 64));
136120

137121
return await this.#samplesBuffer.read();
138122
}

apps/typegpu-docs/src/examples/algorithms/probability/helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,4 @@ const GENERATOR_MAP = {
100100
[Generator.LCG]: LCG,
101101
};
102102

103-
export const getGenerator = (gen: Generator): StatefulGenerator =>
104-
GENERATOR_MAP[gen];
103+
export const getGenerator = (gen: Generator): StatefulGenerator => GENERATOR_MAP[gen];

apps/typegpu-docs/src/examples/algorithms/probability/index.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,19 @@ export const controls = defineControls({
7070
Reseed: {
7171
async onButtonClick() {
7272
executor.reseed();
73-
await replot(
74-
currentDistribution,
75-
currentGenerator,
76-
true,
77-
);
73+
await replot(currentDistribution, currentGenerator, true);
7874
plotter.resetView(getCameraPosition(currentDistribution));
7975
},
8076
},
81-
'Generator': {
77+
Generator: {
8278
initial: c.initialGenerator,
8379
options: c.generators,
8480
onSelectChange: async (value: Generator) => {
8581
if (currentGenerator === value) {
8682
return;
8783
}
8884
currentGenerator = value;
89-
await replot(
90-
currentDistribution,
91-
currentGenerator,
92-
true,
93-
);
85+
await replot(currentDistribution, currentGenerator, true);
9486
plotter.resetView(getCameraPosition(currentDistribution));
9587
},
9688
},
@@ -103,11 +95,7 @@ export const controls = defineControls({
10395
}
10496

10597
currentDistribution = value;
106-
await replot(
107-
currentDistribution,
108-
currentGenerator,
109-
true,
110-
);
98+
await replot(currentDistribution, currentGenerator, true);
11199
plotter.resetView(getCameraPosition(currentDistribution));
112100
},
113101
},
@@ -116,15 +104,16 @@ export const controls = defineControls({
116104
options: c.numSamplesOptions,
117105
async onSelectChange(value) {
118106
executor.count = value;
119-
await replot(
120-
currentDistribution,
121-
currentGenerator,
122-
);
107+
await replot(currentDistribution, currentGenerator);
123108
},
124109
},
125110
'Test Resolution': import.meta.env.DEV && {
126111
onButtonClick() {
127-
for (const [i, j] of [[0, 0], [8, 1], [10, 0]]) {
112+
for (const [i, j] of [
113+
[0, 0],
114+
[8, 1],
115+
[10, 0],
116+
]) {
128117
const code = tgpu.resolve({
129118
externals: {
130119
p: executor.pipelineCacheGet(

apps/typegpu-docs/src/examples/algorithms/probability/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ export const Generator = {
7575
LCG: 'lcg',
7676
} as const;
7777

78-
export type Generator = typeof Generator[keyof typeof Generator];
78+
export type Generator = (typeof Generator)[keyof typeof Generator];

packages/typegpu-noise/src/generator.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ export const BPETER: StatefulGenerator = (() => {
5454
export const LCG: StatefulGenerator = (() => {
5555
const seed = tgpu.privateVar(d.u32);
5656

57-
const u32To01Float = tgpu.fn([d.u32], d.f32)((value) => {
57+
const u32To01Float = tgpu.fn(
58+
[d.u32],
59+
d.f32,
60+
)((value) => {
5861
const mantissa = value >> 9;
59-
const bits = 0x3F800000 | mantissa;
62+
const bits = 0x3f800000 | mantissa;
6063
const f = bitcastU32toF32(bits);
6164
return f - 1;
6265
});
@@ -71,16 +74,12 @@ export const LCG: StatefulGenerator = (() => {
7174
}),
7275

7376
seed3: tgpu.fn([d.vec3f])((value) => {
74-
seed.$ = d.u32(
75-
value.x * pow(32, 3) + value.y * pow(32, 2) +
76-
value.z * pow(32, 1),
77-
);
77+
seed.$ = d.u32(value.x * pow(32, 3) + value.y * pow(32, 2) + value.z * pow(32, 1));
7878
}),
7979

8080
seed4: tgpu.fn([d.vec4f])((value) => {
8181
seed.$ = d.u32(
82-
value.x * pow(32, 3) + value.y * pow(32, 2) +
83-
value.z * pow(32, 1) + value.w * pow(32, 0),
82+
value.x * pow(32, 3) + value.y * pow(32, 2) + value.z * pow(32, 1) + value.w * pow(32, 0),
8483
);
8584
}),
8685

@@ -95,6 +94,4 @@ export const LCG: StatefulGenerator = (() => {
9594
// The default (Can change between releases to improve uniformity).
9695
export const DefaultGenerator: StatefulGenerator = BPETER;
9796

98-
export const randomGeneratorSlot: TgpuSlot<StatefulGenerator> = tgpu.slot(
99-
DefaultGenerator,
100-
);
97+
export const randomGeneratorSlot: TgpuSlot<StatefulGenerator> = tgpu.slot(DefaultGenerator);

packages/typegpu/tests/examples/individual/probability.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ describe('probability distribution plot example', () => {
1010
setupCommonMocks();
1111

1212
it('should produce valid code', async ({ device }) => {
13-
const shaderCodes = await runExampleTest({
14-
category: 'algorithms',
15-
name: 'probability',
16-
controlTriggers: ['Test Resolution'],
17-
expectedCalls: 3,
18-
}, device);
13+
const shaderCodes = await runExampleTest(
14+
{
15+
category: 'algorithms',
16+
name: 'probability',
17+
controlTriggers: ['Test Resolution'],
18+
expectedCalls: 3,
19+
},
20+
device,
21+
);
1922

2023
expect(shaderCodes).toMatchInlineSnapshot(`
2124
"@group(0) @binding(1) var<storage, read_write> samplesBuffer: array<vec3f>;

0 commit comments

Comments
 (0)