Repository navigation
Accept high-precision matrix storage in native splat sorting #1894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bkaradzic-microsoft
merged 6 commits into
BabylonJS:master
from
bkaradzic-microsoft:pr/native-splat-matrix-storage
Oct 1, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
adff1d0
Accept number-array matrices in native splat sorting
bkaradzic-microsoft 633a798
Validate supported splat matrix storage explicitly
bkaradzic-microsoft 843d834
Report invalid splat coefficients and test timeouts clearly
bkaradzic-microsoft 1738cec
Make splat validation test portable to JSI
883201d
Check native splat validation message across JSI wrappers
09c9864
Accept JSI host-function exception prefix in splat validation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #include <gtest/gtest.h> | ||
| #ifdef HAS_NATIVE_OPTIMIZATIONS | ||
| #include <Babylon/AppRuntime.h> | ||
| #include <Babylon/Plugins/NativeOptimizations.h> | ||
| #include <napi/env.h> | ||
|
|
||
| #include <chrono> | ||
| #include <cstdlib> | ||
| #include <future> | ||
| #include <stdexcept> | ||
| #endif | ||
|
|
||
| TEST(NativeOptimizations, SplatSortingAcceptsTypedAndNumberArrayMatrices) | ||
| { | ||
| #ifndef HAS_NATIVE_OPTIMIZATIONS | ||
| GTEST_SKIP() << "NativeOptimizations is disabled"; | ||
| #else | ||
| std::promise<void> completed; | ||
| auto completion = completed.get_future(); | ||
| Babylon::AppRuntime runtime{}; | ||
| runtime.Dispatch([&](Napi::Env env) { | ||
| try | ||
| { | ||
| Babylon::Plugins::NativeOptimizations::Initialize(env); | ||
| Napi::Eval(env, R"( | ||
| (function() { | ||
| const positions = new Float32Array([ | ||
| 1, 0, 0, 1, | ||
| 0, 1, 0, 1, | ||
| 0, 0, 1, 1, | ||
| 1, 1, 1, 1, | ||
| -1, 0, -1, 1 | ||
| ]); | ||
| for (const typed of [true, false]) { | ||
| const matrix = typed ? new Float32Array(16) : new Array(16).fill(0); | ||
| matrix[2] = 2; | ||
| matrix[6] = -3; | ||
| matrix[10] = 5; | ||
| const modelView = { _m: matrix }; | ||
| for (const rightHanded of [false, true]) { | ||
| const indices = new Float32Array(5); | ||
| _native.sortSplats(modelView, positions, indices, rightHanded); | ||
| // Distinct depths [2, -3, 5, 4, -7] give an algorithm-independent ordering. | ||
| const expected = rightHanded ? [4, 1, 0, 3, 2] : [2, 3, 0, 1, 4]; | ||
| for (let index = 0; index < indices.length; ++index) { | ||
| if (indices[index] !== expected[index]) { | ||
| throw new Error("Unexpected splat order for typed=" + typed + | ||
| ", rightHanded=" + rightHanded + ", index=" + index); | ||
| } | ||
| } | ||
| const single = new Float32Array([99]); | ||
| _native.sortSplats(modelView, positions.subarray(0, 4), single, rightHanded); | ||
| if (single[0] !== 0) { | ||
| throw new Error("Unexpected single-splat index"); | ||
| } | ||
| _native.sortSplats(modelView, new Float32Array(0), new Float32Array(0), rightHanded); | ||
| } | ||
| } | ||
| function expectMatrixError(matrix, message) { | ||
| let error; | ||
| try { | ||
| _native.sortSplats({ _m: matrix }, positions, new Float32Array(5), false); | ||
| } catch (caught) { | ||
| error = caught; | ||
| } | ||
| // JSI wraps exceptions thrown from host functions with this prefix. | ||
| if (!(error instanceof Error) || | ||
| (error.message !== message && error.message !== "Exception in HostFunction: " + message)) { | ||
| throw new Error("Invalid matrix must report: " + message + | ||
| "; received: " + String(error)); | ||
| } | ||
| } | ||
| for (const matrix of [undefined, null, {}, 42, new Uint8Array(16), new Float64Array(16)]) { | ||
| expectMatrixError(matrix, "sortSplats requires modelView._m to be a Float32Array or Array."); | ||
| } | ||
| for (const component of [2, 6, 10]) { | ||
| const matrix = new Array(16).fill(0); | ||
| delete matrix[component]; | ||
| expectMatrixError(matrix, "sortSplats requires modelView._m[2], [6], [10] to be numbers."); | ||
| for (const value of [undefined, null, "2", false, {}]) { | ||
| matrix[component] = value; | ||
| expectMatrixError(matrix, "sortSplats requires modelView._m[2], [6], [10] to be numbers."); | ||
| } | ||
| } | ||
| })(); | ||
| )", "native-splat-matrix-storage.js"); | ||
| completed.set_value(); | ||
| } | ||
| catch (const Napi::Error& error) | ||
| { | ||
| completed.set_exception(std::make_exception_ptr(std::runtime_error{Napi::GetErrorString(error)})); | ||
| } | ||
| catch (...) | ||
| { | ||
| completed.set_exception(std::current_exception()); | ||
| } | ||
| }); | ||
| if (completion.wait_for(std::chrono::seconds{30}) != std::future_status::ready) | ||
| { | ||
| // AppRuntime teardown joins the worker; returning would hang if that worker is stuck. | ||
| ADD_FAILURE() << "Timed out waiting for NativeOptimizations matrix storage regression"; | ||
| std::quick_exit(1); | ||
| } | ||
| EXPECT_NO_THROW(completion.get()); | ||
| #endif | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.