Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DBUILD_RUNTIME_BROWSER=ON \
-DBUILD_RUNTIME_NODE=OFF \
-DPYJS_WEBGPU=ON \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DLINK_LIBLZMA=ON \
-DPY_VERSION=$PY_VER \
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(WASM64 "Enable WebAssembly 64-bit support" OFF)

option(PYJS_WEBGPU "Enable WebGPU support (emdawnwebgpu port)" OFF)


if (NOT DEFINED PY_VERSION)
Expand Down Expand Up @@ -219,6 +220,11 @@ target_link_options(pyjs_runtime_browser
PUBLIC "SHELL: -lembind"
)

if(PYJS_WEBGPU)
target_compile_options(pyjs_runtime_browser PUBLIC "SHELL: --use-port=emdawnwebgpu")
target_link_options(pyjs_runtime_browser PUBLIC "SHELL: --use-port=emdawnwebgpu")
endif()


# target_link_options(pyjs_runtime_browser PRIVATE
# "-sEXPORTED_FUNCTIONS=['_emscripten_dlopen_promise','_dlerror','FS']"
Expand Down
42 changes: 42 additions & 0 deletions tests/atests/async_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,48 @@ async def test_callbacks_in_async_2():
assert result == 42


async def test_js_webgpu():

has_webgpu = pyjs.to_py(
pyjs.js.Function(
"return typeof navigator !== 'undefined' && navigator.gpu !== undefined"
)()
)
assert has_webgpu, "this browser does not expose navigator.gpu"

async_js_function = pyjs.js.Function(
"""
return async function(){
const format = navigator.gpu.getPreferredCanvasFormat()
const adapter = await navigator.gpu.requestAdapter()
if (adapter === null){
return {status: "no adapter", format: format}
}
const device = await adapter.requestDevice()
if (device === null){
return {status: "no device", format: format}
}
return {
status: "ok",
format: format,
maxComputeWorkgroupSizeX: device.limits.maxComputeWorkgroupSizeX,
}
}
"""
)()

result = pyjs.to_py(await async_js_function())

# no adapter needed to query the preferred canvas format
assert result["format"] in ("bgra8unorm", "rgba8unorm")

if result["status"] != "ok":
print(f"skip adapter/device part of the browser webgpu test: {result['status']}")
return

assert result["maxComputeWorkgroupSizeX"] >= 1


async def trigger_js_tests():

js_test_path = Path(__file__).parents[1] / "jtests" / "test_main.js"
Expand Down