maierfelix / webgpu-path-tracer Goto Github PK
View Code? Open in Web Editor NEWToy path tracer using WebGPU RT
License: MIT License
Toy path tracer using WebGPU RT
License: MIT License
I run this project on win10, and I installed the Windows 452.28 vulkan beta driver, I got this error.
(node:19768) UnhandledPromiseRejectionWarning: ReferenceError: GPURayTracingAccelerationContainerFlag is not defined
at GeometryBuffer.init (file:///E:/PHPStormProjects/WebGPU-Path-Tracer/buffers/GeometryBuffer.mjs:99:14)
at new GeometryBuffer (file:///E:/PHPStormProjects/WebGPU-Path-Tracer/buffers/GeometryBuffer.mjs:12:10)
at RayTracingPass.init (file:///E:/PHPStormProjects/WebGPU-Path-Tracer/passes/RayTracingPass.mjs:63:24)
at new RayTracingPass (file:///E:/PHPStormProjects/WebGPU-Path-Tracer/passes/RayTracingPass.mjs:16:10)
at main (file:///E:/PHPStormProjects/WebGPU-Path-Tracer/index.mjs:211:16)
(Usenode --trace-warnings ...
to show where the warning was created)
Issue Description
When attempting to run the WebGPU Path Tracer in a Node.js environment locally, the application fails to load the WebAssembly (Wasm) binary file due to an "unknown scheme" error. This issue arises because the application uses the fetch API to load the Wasm file, which is not compatible with local file paths in Node.js.
Environment
Node.js Version: 18.17.1
Operating System: Windows 10
Path to Wasm File: ...WebGPU-Path-Tracer\node_modules\tolw\tolw.wasm
Detailed Error Output
node:internal/deps/undici/undici:11576
Error.captureStackTrace(err, this);
^
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11) {
cause: Error: unknown scheme
at makeNetworkError (node:internal/deps/undici/undici:6893:35)
at schemeFetch (node:internal/deps/undici/undici:11036:18)
at node:internal/deps/undici/undici:10909:26
at mainFetch (node:internal/deps/undici/undici:10926:11)
at fetching (node:internal/deps/undici/undici:10883:7)
at fetch2 (node:internal/deps/undici/undici:10761:20)
at Object.fetch (node:internal/deps/undici/undici:11574:18)
at fetch (node:internal/process/pre_execution:229:25)
at instantiateAsync (C:\...\node_modules\tolw\tolw.js:693:7)
at createWasm (C:\...\WebGPU-Path-Tracer\node_modules\tolw\tolw.js:717:3)
}
Steps to Reproduce
Clone the WebGPU Path Tracer repository.
Run npm install to install dependencies.
Execute npm run start to start the application.
Proposed Solution
The solution involves modifying the instantiateAsync function to bypass the fetch API in Node.js environments and instead use Node.js's fs module to read the Wasm file directly from the filesystem. This approach ensures compatibility with local file paths in Node.js.
To correct this bug got to WebGPU-Path-Tracer\node_modules\tolw\tolw.js
Here's an adjustment to the instantiateAsync function taht worked for me:
async function instantiateAsync() {
// Check if running in Node.js environment
if (ENVIRONMENT_IS_NODE) {
const fs = require('fs').promises;
try {
const path = require('path');
// Ensure the path is correctly resolved, especially if running from different directories
const wasmPath = path.resolve(__dirname, wasmBinaryFile);
const wasmBinary = await fs.readFile(wasmPath);
const wasmObject = await WebAssembly.instantiate(new Uint8Array(wasmBinary), info);
receiveInstance(wasmObject.instance);
} catch (err) {
console.error('Error during Wasm instantiation:', err);
abort(err);
}
} else if (typeof WebAssembly.instantiateStreaming === 'function' && !isDataURI(wasmBinaryFile) && typeof fetch === 'function') {
// Existing fetch logic for web environments...
fetch(wasmBinaryFile, { credentials: 'same-origin' })
.then(response => {
const result = WebAssembly.instantiateStreaming(response, info);
return result.then(receiveInstantiatedSource, reason => {
console.error('Wasm streaming compile failed:', reason);
console.error('Falling back to ArrayBuffer instantiation');
instantiateArrayBuffer(receiveInstantiatedSource);
});
});
} else {
return instantiateArrayBuffer(receiveInstantiatedSource);
}
}
Hope tht works for you!
Could you please specify which version of node this project run on .
as running using "npm install" the latest stable version is giving ->
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 13.0.0"} (current: {"node":"12.16.3","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN WebGPU-Path-Tracer No repository field.
npm WARN WebGPU-Path-Tracer No license field.
added 5 packages from 3 contributors and audited 5 packages in 2.61s
found 0 vulnerabilities
and on running gives :
> @ start /home/mj/Downloads/All git/WebGPU-Path-Tracer
> node index.mjs
internal/modules/cjs/loader.js:975
throw new ERR_REQUIRE_ESM(filename);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/mj/Downloads/All git/WebGPU-Path-Tracer/index.mjs
at Module.load (internal/modules/cjs/loader.js:975:11)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'ERR_REQUIRE_ESM'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ start: `node index.mjs`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/mj/.npm/_logs/2020-05-03T15_43_38_519Z-debug.log
and using the latest 14.1 version is giving the following errors ->
Warning: Couldn't open libvulkan.so.1
Info: Couldn't load Vulkan
(node:5563) UnhandledPromiseRejectionWarning: Error: Unknown failure
at main (file:///home/mj/Downloads/All%20git/WebGPU-Path-Tracer/index.mjs:36:27)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5563) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5563) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I am running on Ubunut 18 + nvidia rtx with driver version 335
Thanks !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.