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§
Sourcefn create_shader_module(
&self,
descriptor: &ShaderModuleDescriptor<'_>,
) -> Result<ShaderModuleId, ResourceError>
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.
Sourcefn destroy_shader_module(&self, id: ShaderModuleId) -> Result<(), ResourceError>
fn destroy_shader_module(&self, id: ShaderModuleId) -> Result<(), ResourceError>
Destroys a shader module, releasing its GPU resources.
Sourcefn create_render_pipeline(
&self,
descriptor: &RenderPipelineDescriptor<'_>,
) -> Result<RenderPipelineId, ResourceError>
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.
Sourcefn create_pipeline_layout(
&self,
descriptor: &PipelineLayoutDescriptor<'_>,
) -> Result<PipelineLayoutId, ResourceError>
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.
Sourcefn destroy_render_pipeline(
&self,
id: RenderPipelineId,
) -> Result<(), ResourceError>
fn destroy_render_pipeline( &self, id: RenderPipelineId, ) -> Result<(), ResourceError>
Destroys a render pipeline, releasing its GPU resources.
Sourcefn create_buffer(
&self,
descriptor: &BufferDescriptor<'_>,
) -> Result<BufferId, ResourceError>
fn create_buffer( &self, descriptor: &BufferDescriptor<'_>, ) -> Result<BufferId, ResourceError>
Creates a new GPU buffer.
Sourcefn create_buffer_with_data(
&self,
descriptor: &BufferDescriptor<'_>,
data: &[u8],
) -> Result<BufferId, ResourceError>
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.
Sourcefn destroy_buffer(&self, id: BufferId) -> Result<(), ResourceError>
fn destroy_buffer(&self, id: BufferId) -> Result<(), ResourceError>
Destroys a GPU buffer, releasing its memory.
Sourcefn write_buffer(
&self,
id: BufferId,
offset: u64,
data: &[u8],
) -> Result<(), ResourceError>
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.
Sourcefn write_buffer_async<'a>(
&'a self,
id: BufferId,
offset: u64,
data: &'a [u8],
) -> Box<dyn Future<Output = Result<(), ResourceError>> + Send + 'static>
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.
Sourcefn create_texture(
&self,
descriptor: &TextureDescriptor<'_>,
) -> Result<TextureId, ResourceError>
fn create_texture( &self, descriptor: &TextureDescriptor<'_>, ) -> Result<TextureId, ResourceError>
Creates a new GPU texture.
Sourcefn destroy_texture(&self, id: TextureId) -> Result<(), ResourceError>
fn destroy_texture(&self, id: TextureId) -> Result<(), ResourceError>
Destroys a GPU texture, releasing its memory.
Sourcefn write_texture(
&self,
texture_id: TextureId,
data: &[u8],
bytes_per_row: Option<u32>,
offset: Origin3D,
size: Extent3D,
) -> Result<(), ResourceError>
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 indata
.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.
Sourcefn create_texture_view(
&self,
texture_id: TextureId,
descriptor: &TextureViewDescriptor<'_>,
) -> Result<TextureViewId, ResourceError>
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).
Sourcefn destroy_texture_view(&self, id: TextureViewId) -> Result<(), ResourceError>
fn destroy_texture_view(&self, id: TextureViewId) -> Result<(), ResourceError>
Destroys a texture view.
Sourcefn create_sampler(
&self,
descriptor: &SamplerDescriptor<'_>,
) -> Result<SamplerId, ResourceError>
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).
Sourcefn destroy_sampler(&self, id: SamplerId) -> Result<(), ResourceError>
fn destroy_sampler(&self, id: SamplerId) -> Result<(), ResourceError>
Destroys a sampler.
Sourcefn create_command_encoder(&self, label: Option<&str>) -> Box<dyn CommandEncoder>
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.
Sourcefn submit_command_buffer(&self, command_buffer: CommandBufferId)
fn submit_command_buffer(&self, command_buffer: CommandBufferId)
Submits a previously recorded command buffer to the GPU’s command queue for execution.
Sourcefn get_surface_format(&self) -> Option<TextureFormat>
fn get_surface_format(&self) -> Option<TextureFormat>
Gets the texture format of the primary render surface.
Sourcefn get_adapter_info(&self) -> RendererAdapterInfo
fn get_adapter_info(&self) -> RendererAdapterInfo
Gets information about the active graphics adapter (GPU).
Sourcefn supports_feature(&self, feature_name: &str) -> bool
fn supports_feature(&self, feature_name: &str) -> bool
Checks if a specific, optional rendering feature is supported by the backend.