pygfx / pyshader

Write modern GPU shaders in Python!
BSD 2-Clause "Simplified" License
72 stars 1 forks source link

Compiling to file #58

Closed Korijn closed 3 years ago

Korijn commented 3 years ago

Is it possible to precompile shaders to files with the current pyshader API? Or would that still need to happen at runtime because it depends on drivers & hardware?

almarklein commented 3 years ago

That should certainly be possible. Can be done for either bytecode or SpirV.

Korijn commented 3 years ago

Example:

from pyshader import python2shader, i32, f32, ivec3, Array

@python2shader
def compute_shader_copy(
    index: ("input", "GlobalInvocationId", ivec3),
    data1: ("buffer", 0, Array(i32)),
    data2: ("buffer", 1, Array(i32)),
):
    i = index.x
    data2[i] = data1[i]

with open("copy.comp.spv", "wb") as fh:
    fh.write(compute_shader_copy.to_spirv())