Skip to content

Commit

Permalink
Update sample/timestampQuery/TimestampQueryManager.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Kai Ninomiya <[email protected]>
  • Loading branch information
eliemichel and kainino0x authored Nov 14, 2024
1 parent 686c801 commit 2e3489a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions sample/timestampQuery/TimestampQueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,22 @@ export default class TimestampQueryManager {
}

// Once resolved, we can read back the value of timestamps
readAsync(onTimestampReadBack: (timestamps: BigUint64Array) => void) {
if (!this.timestampSupported) return new Promise(() => {});
if (this.hasOngoingTimestampReadback) return new Promise(() => {});
readAsync(onTimestampReadBack: (timestamps: BigUint64Array) => void): void {
if (!this.timestampSupported) return;
if (this.hasOngoingTimestampReadback) return;

this.hasOngoingTimestampReadback = true;

const buffer = this.timestampMapBuffer;
return new Promise(resolve => {
buffer.mapAsync(GPUMapMode.READ, 0, buffer.size)
void buffer.mapAsync(GPUMapMode.READ)
.then(() => {
const rawData = buffer.getMappedRange(0, buffer.size);
const rawData = buffer.getMappedRange();
const timestamps = new BigUint64Array(rawData);

onTimestampReadBack(timestamps);

buffer.unmap();
this.hasOngoingTimestampReadback = false;
})
});
});
}
}

0 comments on commit 2e3489a

Please sign in to comment.