Raxol.Terminal.Graphics.GPUAccelerator (Raxol v2.0.1)

View Source

GPU acceleration specifically for terminal graphics operations.

This module provides hardware acceleration for:

  • Image processing and transformation
  • Graphics rendering pipeline optimization
  • Memory-efficient texture management
  • Parallel graphics operations
  • Real-time visual effects

Built on top of the existing Raxol.Terminal.Rendering.GPUAccelerator, this module focuses specifically on graphics element acceleration.

Features

  • Hardware-accelerated image scaling and rotation
  • GPU-based image format conversion
  • Parallel graphics element rendering
  • Texture atlas management for graphics
  • Memory pooling for large graphics operations
  • Real-time visual effects (blur, glow, shadows)

Usage

# Initialize graphics GPU acceleration
{:ok, context} = GraphicsGPUAccelerator.init()

# Accelerate image processing
{:ok, processed} = GraphicsGPUAccelerator.process_image(context, image_data, %{
  scale: 0.5,
  rotation: 90,
  effects: [:blur, :glow]
})

# Batch process multiple graphics
{:ok, results} = GraphicsGPUAccelerator.batch_process(context, graphics_list)

Summary

Functions

Processes multiple graphics elements in parallel using GPU.

Returns a specification to start this module under a supervisor.

Creates optimized texture atlas for frequently used graphics.

Gets current GPU performance metrics.

Checks if GPU acceleration is available and working.

Initializes GPU acceleration for terminal graphics.

Processes a single graphics element with GPU acceleration.

Types

batch_job()

@type batch_job() :: %{
  id: String.t(),
  operations: [graphics_operation()],
  graphics_data: [binary()],
  callback: function() | nil
}

gpu_context()

@type gpu_context() :: %{
  backend: :metal | :vulkan | :opengl | :software,
  device: term(),
  command_queue: term(),
  memory_pool: term(),
  texture_atlas: term()
}

graphics_operation()

@type graphics_operation() :: %{
  type: :scale | :rotate | :filter | :composite | :effect,
  parameters: map(),
  priority: :low | :normal | :high | :critical
}

Functions

batch_process(context, graphics_list, options \\ %{})

@spec batch_process(gpu_context(), [{binary(), map()}], map()) ::
  {:ok, [binary()]} | {:error, term()}

Processes multiple graphics elements in parallel using GPU.

Parameters

  • context - GPU context
  • graphics_list - List of {graphics_data, operations} tuples
  • options - Batch processing options

Returns

  • {:ok, [processed_graphics]} - Successfully processed graphics
  • {:error, reason} - Processing failed

Examples

graphics = [
  {image1_data, %{scale: 0.5}},
  {image2_data, %{rotation: 90}},
  {image3_data, %{effects: [:blur]}}
]

{:ok, results} = GPUAccelerator.batch_process(context, graphics)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

create_texture_atlas(context, graphics_list, options \\ %{})

@spec create_texture_atlas(gpu_context(), [binary()], map()) ::
  {:ok, term()} | {:error, term()}

Creates optimized texture atlas for frequently used graphics.

get_performance_metrics()

@spec get_performance_metrics() :: map()

Gets current GPU performance metrics.

gpu_available?()

@spec gpu_available?() :: boolean()

Checks if GPU acceleration is available and working.

handle_manager_cast(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.

handle_manager_info(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.

initialize(config \\ %{})

@spec initialize(map()) :: {:ok, gpu_context()} | {:error, term()}

Initializes GPU acceleration for terminal graphics.

process_graphics(context, graphics_data, operations)

@spec process_graphics(gpu_context(), binary(), map()) ::
  {:ok, binary()} | {:error, term()}

Processes a single graphics element with GPU acceleration.

Parameters

  • context - GPU context from init/1
  • graphics_data - Binary graphics data (image, etc.)
  • operations - Map of operations to perform

Examples

{:ok, processed} = GPUAccelerator.process_graphics(context, image_data, %{
  scale: {0.5, 0.8},  # width 50%, height 80%
  rotation: 45,        # degrees
  effects: [:blur, :shadow],
  quality: :high
})

start_link(init_opts \\ [])