pyvk
is a Python port of the wonderful framework from Sascha Willems vulkan examples.
It has been started as a mean for me to discover Vulkan. The initial objectives were:
- use some of the proposed classes to ease development (but some classes require stuff not ported to python (gli?))
- part of these classes are in a
vks
namespace, thus make avks
python module - port the main class (
VulkanExampleBase
) to Python - try to implement
triangle
andscenerendering
Essential classes have been ported to Python in a vks
Pyhton module, and the triangle
, texture
and scenerendering
examples are running.
Moreover imgui
integration is also effective (included in the triangle
demo). However not every methods have yet been rewritten in those classes. For instance there is no benchmarking facilities.
Only the XCB platform binding has been made, so this only runs on linux
. It has been tested under Fedora 30 and Ubuntu 18.04, using both IGP Intel drivers and nvidia proprietary drivers.
The Windows platform binding is in development. If you use thonny
for editing/running (I do), please note that the 32-bit Vulkan libraries
are not tested. I had a pointer issue when using the 32bit default thonny
interpreter (GetPhysicalDeviceSurfaceSupportKHR
). Install
a 64bit Python interpreter and point to it in thonny
. Be aware to uninstall and reinstall every packages from thonny
manager.
These are Frames Per Second values computed in the program itself. They are read directly from the screenshots. All FPS values here are stable during one execution, but there are some differences between executions (GPU Temp?). Min/Max frame times may also be added.
Example | CPU-Card-Driver-platform-os | C++ | Python |
---|---|---|---|
triangle | i3 3220T-IGP-Intel Ivybridge-XCB-linux | 798 | 757 |
triangle (imgui) | i3 3220T-IGP-Intel Ivybridge-XCB-linux | 637 | 427 |
triangle | Pentium G4400-GTX950-nvidia proprietary-XCB-linux | 4794 | 4279 |
triangle (imgui) | Pentium G4400-GTX950-nvidia proprietary-XCB-linux | 4712 | 2561 |
texture | Pentium G4400-GTX950-nvidia proprietary-XCB-linux | 3400 | 2800 |
scenerendering | Pentium G4400-GTX950-nvidia proprietary-XCB-linux | 1800 | 1330 |
Note: All C++ examples were run without validation enabled, whereas Python examples were run with validation enabled.
First install the requirements (see below).
At the moment I also use numpy as a mean to access C arrays from Python, thus you should also install it (pip3 install --user numpy
).
Simply clone the repository in a directory of your choice and change directory
git clone https://github.com/geehalel/pyvk.git
cd pyvk
then run the desired demo
python3 triangle.py
- install python vulkan binding
pip3 install vulkan --user
- install python xcb binding
pip3 install xcffib --user
- install python glm binding
pip3 install pyglm --user
- install python imgui binding
pip3 install imgui --user
- install python wayland binding (not useful for now)
pip3 install pywayland --user
Install the assimp
python port from your distribution (python3-pyassimp
) or from Pypi
.
apt-get install python3-pyassimp
The tutorials mainly use the Khronos groupe ktx
format for storing textures,
but this format is not installed on Linux (no packages on Ubuntu and Fedora).
The python vks
module here includes a simple class in ktxfile.py
to load such textures.
Here are some links about this format:
KTX
File format specification- The Khronos Group Library and Tools which contains source code for
libktx
library - OpenGL Image (
gli
) library, C++ header only, used in the tutorials
There are otherwise numerous image libraries in Python, none of them reading ktx
files, but some of them reading dds
files (Microsoft texture file format).
- Pillow, the Python Image Library
- OpenImageIO which supports image formats used in VFX (visual effects for films/TV) and embeds an ImageCache framework. Supports Python directly. On Ubuntu the Python support is only packaged for Python 2.7 (
python-openimageio
). For Python 3, a package may be manually installed:
wget https://github.com/fredrikaverpil/oiio-python/releases/download/2.0.5%2B20190203/oiio-2.0.5-cp36-none-linux_x86_64.whl
pip3 install --user oiio-2.0.5-cp36-none-linux_x86_64.whl
Check your Python version, there is also a wheel for Python 3.7.
These are comparative screenshots of the original examples written in C++ and the ones here written in Python.
- Core i3-3220T, IGP, Intel Ivybridge, XCB, linux
Example | C++ | Python |
---|---|---|
triangle | ![]() |
![]() |
triangle (imgui) | ![]() |
![]() |
- Pentium G4400, GTX950, nvidia proprietary, XCB, linux
Example | C++ | Python |
---|---|---|
triangle | ![]() |
![]() |
triangle (imgui) | ![]() |
![]() |
texture | ![]() |
![]() |
scenerendering | ![]() |
![]() |