Trait GraphicsDevice

Source
pub trait GraphicsDevice:
    Send
    + Sync
    + Debug
    + 'static {
Show 22 methods // Required methods fn create_shader_module( &self, descriptor: &ShaderModuleDescriptor<'_>, ) -> Result<ShaderModuleId, ResourceError>; fn destroy_shader_module( &self, id: ShaderModuleId, ) -> Result<(), ResourceError>; fn create_render_pipeline( &self, descriptor: &RenderPipelineDescriptor<'_>, ) -> Result<RenderPipelineId, ResourceError>; fn create_pipeline_layout( &self, descriptor: &PipelineLayoutDescriptor<'_>, ) -> Result<PipelineLayoutId, ResourceError>; fn destroy_render_pipeline( &self, id: RenderPipelineId, ) -> Result<(), ResourceError>; fn create_buffer( &self, descriptor: &BufferDescriptor<'_>, ) -> Result<BufferId, ResourceError>; fn create_buffer_with_data( &self, descriptor: &BufferDescriptor<'_>, data: &[u8], ) -> Result<BufferId, ResourceError>; fn destroy_buffer(&self, id: BufferId) -> Result<(), ResourceError>; fn write_buffer( &self, id: BufferId, offset: u64, data: &[u8], ) -> Result<(), ResourceError>; fn write_buffer_async<'a>( &'a self, id: BufferId, offset: u64, data: &'a [u8], ) -> Box<dyn Future<Output = Result<(), ResourceError>> + Send + 'static>; fn create_texture( &self, descriptor: &TextureDescriptor<'_>, ) -> Result<TextureId, ResourceError>; fn destroy_texture(&self, id: TextureId) -> Result<(), ResourceError>; fn write_texture( &self, texture_id: TextureId, data: &[u8], bytes_per_row: Option<u32>, offset: Origin3D, size: Extent3D, ) -> Result<(), ResourceError>; fn create_texture_view( &self, texture_id: TextureId, descriptor: &TextureViewDescriptor<'_>, ) -> Result<TextureViewId, ResourceError>; fn destroy_texture_view( &self, id: TextureViewId, ) -> Result<(), ResourceError>; fn create_sampler( &self, descriptor: &SamplerDescriptor<'_>, ) -> Result<SamplerId, ResourceError>; fn destroy_sampler(&self, id: SamplerId) -> Result<(), ResourceError>; fn create_command_encoder( &self, label: Option<&str>, ) -> Box<dyn CommandEncoder>; fn submit_command_buffer(&self, command_buffer: CommandBufferId); fn get_surface_format(&self) -> Option<TextureFormat>; fn get_adapter_info(&self) -> RendererAdapterInfo; fn supports_feature(&self, feature_name: &str) -> bool;
}
Expand description

Defines the abstract interface for a graphics device.

This trait is the central point of interaction with the underlying graphics API (like WGPU, Vulkan, etc.). It abstracts away the specifics of the backend and provides a unified API for creating, managing, and destroying GPU resources such as buffers, textures, and pipelines.

It is the cornerstone of the khora-infra crate’s responsibility, where a concrete type will implement this trait to provide actual rendering capabilities.

Required Methods§

Source

fn create_shader_module( &self, descriptor: &ShaderModuleDescriptor<'_>, ) -> Result<ShaderModuleId, ResourceError>

Creates a shader module from a descriptor.

§Errors

Returns a ResourceError if the shader source is invalid or fails to compile.

Source

fn destroy_shader_module(&self, id: ShaderModuleId) -> Result<(), ResourceError>

Destroys a shader module, releasing its GPU resources.

Source

fn create_render_pipeline( &self, descriptor: &RenderPipelineDescriptor<'_>, ) -> Result<RenderPipelineId, ResourceError>

Creates a render pipeline from a descriptor.

A render pipeline represents the entire configurable state of the GPU for a draw call, including shaders, vertex layouts, and blend states.

§Errors

Returns a ResourceError if the pipeline configuration is invalid or compilation fails.

Source

fn create_pipeline_layout( &self, descriptor: &PipelineLayoutDescriptor<'_>, ) -> Result<PipelineLayoutId, ResourceError>

Creates a pipeline layout from a descriptor.

The pipeline layout defines the set of resource bindings (e.g., uniform buffers, textures) that a pipeline can access.

§Errors

Returns a ResourceError if the layout is invalid.

Source

fn destroy_render_pipeline( &self, id: RenderPipelineId, ) -> Result<(), ResourceError>

Destroys a render pipeline, releasing its GPU resources.

Source

fn create_buffer( &self, descriptor: &BufferDescriptor<'_>, ) -> Result<BufferId, ResourceError>

Creates a new GPU buffer.

Source

fn create_buffer_with_data( &self, descriptor: &BufferDescriptor<'_>, data: &[u8], ) -> Result<BufferId, ResourceError>

Creates a new GPU buffer and initializes it with the provided data. This is often more efficient than create_buffer followed by write_buffer for static data.

Source

fn destroy_buffer(&self, id: BufferId) -> Result<(), ResourceError>

Destroys a GPU buffer, releasing its memory.

Source

fn write_buffer( &self, id: BufferId, offset: u64, data: &[u8], ) -> Result<(), ResourceError>

Writes data to a specific region of a GPU buffer.

§Arguments
  • id: The identifier of the buffer to write to.
  • offset: The offset in bytes from the beginning of the buffer to start writing.
  • data: The slice of bytes to write into the buffer.
Source

fn write_buffer_async<'a>( &'a self, id: BufferId, offset: u64, data: &'a [u8], ) -> Box<dyn Future<Output = Result<(), ResourceError>> + Send + 'static>

Asynchronously writes data to a GPU buffer. This can be more performant for large data uploads by avoiding stalls.

Source

fn create_texture( &self, descriptor: &TextureDescriptor<'_>, ) -> Result<TextureId, ResourceError>

Creates a new GPU texture.

Source

fn destroy_texture(&self, id: TextureId) -> Result<(), ResourceError>

Destroys a GPU texture, releasing its memory.

Source

fn write_texture( &self, texture_id: TextureId, data: &[u8], bytes_per_row: Option<u32>, offset: Origin3D, size: Extent3D, ) -> Result<(), ResourceError>

Writes data to a specific region of a GPU texture.

§Arguments
  • texture_id: The identifier of the texture to write to.
  • data: The raw image data to write.
  • bytes_per_row: The number of bytes for a single row of texels in data.
  • offset: The 3D offset (x, y, z/layer) in the texture to start writing.
  • size: The 3D extent (width, height, depth/layers) of the data to write.
Source

fn create_texture_view( &self, texture_id: TextureId, descriptor: &TextureViewDescriptor<'_>, ) -> Result<TextureViewId, ResourceError>

Creates a new texture view for a given texture. A view describes how a shader will interpret a texture’s data (e.g., its format, mip levels).

Source

fn destroy_texture_view(&self, id: TextureViewId) -> Result<(), ResourceError>

Destroys a texture view.

Source

fn create_sampler( &self, descriptor: &SamplerDescriptor<'_>, ) -> Result<SamplerId, ResourceError>

Creates a new sampler. A sampler defines how a shader will sample from a texture (e.g., filtering, wrapping).

Source

fn destroy_sampler(&self, id: SamplerId) -> Result<(), ResourceError>

Destroys a sampler.

Source

fn create_command_encoder(&self, label: Option<&str>) -> Box<dyn CommandEncoder>

Creates a new command encoder to record GPU commands.

§Arguments
  • label: An optional debug label for the command encoder.
Source

fn submit_command_buffer(&self, command_buffer: CommandBufferId)

Submits a previously recorded command buffer to the GPU’s command queue for execution.

Source

fn get_surface_format(&self) -> Option<TextureFormat>

Gets the texture format of the primary render surface.

Source

fn get_adapter_info(&self) -> RendererAdapterInfo

Gets information about the active graphics adapter (GPU).

Source

fn supports_feature(&self, feature_name: &str) -> bool

Checks if a specific, optional rendering feature is supported by the backend.

Implementors§