Skip to main content

Python bindings for the Goldy GPU library

Project description

Goldy Python Bindings

Python bindings for the Goldy GPU library.

Installation

pip install goldy

Or build from source:

cd goldy-py
pip install maturin
maturin develop

Quick Start

import goldy
import numpy as np

# Create device
instance = goldy.Instance()
device = instance.create_device(goldy.DeviceType.DISCRETE_GPU)

# Create vertex buffer with a triangle
vertices = np.array([
    # x, y, r, g, b, a
     0.0, -0.5, 1.0, 0.0, 0.0, 1.0,  # red
    -0.5,  0.5, 0.0, 1.0, 0.0, 1.0,  # green
     0.5,  0.5, 0.0, 0.0, 1.0, 1.0,  # blue
], dtype=np.float32)
buffer = goldy.Buffer(device, vertices, goldy.BufferUsage.VERTEX)

# Create shader and pipeline
shader = goldy.ShaderModule.from_slang(device, goldy.Builtins.VERTEX_COLOR_2D)
pipeline = goldy.RenderPipeline(device, shader, shader, goldy.RenderPipelineDesc())

# Render
target = goldy.RenderTarget(device, 800, 600, goldy.TextureFormat.RGBA8_UNORM)
encoder = goldy.CommandEncoder()
with encoder.begin_render_pass() as rp:
    rp.clear(goldy.Color(0.1, 0.1, 0.2, 1.0))
    rp.set_pipeline(pipeline)
    rp.set_vertex_buffer(0, buffer)
    rp.draw(range(3))

target.render(encoder)
pixels = target.read_to_cpu()  # Returns numpy.ndarray with shape (600, 800, 4)

Examples

See the examples/ directory for complete examples:

  • hello_triangle.py - Basic triangle rendering
  • gradient.py - Custom shader with goldy_exp library
  • adapter_info.py - Print GPU adapter information
  • compute_demo.py - Compute shader placeholder

Run an example:

cd goldy-py
maturin develop
python examples/hello_triangle.py

Features

NumPy Integration

Buffers accept numpy arrays directly:

vertices = np.array([...], dtype=np.float32)
buffer = goldy.Buffer(device, vertices, goldy.BufferUsage.VERTEX)

Render targets return numpy arrays:

pixels = target.read_to_cpu()  # Shape: (height, width, 4), dtype: uint8

Context Managers

Pythonic API with with statements for render passes:

with encoder.begin_render_pass() as rp:
    rp.clear(goldy.Color.RED)
    rp.set_pipeline(pipeline)
    rp.draw(range(3))

Shader Libraries

Use the built-in goldy_exp library or register custom ones:

# Built-in library
shader = goldy.ShaderModule.from_slang(device, '''
    import goldy_exp;
    
    [shader("fragment")]
    float4 fs_main(FullscreenVarying input) : SV_Target {
        return float4(rainbow(input.uv.x), 1.0);
    }
''')

# Custom library
device.register_library('mylib', '''
    module mylib;
    public float3 my_color() { return float3(1.0, 0.5, 0.0); }
''')

API Reference

Core Classes

Class Description
Instance Entry point, enumerate adapters
Device GPU device for creating resources
Buffer GPU buffer for vertex/index/uniform data
ShaderModule Compiled Slang shader
RenderPipeline Complete render state
RenderTarget Off-screen render target
CommandEncoder Record render commands
RenderPass Draw commands within a pass

Enums

Enum Values
DeviceType DISCRETE_GPU, INTEGRATED_GPU, CPU, OTHER
TextureFormat RGBA8_UNORM, BGRA8_UNORM, RGBA16_FLOAT, ...
BufferUsage VERTEX, INDEX, UNIFORM, STORAGE, ...
PrimitiveTopology TRIANGLE_LIST, LINE_LIST, POINT_LIST, ...

Types

Type Description
Color RGBA color (float or byte)
VertexBufferLayout Vertex format description
RenderPipelineDesc Pipeline configuration
DepthStencilState Depth testing configuration

Testing

cd goldy-py
maturin develop
pytest tests/ -v

Tests are organized into:

  • test_types.py - Type wrapper tests (no GPU required)
  • test_gpu.py - GPU integration tests (skipped if no GPU)

Requirements

  • Python 3.9+
  • NumPy 1.20+
  • Vulkan 1.3+ compatible GPU

Publishing to PyPI

This package uses GitHub Actions with PyPI Trusted Publishers for automated releases.

Creating a release

  1. Update version in pyproject.toml and python/goldy/__init__.py
  2. Commit and push changes
  3. Create a git tag matching the version:
    git tag v0.1.1dev0
    git push origin v0.1.1dev0
    
  4. create a release: gh release create v0.1.1dev0 --title "v0.1.1dev0" --notes "..."
  5. The publish workflow will automatically build wheels and upload to PyPI

Manual testing (TestPyPI)

For testing before a real release, you can configure a separate Trusted Publisher for TestPyPI at https://test.pypi.org/manage/account/publishing/ and modify the workflow to publish there first.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

goldy-0.1.0-cp312-cp312-win_amd64.whl (446.6 kB view details)

Uploaded CPython 3.12Windows x86-64

goldy-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (570.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

goldy-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl (576.5 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

goldy-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (632.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file goldy-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: goldy-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 446.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for goldy-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 233d148b30bb2965e64719ed3f2e7ef6190055bc8852c4d5859e247fde98775b
MD5 8c2fe9795cb2d2becb95bfa1b7dee552
BLAKE2b-256 b0c1922ab1c63dae1d07164c4b07fd8fd1ede8249587ee51a8781ab22023ba82

See more details on using hashes here.

Provenance

The following attestation bundles were made for goldy-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on koubaa/goldy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file goldy-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for goldy-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b63e524e63bbb72fa896234ef3d2a786cdefc4b19f0f9be6de4231f8c9127ab
MD5 806e94240388a27c565d644ff7530f49
BLAKE2b-256 64bfb9ff743ccccbd54cd7948c1af8be3330eb33a9b3d720f0f20cf1f2f0f0eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for goldy-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on koubaa/goldy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file goldy-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for goldy-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0e901891de2002c844d1a1c57aca07f9fa5c4e2427d3c96092480dfac7cc3e29
MD5 8bc443d5f9c103bc3a283eb5cb034963
BLAKE2b-256 4e9935f66180baf90412a4443fac244ad7b4a401559c952fd8add6e53fc24d66

See more details on using hashes here.

Provenance

The following attestation bundles were made for goldy-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: publish.yml on koubaa/goldy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file goldy-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for goldy-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99406a8e677f20a238c11a74c5141494668f17b06f4fafe5648ca8b5a3dca6f3
MD5 3e2db05fec6e21430585164fbb864002
BLAKE2b-256 a1131f9262774c92f5743336011bfc0130c465ab39927fafacf7c7945635808c

See more details on using hashes here.

Provenance

The following attestation bundles were made for goldy-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on koubaa/goldy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page