Next generation GPU API for Python
Project description
Copyright (c) 2019, Almar Klein All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Description: [![Build Status](https://dev.azure.com/almarklein/wgpu-py/_apis/build/status/almarklein.wgpu-py?branchName=master)](https://dev.azure.com/almarklein/wgpu-py/_build/latest?definitionId=1&branchName=master)
# wgpu-py
Next generation GPU API for Python
## Introduction
In short, this is a Python lib wrapping the Rust wgpu lib and exposing it with a Pythonic API similar to WebGPU.
The OpenGL API is old and showing it’s cracks. New API’s like Vulkan, Metal and DX12 provide a modern way to control the GPU, but these API’s are too low-level for general use. The WebGPU API follows the same concepts, but with a simpler (higher level) spelling. The Python wgpu library brings the WebGPU API to Python. Based on [wgpu-native](https://github.com/gfx-rs/wgpu).
To get an idea of what this API looks like have a look at [triangle.py](https://github.com/almarklein/wgpu-py/blob/master/examples/triangle.py) and the other [examples](https://github.com/almarklein/wgpu-py/blob/master/examples/).
## Status
This is experimental, work in progress, you probably don’t want to use this just yet!
We have a few working examples!
Support for Windows and Linux. Support for MacOS is underway.
We have not fully implemented the API yet.
The API may change. We’re still figuring out what works best.
The API may change more. Until WebGPU settles as a standard, its specification may change, and with that our API will probably too.
## Installation
` pip install wgpu pip install python-shader # optional - our examples use this to define shaders `
The library ships with Rust binaries for Windows, MacOS and Linux. If you want to use a custom build instead, you can set the environment variable WGPU_LIB_PATH.
## Platform requirements
Under the hood, wgpu runs on Vulkan or Metal, and eventually also DX12 or OpenGL.
On Windows 10, things should just work. On older Windows versions you may need to install the Vulkan drivers (or wait for the DX12 backend to become more mature).
On Linux, it’s advisable to install the proprietary drivers of your GPU (if you have a dedicated GPU). You may need to apt install mesa-vulkan-drivers. Note that on Linux, the tk canvas does not work. Wayland currently only works with the GLFW canvas (and is unstable).
On MacOS you need at least 10.13 (High Sierra) to have Vulkan support. At the moment, we’ve not implemented drawing to a window yet (see #29).
## Usage
The full API is accessable via the main namespace: `py import wgpu `
But to use it, you need to select a backend first. You do this by importing it. There is currently only one backend: `py import wgpu.backend.rs `
## GUI integration
To render to the screen you can use any of the following GUI toolkits: Tk (included with Python), glfw, PySide2, PyQt5, PySide, PyQt4.
## Web support
We are considering future support for compiling (Python) visualizations to the web via PScript and Flexx. We try to keep that option open as long as it does not get in the way too much. No promises.
## License
This code is distributed under the 2-clause BSD license.
## Developers
Clone the repo.
Install devtools using pip install -r dev-requirements.txt (you can replace pip with pipenv to install to a virtualenv).
Install wgpu-py in editable mode by running python setup.py develop, this will also install our only runtime dependency cffi
Run python download-wgpu-native.py to download the upstream wgpu-native binaries. * Or alternatively point the WGPU_LIB_PATH environment variable to a custom build.
Use black . to apply autoformatting.
Use flake8 . to check for flake errors.
Use pytest . to run the tests.
### Changing the upstream wgpu-native version
Use the optional arguments to python download-wgpu-native.py –help to download a different version of the upstream wgpu-native binaries.
The file wgpu/resources/wgpu_native-version will be updated by the script to track which version we depend upon.
Platform: UNKNOWN Requires-Python: >=3.6.0 Description-Content-Type: text/markdown
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file wgpu-0.1.1-py3-none-win_amd64.whl
.
File metadata
- Download URL: wgpu-0.1.1-py3-none-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dd616addabbe9614ab312d3e63a64f27927d3f519d578423a9ad41c59bc7104 |
|
MD5 | 72dfff4a75ef05338d7bdff2b1453dd7 |
|
BLAKE2b-256 | a14c0af0033a817c5ee0f10b997b6d862f59ee3cdcca4eab2898a4e134c0f404 |
Provenance
File details
Details for the file wgpu-0.1.1-py3-none-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: wgpu-0.1.1-py3-none-macosx_10_13_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: Python 3, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbf29bc7b9f3ddc1b95caa2dd0965506b4ea116284b417172ee75827dde1cab1 |
|
MD5 | 012d45b88ce92208cd5a1a535472face |
|
BLAKE2b-256 | c9fa9c34b952ed25afcfd79059514c99853e560d022da489191fc3bca7b91bea |