Skip to content

feat: bit pack relic set solutions array#566

Draft
fribbels wants to merge 1 commit intobetafrom
feat/relic-set-packing
Draft

feat: bit pack relic set solutions array#566
fribbels wants to merge 1 commit intobetafrom
feat/relic-set-packing

Conversation

@fribbels
Copy link
Owner

@fribbels fribbels commented Sep 6, 2024

Pull Request

Description

Related Issue

Checklist

  • I have added commit messages that are descriptive and meaningful.
  • I have tested the changes locally.
  • I have reviewed the code changes.

Screenshots

@fribbels fribbels marked this pull request as draft September 6, 2024 00:29
@fribbels
Copy link
Owner Author

fribbels commented Feb 28, 2026

+  const condensedRelicSets = condenseRelicSetSolutions(relicSetSolutions)

   const relicsMatrixBuffer = createGpuBuffer(device, new Float32Array(mergedRelics), GPUBufferUsage.STORAGE)
-  const relicSetSolutionsMatrixBuffer = createGpuBuffer(device, new Int32Array(relicSetSolutions), GPUBufferUsage.STORAGE, true, true)
+  const relicSetSolutionsMatrixBuffer = createGpuBuffer(device, new Int32Array(condensedRelicSets), GPUBufferUsage.STORAGE, true, true)
   const ornamentSetSolutionsMatrixBuffer = createGpuBuffer(device, new Int32Array(ornamentSetSolutions), GPUBufferUsage.STORAGE, true, true)
   const precomputedStatsBuffer = createGpuBuffer(device, context.precomputedStatsData!, GPUBufferUsage.STORAGE)

diff --git a/src/lib/optimization/relicSetSolver.ts b/src/lib/optimization/relicSetSolver.ts
index f6a42cd8d..9006d0c20 100644
--- a/src/lib/optimization/relicSetSolver.ts
+++ b/src/lib/optimization/relicSetSolver.ts
@@ -130,6 +130,23 @@ function convertRelicSetIndicesTo1D(setIndices: number[][]) {
   return arr
 }

+export function condenseRelicSetSolutions(relicSetSolutions: number[]) {
+  const paddedLength = Math.ceil(relicSetSolutions.length / 32) * 32
+  const paddedArray = new Array(paddedLength).fill(0)
+  for (let i = 0; i < relicSetSolutions.length; i++) {
+    paddedArray[i] = relicSetSolutions[i]
+  }
+  const result: number[] = []
+  for (let i = 0; i < paddedArray.length; i += 32) {
+    let packedValue = 0
+    for (let j = 0; j < 32; j++) {
+      packedValue |= (paddedArray[i + j] << (31 - j))
+    }
+    result.push(packedValue >>> 0)
+  }
+  return result
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant