-
-
Notifications
You must be signed in to change notification settings - Fork 25
docs: Generator slot #1665
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
Open
cieplypolar
wants to merge
84
commits into
release
Choose a base branch
from
docs/generator-slot
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
docs: Generator slot #1665
Changes from 62 commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
1de9166
Histograms
cieplypolar 7462dfa
Normal, Exp
cieplypolar 2a69945
Work on cauchy
cieplypolar 98dfac7
All continuous
cieplypolar 73a6eef
3d scatter
cieplypolar e7ae4ea
on unit sphere
cieplypolar 86e10cc
onUnitCube
cieplypolar d228417
Something
cieplypolar 71c4a0b
Updated docs
cieplypolar 7ec72e8
Restored old pnpm lock file
cieplypolar f086faa
Restored old pnpm lock file
cieplypolar f27fdb1
typos
cieplypolar 1912024
Corrected docs
cieplypolar a6a657a
Skeleton of an example
cieplypolar 60871d5
Nice html layout + camera reset
cieplypolar 450b303
Added tag
cieplypolar c745a53
Small refactor
cieplypolar 5cbd897
Dont care about 0
cieplypolar 4216899
More refactor
cieplypolar 0b38fff
Histogram plot
cieplypolar 19d8aa6
All plots
cieplypolar f00de44
thumbnail
cieplypolar 18954d5
Optimized replotting
cieplypolar 04c2d14
Left console.logs
cieplypolar da6696e
Not working animations
cieplypolar 1659a3a
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 028ba89
Fixed force reexe
cieplypolar 515d56e
Working transitions!
cieplypolar 70f85c5
Not this bool
cieplypolar 8c5d66b
Fixed seed
cieplypolar 03afea4
Docs update
cieplypolar 2839bfe
Math in docs
cieplypolar b85304e
Refactor in plotter
cieplypolar 88e6b66
Refactor in plotter
cieplypolar 516ba05
Added controls popup
cieplypolar e604da9
deno fmt
cieplypolar 37ab92f
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 6e0cce0
Broken lockfile
cieplypolar 2a29e5b
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 3fc3050
Example tests alignment
cieplypolar 8763ef6
Some review fixes
cieplypolar 8d2c97c
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar abc9b2a
rescaling instead of clamping
cieplypolar 1c05a69
Brutal replotFlag
cieplypolar e5a8dff
Review changes
cieplypolar 3eae7b5
Reseed button and minor changes
cieplypolar b4f0831
Fix randf.sampleExclusive
cieplypolar 641e621
Bind Group Layouts
cieplypolar e7d370c
Buffer cache
cieplypolar 5521cb3
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 4c5bf8e
Pipeline cache
cieplypolar b2bb9d2
Generator slot docs
cieplypolar 31b9131
more docs
cieplypolar bcd57b1
Visual uniformity test
cieplypolar cabf42a
Typos
cieplypolar 553b6ea
Nice uniformity test
cieplypolar 2c70cee
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 21442d1
Example resolution test
cieplypolar c739ecd
Merge branch 'feat/uniform01-derivatives' into docs/generator-slot
cieplypolar a751ae7
More controls and thumbnail
cieplypolar 63ebd3e
Resolution test
cieplypolar df71137
final polish
cieplypolar 19acd22
Merge branch 'main' into docs/generator-slot
cieplypolar 6b0aff3
Broken pnpm-lock
cieplypolar a433a0a
Merge branch 'main' into docs/generator-slot
cieplypolar 9e34138
nits
cieplypolar c89dc3b
typo
cieplypolar 8c9a9a9
shellless
cieplypolar 6c3ca10
Merge branch 'main' into docs/generator-slot
cieplypolar 339309a
optional seeds
cieplypolar d2b47b3
Merge branch 'main' into docs/generator-slot
cieplypolar e693bd8
Merge branch 'main' into docs/generator-slot
cieplypolar a6bf42a
Merge branch 'main' into docs/generator-slot
cieplypolar 3f112be
more descriptive function name
cieplypolar eb33788
Fix example test
cieplypolar 23e8f7d
Merge branch 'main' into docs/generator-slot
cieplypolar a08f37d
Merge branch 'main' into docs/generator-slot
cieplypolar ba20104
Merge branch 'main' into docs/generator-slot
cieplypolar 0658581
Merge branch 'main' into docs/generator-slot
cieplypolar 28d2c1e
Merge branch 'main' into docs/generator-slot
cieplypolar 9175886
review fixes
cieplypolar 969b270
update wgsl test
cieplypolar 03b5160
Merge branch 'main' into docs/generator-slot
cieplypolar 905ae70
Merge branch 'main' into docs/generator-slot
cieplypolar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
apps/typegpu-docs/src/content/examples/simple/probability/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Distribution } from './types.ts'; | ||
|
|
||
| export const popupCooldown = 100000; | ||
| export const cameraPositionGeo = [0, 0, 0.5]; | ||
| export const cameraPositionHist = [0, 0, 0.2]; | ||
| export const initialCameraAngle = 15; | ||
| export const numSamplesOptions = [100, 1000, 2000, 5000, 10000, 50000]; | ||
| export const initialNumSamples = numSamplesOptions[2]; | ||
| export const initialDistribution: Distribution = Distribution.NORMAL; | ||
| export const distributions: Distribution[] = Object.values(Distribution); |
134 changes: 134 additions & 0 deletions
134
apps/typegpu-docs/src/content/examples/simple/probability/executor.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import tgpu from 'typegpu'; | ||
| import type { | ||
| StorageFlag, | ||
| TgpuBindGroup, | ||
| TgpuBindGroupLayout, | ||
| TgpuBuffer, | ||
| TgpuComputeFn, | ||
| TgpuComputePipeline, | ||
| TgpuFn, | ||
| TgpuRoot, | ||
| TgpuSlot, | ||
| } from 'typegpu'; | ||
| import * as d from 'typegpu/data'; | ||
| import { randf } from '@typegpu/noise'; | ||
|
|
||
| export class Executor { | ||
| // don't exceed max workgroup grid X dimension size | ||
| #count!: number; | ||
| #samplesBuffer!: | ||
| & TgpuBuffer<d.WgslArray<d.Vec3f>> | ||
| & StorageFlag; | ||
| #seedBuffer!: | ||
| & TgpuBuffer<d.WgslArray<d.F32>> | ||
| & StorageFlag; | ||
| #bindGroup!: TgpuBindGroup; | ||
| readonly #root: TgpuRoot; | ||
| readonly #dataMoreWorkersFunc: TgpuComputeFn; | ||
| readonly #distributionSlot: TgpuSlot<TgpuFn<() => d.Vec3f>>; | ||
| readonly #bindGroupLayout: TgpuBindGroupLayout; | ||
| readonly #bufferCache: Map< | ||
| number, | ||
| [ | ||
| & TgpuBuffer<d.WgslArray<d.Vec3f>> | ||
| & StorageFlag, | ||
| & TgpuBuffer<d.WgslArray<d.F32>> | ||
| & StorageFlag, | ||
| ] | ||
| >; | ||
| readonly #pipelineCache: Map<TgpuFn, TgpuComputePipeline>; | ||
|
|
||
| constructor(root: TgpuRoot) { | ||
| this.#root = root; | ||
| this.#bufferCache = new Map(); | ||
| this.#pipelineCache = new Map(); | ||
|
|
||
| const distributionSlotTempAlias = tgpu.slot<TgpuFn<() => d.Vec3f>>(); | ||
| this.#distributionSlot = distributionSlotTempAlias; | ||
|
|
||
| const bindGroupLayoutTempAlias = tgpu.bindGroupLayout({ | ||
| seedBuffer: { storage: d.arrayOf(d.f32), access: 'readonly' }, | ||
| samplesBuffer: { storage: d.arrayOf(d.vec3f), access: 'mutable' }, | ||
| }); | ||
| this.#bindGroupLayout = bindGroupLayoutTempAlias; | ||
|
|
||
| this.#dataMoreWorkersFunc = tgpu['~unstable'].computeFn({ | ||
| in: { gid: d.builtin.globalInvocationId }, | ||
| workgroupSize: [64], | ||
| })((input) => { | ||
| const id = input.gid.x; | ||
| if (id >= bindGroupLayoutTempAlias.$.samplesBuffer.length) return; | ||
| randf.seed(bindGroupLayoutTempAlias.$.seedBuffer[id]); | ||
| bindGroupLayoutTempAlias.$.samplesBuffer[id] = distributionSlotTempAlias | ||
| .$(); | ||
| }); | ||
| } | ||
|
|
||
| reseed() { | ||
| this.#seedBuffer.write( | ||
| Array.from({ length: this.#count }, () => Math.random()), | ||
| ); | ||
| } | ||
|
|
||
| set count(value: number) { | ||
| this.#count = value; | ||
| if (this.#bufferCache.has(value)) { | ||
| // biome-ignore lint/style/noNonNullAssertion: just checked it above | ||
| [this.#samplesBuffer, this.#seedBuffer] = this.#bufferCache.get(value)!; | ||
| } else { | ||
| this.#samplesBuffer = this.#root | ||
| .createBuffer(d.arrayOf(d.vec3f, value)) | ||
| .$usage('storage'); | ||
| this.#seedBuffer = this.#root | ||
| .createBuffer( | ||
| d.arrayOf(d.f32, value), | ||
| Array.from({ length: value }, () => Math.random()), | ||
| ).$usage('storage'); | ||
| this.#bufferCache.set(value, [this.#samplesBuffer, this.#seedBuffer]); | ||
| } | ||
|
|
||
| this.#bindGroup = this.#root.createBindGroup(this.#bindGroupLayout, { | ||
| seedBuffer: this.#seedBuffer, | ||
| samplesBuffer: this.#samplesBuffer, | ||
| }); | ||
| } | ||
|
|
||
| cachedPipeline(distribution: TgpuFn<() => d.Vec3f>) { | ||
| if (!import.meta.env.DEV) { | ||
| throw new Error('Function only for testing purposes'); | ||
| } | ||
|
|
||
| if (!this.#pipelineCache.has(distribution)) { | ||
| const pipeline = this.#root['~unstable'] | ||
| .with(this.#distributionSlot, distribution) | ||
| .withCompute(this.#dataMoreWorkersFunc as TgpuComputeFn) | ||
| .createPipeline(); | ||
| this.#pipelineCache.set(distribution, pipeline); | ||
| } | ||
|
|
||
| // biome-ignore lint/style/noNonNullAssertion: just checked it above | ||
| return this.#pipelineCache.get(distribution)!; | ||
| } | ||
|
|
||
| async executeMoreWorkers( | ||
| distribution: TgpuFn<() => d.Vec3f>, | ||
| ): Promise<d.v3f[]> { | ||
| let pipeline: TgpuComputePipeline; | ||
| if (this.#pipelineCache.has(distribution)) { | ||
| // biome-ignore lint/style/noNonNullAssertion: just checked it above | ||
| pipeline = this.#pipelineCache.get(distribution)!; | ||
| } else { | ||
| pipeline = this.#root['~unstable'] | ||
| .with(this.#distributionSlot, distribution) | ||
| .withCompute(this.#dataMoreWorkersFunc as TgpuComputeFn) | ||
| .createPipeline(); | ||
| this.#pipelineCache.set(distribution, pipeline); | ||
| } | ||
|
|
||
| pipeline | ||
| .with(this.#bindGroupLayout, this.#bindGroup) | ||
| .dispatchWorkgroups(Math.ceil(this.#count / 64)); | ||
|
|
||
| return await this.#samplesBuffer.read(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.