simvx.graphics.gpu.memory¶
Buffer and image allocation helpers.
Module Contents¶
Functions¶
Create a VkBuffer with bound memory. Returns (buffer, memory). |
|
Create a VkImage with bound memory. Returns (image, memory). |
|
Create a multi-mip block-compressed VkImage with bound memory. |
|
Return True if |
|
True when |
|
Number of levels in a full mip chain for a |
|
Create a VkSampler with configurable filtering and addressing. |
|
Transition image layout via one-time command buffer. |
|
Map device memory and copy a numpy array into it at |
|
Allocate and begin a one-time command buffer. |
|
End, submit, wait, and free a one-time command buffer. |
|
Upload pixel data to a device-local image via staging buffer. |
|
Upload block-compressed mip data to a device-local image. |
|
Re-upload pixel data to an existing VkImage (same dimensions). |
|
Create a host-visible buffer for VkDrawIndexedIndirectCommand array. |
Data¶
API¶
- simvx.graphics.gpu.memory.log¶
‘getLogger(…)’
- simvx.graphics.gpu.memory.__all__¶
[‘create_buffer’, ‘create_image’, ‘create_compressed_image’, ‘create_sampler’, ‘format_blit_supporte…
- simvx.graphics.gpu.memory.create_buffer(device: Any, physical_device: Any, size: int, usage: int, memory_flags: int, *, concurrent_families: list[int] | None = None) tuple[Any, Any][source]¶
Create a VkBuffer with bound memory. Returns (buffer, memory).
concurrent_familiesopts a buffer intoVK_SHARING_MODE_CONCURRENT: pass the distinct queue-family indices that will touch it (e.g.[graphics_qf, compute_qf]) so the async-compute scheduler can read/write it from a separate compute queue without an explicit ownership transfer. The list must have >= 2 distinct families to be meaningful: a single family (or duplicates collapsing to one) falls back toEXCLUSIVEbecause CONCURRENT with one family is invalid (VUID-VkBufferCreateInfo-sharingMode-00914). The default (None) keeps the historicalEXCLUSIVEpath byte-identical, so callers that do not opt in are unaffected.
- simvx.graphics.gpu.memory.create_image(device: Any, physical_device: Any, width: int, height: int, fmt: int, usage: int, *, mip_levels: int = 1) tuple[Any, Any][source]¶
Create a VkImage with bound memory. Returns (image, memory).
mip_levelssizes the image’s mip chain; the default of 1 keeps every existing single-mip caller byte-identical.
- simvx.graphics.gpu.memory.create_compressed_image(device: Any, physical_device: Any, width: int, height: int, fmt: int, mip_count: int) tuple[Any, Any][source]¶
Create a multi-mip block-compressed VkImage with bound memory.
Mirrors :func:
create_imagebut takes a compressedVkFormatand a mip count. Usage is TRANSFER_DST | SAMPLED. Returns (image, memory).
- simvx.graphics.gpu.memory.format_sampled_supported(physical_device: Any, fmt: int) bool[source]¶
Return True if
fmtcan be sampled from an optimal-tiled image.The authoritative per-format gate (the coarse
textureCompressionBCfeature is necessary but not sufficient: each BC format must also reportSAMPLED_IMAGEin its optimal-tiling features).
- simvx.graphics.gpu.memory.format_blit_supported(physical_device: Any, fmt: int) bool[source]¶
True when
fmtsupports the linear-filtered blit chain runtime mipgen uses.Requires BLIT_SRC + BLIT_DST (
vkCmdBlitImagelegality) and SAMPLED_IMAGE_FILTER_LINEAR (the chain downsamples withVK_FILTER_LINEAR) in the format’s optimal-tiling features. Callers fall back to a single mip when any bit is missing, so unsupported formats degrade gracefully instead of tripping validation errors.
- simvx.graphics.gpu.memory.mip_chain_length(width: int, height: int) int[source]¶
Number of levels in a full mip chain for a
widthxheightimage.Level 0 included: a 1x1 image has a chain of 1, and each level halves the larger dimension (
floor(log2(max)) + 1, i.e.max.bit_length()).
- simvx.graphics.gpu.memory.create_sampler(device: Any, filter_mode: int = vk.VK_FILTER_LINEAR, max_lod: float = 0.0, address_mode: int = vk.VK_SAMPLER_ADDRESS_MODE_REPEAT) Any[source]¶
Create a VkSampler with configurable filtering and addressing.
address_modeapplies to all three axes. REPEAT is the correct default for tiled mesh textures; screen-space post-process passes must pass CLAMP_TO_EDGE so neighbour-texel taps at the frame edge do not wrap to the opposite edge.
- simvx.graphics.gpu.memory.transition_image_layout(device: Any, queue: Any, cmd_pool: Any, image: Any, old_layout: int, new_layout: int, aspect_mask: int = vk.VK_IMAGE_ASPECT_COLOR_BIT, level_count: int = 1) None[source]¶
Transition image layout via one-time command buffer.
level_counttransitions that many mip levels frombaseMipLevel=0; the default of 1 keeps the single-mip uncompressed path byte-identical.
- simvx.graphics.gpu.memory.upload_numpy(device: Any, memory: Any, data: numpy.ndarray, byte_offset: int = 0) None[source]¶
Map device memory and copy a numpy array into it at
byte_offset.
- simvx.graphics.gpu.memory.begin_single_time_commands(device: Any, cmd_pool: Any) Any[source]¶
Allocate and begin a one-time command buffer.
- simvx.graphics.gpu.memory.end_single_time_commands(device: Any, queue: Any, cmd_pool: Any, cmd: Any) None[source]¶
End, submit, wait, and free a one-time command buffer.
- simvx.graphics.gpu.memory.upload_image_data(device: Any, physical_device: Any, queue: Any, cmd_pool: Any, pixels: numpy.ndarray, width: int, height: int, fmt: int = vk.VK_FORMAT_R8G8B8A8_UNORM, *, mip_count: int = 1) tuple[Any, Any][source]¶
Upload pixel data to a device-local image via staging buffer.
mip_count> 1 allocates the full chain (plus TRANSFER_SRC usage), uploads level 0, and generates the remaining levels on the GPU with a linear-filteredvkCmdBlitImagechain. The caller is responsible for checking :func:format_blit_supportedfirst. The default of 1 keeps the historical single-mip path byte-identical.Args: pixels: Contiguous RGBA uint8 array, shape (height, width, 4).
Returns: (image, memory)
- simvx.graphics.gpu.memory.upload_compressed_image(device: Any, physical_device: Any, queue: Any, cmd_pool: Any, mip_block_bytes: list[bytes], width: int, height: int, fmt: int, block_size: int) tuple[Any, Any][source]¶
Upload block-compressed mip data to a device-local image.
Concatenates all mip levels into ONE staging buffer at block-aligned offsets (tight concatenation keeps every offset a multiple of
block_size), then issues one VkBufferImageCopy per mip. Block-row math follows the Vulkan spec:bufferRowLength/bufferImageHeightare in TEXELS rounded up to whole 4x4 blocks;imageExtentis the true texel size of the mip (Vulkan derives the block count internally).Args: mip_block_bytes: tightly-packed block bytes per mip, level 0 first. block_size: 8 (BC1/BC4) or 16 (BC2/BC3/BC5/BC6H/BC7).
Returns: (image, memory).
- simvx.graphics.gpu.memory.update_image_data(device: Any, physical_device: Any, queue: Any, cmd_pool: Any, image: Any, pixels: numpy.ndarray, width: int, height: int) None[source]¶
Re-upload pixel data to an existing VkImage (same dimensions).
Transitions the image from SHADER_READ_ONLY → TRANSFER_DST, copies the new pixel data via a staging buffer, then transitions back to SHADER_READ_ONLY.
- simvx.graphics.gpu.memory.create_indirect_buffer(device: Any, physical_device: Any, draw_count: int, *, concurrent_families: list[int] | None = None) tuple[Any, Any][source]¶
Create a host-visible buffer for VkDrawIndexedIndirectCommand array.
STORAGE_BUFFER usage is included so the GPU occlusion-cull compute (phase O3) can patch
instance_countin place. It stays HOST_VISIBLE|HOST_COHERENT so the batch upload (host write) and the telemetry readback both map it directly.concurrent_familiesforwards to :func:create_buffer: when the occlusion compute that writesinstance_countruns on a dedicated compute queue (async-compute path), the indirect buffer must be visible to both that queue and the graphics queue that consumes it viavkCmdDrawIndexedIndirect.None(single-queue path) keeps EXCLUSIVE.