Skip to content

szabolcsdombi/python-compute-shader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python ComputeShader

The main idea is to simpify the process of coding a compute shader in OpenGL for python This module has no ability to handle image2D, Uniform Buffers, etc...
The idea is to fill an SSBO with data, run a compute shader on it, then read the SSBO's content.
One can use multiple buffers for the communication, there is no optimization possibilities yet for read-only and write-only buffers.

Requirements

OpenGL 4.3+
Python 3.3
Python 3.4
Python 3.5

Common

Info()
StartTimer()
GetTimer()

Info returns a python dict filled with glGet

  • GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS
  • GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS
  • GL_MAX_COMPUTE_SHARED_MEMORY_SIZE
  • GL_MAX_COMPUTE_ATOMIC_COUNTERS
  • GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS
  • GL_MAX_COMPUTE_WORK_GROUP_COUNT
  • GL_MAX_COMPUTE_WORK_GROUP_SIZE
  • GL_MAX_UNIFORM_BLOCK_SIZE
  • GL_MAX_COMPUTE_UNIFORM_BLOCKS
  • GL_MAX_COMPUTE_UNIFORM_COMPONENTS
  • GL_MAJOR_VERSION
  • GL_MINOR_VERSION

GetTimer returns a float in seconds

Compute Shader (CS)

NewCS(source)
UseCS(cs, x, y, z)
DeleteCS(cs)

NewCS returns a new compute shader compiled from the source
rest of the functions return None

Shader Storage Buffer Object (SSBO)

NewSSBO(content)
UseSSBO(ssbo, cs, binding)
UpdateSSBO(ssbo, data, offset)
ReadSSBO(ssbo, size, offset)
DeleteSSBO(ssbo)

NewSSBO returns a new compute shader initialized with the content
ReadSSBO returns the value read from the GPU starting at the offset
rest of the functions return None


Optional parameters

NewCS(source)
UseCS(cs, [x = 1, y = 1, z = 1])
DeleteCS(cs)
NewSSBO(content)
UseSSBO(ssbo, cs, [binding = 0])
UpdateSSBO(ssbo, data, [offset = 0])
ReadSSBO(ssbo, size, [offset = 0])
DeleteSSBO(ssbo)

Exceptions

There is a poor implementation for exceptions inside the module but they are hard to catch since the 32 and 64 bit version of this module has it's own Exception