vulk package

Submodules

vulk.audio module

vulk.baseapp module

vulk.context module

Module to create Window and Vulkan context

This module contains class to create the SDL2 window and the Vulkan logical device and queues. The context will be then passed to the Application to use it.

Vulk uses a specific way to interact with Vulkan that allow a good abstraction. Instead of performing the final drawing operation directly on the swapchain’s images, Vulk performs all operations on custom images and framebuffer and finally just copy the result in the swapchain’s image.

class vulk.context.VulkContext[source]

Bases: object

clear_final_image(colors)[source]

Clear the final image with colors

Parameters:

  • colors: list of 4 float (rgba)
create(window, configuration)[source]

Create Vulkan context

Parameters:

  • window: The VulkWindow
  • configuration: Configuration from Application
get_events()[source]
swap(semaphores=None)[source]

Display final image on screen.

This function makes all the rendering work. To proceed, it copies the final_image into the current swapchain image previously acquired. You can pass custom semaphores (and you should) to synchronize the command.

Parameters:

  • semaphore: A list of Semaphore to wait on
**Note: final_image layout is handled by VulkContext. You must
let it to COLOR_ATTACHMENT_OPTIMAL**
class vulk.context.VulkWindow[source]

Bases: object

close()[source]
open(configuration)[source]

Open the SDL2 Window

Parameters:

  • configuration: Configurations parameters from Application

vulk.event module

class vulk.event.BaseEventListener[source]

Bases: vulk.event.DispatchEventListener

Extends DispatchEventListener with smarter functions

mouse_down(x, y, button)[source]
mouse_drag(x, y, xr, yr, button)[source]

Called when mouse is dragged

Parameters:

  • x: X position in Screen coordinate
  • y: Y position in Screen coordinate
  • xr: X relative position since the last move
  • yr: Y relative position since the last move
  • button: vulk.input.Button
mouse_move(x, y, xr, yr)[source]
mouse_up(x, y, button)[source]
class vulk.event.CallbackEventListener(key_down=None, key_up=None, mouse_down=None, mouse_drag=None, mouse_move=None, mouse_up=None, quit=None)[source]

Bases: vulk.event.BaseEventListener

Like BaseEventListener but with callback. You must pass named parameters with the exact same name as in BaseEventListener.

Example:

` listener = CallbackEventListener(key_up=callback1, key_down=callback2) `

key_down(*args)[source]
key_up(*args)[source]
mouse_down(*args)[source]
mouse_drag(*args)[source]
mouse_move(*args)[source]
mouse_up(*args)[source]
quit(*args)[source]
class vulk.event.DispatchEventListener[source]

Bases: vulk.event.RawEventListener

This class dispatch each event to its specific function. This class is very basic and performs no logic. To get more logic, you must use BaseEventListener.

handle(event)[source]

Called for each event received

Parameters:

  • event: eventconstant.BaseEvent

Returns:

  • True if event handled
  • False otherwise
key_down(keycode)[source]

Called when a key is pressed

Parameters:

  • keycode: vulk.input.KeyCode
key_up(keycode)[source]

Called when a key is released

Parameters:

  • keycode: vulk.input.KeyCode
mouse_down(x, y, button)[source]

Called when mouse is released

Parameters:

  • x: X position in Screen coordinate
  • y: Y position in Screen coordinate
  • button: vulk.input.Button
mouse_move(x, y, xr, yr)[source]

Called when mouse is moving

Parameters:

  • x: X position in Screen coordinate
  • y: Y position in Screen coordinate
  • xr: X relative position since the last move
  • yr: Y relative position since the last move
mouse_up(x, y, button)[source]

Called when mouse is clicked

Parameters:

  • x: X position in Screen coordinate
  • y: Y position in Screen coordinate
  • button: vulk.input.Button
quit()[source]

Called when App must quit

class vulk.event.EventChainListener(event_listeners=None)[source]

Bases: vulk.event.RawEventListener

Allow to chain events. When an event is sent to the EventChain, included event listeners will intercept events until one of them return False.

handle(event)[source]

Call event listener until one of them return False.

Parameters:

class vulk.event.RawEventListener[source]

Bases: abc.ABC

Base class for event listener. You shouldn’t need to inherit directly from this class, it’s very low level.

handle(event)[source]

Called for each event received

Parameters:

  • event: eventconstant.BaseEvent

Returns:

  • True if event handled
  • False otherwise
vulk.event.wrap_callback(f)[source]

Decorator used in CallbackEventListener. If a callback exists for the event, we call the callback, else we return False.

vulk.eventconstant module

class vulk.eventconstant.BaseEvent(event)[source]

Bases: object

class vulk.eventconstant.Button[source]

Bases: enum.IntEnum

An enumeration.

LEFT = 1
MIDDLE = 2
RIGHT = 3
X1 = 4
X2 = 5
class vulk.eventconstant.EventType[source]

Bases: enum.IntEnum

An enumeration.

AUDIO_DEVICE_ADDED = 4352
AUDIO_DEVICE_REMOVED = 4353
CONTROLLER_AXIS_MOTION = 1616
CONTROLLER_BUTTON_DOWN = 1617
CONTROLLER_BUTTON_UP = 1618
CONTROLLER_DEVICE_ADDED = 1619
CONTROLLER_DEVICE_REMAPPED = 1621
CONTROLLER_DEVICE_REMOVED = 1620
DROP_BEGIN = 4098
DROP_COMPLETE = 4099
DROP_FILE = 4096
DROP_TEXT = 4097
FINGER_DOWN = 1792
FINGER_MOTION = 1794
FINGER_UP = 1793
JOY_AXISMOTION = 1536
JOY_BALLMOTION = 1537
JOY_BUTTONDOWN = 1539
JOY_BUTTONUP = 1540
JOY_DEVICEADDED = 1541
JOY_DEVICEREMOVED = 1542
JOY_HATMOTION = 1538
KEY_DOWN = 768
KEY_UP = 769
MOUSE_BUTTONDOWN = 1025
MOUSE_BUTTONUP = 1026
MOUSE_MOTION = 1024
MOUSE_WHEEL = 1027
QUIT = 256
WINDOW = 512
class vulk.eventconstant.KeyCode[source]

Bases: enum.IntEnum

An enumeration.

LEFT = 80
RIGHT = 79
class vulk.eventconstant.KeyboardEvent(event)[source]

Bases: vulk.eventconstant.BaseEvent

class vulk.eventconstant.MouseButtonEvent(event)[source]

Bases: vulk.eventconstant.BaseEvent

class vulk.eventconstant.MouseMotionEvent(event)[source]

Bases: vulk.eventconstant.BaseEvent

class vulk.eventconstant.QuitEvent(event)[source]

Bases: vulk.eventconstant.BaseEvent

vulk.eventconstant.to_vulk_event(event)[source]

Convert a SDL2 event to a Vulk Event

Parameters:

  • event : SDL_Event

vulk.exception module

exception vulk.exception.SDL2Error[source]

Bases: vulk.exception.VulkError

exception vulk.exception.SoundError[source]

Bases: vulk.exception.VulkError

exception vulk.exception.VulkError[source]

Bases: Exception

vulk.util module

vulk.util.millis()[source]

Return the time in milliseconds

vulk.util.mipmap_levels(base_width, base_height)[source]

Return max number of mipmap for the size

Args:
base_width (int): Width source base_height (int): Height source
Returns:
int: Number of mipmap levels
vulk.util.mipmap_size(base_width, base_height, mip_level)[source]

Return mipmap width and height

Args:
base_width (int): Width of the base image (mip level 0) base_height (int): Height of the base image (mip level 0) mip_level (int): Level of mip to get
Returns:
tuple(mip_width, mip_height)
vulk.util.nanos()[source]

Return the time in nanoseconds

vulk.util.next_multiple(query, multiple)[source]

Get the next multiple

Args:
query (int): To test multiple (int): Divider
Returns:
int: Next multiple of divider
vulk.util.time_since_millis(previous_time)[source]

Return the time in milliseconds from the previous_time argument

vulk.vulkanconstant module

This module contains useful mapping or constants.

Vulkan enum are translated to Python enum. There are two types of enumeration, IntEnum and IntFlag. IntEnum are classic enumeration whereas IntFlag are different. IntFlag allows to realize bitwise operation and corresponds to the Vulkan enumeration that ends by ‘_BIT’. All enumerations have a specific field NONE which is equals to 0.

class vulk.vulkanconstant.Access[source]

Bases: enum.IntFlag

An enumeration.

COLOR_ATTACHMENT_READ = 128
COLOR_ATTACHMENT_WRITE = 256
DEPTH_STENCIL_ATTACHMENT_READ = 512
DEPTH_STENCIL_ATTACHMENT_WRITE = 1024
HOST_READ = 8192
HOST_WRITE = 16384
INDEX_READ = 2
INDIRECT_COMMAND_READ = 1
INPUT_ATTACHMENT_READ = 16
MEMORY_READ = 32768
MEMORY_WRITE = 65536
NONE = 0
SHADER_READ = 32
SHADER_WRITE = 64
TRANSFER_READ = 2048
TRANSFER_WRITE = 4096
UNIFORM_READ = 8
VERTEX_ATTRIBUTE_READ = 4
class vulk.vulkanconstant.AttachmentLoadOp[source]

Bases: enum.IntEnum

An enumeration.

CLEAR = 1
DONT_CARE = 2
LOAD = 0
NONE = 0
class vulk.vulkanconstant.AttachmentStoreOp[source]

Bases: enum.IntEnum

An enumeration.

DONT_CARE = 1
NONE = 0
STORE = 0
class vulk.vulkanconstant.BlendFactor[source]

Bases: enum.IntEnum

An enumeration.

CONSTANT_ALPHA = 12
CONSTANT_COLOR = 10
DST_ALPHA = 8
DST_COLOR = 4
NONE = 0
ONE = 1
ONE_MINUS_CONSTANT_ALPHA = 13
ONE_MINUS_CONSTANT_COLOR = 11
ONE_MINUS_DST_ALPHA = 9
ONE_MINUS_DST_COLOR = 5
ONE_MINUS_SRC1_ALPHA = 18
ONE_MINUS_SRC1_COLOR = 16
ONE_MINUS_SRC_ALPHA = 7
ONE_MINUS_SRC_COLOR = 3
SRC1_ALPHA = 17
SRC1_COLOR = 15
SRC_ALPHA = 6
SRC_ALPHA_SATURATE = 14
SRC_COLOR = 2
ZERO = 0
class vulk.vulkanconstant.BlendOp[source]

Bases: enum.IntEnum

An enumeration.

ADD = 0
MAX = 4
MIN = 3
NONE = 0
REVERSE_SUBSTRACT = 2
SUBSTRACT = 1
class vulk.vulkanconstant.BorderColor[source]

Bases: enum.IntEnum

An enumeration.

FLOAT_OPAQUE_BLACK = 2
FLOAT_OPAQUE_WHITE = 4
FLOAT_TRANSPARENT_BLACK = 0
INT_OPAQUE_BLACK = 3
INT_OPAQUE_WHITE = 5
INT_TRANSPARENT_BLACK = 1
NONE = 0
class vulk.vulkanconstant.BufferCreate[source]

Bases: enum.IntFlag

An enumeration.

NONE = 0
SPARSE_ALIASED = 4
SPARSE_BINDING = 1
SPARSE_RESIDENCY = 2
class vulk.vulkanconstant.BufferUsage[source]

Bases: enum.IntFlag

An enumeration.

INDEX_BUFFER = 64
INDIRECT_BUFFER = 256
NONE = 0
STORAGE_BUFFER = 32
STORAGE_TEXEL_BUFFER = 8
TRANSFER_DST = 2
TRANSFER_SRC = 1
UNIFORM_BUFFER = 16
UNIFORM_TEXEL_BUFFER = 4
VERTEX_BUFFER = 128
class vulk.vulkanconstant.ColorComponent[source]

Bases: enum.IntFlag

An enumeration.

A = 8
B = 4
G = 2
NONE = 0
R = 1
class vulk.vulkanconstant.CommandBufferLevel[source]

Bases: enum.IntEnum

An enumeration.

NONE = 0
PRIMARY = 0
SCONDARY = 1
class vulk.vulkanconstant.CommandBufferReset[source]

Bases: enum.IntFlag

An enumeration.

NONE = 0
RELEASE_RESOURCES = 1
class vulk.vulkanconstant.CommandBufferUsage[source]

Bases: enum.IntFlag

An enumeration.

NONE = 0
ONE_TIME_SUBMIT = 1
RENDER_PASS_CONTINUE = 2
SIMULTANEOUS_USE = 4
class vulk.vulkanconstant.CommandPoolCreate[source]

Bases: enum.IntFlag

An enumeration.

NONE = 0
RESET_COMMAND_BUFFER = 2
TRANSIENT = 1
class vulk.vulkanconstant.CompareOp[source]

Bases: enum.IntEnum

An enumeration.

ALWAYS = 7
EQUAL = 2
GREATER = 4
GREATER_OR_EQUAL = 6
LESS = 1
LESS_OR_EQUAL = 3
NEVER = 0
NONE = 0
NOT_EQUAL = 5
class vulk.vulkanconstant.ComponentSwizzle[source]

Bases: enum.IntEnum

An enumeration.

A = 6
B = 5
G = 4
IDENTITY = 0
NONE = 0
ONE = 2
R = 3
ZERO = 1
class vulk.vulkanconstant.CullMode[source]

Bases: enum.IntFlag

An enumeration.

BACK = 2
FRONT = 1
FRONT_AND_BACK = 3
NONE = 0
class vulk.vulkanconstant.DataType[source]

Bases: enum.IntEnum

An enumeration.

SFLOAT16 = 7
SFLOAT32 = 8
SINT16 = 4
SINT32 = 6
SINT8 = 2
SNORM16 = 12
SNORM32 = 14
SNORM8 = 10
UINT16 = 3
UINT32 = 5
UINT8 = 1
UNORM16 = 11
UNORM32 = 13
UNORM8 = 9
class vulk.vulkanconstant.Dependency[source]

Bases: enum.IntFlag

An enumeration.

BY_REGION = 1
NONE = 0
class vulk.vulkanconstant.DescriptorPoolCreate[source]

Bases: enum.IntFlag

An enumeration.

FREE_DESCRIPTOR_SET = 1
NONE = 0
class vulk.vulkanconstant.DescriptorType[source]

Bases: enum.IntEnum

An enumeration.

COMBINED_IMAGE_SAMPLER = 1
INPUT_ATTACHMENT = 10
NONE = 0
SAMPLED_IMAGE = 2
SAMPLER = 0
STORAGE_BUFFER = 7
STORAGE_BUFFER_DYNAMIC = 9
STORAGE_IMAGE = 3
STORAGE_TEXEL_BUFFER = 5
UNIFORM_BUFFER = 6
UNIFORM_BUFFER_DYNAMIC = 8
UNIFORM_TEXEL_BUFFER = 4
class vulk.vulkanconstant.Filter[source]

Bases: enum.IntEnum

An enumeration.

LINEAR = 1
NEAREST = 0
NONE = 0
class vulk.vulkanconstant.Format[source]

Bases: enum.IntEnum

An enumeration.

A1R5G5B5_UNORM_PACK16 = 8
A2B10G10R10_SINT_PACK32 = 69
A2B10G10R10_SNORM_PACK32 = 65
A2B10G10R10_SSCALED_PACK32 = 67
A2B10G10R10_UINT_PACK32 = 68
A2B10G10R10_UNORM_PACK32 = 64
A2B10G10R10_USCALED_PACK32 = 66
A2R10G10B10_SINT_PACK32 = 63
A2R10G10B10_SNORM_PACK32 = 59
A2R10G10B10_SSCALED_PACK32 = 61
A2R10G10B10_UINT_PACK32 = 62
A2R10G10B10_UNORM_PACK32 = 58
A2R10G10B10_USCALED_PACK32 = 60
A8B8G8R8_SINT_PACK32 = 56
A8B8G8R8_SNORM_PACK32 = 52
A8B8G8R8_SRGB_PACK32 = 57
A8B8G8R8_SSCALED_PACK32 = 54
A8B8G8R8_UINT_PACK32 = 55
A8B8G8R8_UNORM_PACK32 = 51
A8B8G8R8_USCALED_PACK32 = 53
ASTC_10x10_SRGB_BLOCK = 180
ASTC_10x10_UNORM_BLOCK = 179
ASTC_10x5_SRGB_BLOCK = 174
ASTC_10x5_UNORM_BLOCK = 173
ASTC_10x6_SRGB_BLOCK = 176
ASTC_10x6_UNORM_BLOCK = 175
ASTC_10x8_SRGB_BLOCK = 178
ASTC_10x8_UNORM_BLOCK = 177
ASTC_12x10_SRGB_BLOCK = 182
ASTC_12x10_UNORM_BLOCK = 181
ASTC_12x12_SRGB_BLOCK = 184
ASTC_12x12_UNORM_BLOCK = 183
ASTC_4x4_SRGB_BLOCK = 158
ASTC_4x4_UNORM_BLOCK = 157
ASTC_5x4_SRGB_BLOCK = 160
ASTC_5x4_UNORM_BLOCK = 159
ASTC_5x5_SRGB_BLOCK = 162
ASTC_5x5_UNORM_BLOCK = 161
ASTC_6x5_SRGB_BLOCK = 164
ASTC_6x5_UNORM_BLOCK = 163
ASTC_6x6_SRGB_BLOCK = 166
ASTC_6x6_UNORM_BLOCK = 165
ASTC_8x5_SRGB_BLOCK = 168
ASTC_8x5_UNORM_BLOCK = 167
ASTC_8x6_SRGB_BLOCK = 170
ASTC_8x6_UNORM_BLOCK = 169
ASTC_8x8_SRGB_BLOCK = 172
ASTC_8x8_UNORM_BLOCK = 171
B10G11R11_UFLOAT_PACK32 = 122
B4G4R4A4_UNORM_PACK16 = 3
B5G5R5A1_UNORM_PACK16 = 7
B5G6R5_UNORM_PACK16 = 5
B8G8R8A8_SINT = 49
B8G8R8A8_SNORM = 45
B8G8R8A8_SRGB = 50
B8G8R8A8_SSCALED = 47
B8G8R8A8_UINT = 48
B8G8R8A8_UNORM = 44
B8G8R8A8_USCALED = 46
B8G8R8_SINT = 35
B8G8R8_SNORM = 31
B8G8R8_SRGB = 36
B8G8R8_SSCALED = 33
B8G8R8_UINT = 34
B8G8R8_UNORM = 30
B8G8R8_USCALED = 32
BC1_RGBA_SRGB_BLOCK = 134
BC1_RGBA_UNORM_BLOCK = 133
BC1_RGB_SRGB_BLOCK = 132
BC1_RGB_UNORM_BLOCK = 131
BC2_SRGB_BLOCK = 136
BC2_UNORM_BLOCK = 135
BC3_SRGB_BLOCK = 138
BC3_UNORM_BLOCK = 137
BC4_SNORM_BLOCK = 140
BC4_UNORM_BLOCK = 139
BC5_SNORM_BLOCK = 142
BC5_UNORM_BLOCK = 141
BC6H_SFLOAT_BLOCK = 144
BC6H_UFLOAT_BLOCK = 143
BC7_SRGB_BLOCK = 146
BC7_UNORM_BLOCK = 145
D16_UNORM = 124
D16_UNORM_S8_UINT = 128
D24_UNORM_S8_UINT = 129
D32_SFLOAT = 126
D32_SFLOAT_S8_UINT = 130
E5B9G9R9_UFLOAT_PACK32 = 123
EAC_R11G11_SNORM_BLOCK = 156
EAC_R11G11_UNORM_BLOCK = 155
EAC_R11_SNORM_BLOCK = 154
EAC_R11_UNORM_BLOCK = 153
ETC2_R8G8B8A1_SRGB_BLOCK = 150
ETC2_R8G8B8A1_UNORM_BLOCK = 149
ETC2_R8G8B8A8_SRGB_BLOCK = 152
ETC2_R8G8B8A8_UNORM_BLOCK = 151
ETC2_R8G8B8_SRGB_BLOCK = 148
ETC2_R8G8B8_UNORM_BLOCK = 147
NONE = 0
R16G16B16A16_SFLOAT = 97
R16G16B16A16_SINT = 96
R16G16B16A16_SNORM = 92
R16G16B16A16_SSCALED = 94
R16G16B16A16_UINT = 95
R16G16B16A16_UNORM = 91
R16G16B16A16_USCALED = 93
R16G16B16_SFLOAT = 90
R16G16B16_SINT = 89
R16G16B16_SNORM = 85
R16G16B16_SSCALED = 87
R16G16B16_UINT = 88
R16G16B16_UNORM = 84
R16G16B16_USCALED = 86
R16G16_SFLOAT = 83
R16G16_SINT = 82
R16G16_SNORM = 78
R16G16_SSCALED = 80
R16G16_UINT = 81
R16G16_UNORM = 77
R16G16_USCALED = 79
R16_SFLOAT = 76
R16_SINT = 75
R16_SNORM = 71
R16_SSCALED = 73
R16_UINT = 74
R16_UNORM = 70
R16_USCALED = 72
R32G32B32A32_SFLOAT = 109
R32G32B32A32_SINT = 108
R32G32B32A32_UINT = 107
R32G32B32_SFLOAT = 106
R32G32B32_SINT = 105
R32G32B32_UINT = 104
R32G32_SFLOAT = 103
R32G32_SINT = 102
R32G32_UINT = 101
R32_SFLOAT = 100
R32_SINT = 99
R32_UINT = 98
R4G4B4A4_UNORM_PACK16 = 2
R4G4_UNORM_PACK8 = 1
R5G5B5A1_UNORM_PACK16 = 6
R5G6B5_UNORM_PACK16 = 4
R64G64B64A64_SFLOAT = 121
R64G64B64A64_SINT = 120
R64G64B64A64_UINT = 119
R64G64B64_SFLOAT = 118
R64G64B64_SINT = 117
R64G64B64_UINT = 116
R64G64_SFLOAT = 115
R64G64_SINT = 114
R64G64_UINT = 113
R64_SFLOAT = 112
R64_SINT = 111
R64_UINT = 110
R8G8B8A8_SINT = 42
R8G8B8A8_SNORM = 38
R8G8B8A8_SRGB = 43
R8G8B8A8_SSCALED = 40
R8G8B8A8_UINT = 41
R8G8B8A8_UNORM = 37
R8G8B8A8_USCALED = 39
R8G8B8_SINT = 28
R8G8B8_SNORM = 24
R8G8B8_SRGB = 29
R8G8B8_SSCALED = 26
R8G8B8_UINT = 27
R8G8B8_UNORM = 23
R8G8B8_USCALED = 25
R8G8_SINT = 21
R8G8_SNORM = 17
R8G8_SRGB = 22
R8G8_SSCALED = 19
R8G8_UINT = 20
R8G8_UNORM = 16
R8G8_USCALED = 18
R8_SINT = 14
R8_SNORM = 10
R8_SRGB = 15
R8_SSCALED = 12
R8_UINT = 13
R8_UNORM = 9
R8_USCALED = 11
S8_UINT = 127
UNDEFINED = 0
X8_D24_UNORM_PACK32 = 125
class vulk.vulkanconstant.FormatType[source]

Bases: enum.Enum

Mapping between Format and (DataType, num_components)

B8G8R8A8_SINT = (<DataType.SINT8: 2>, 4)
B8G8R8A8_UINT = (<DataType.UINT8: 1>, 4)
R16G16B16A16_SFLOAT = (<DataType.SFLOAT16: 7>, 4)
R16G16B16A16_SINT = (<DataType.SINT16: 4>, 4)
R16G16B16A16_UINT = (<DataType.UINT16: 3>, 1)
R16G16B16_SFLOAT = (<DataType.SFLOAT16: 7>, 3)
R16G16B16_SINT = (<DataType.SINT16: 4>, 3)
R16G16B16_UINT = (<DataType.UINT16: 3>, 3)
R16G16_SFLOAT = (<DataType.SFLOAT16: 7>, 2)
R16G16_SINT = (<DataType.SINT16: 4>, 2)
R16G16_UINT = (<DataType.UINT16: 3>, 2)
R16_SFLOAT = (<DataType.SFLOAT16: 7>, 1)
R16_SINT = (<DataType.SINT16: 4>, 1)
R16_UINT = (<DataType.UINT16: 3>, 1)
R32G32B32A32_SFLOAT = (<DataType.SFLOAT32: 8>, 4)
R32G32B32A32_SINT = (<DataType.SINT32: 6>, 4)
R32G32B32A32_UINT = (<DataType.UINT32: 5>, 4)
R32G32B32_SFLOAT = (<DataType.SFLOAT32: 8>, 3)
R32G32B32_SINT = (<DataType.SINT32: 6>, 3)
R32G32B32_UINT = (<DataType.UINT32: 5>, 3)
R32G32_SFLOAT = (<DataType.SFLOAT32: 8>, 2)
R32G32_SINT = (<DataType.SINT32: 6>, 2)
R32G32_UINT = (<DataType.UINT32: 5>, 2)
R32_SFLOAT = (<DataType.SFLOAT32: 8>, 1)
R32_SINT = (<DataType.SINT32: 6>, 1)
R32_UINT = (<DataType.UINT32: 5>, 1)
R8G8B8A8_SINT = (<DataType.SINT8: 2>, 4)
R8G8B8A8_SNORM = (<DataType.UNORM8: 9>, 4)
R8G8B8A8_UINT = (<DataType.UINT8: 1>, 4)
R8G8B8A8_UNORM = (<DataType.UNORM8: 9>, 4)
R8G8B8_SINT = (<DataType.SINT8: 2>, 3)
R8G8B8_SNORM = (<DataType.UNORM8: 9>, 3)
R8G8B8_UINT = (<DataType.UINT8: 1>, 3)
R8G8B8_UNORM = (<DataType.UNORM8: 9>, 3)
R8G8_SINT = (<DataType.SINT8: 2>, 2)
R8G8_SNORM = (<DataType.SNORM8: 10>, 2)
R8G8_UINT = (<DataType.UINT8: 1>, 2)
R8G8_UNORM = (<DataType.UNORM8: 9>, 2)
R8_SINT = (<DataType.SINT8: 2>, 1)
R8_SNORM = (<DataType.SNORM8: 10>, 1)
R8_UINT = (<DataType.UINT8: 1>, 1)
R8_UNORM = (<DataType.UNORM8: 9>, 1)
class vulk.vulkanconstant.FrontFace[source]

Bases: enum.IntEnum

An enumeration.

CLOCKWISE = 1
COUNTER_CLOCKWISE = 0
NONE = 0
class vulk.vulkanconstant.ImageAspect[source]

Bases: enum.IntFlag

An enumeration.

COLOR = 1
DEPTH = 2
METADATA = 8
NONE = 0
STENCIL = 4
class vulk.vulkanconstant.ImageLayout[source]

Bases: enum.IntEnum

An enumeration.

COLOR_ATTACHMENT_OPTIMAL = 2
DEPTH_STENCIL_ATTACHMENT_OPTIMAL = 3
DEPTH_STENCIL_READ_ONLY_OPTIMAL = 4
GENERAL = 1
NONE = 0
PREINITIALIZED = 8
PRESENT_SRC_KHR = 1000001002
SHADER_READ_ONLY_OPTIMAL = 5
TRANSFER_DST_OPTIMAL = 7
TRANSFER_SRC_OPTIMAL = 6
UNDEFINED = 0
class vulk.vulkanconstant.ImageTiling[source]

Bases: enum.IntEnum

An enumeration.

LINEAR = 1
NONE = 0
OPTIMAL = 0
class vulk.vulkanconstant.ImageType[source]

Bases: enum.IntEnum

An enumeration.

NONE = 0
TYPE_1D = 0
TYPE_2D = 1
TYPE_3D = 2
class vulk.vulkanconstant.ImageUsage[source]

Bases: enum.IntFlag

An enumeration.

COLOR_ATTACHMENT = 16
DEPTH_STENCIL_ATTACHMENT = 32
INPUT_ATTACHMENT = 128
NONE = 0
SAMPLED = 4
STORAGE = 8
TRANSFER_DST = 2
TRANSFER_SRC = 1
TRANSIENT_ATTACHMENT = 64
class vulk.vulkanconstant.ImageViewType[source]

Bases: enum.IntEnum

An enumeration.

NONE = 0
TYPE_1D = 0
TYPE_1D_ARRAY = 4
TYPE_2D = 1
TYPE_2D_ARRAY = 5
TYPE_3D = 2
TYPE_CUBE = 3
TYPE_CUBE_ARRAY = 6
class vulk.vulkanconstant.IndexType[source]

Bases: enum.IntEnum

An enumeration.

NONE = 0
UINT16 = 0
UINT32 = 1
class vulk.vulkanconstant.LogicOp[source]

Bases: enum.IntEnum

An enumeration.

AND = 1
AND_INVERTED = 4
AND_REVERSE = 2
CLEAR = 0
COPY = 3
COPY_INVERTED = 12
EQUIVALENT = 9
INVERT = 10
NAND = 14
NONE = 0
NOR = 8
NO_OP = 5
OR = 7
OR_INVERTED = 13
OR_REVERSE = 11
SET = 15
XOR = 6
class vulk.vulkanconstant.MemoryProperty[source]

Bases: enum.IntFlag

An enumeration.

DEVICE_LOCAL = 1
HOST_CACHED = 8
HOST_COHERENT = 4
HOST_VISIBLE = 2
LAZILY_ALLOCATED = 16
NONE = 0
class vulk.vulkanconstant.PipelineBindPoint[source]

Bases: enum.IntEnum

An enumeration.

COMPUTE = 1
GRAPHICS = 0
NONE = 0
class vulk.vulkanconstant.PipelineStage[source]

Bases: enum.IntFlag

An enumeration.

ALL_COMMANDS = 65536
ALL_GRAPHICS = 32768
BOTTOM_OF_PIPE = 8192
COLOR_ATTACHMENT_OUTPUT = 1024
COMPUTE_SHADER = 2048
DRAW_INDIRECT = 2
EARLY_FRAGMENT_TESTS = 256
FRAGMENT_SHADER = 128
GEOMETRY_SHADER = 64
HOST = 16384
LATE_FRAGMENT_TESTS = 512
NONE = 0
TESSELLATION_CONTROL_SHADER = 16
TESSELLATION_EVALUATION_SHADER = 32
TOP_OF_PIPE = 1
TRANSFER = 4096
VERTEX_INPUT = 4
VERTEX_SHADER = 8
class vulk.vulkanconstant.PolygonMode[source]

Bases: enum.IntEnum

An enumeration.

FILL = 0
LINE = 1
NONE = 0
POINT = 2
class vulk.vulkanconstant.PrimitiveTopology[source]

Bases: enum.IntEnum

An enumeration.

LINE_LIST = 1
LINE_LIST_WITH_ADJACENCY = 6
LINE_STRIP = 2
LINE_STRIP_WITH_ADJACENCY = 7
NONE = 0
PATCH_LIST = 10
POINT_LIST = 0
TRIANGLE_FAN = 5
TRIANGLE_LIST = 3
TRIANGLE_LIST_WITH_ADJACENCY = 8
TRIANGLE_STRIP = 4
TRIANGLE_STRIP_WITH_ADJACENCY = 9
class vulk.vulkanconstant.SampleCount[source]

Bases: enum.IntFlag

An enumeration.

COUNT_1 = 1
COUNT_16 = 16
COUNT_2 = 2
COUNT_32 = 32
COUNT_4 = 4
COUNT_64 = 64
COUNT_8 = 8
NONE = 0
class vulk.vulkanconstant.SamplerAddressMode[source]

Bases: enum.IntEnum

An enumeration.

CLAMP_TO_BORDER = 3
CLAMP_TO_EDGE = 2
MIRRORED_REPEAT = 1
MIRROR_CLAMP_TO_EDGE = 4
NONE = 0
REPEAT = 0
class vulk.vulkanconstant.SamplerMipmapMode[source]

Bases: enum.IntEnum

An enumeration.

LINEAR = 1
NEAREST = 0
NONE = 0
class vulk.vulkanconstant.ShaderStage[source]

Bases: enum.IntFlag

An enumeration.

ALL = 2147483647
ALL_GRAPHICS = 31
COMPUTE = 32
FRAGMENT = 16
GEOMETRY = 8
NONE = 0
TESSELLATION_CONTROL = 2
TESSELLATION_EVALUATION = 4
VERTEX = 1
class vulk.vulkanconstant.SharingMode[source]

Bases: enum.IntEnum

An enumeration.

CONCURRENT = 1
EXCLUSIVE = 0
NONE = 0
class vulk.vulkanconstant.SubpassContents[source]

Bases: enum.IntEnum

An enumeration.

INLINE = 0
NONE = 0
SECONDARY_COMMAND_BUFFERS = 1
class vulk.vulkanconstant.VertexInputRate[source]

Bases: enum.IntEnum

An enumeration.

INSTANCE = 1
NONE = 0
VERTEX = 0
vulk.vulkanconstant.format_info(f)[source]

Return detailed information of format f

Parameters:

  • f: Format

Returns:

Tuple containing:

  • DataType
  • Number of components
  • Size in bytes (not bits)
vulk.vulkanconstant.index_type_size(t)[source]

Return the size in byte of the index type

Parameters:

  • t: IndexType

vulk.vulkanobject module

Vulkan objects modules

This module contains the High level Vulkan object. It’s not that high level, you need to understand fully Vulkan to use theses objects. This module must be use by Vulkan expert and is very complicated to work with. You will see a lot of namedtuple here, they are used to better document the object arguments. Instead of passing a dict whith unknow keys, you pass a documented namedtuple, I think it’s better. If you want to understand internal Vulkan functions, you can hack around this module.

**Note: All classes, functions, tuples of this module are sorted
alphabetically.**
**Note: In this module, when it’s needed, the parameter type is indicated. If
the type begins with Vk…, it means a real Vulkan object and not an object in this module.**
class vulk.vulkanobject.AttachmentDescription

Bases: tuple

AttachmentDescription describes the attachment.

Parameters:

  • format: Format vulk constant
  • samples: SampleCount vulk constant
  • load: AttachmentLoadOp vulk constant
  • store: AttachmentStoreOp vulk constant
  • stencil_load: AttachmentLoadOp vulk constant
  • stencil_store: AttachmentStoreOp vulk constant
  • initial_layout: ImageLayout vulk constant
  • final_layout: ImageLayout vulk constant
final_layout

Alias for field number 7

format

Alias for field number 0

initial_layout

Alias for field number 6

load

Alias for field number 2

samples

Alias for field number 1

stencil_load

Alias for field number 4

stencil_store

Alias for field number 5

store

Alias for field number 3

class vulk.vulkanobject.AttachmentReference

Bases: tuple

AttachmentReference links an attachment index with a layout.

Parameters:

  • index: Index of attachment description
  • layout: ImageLayout vulk constant
index

Alias for field number 0

layout

Alias for field number 1

class vulk.vulkanobject.Buffer(context, flags, size, usage, sharing_mode, queue_families, memory_properties)[source]

Bases: object

Buffer wrap a VkBuffer and a VkMemory

bind(context, offset=0, size=0)[source]

Map this buffer to upload data in it

This function is a context manager and must be called with with. It return a python buffer and let you do what you want with it, be careful!

Args:
context (VulkContext) offset (int): Where to begin uploading in buffer size (int): Max size to write into the buffer (0 = all)

Warning: Buffer memory must be host visible

copy_to(cmd, dst_buffer)[source]

Copy this buffer to the destination buffer

Commands to copy are registered in the commandbuffer but it’s up to you to start and submit the command buffer to the execution queue.

Args:
cmd (CommandBufferRegister): used to register commands dst_buffer (Buffer): Destination buffer

Note: Buffers must have the same size

copy_to_image(cmd, dst_image, mip_infos)[source]

Copy this buffer to the destination image

Commands to copy are registered in the commandbuffer but it’s up to you to start and submit the command buffer to the execution queue.

Args:

cmd (CommandBufferRegister): used to register commands dst_image (Image): Destination image mip_infos (list): List containing for each mipmap a dict like

{‘offset’:, ‘size’:, ‘width’:, ‘height’:}
**Note: Layout of destination image must be TRANSFERT_DST_OPTIMAL.
It’s up to you.**
class vulk.vulkanobject.ClearColorValue(float32=None, uint32=None, int32=None)[source]

Bases: object

ClearValue for color clearing

class vulk.vulkanobject.ClearDepthStencilValue(depth, stencil)[source]

Bases: object

ClearValue for depth and stencil clearing

class vulk.vulkanobject.CommandBuffer(commandbuffer)[source]

Bases: object

Commands in Vulkan, like drawing operations and memory transfers, are not executed directly using function calls. You have to record all of the operations you want to perform in command buffer objects. The advantage of this is that all of the hard work of setting up the drawing commands can be done in advance and in multiple threads. After that, you just have to tell Vulkan to execute the commands in the main loop.

Commands are executed directly from the CommandBufferRegister subclass. The naming convention is simple: vkCmd[CommandName] becomes command_name

bind(flags=<CommandBufferUsage.NONE: 0>)[source]

Bind this buffer to register command.

Parameters:

  • flags: CommandBufferUsage vulk constant, default to 0

Returns:

CommandBufferRegister object

Todo: `pInheritanceInfo` must be implemented

reset(flags=<CommandBufferReset.NONE: 0>)[source]

Reset the command buffer

Parameters:

  • flags: CommandBufferReset vulk constant, default to 0
class vulk.vulkanobject.CommandBufferRegister(commandbuffer)[source]

Bases: object

Allow to call command on command buffer. CommandBufferRegister is not in charge of begin and end the command buffer. You should not use it directly but with bind method of CommandBuffer.

begin_renderpass(renderpass, framebuffer, renderarea, clears, contents=<SubpassContents.NONE: 0>)[source]

Begin a new renderpass

Parameters:

  • renderpass: The RenderPass to begin an instance of
  • framebuffer: The Framebuffer containing the attachments that
    are used with the render pass
  • renderarea: Rect2D size to render
  • clears: list of ClearValue for each Framebuffer
  • contents: SubpassContents vulk constant (default: INLINE)
bind_descriptor_sets(layout, first, descriptors, offsets, bind_point=<PipelineBindPoint.NONE: 0>)[source]

Binds descriptor sets to this CommandBuffer

Parameters:

  • layout: PipelineLayout
  • first: Number of the first descriptor set to be bound
  • descriptors: list of DescriptorSet
  • offsets: list of dynamic offsets
  • bind_point: PipelineBindPoint vulk constant (default: GRAPHICS)
bind_index_buffer(buffer, offset, index_type)[source]

Bind an index buffer to a command buffer

Parameters:

  • buffer: Index Buffer
  • offset: Offset (int)
  • index_type: IndexType vulk constant
bind_pipeline(pipeline, bind_point=<PipelineBindPoint.NONE: 0>)[source]

Bind the pipeline to this CommandBuffer.

Parameters:

  • pipeline: The Pipeline to bind
  • bind_point: PipelineBindPoint vulk constant (default: GRAPHICS)
bind_vertex_buffers(first, count, buffers, offsets)[source]

Bind vertex buffers to a command buffer

Parameters:

  • first: Index of the first vertex input binding
  • count: Number of vertex input bindings
  • buffers: list of Buffer
  • offsets: list of offset (int)
**Note: I don’t understand what is the point with offset but you
must pass an array of the same size as buffers.**

Note: Generally, `count = len(buffers)` and `first = 0`

clear_color_image(image, layout, clear_color, ranges)[source]

Clear image with color values

Parameters:

  • image: Image to clear
  • layout: ImageLayout of image
  • clear_color: ClearColorValue
  • ranges: list of ImageSubresourceRange
copy_buffer(src_buffer, dst_buffer, regions)[source]

Copy data between buffers

Parameters:

  • src_buffer: Buffer
  • dst_buffer: Buffer
  • regions: list of VkBufferCopy
copy_buffer_to_image(src_buffer, dst_image, dst_layout, regions)[source]

Copy a buffer into an image

Args:
src_buffer (Buffer): Source buffer dst_image (Image): Destination image dst_layout (ImageLayout): Image layout regions (list): List of VkBufferImageCopy
copy_image(src_image, src_layout, dst_image, dst_layout, regions)[source]

Copy data between images

Parameters:

  • src_image: Image
  • src_layout: ImageLayout vulk constant
  • dst_image: Image
  • dst_layout: ImageLayout vulk constant
  • regions: list of VkImageCopy
draw(vertex_count, first_vertex, instance_count=1, first_instance=0)[source]

Draw the vertice buffer.

When the command is executed, primitives are assembled using the current primitive topology and vertexCount consecutive vertex indices with the first vertexIndex value equal to firstVertex. The primitives are drawn instanceCount times with instanceIndex starting with firstInstance and increasing sequentially for each instance. The assembled primitives execute the currently bound graphics pipeline.

Parameters:

  • vertex_count: Number of vertices to draw
  • first_vertex: Index of the first vertex to draw
  • instance_count: Number of instance to draw (default: 1)
  • first_instance: First instance to draw (default: 0)
draw_indexed(index_count, first_index, vertex_offset=0, instance_count=1, first_instance=0)[source]

Draw the index buffer.

When the command is executed, primitives are assembled using the current primitive topology and indexCount vertices whose indices are retrieved from the index buffer. The index buffer is treated as an array of tightly packed unsigned integers of size defined by the vkCmdBindIndexBuffer::indexType parameter with which the buffer was bound.

The first vertex index is at an offset of firstIndex * indexSize + offset within the currently bound index buffer, where offset is the offset specified by vkCmdBindIndexBuffer and indexSize is the byte size of the type specified by indexType. Subsequent index values are retrieved from consecutive locations in the index buffer. Indices are first compared to the primitive restart value, then zero extended to 32 bits (if the indexType is VK_INDEX_TYPE_UINT16) and have vertexOffset added to them, before being supplied as the vertexIndex value.

The primitives are drawn instanceCount times with instanceIndex starting with firstInstance and increasing sequentially for each instance. The assembled primitives execute the currently bound graphics pipeline.

Parameters:

  • index_count: Number of vertices to draw
  • first_index: Base index within the index buffer
  • vertex_offset: Value added to the vertex index before indexing
    into the vertex buffer (default: 0)
  • instance_count: Number of instance to draw (default: 1)
  • first_instance: First instance to draw (default: 0)
end_renderpass()[source]

End the current render pass

pipeline_barrier(src_stage, dst_stage, dependency, memories, buffers, images)[source]

Insert a memory dependency

Parameters:

  • src_stage: PipelineStage vulk constant
  • dst_stage: PipelineStage vulk constant
  • dependency: Dependency vulk constant
  • memories: list of VkMemoryBarrier Vulkan objects
  • buffers: list of VkBufferMemoryBarrier Vulkan objects
  • images: list of VkImageMemoryBarrier Vulkan objects
class vulk.vulkanobject.CommandPool(context, queue_family_index, flags=<CommandPoolCreate.NONE: 0>)[source]

Bases: object

Command pools manage the memory that is used to store the buffers and command buffers are allocated from them.

allocate_buffers(context, level, count)[source]

Allocate list of CommandBuffer from pool.

Parameters:

  • context: The VulkContext
  • level: CommandBufferLevel vulk constant
  • count: Number of CommandBuffer to create

Returns:

list of CommandBuffer

free(context)[source]

Free this command pool

Parameters:

  • context: VulkContext
free_buffers(context, buffers)[source]

Free list of CommandBuffer allocated from this pool.

Parameters:

  • context: The VulkContext
  • buffers: list of CommandBuffer to free
class vulk.vulkanobject.DescriptorBufferInfo

Bases: tuple

Structure specifying descriptor buffer info

Parameters:

  • buffer: Buffer ressource
  • offset: Offset in bytes from the start of buffer
  • range: Size in bytes that is used for this descriptor update
buffer

Alias for field number 0

offset

Alias for field number 1

range

Alias for field number 2

class vulk.vulkanobject.DescriptorImageInfo

Bases: tuple

Structure specifying descriptor image info

Parameters:

  • sampler: Sampler ressource
  • view: ImageView
  • layout: ImageLayout vulk constant
layout

Alias for field number 2

sampler

Alias for field number 0

view

Alias for field number 1

class vulk.vulkanobject.DescriptorPool(context, poolsizes, max_sets, flags=<DescriptorPoolCreate.NONE: 0>)[source]

Bases: object

A descriptor pool maintains a pool of descriptors, from which descriptor sets are allocated. Descriptor pools are externally synchronized, meaning that the application must not allocate and/or free descriptor sets from the same pool in multiple threads simultaneously.

allocate_descriptorsets(context, count, layouts)[source]

Allocate list of DescriptorSet from pool.

Parameters:

  • context: VulkContext
  • count: Number of DescriptorSet to create
  • layouts: list of DescriptorSetLayout

Returns:

list of DescriptorSet

Note: Size of `layouts` list must be equals to `count`

class vulk.vulkanobject.DescriptorPoolSize

Bases: tuple

Structure specifying descriptor pool size.

Parameters:

  • type: DescriptorType vulk constant
  • count: Number of descriptors of that type to allocate
count

Alias for field number 1

type

Alias for field number 0

class vulk.vulkanobject.DescriptorSet(descriptorset)[source]

Bases: object

A descriptor set specifies the actual buffer or image resources that will be bound to the descriptors, just like a framebuffer specifies the actual image views to bind to render pass attachments. The descriptor set is then bound for the drawing commands just like the vertex buffers and framebuffer.

class vulk.vulkanobject.DescriptorSetLayout(context, bindings)[source]

Bases: object

A descriptor set layout object is defined by an array of zero or more descriptor bindings. Each individual descriptor binding is specified by a descriptor type, a count (array size) of the number of descriptors in the binding, a set of shader stages that can access the binding, and (if using immutable samplers) an array of sampler descriptors.

class vulk.vulkanobject.DescriptorSetLayoutBinding

Bases: tuple

Structure specifying a descriptor set layout binding.

Parameters:

  • binding: Binding number of this entry and corresponds to a resource
    of the same binding number in the shader stages
  • type: DescriptorType specifying which type of resource descriptors
    are used for this binding
  • count: Number of descriptors contained in the binding,
    accessed in a shader as an array
  • stage: ShaderStage vulk constant specifying which pipeline shader
    stages can access a resource for this binding
  • immutable_samplers: Immutable Sampler (can be None)
binding

Alias for field number 0

count

Alias for field number 2

immutable_samplers

Alias for field number 4

stage

Alias for field number 3

type

Alias for field number 1

class vulk.vulkanobject.Extent2D

Bases: tuple

Parameters:

  • width: Width
  • height: Height
height

Alias for field number 1

width

Alias for field number 0

class vulk.vulkanobject.Extent3D

Bases: tuple

Parameters:

  • width: Width
  • height: Height
  • depth: Depth
depth

Alias for field number 2

height

Alias for field number 1

width

Alias for field number 0

class vulk.vulkanobject.Framebuffer(context, renderpass, attachments, width, height, layers)[source]

Bases: object

In Vulkan, a Framebuffer references all of the VkImageView objects that represent the attachments of a Renderpass.

class vulk.vulkanobject.HighPerformanceBuffer(context, size, usage, sharing_mode=<SharingMode.NONE: 0>, queue_families=None)[source]

Bases: object

HighPerformanceBuffer allows to use high performance buffer to be accessed in your vertex stage.

To get the maximum performance, we are going to create two Buffer, a staging buffer which memory can be updated and a final buffer with very fast memory that we will use in pipeline. When we create a buffer, we first upload data in the staging buffer and then copy the memory in the final buffer. Of course, both of the buffer have the same properties.

bind(context)[source]

Bind buffer for writing

It calls bind method of the staging buffer and copy the buffer when the contextmanager is released. Must be used with with.

Parameters:

  • context: VulkContext
class vulk.vulkanobject.HighPerformanceImage(context, image_type, image_format, width, height, depth, mip_levels, layers, samples, sharing_mode=<SharingMode.NONE: 0>, queue_families=None)[source]

Bases: object

HighPerformanceImage allows to use high performance image to be sampled in your shaders.

To get the maximum performance, we are going to create a staging buffer which memory can be updated (with our texture) and a final image with very fast memory that we will use in shaders. When we create an image, we first upload the pixels in the staging buffer and then copy the memory in the final image.

bind_buffer(context, mip_level)[source]

Bind staging buffer

It calls bind method of the staging buffer to allow writing.

Args:
context (VulkContext) offset (int): Offset in buffer size (int): Bytes to reserve in buffer mip_level (int): Mip level to copy image to
finalize(context)[source]

Copy staging buffer to final image

Args:
context (VulkContext)
class vulk.vulkanobject.Image(context, image_type, image_format, width, height, depth, mip_level, layers, samples, sharing_mode, queue_families, layout, tiling, usage, memory_properties)[source]

Bases: object

Image is a wrapper around a VkImage and a VkMemory

bind(context)[source]

Map this image to upload data in it. This function is a context manager and must be called with with. It return a python buffer and let you do what you want with it, be careful!

Parameters:

  • context: The VulkContext

Warning: Image memory must be host visible

copy_to(cmd, dst_image)[source]

Copy this image to the destination image

Commands to copy are registered in the commandbuffer but it’s up to you to start and submit the command buffer to the execution queue.

Args:
cmd (CommandBufferRegister): Command used to register commands dst_image (Image): Destination image
**Note: Layout of source image must be TRANSFERT_SRC_OPTIMAL and
layout of destination image must be TRANSFERT_DST_OPTIMAL. It’s up to you.**

Warning: Format of both images must be compatible

update_layout(cmd, old_layout, new_layout, src_stage, dst_stage, src_access, dst_access, base_mip_level=0, mip_levels=1)[source]

Update the image layout

Command to update layout are registered in the commandbuffer but it’s up to you to start and submit the command buffer to the execution queue.

Args:
cmd (CommandBufferRegister): Register commands old_layout (ImageLayout): Previous layout new_layout (ImageLayout): Next layout src_stage (PipelineStage): Source stage dst_stage (PipelineStage): Destination stage src_access (Access): Source access dst_access (Access): Destination access base_mip_level (int): Starting mip level mip_levels (int): Number of mip levels
class vulk.vulkanobject.ImageSubresourceRange

Bases: tuple

ImageSubresourceRange object describes what the image’s purpose is and which part of the image should be accessed.

Parameters:

  • aspect: ImageAspect vulk constant indicating which aspect(s) of the
    image are included in the view
  • base_miplevel: The first mipmap level accessible to the view
  • level_count: Number of mipmap levels (starting from base_miplevel)
    accessible to the view
  • base_layer: First array layer accessible to the view
  • layer_count: Number of array layers (starting from base_layer)
    accessible to the view
aspect

Alias for field number 0

base_layer

Alias for field number 3

base_miplevel

Alias for field number 1

layer_count

Alias for field number 4

level_count

Alias for field number 2

class vulk.vulkanobject.ImageView(context, image, view_type, image_format, subresource_range, swizzle_r=<ComponentSwizzle.NONE: 0>, swizzle_g=<ComponentSwizzle.NONE: 0>, swizzle_b=<ComponentSwizzle.NONE: 0>, swizzle_a=<ComponentSwizzle.NONE: 0>)[source]

Bases: object

An image view is quite literally a view into an image. It describes how to access the image and which part of the image to access, for example if it should be treated as a 2D texture depth texture without any mipmapping levels.

class vulk.vulkanobject.Offset2D

Bases: tuple

Parameters:

  • x: x offset
  • y: y offset
x

Alias for field number 0

y

Alias for field number 1

class vulk.vulkanobject.Pipeline(context, stages, vertex_input, input_assembly, viewport_state, rasterization, multisample, depth, blend, dynamic, layout, renderpass)[source]

Bases: object

Pipeline (graphic) object

The graphics pipeline is the sequence of operations that take the vertices and textures of your meshes all the way to the pixels in the render targets. The pipeline combines the following elements:

  • Shader stages: the shader modules that define the functionality of
    the programmable stages of the graphics pipeline
  • Fixed-function state: all of the structures that define the
    fixed-function stages of the pipeline, like input assembly, rasterizer, viewport and color blending
  • Pipeline layout: the uniform and push values referenced by the
    shader that can be updated at draw time
  • Render pass: the attachments referenced by the pipeline stages
    and their usage
class vulk.vulkanobject.PipelineColorBlendAttachmentState

Bases: tuple

Parameters:

  • enable: Enable blending
  • src_color: BlendFactor vulk constant for source color
  • dst_color: BlendFactor vulk constant for destination color
  • color_op: BlendOp vulk constant Operation on color
  • src_alpha: BlendFactor vulk constant for source alpha
  • dst_alpha: BlendFactor vulk constant for destination alpha
  • alpha_op: BlendOp vulk constant operation on alpha
  • color_mask: ColorComponent vulk constant selecting which of the
    R, G, B, and A components are enabled for writing
alpha_op

Alias for field number 6

color_mask

Alias for field number 7

color_op

Alias for field number 3

dst_alpha

Alias for field number 5

dst_color

Alias for field number 2

enable

Alias for field number 0

src_alpha

Alias for field number 4

src_color

Alias for field number 1

class vulk.vulkanobject.PipelineColorBlendState

Bases: tuple

Parameters:

  • op_enable: Enable bitwise combination
  • op: LogicOp vulk constant operation to perform
  • attachments: List of blend attachments for each framebuffer
  • constants: Constants depending on blend factor (list of 4 float)
attachments

Alias for field number 2

constants

Alias for field number 3

op

Alias for field number 1

op_enable

Alias for field number 0

class vulk.vulkanobject.PipelineDepthStencilState

Bases: tuple

Parameters:

  • depth_test_enable: Enable depth test
  • depth_write_enable: Enable depth write
  • depth_bounds_test_enable: Enable bounds test
  • depth_compare: CompareOp vulk constant condition to overwrite depth
  • stencil_test_enable: Enable stencil test
  • front: Control stencil parameter (StencilOpState)
  • back: Control stencil parameter (StencilOpState)
  • min: Define the min value in depth bound test (float)
  • max: Define the max value in depth bound test (float)
back

Alias for field number 6

depth_bounds_test_enable

Alias for field number 2

depth_compare

Alias for field number 3

depth_test_enable

Alias for field number 0

depth_write_enable

Alias for field number 1

front

Alias for field number 5

max

Alias for field number 8

min

Alias for field number 7

stencil_test_enable

Alias for field number 4

class vulk.vulkanobject.PipelineDynamicState

Bases: tuple

  • states: List of VkDynamicState
states

Alias for field number 0

class vulk.vulkanobject.PipelineInputAssemblyState

Bases: tuple

Parameters:

  • topology: PrimitiveTopology vulk constant to use when drawing
topology

Alias for field number 0

class vulk.vulkanobject.PipelineLayout(context, descriptors)[source]

Bases: object

Pipeline layout object

Access to descriptor sets from a pipeline is accomplished through a pipeline layout. Zero or more descriptor set layouts and zero or more push constant ranges are combined to form a pipeline layout object which describes the complete set of resources that can be accessed by a pipeline. The pipeline layout represents a sequence of descriptor sets with each having a specific layout. This sequence of layouts is used to determine the interface between shader stages and shader resources. Each pipeline is created using a pipeline layout.

class vulk.vulkanobject.PipelineMultisampleState

Bases: tuple

Parameters:

  • shading_enable: Enable multisampling (boolean)
  • samples: Number of samples, SampleCount vulk constant
  • min_sample_shading: Minimum of sample (float)
min_sample_shading

Alias for field number 2

samples

Alias for field number 1

shading_enable

Alias for field number 0

class vulk.vulkanobject.PipelineRasterizationState

Bases: tuple

Parameters:

  • depth_clamp_enable: Whether to enable depth clamping (boolean)
  • polygon_mode: Which PolygonMode vulk constant to use
  • line_width: Width of line (float)
  • cull_mode: The way of culling, CullMode vulk constant
  • front_face: FrontFace vulk constant
  • depth_bias_constant: Constant to add to depth (float)
  • depth_bias_clamp: Max depth bias (float)
  • depth_bias_slope: Factor to slope (float)
cull_mode

Alias for field number 3

depth_bias_clamp

Alias for field number 6

depth_bias_constant

Alias for field number 5

depth_bias_slope

Alias for field number 7

depth_clamp_enable

Alias for field number 0

front_face

Alias for field number 4

line_width

Alias for field number 2

polygon_mode

Alias for field number 1

class vulk.vulkanobject.PipelineShaderStage

Bases: tuple

Parameters:

  • module: The ShaderModule to bind
  • stage: ShaderStage vulk constant
module

Alias for field number 0

stage

Alias for field number 1

class vulk.vulkanobject.PipelineVertexInputState

Bases: tuple

Parameters:

  • bindings: List of VertexInputBindingDescription
  • attributes: List of VertexInputAttributeDescription

Note: `bindings` and `attributes` can be empty `list`

attributes

Alias for field number 1

bindings

Alias for field number 0

class vulk.vulkanobject.PipelineViewportState

Bases: tuple

The PipelineViewportState object contains viewports and scissors.

Parameters:

  • viewports: list of Viewport
  • scissors: list of Rect2D
scissors

Alias for field number 1

viewports

Alias for field number 0

vulk.vulkanobject.Rect2D

alias of Rect2d

class vulk.vulkanobject.Renderpass(context, attachments, subpasses, dependencies)[source]

Bases: object

Renderpass object

When creating the pipeline, we need to tell Vulkan about the framebuffer attachments that will be used while rendering. We need to specify how many color and depth buffers there will be, how many samples to use for each of them and how their contents should be handled throughout the rendering operations. All of this information is wrapped in a RenderPass object

class vulk.vulkanobject.Sampler(context, mag_filter, min_filter, mipmap_mode, address_mode_u, address_mode_v, address_mode_w, mip_lod_bias, anisotropy_enable, max_anisotropy, compare_enable, compare_op, min_lod, max_lod, border_color, unnormalized_coordinates)[source]

Bases: object

Sampler objects represent the state of an image sampler which is used by the implementation to read image data and apply filtering and other transformations for the shader.

destroy(context)[source]

Destroy sampler

Args:
context (VulkContext): Context containing device
class vulk.vulkanobject.Semaphore(context)[source]

Bases: object

Semaphores are a synchronization primitive that can be used to insert a dependency between batches submitted to queues. Semaphores have two states - signaled and unsignaled. The state of a semaphore can be signaled after execution of a batch of commands is completed. A batch can wait for a semaphore to become signaled before it begins execution, and the semaphore is also unsignaled before the batch begins execution.

class vulk.vulkanobject.ShaderModule(context, code)[source]

Bases: object

ShaderModule Vulkan object

A shader module is a Spir-V shader loaded into Vulkan. After being created, it must be inserted in a pipeline stage. The real Vulkan module can be accessed by the ‘module’ property.

class vulk.vulkanobject.ShaderProgram(context, modules)[source]

Bases: object

A ShaderProgram embed all ShaderModule of a Pipeline.

class vulk.vulkanobject.ShaderProgramGlsl(context, modules)[source]

Bases: vulk.vulkanobject.ShaderProgram

A ShaderProgramGlsl is a ShaderProgram which compiles glsl to spirv.

shaderc_mapping = {<ShaderStage.VERTEX: 1>: ‘vert’, <ShaderStage.TESSELLATION_CONTROL: 2>: ‘tesc’, <ShaderStage.TESSELLATION_EVALUATION: 4>: ‘tese’, <ShaderStage.GEOMETRY: 8>: ‘geom’, <ShaderStage.FRAGMENT: 16>: ‘frag’, <ShaderStage.COMPUTE: 32>: ‘comp’}
class vulk.vulkanobject.ShaderProgramGlslFile(context, modules)[source]

Bases: vulk.vulkanobject.ShaderProgramGlsl

It’s a ShaderProgramGlsl which needs only file paths.

class vulk.vulkanobject.SubmitInfo

Bases: tuple

Submit information when submitting to queue

Parameters:

  • wait_semaphores: list of Semaphore to wait on
  • wait_stages: list of PipelineStage vulk constant at which each
    corresponding semaphore wait will occur. Must be the same size as wait_semaphores
  • signal_semaphores: list of Semaphore to signal when commands
    are finished
  • commandbuffers: list of CommandBuffer to execute
commandbuffers

Alias for field number 3

signal_semaphores

Alias for field number 2

wait_semaphores

Alias for field number 0

wait_stages

Alias for field number 1

class vulk.vulkanobject.SubpassDependency

Bases: tuple

SubpassDependency describes all dependencies of the subpass.

Parameters:

  • src_subpass: Source subpass int or SUBPASS_EXTERNAL vulk constant
  • src_stage: Source stage PipelineStage vulk constant
  • src_access: Source Access vulk constant
  • dst_subpass: Destination subpass int or
    SUBPASS_EXTERNAL vulk constant
  • dst_stage: Destination stage PipelineStage vulk constant
  • dst_access: Destination Access vulk constant
dst_access

Alias for field number 5

dst_stage

Alias for field number 4

dst_subpass

Alias for field number 3

src_access

Alias for field number 2

src_stage

Alias for field number 1

src_subpass

Alias for field number 0

class vulk.vulkanobject.SubpassDescription

Bases: tuple

SubpassDescription describes all attachments in the subpass. All parameters are of type AttachmentReference. If you don’t want an attachment, set it to an empty list.

Parameters:

  • colors: list of colors attachments
  • inputs: list of inputs attachments
  • resolves: list of resolves attachments (must be the same
    size as inputs)
  • preserves: list of preserves attachments
  • depth_stencil: list containing only one attachment
colors

Alias for field number 0

depth_stencil

Alias for field number 4

inputs

Alias for field number 1

preserves

Alias for field number 3

resolves

Alias for field number 2

class vulk.vulkanobject.VertexInputAttributeDescription

Bases: tuple

Structure specifying vertex input attribute description

Parameters:

  • location: Shader binding location number for this attribute (int)
  • binding: Binding number which this attribute takes its data from
  • format: Format vulk constant of the vertex attribute data
  • offset: Byte offset of this attribute relative to the start of an
    element in the vertex input binding (int)
binding

Alias for field number 1

format

Alias for field number 2

location

Alias for field number 0

offset

Alias for field number 3

class vulk.vulkanobject.VertexInputBindingDescription

Bases: tuple

Structure specifying vertex input binding description

Parameters:

  • binding: Binding number (int)
  • stride: Distance in bytes between two consecutive elements within
    the buffer (int)
  • rate: VertexInputRate vulk constant
binding

Alias for field number 0

rate

Alias for field number 2

stride

Alias for field number 1

class vulk.vulkanobject.Viewport

Bases: tuple

Structure specifying a viewport

Parameters:

  • x: X upper left corner
  • y: Y upper left corner
  • width: Viewport width
  • height: Viewport height
  • min_depth: Depth range for the viewport
  • max_depth: Depth range for the viewport

Note: `min_depth` and `max_depth` must be between 0.0 and 1.0

height

Alias for field number 3

max_depth

Alias for field number 5

min_depth

Alias for field number 4

width

Alias for field number 2

x

Alias for field number 0

y

Alias for field number 1

class vulk.vulkanobject.WriteDescriptorSet

Bases: tuple

Structure specifying the parameters of a descriptor set write operation

Parameters:

  • set: Destination DescriptorSet set to update
  • binding: Descriptor binding within that set
  • set_offset: Offset to start with in the descriptor
  • type: Type of descriptor DescriptorType vulk constant
  • descriptors: list of DescriptorBufferInfo or DescriptorImageInfo
    or BufferView depending on type

Note: The descriptor type must correspond to the `type` parameter

binding

Alias for field number 1

descriptors

Alias for field number 4

set

Alias for field number 0

set_offset

Alias for field number 2

type

Alias for field number 3

vulk.vulkanobject.btov(b)[source]

Convert boolean to Vulkan boolean

vulk.vulkanobject.find_memory_type(context, type_filter, properties)[source]

Graphics cards can offer different types of memory to allocate from. Each type of memory varies in terms of allowed operations and performance characteristics. We need to combine the requirements of the memory and our own application requirements to find the right type of memory to use.

Parameters:

  • context: The VulkContext
  • type_filter: Bit field of the memory types that are suitable
    for the memory (int)
  • properties: MemoryProperty Vulkan constant, type of
    memory we want
**Todo: I made a bitwise comparaison with type_filter, I have to test
it to be sure it’s working**
vulk.vulkanobject.immediate_buffer(context, commandpool=None)[source]

Manage creation and destruction of commandbuffer for one time submit. If commandpool is not given, it is created here.

Parameters:

  • context: VulkContext
  • commandpool: CommandPool (optional)
vulk.vulkanobject.submit_to_graphic_queue(context, submits)[source]

Convenient function to submit commands to graphic queue

Parameters:

  • context: VulkContext
  • submits: list of SubmitInfo
vulk.vulkanobject.submit_to_queue(queue, submits)[source]

Submit commands to queue

Parameters:

  • queue: VkQueue
  • submits: list of SubmitInfo
vulk.vulkanobject.update_descriptorsets(context, writes, copies)[source]

Update the contents of a descriptor set object

Parameters:

  • context: VulkContext
  • writes: list of WriteDescriptorSet
  • copies: list of CopyDescriptorSet

Todo: `copies` is unusable currently Todo: Only `DescriptorBufferInfo` supported

vulk.vulkanutil module

class vulk.vulkanutil.CommandBufferSynchronizedPool(context)[source]

Bases: object

This class allows to synchronize command buffers with semaphores. If you need a unknow quantity of command buffer to be executed with synchronization, this class is for you. It handles command buffer pooling and synchronization.

Exemple:

``` cbpool = CommandBufferSynchronizedChain(context) cbpool.begin(context, semaphore) #Must be called each frame before begining for action in actions:

with cbpool.pull() as commanbuffer:
# Register command in command buffer

semaphore_out = cbpool.end() ```

begin(context, semaphores=None)[source]

Begin pooling and synchronization of command buffers.

Parameters:

  • context: VulkContext
  • semaphores: list of Semaphore to wait on

Note: `context` is borrowed until `end` is called

end()[source]

Release the context.

Returns:

Out Semaphore: Signal semaphore of last command buffer

init_commandpool(context)[source]

Initialize transient command pool

Parameters:

  • context: VulkContext
next_commandbuffer()[source]

Create a new command buffer if requested

next_semaphore()[source]

Create a new semaphore if requested

pull()[source]

Pull a new command buffer. This function is a context manager, you should call it with with keyword to auto-submit the last created buffer.

Returns:

CommandBufferRegister ready to register commands

submit()[source]

Submit the last command buffer

Module contents

Vulk 3D engine

Cross-plateform 3D engine