Skip to content

Commit

Permalink
Increase memory limit to handle high resolution displays
Browse files Browse the repository at this point in the history
  • Loading branch information
Scthe committed Sep 7, 2024
1 parent 045b393 commit f4b32df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const CONFIG = {
binaryFileReader: binaryFileReader_Web,
createTextureFromFile: createTextureFromFile_Web,
},
increaseStorageMemoryLimits: false,
increaseStorageMemoryLimits: true,
displayMode: DISPLAY_MODE.FINAL,

///////////////
Expand Down Expand Up @@ -240,7 +240,7 @@ export const CONFIG = {
* ANYTHING WRONG IF IT WAS A SIMPLE COLLISION (INCREASE SDF OFFSET,
* OR HIDE THE BALL IN THAT CASE).
*/
invalidTilesPerSegmentThreshold: 64,
invalidTilesPerSegmentThreshold: 64 * 2,

////// SORT PASS
sortBuckets: 64,
Expand Down Expand Up @@ -282,7 +282,7 @@ export const CONFIG = {
// https://youtu.be/ool2E8SQPGU?si=yKgmYF6Wjbu6HXsF&t=815
friction: 0.3,
// 0.0 - do not use density gradient as external force. Hair can "squish" together
// >0.0 - move hair strands so from densely oocupied grid cells into ones that are more "free"
// >0.0 - move hair strands from densely occupied grid cells into ones that are more "free"
volumePreservation: 0.00003,
// If you set the radius to 0, the ball will disappear. There is a reason for this statement.
// collisionSphere: [0.05, 1.48, 0.01, 0.06], // inside hair
Expand Down
15 changes: 13 additions & 2 deletions src/utils/webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ export async function createGpuDevice() {
// Limits change: https://gpuweb.github.io/gpuweb/#gpusupportedlimits
const requiredLimits: GPUSupportedLimits = {};
if (CONFIG.increaseStorageMemoryLimits) {
requiredLimits.maxStorageBufferBindingSize = getBytes(1024, 'MB');
requiredLimits.maxBufferSize = getBytes(1024, 'MB');
// Warning: BigInt is used for memory limits (unsigned long long in WebGPU spec)
const lims = adapter.limits;

if (Number.isSafeInteger(lims.maxStorageBufferBindingSize)) {
requiredLimits.maxStorageBufferBindingSize = Number(lims.maxStorageBufferBindingSize); // prettier-ignore
}
if (Number.isSafeInteger(lims.maxBufferSize)) {
requiredLimits.maxBufferSize = Number(lims.maxBufferSize);
}

// defaults just in case
requiredLimits.maxStorageBufferBindingSize ||= getBytes(1024, 'MB');
requiredLimits.maxBufferSize ||= getBytes(1024, 'MB');
}
requiredLimits.maxComputeWorkgroupStorageSize = Math.max(
getLocalMemoryRequirements(),
Expand Down

0 comments on commit f4b32df

Please sign in to comment.