Skip to content

Commit

Permalink
🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon committed Dec 14, 2024
1 parent d37cfff commit 94159ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 68 deletions.
8 changes: 4 additions & 4 deletions apps/example/src/ComputeBoids/ComputeBoids.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const renderBindGroupLayout = tgpu.bindGroupLayout({

const computeBindGroupLayout = tgpu.bindGroupLayout({
currentTrianglePos: { storage: TriangleDataArray },
nextTrianglePos: { storage: TriangleDataArray, access: 'mutable' },
nextTrianglePos: { storage: TriangleDataArray, access: "mutable" },
params: { uniform: Parameters },
});

Expand Down Expand Up @@ -122,7 +122,7 @@ export function ComputeBoids() {

const triangleAmount = 1000;
const trianglePosBuffers = Array.from({ length: 2 }, () =>
root.createBuffer(TriangleDataArray(triangleAmount)).$usage("storage")
root.createBuffer(TriangleDataArray(triangleAmount)).$usage("storage"),
);

randomizePositions.current = () => {
Expand Down Expand Up @@ -234,7 +234,7 @@ export function ComputeBoids() {
computePass.setPipeline(computePipeline);
computePass.setBindGroup(
0,
root.unwrap(even ? computeBindGroups[0] : computeBindGroups[1])
root.unwrap(even ? computeBindGroups[0] : computeBindGroups[1]),
);
computePass.dispatchWorkgroups(triangleAmount);
computePass.end();
Expand All @@ -244,7 +244,7 @@ export function ComputeBoids() {
passEncoder.setVertexBuffer(0, triangleVertexBuffer.buffer);
passEncoder.setBindGroup(
0,
root.unwrap(even ? renderBindGroups[1] : renderBindGroups[0])
root.unwrap(even ? renderBindGroups[1] : renderBindGroups[0]),
);
passEncoder.draw(3, triangleAmount);
passEncoder.end();
Expand Down
6 changes: 3 additions & 3 deletions apps/example/src/GradientTiles/GradientTiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Canvas, useDevice, useGPUContext } from "react-native-wgpu";
import { struct, u32 } from "typegpu/data";
import tgpu, { type TgpuBindGroup, type TgpuBuffer } from "typegpu";

import { vertWGSL, fragWGSL } from './gradientWgsl';
import { vertWGSL, fragWGSL } from "./gradientWgsl";

const Span = struct({
x: u32,
Expand All @@ -18,15 +18,15 @@ const bindGroupLayout = tgpu.bindGroupLayout({
interface RenderingState {
pipeline: GPURenderPipeline;
spanBuffer: TgpuBuffer<typeof Span>;
bindGroup: TgpuBindGroup<(typeof bindGroupLayout)['entries']>;
bindGroup: TgpuBindGroup<(typeof bindGroupLayout)["entries"]>;
}

function useRoot() {
const { device } = useDevice();

return useMemo(
() => (device ? tgpu.initFromDevice({ device }) : null),
[device]
[device],
);
}

Expand Down
8 changes: 5 additions & 3 deletions apps/example/src/Tensorflow/Platform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Platform } from "@tensorflow/tfjs-core";
import { RequestDetails } from "@tensorflow/tfjs-core/dist/io/types";
import type { Platform } from "@tensorflow/tfjs-core";
import type { RequestDetails } from "@tensorflow/tfjs-core/dist/io/types";

export class PlatformReactNative implements Platform {
fetch(path: string, init?: RequestInit, _options?: RequestDetails) {
Expand All @@ -22,7 +22,9 @@ export class PlatformReactNative implements Platform {
throw new Error("react native does not support setTimeoutCustom");
}

isTypedArray(a: unknown) {
isTypedArray(
a: unknown,
): a is Uint8Array | Uint8ClampedArray | Int32Array | Float32Array {
return (
a instanceof Float32Array ||
a instanceof Int32Array ||
Expand Down
65 changes: 7 additions & 58 deletions packages/webgpu/src/Offscreen.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export class GPUOffscreenCanvas implements OffscreenCanvas {
export class GPUOffscreenCanvas {
width: number;
height: number;
oncontextlost: ((this: OffscreenCanvas, ev: Event) => any) | null = null;
oncontextrestored: ((this: OffscreenCanvas, ev: Event) => any) | null = null;

private context: GPUOffscreenCanvasContext;

Expand All @@ -13,66 +10,14 @@ export class GPUOffscreenCanvas implements OffscreenCanvas {
this.context = new GPUOffscreenCanvasContext(this);
}

convertToBlob(_options?: ImageEncodeOptions): Promise<Blob> {
// Implementation for converting the canvas content to a Blob
throw new Error("Method not implemented.");
}

// Overloaded method signatures
getContext(
contextId: "2d",
options?: any,
): OffscreenCanvasRenderingContext2D | null;
getContext(
contextId: "bitmaprenderer",
options?: any,
): ImageBitmapRenderingContext | null;
getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null;
getContext(contextId: "webgl2", options?: any): WebGL2RenderingContext | null;
getContext(
contextId: OffscreenRenderingContextId,
options?: any,
): OffscreenRenderingContext | null;
getContext(contextId: "webgpu"): GPUOffscreenCanvasContext | null;
getContext(
contextId: unknown,
_options?: any,
): OffscreenRenderingContext | GPUOffscreenCanvasContext | null {
getContext(contextId: "webgpu"): GPUOffscreenCanvasContext | null {
if (contextId === "webgpu") {
return this.context;
}
// Implement other context types if necessary
return null;
}

transferToImageBitmap(): ImageBitmap {
// Implementation for transferring the canvas content to an ImageBitmap
throw new Error("Method not implemented.");
}

addEventListener<K extends keyof OffscreenCanvasEventMap>(
_type: K,
_listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
_options?: boolean | AddEventListenerOptions,
): void {
// Event listener implementation
throw new Error("Method not implemented.");
}

removeEventListener<K extends keyof OffscreenCanvasEventMap>(
_type: K,
_listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
_options?: boolean | EventListenerOptions,
): void {
// Remove event listener implementation
throw new Error("Method not implemented.");
}

dispatchEvent(_event: Event): boolean {
// Event dispatch implementation
throw new Error("Method not implemented.");
}

getImageData() {
const device = this.context.getDevice();
const texture = this.context.getTexture();
Expand Down Expand Up @@ -111,9 +56,13 @@ class GPUOffscreenCanvasContext implements GPUCanvasContext {
private texture: GPUTexture | null = null;
private device: GPUDevice | null = null;

constructor(public readonly canvas: OffscreenCanvas) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(public readonly canvas: any) {
this.textureFormat = navigator.gpu.getPreferredCanvasFormat();
}
getConfiguration(): GPUCanvasConfigurationOut | null {
throw new Error("Method not implemented.");
}

present() {
// Do nothing
Expand Down

0 comments on commit 94159ed

Please sign in to comment.