Skip to content

Commit

Permalink
temporary wasm package integration for CI and sandcastle until NPM
Browse files Browse the repository at this point in the history
  • Loading branch information
keyboardspecialist committed Nov 22, 2024
1 parent b2f5aa2 commit 361312b
Show file tree
Hide file tree
Showing 25 changed files with 1,980 additions and 15 deletions.
5 changes: 3 additions & 2 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/node_modules
/ThirdParty
/Tools/**
temp_wasm/*

CHANGES.md
LICENSE.md
CHANGES.md
LICENSE.md
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default [
"packages/engine/Source/Shaders/**/*",
"Specs/jasmine/*",
"**/*/SpecList.js",
"temp_wasm/*",
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"dependencies": {
"@cesium/engine": "^11.1.0",
"@cesium/widgets": "^8.1.0",
"cesiumjs-gsplat-utils": "file:../gsplat-wasm/cesiumjs-gsplat-utils/pkg",
"cesiumjs-gsplat-utils": "file:./temp_wasm/cesiumjs-gsplat-utils/pkg",
"esbuild-plugin-wasm": "^1.1.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ GaussianSplatPipelineStage.process = function (
}

shaderBuilder.addAttribute("vec2", "a_screenQuadPosition");
shaderBuilder.addAttribute("float", "a_dummy");
shaderBuilder.addAttribute("vec3", "a_splatPosition");
shaderBuilder.addAttribute("vec4", "a_splatColor");
//shaderBuilder.addAttribute("float", "a_splatOpacity");
Expand Down Expand Up @@ -245,7 +246,9 @@ GaussianSplatPipelineStage.process = function (
async function ensureWasmInitialized() {
if (!initPromise) {
initPromise = await __wbg_init(
buildModuleUrl("ThirdParty/cesiumjs_gsplat_utils_bg.wasm"),
buildModuleUrl(
"ThirdParty/cesium-gsplat/cesiumjs_gsplat_utils_bg.wasm",
),
)
.then((wasm) => {
wasmInitialized = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,69 @@ GaussianSplatTextureGenerator.generateFromAttrs = async function (
count,
);
};
////////////////////////////////////////////////////
///////

// import defined from "../../Core/defined.js";
// import FeatureDetection from "../../Core/FeatureDetection.js";
// import RuntimeError from "../../Core/RuntimeError.js";
// import TaskProcessor from "../../Core/TaskProcessor.js";

// function GaussianSplatTextureGenerator() {}

// GaussianSplatTextureGenerator._maxSortingConcurrency = Math.max(
// FeatureDetection.hardwareConcurrency - 1,
// 1,
// );

// GaussianSplatTextureGenerator._textureTaskProcessor = undefined;
// GaussianSplatTextureGenerator._taskProcessorReady = false;
// GaussianSplatTextureGenerator._error = undefined;
// GaussianSplatTextureGenerator._getTextureTaskProcessor = function () {
// if (!defined(GaussianSplatTextureGenerator._textureTaskProcessor)) {
// const processor = new TaskProcessor(
// "gaussianSplatTextureGenerator",
// GaussianSplatTextureGenerator._maxSortingConcurrency,
// );
// processor
// .initWebAssemblyModule({
// wasmBinaryFile: "ThirdParty/cesium-gsplat/cesiumjs_gsplat_utils_bg.wasm",
// })
// .then(function (result) {
// if (result) {
// GaussianSplatTextureGenerator._taskProcessorReady = true;
// } else {
// GaussianSplatTextureGenerator._error = new RuntimeError(
// "Gaussian splat sorter could not be initialized.",
// );
// }
// })
// .catch((error) => {
// GaussianSplatTextureGenerator._error = error;
// });
// GaussianSplatTextureGenerator._textureTaskProcessor = processor;
// }

// return GaussianSplatTextureGenerator._textureTaskProcessor;
// };

// GaussianSplatTextureGenerator.generateFromAttrs = function (parameters) {
// const textureTaskProcessor = GaussianSplatTextureGenerator._getTextureTaskProcessor();
// if (defined(GaussianSplatTextureGenerator._error)) {
// throw GaussianSplatTextureGenerator._error;
// }

// if (!GaussianSplatTextureGenerator._taskProcessorReady) {
// return;
// }

// const { attributes } = parameters;
// return textureTaskProcessor.scheduleTask(parameters,[
// attributes.positions.typedArray,
// attributes.scales.typedArray,
// attributes.rotations.typedArray,
// attributes.colors.typedArray
// ]);
// };

export default GaussianSplatTextureGenerator;
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ GaussianSplatTexturePipelineStage.process = function (
async function ensureWasmInitialized() {
if (!initPromise) {
initPromise = await __wbg_init(
buildModuleUrl("ThirdParty/cesiumjs_gsplat_utils_bg.wasm"),
buildModuleUrl(
"ThirdParty/cesium-gsplat/cesiumjs_gsplat_utils_bg.wasm",
),
)
.then((wasm) => {
wasmInitialized = true;
Expand Down Expand Up @@ -336,7 +338,9 @@ GaussianSplatTexturePipelineStage.process = function (
async function ensureWasmInitialized() {
if (!initPromise) {
initPromise = await __wbg_init(
buildModuleUrl("ThirdParty/cesiumjs_gsplat_utils_bg.wasm"),
buildModuleUrl(
"ThirdParty/cesium-gsplat/cesiumjs_gsplat_utils_bg.wasm",
),
)
.then((wasm) => {
wasmInitialized = true;
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/Source/Scene/Model/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import StyleCommandsNeeded from "./StyleCommandsNeeded.js";
import pickModel from "./pickModel.js";

import GaussianSplatSorter from "../GaussianSplatSorter.js";

//import Buffer from "../../Renderer/Buffer.js";
//import BufferUsage from "../../Renderer/BufferUsage.js";
/**
* <div class="notice">
* To construct a Model, call {@link Model.fromGltfAsync}. Do not call the constructor directly.
Expand Down Expand Up @@ -2146,6 +2147,7 @@ function updateGaussianSplatting(model, frameState) {
if (prim?.isGaussianSplatPrimitive ?? false) {
const idxAttr = prim.attributes.find((a) => a.name === "_SPLAT_INDEXES");
const posAttr = prim.attributes.find((a) => a.name === "POSITION");

const modelView = new Matrix4();
Matrix4.multiply(
frameState.camera.viewMatrix,
Expand Down
6 changes: 3 additions & 3 deletions packages/engine/Source/Scene/Model/ModelDrawCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ function buildDrawCommandForGaussianSplatPrimitive(
)
) {
const splatQuadAttrLocations = {
0: 8,
0: 9,
1: 1,
2: 2,
3: 3,
4: 4,
splatPosition: 6,
splatColor: 7,
splatPosition: 7,
splatColor: 8,
};
const geometry = new Geometry({
attributes: {
Expand Down
7 changes: 7 additions & 0 deletions packages/engine/Source/Workers/gaussianSplatSorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ function generateGaussianSortWorker(parameters, transferableObjects) {
2048,
primitive.count,
);
} else if (sortType === "SIMD Index") {
return radix_sort_gaussians_indexes(
primitive.positions,
primitive.modelView,
2048,
primitive.count,
);
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/engine/Source/Workers/gaussianSplatTextureGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ async function generateSplatTextureWorker(parameters, transferableObjects) {
return initWorker(parameters, transferableObjects);
}

const { positions, scales, rotations, colors, count } = parameters;
const { attributes, count } = parameters;
return generate_texture_from_attrs(
positions,
scales,
rotations,
colors,
attributes.positions,
attributes.scales,
attributes.rotations,
attributes.colors,
count,
);
}
Expand Down
11 changes: 11 additions & 0 deletions temp_wasm/cesiumjs-gsplat-utils/.appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
install:
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- if not defined RUSTFLAGS rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustc -V
- cargo -V

build: false

test_script:
- cargo test --locked
6 changes: 6 additions & 0 deletions temp_wasm/cesiumjs-gsplat-utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log
69 changes: 69 additions & 0 deletions temp_wasm/cesiumjs-gsplat-utils/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
language: rust
sudo: false

cache: cargo

matrix:
include:

# Builds with wasm-pack.
- rust: beta
env: RUST_BACKTRACE=1
addons:
firefox: latest
chrome: stable
before_script:
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
- cargo install-update -a
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
script:
- cargo generate --git . --name testing
# Having a broken Cargo.toml (in that it has curlies in fields) anywhere
# in any of our parent dirs is problematic.
- mv Cargo.toml Cargo.toml.tmpl
- cd testing
- wasm-pack build
- wasm-pack test --chrome --firefox --headless

# Builds on nightly.
- rust: nightly
env: RUST_BACKTRACE=1
before_script:
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
- cargo install-update -a
- rustup target add wasm32-unknown-unknown
script:
- cargo generate --git . --name testing
- mv Cargo.toml Cargo.toml.tmpl
- cd testing
- cargo check
- cargo check --target wasm32-unknown-unknown
- cargo check --no-default-features
- cargo check --target wasm32-unknown-unknown --no-default-features
- cargo check --no-default-features --features console_error_panic_hook
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook
- cargo check --no-default-features --features "console_error_panic_hook wee_alloc"
- cargo check --target wasm32-unknown-unknown --no-default-features --features "console_error_panic_hook wee_alloc"

# Builds on beta.
- rust: beta
env: RUST_BACKTRACE=1
before_script:
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
- cargo install-update -a
- rustup target add wasm32-unknown-unknown
script:
- cargo generate --git . --name testing
- mv Cargo.toml Cargo.toml.tmpl
- cd testing
- cargo check
- cargo check --target wasm32-unknown-unknown
- cargo check --no-default-features
- cargo check --target wasm32-unknown-unknown --no-default-features
- cargo check --no-default-features --features console_error_panic_hook
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook
# Note: no enabling the `wee_alloc` feature here because it requires
# nightly for now.
32 changes: 32 additions & 0 deletions temp_wasm/cesiumjs-gsplat-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "cesiumjs-gsplat-utils"
version = "0.1.0"
authors = ["Jason Sobotka <jason.sobotka@cesium.com>"]
edition = "2021"


[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.84"
js-sys = "0.3.72"
web-sys = { version="0.3.72", features=["console"]}

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.34"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = 3
lto = true
codegen-units = 1
Loading

0 comments on commit 361312b

Please sign in to comment.