From 8ef12ff1ac3d6e6d8c33c5f60860298052f6c660 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 21 Apr 2025 12:25:45 +0800 Subject: [PATCH] [Fix] (multidraw: compute): restore original program --- src/main/cpp/gl/multidraw.cpp | 13 +++---------- src/main/cpp/shaders/multidraw_compute.comp | 16 +++------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/main/cpp/gl/multidraw.cpp b/src/main/cpp/gl/multidraw.cpp index fa02f85..6fb03c3 100644 --- a/src/main/cpp/gl/multidraw.cpp +++ b/src/main/cpp/gl/multidraw.cpp @@ -267,17 +267,8 @@ void main() { if (outIdx >= prefixSums[prefixSums.length() - 1]) return; - // bisect to find out draw call # + // Find out draw call # int low = 0; -// int high = draws.length() - 1; -// while (low < high) { -// int mid = (low + high + 1) / 2; -// if (prefixSums[mid] <= outIdx) { -// low = mid; -// } else { -// high = mid - 1; -// } -// } int l = draws.length() - 1; for (low = 0; low < l; ++low) { if (prefixSums[low] > outIdx) { @@ -433,6 +424,8 @@ GLAPI GLAPIENTRY void mg_glMultiDrawElementsBaseVertex_compute( // Bind index buffer and do draw LOG_D("draw") + GLES.glUseProgram(prev_program); + CHECK_GL_ERROR_NO_INIT GLES.glBindBuffer(GL_VERTEX_ARRAY, prev_vb); CHECK_GL_ERROR_NO_INIT GLES.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_outputibo); diff --git a/src/main/cpp/shaders/multidraw_compute.comp b/src/main/cpp/shaders/multidraw_compute.comp index a4f4123..1393983 100644 --- a/src/main/cpp/shaders/multidraw_compute.comp +++ b/src/main/cpp/shaders/multidraw_compute.comp @@ -18,20 +18,10 @@ layout(std430, binding = 3) writeonly buffer Output { uint out_indices[]; }; void main() { uint outIdx = gl_GlobalInvocationID.x; if (outIdx >= prefixSums[prefixSums.length() - 1]) - return; + return; - // bisect to find out draw call # + // Find out draw call # int low = 0; -// int high = draws.length() - 1; -// while (low < high) { -// int mid = (low + ) -// int mid = (low + high + 1) / 2; -// if (prefixSums[mid] <= outIdx) { -// low = mid; -// } else { -// high = mid - 1; -// } -// } int l = draws.length() - 1; for (low = 0; low < l; ++low) { if (prefixSums[low] > outIdx) { @@ -41,7 +31,7 @@ void main() { // figure out which index to take DrawCommand cmd = draws[low]; - uint localIdx = outIdx - prefixSums[low]; + uint localIdx = outIdx - ((low == 0) ? 0u : (prefixSums[low - 1])); uint inIndex = localIdx + cmd.firstIndex; // Write out