From e3c7bab0af63eda2ea76815b5e70896829b2da29 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 24 Apr 2025 10:03:39 +0800 Subject: [PATCH] [Optimization] (multidraw: compute): why bisect still not working??? --- src/main/cpp/gl/multidraw.cpp | 9 ++++---- src/main/cpp/shaders/multidraw_compute.comp | 23 +++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/cpp/gl/multidraw.cpp b/src/main/cpp/gl/multidraw.cpp index 0b778d7..d5afcdd 100644 --- a/src/main/cpp/gl/multidraw.cpp +++ b/src/main/cpp/gl/multidraw.cpp @@ -280,11 +280,11 @@ void main() { int high = draws.length(); while (low < high) { int mid = low + (high - low) / 2; - if (prefixSums[mid] <= outIdx) { - low = mid + 1; // next [mid + 1, high) + if (prefixSums[mid] > outIdx) { + high = mid; // next [low, mid) } else { - high = mid; // next [low, mid) + low = mid + 1; // next [mid + 1, high) } } @@ -294,7 +294,8 @@ void main() { uint inIndex = localIdx + cmd.firstIndex; // Write out - out_indices[outIdx] = uint(int(in_indices[inIndex]) + cmd.baseVertex); + out_indices[outIdx] = uint(in_indices[inIndex] + uint(cmd.baseVertex)); +// out_indices[outIdx] = uint(cmd.baseVertex); } )"; diff --git a/src/main/cpp/shaders/multidraw_compute.comp b/src/main/cpp/shaders/multidraw_compute.comp index f4c3357..9a377b1 100644 --- a/src/main/cpp/shaders/multidraw_compute.comp +++ b/src/main/cpp/shaders/multidraw_compute.comp @@ -21,23 +21,23 @@ void main() { return; // Find out draw call # -// int low = 0; -// int high = draws.length(); -// for (low = 0; low < high; ++low) { -// if (prefixSums[low] > outIdx) { -// break; -// } -// } + // int low = 0; + // int high = draws.length(); + // for (low = 0; low < high; ++low) { + // if (prefixSums[low] > outIdx) { + // break; + // } + // } int low = 0; int high = draws.length(); while (low < high) { int mid = low + (high - low) / 2; - if (prefixSums[mid] <= outIdx) { - low = mid + 1; // next [mid + 1, high) + if (prefixSums[mid] > outIdx) { + high = mid; // next [low, mid) } else { - high = mid; // next [low, mid) + low = mid + 1; // next [mid + 1, high) } } @@ -47,5 +47,6 @@ void main() { uint inIndex = localIdx + cmd.firstIndex; // Write out - out_indices[outIdx] = uint(int(in_indices[inIndex]) + cmd.baseVertex); + out_indices[outIdx] = uint(in_indices[inIndex] + uint(cmd.baseVertex)); + // out_indices[outIdx] = uint(cmd.baseVertex); }