pub struct GpuContext { /* private fields */ }Expand description
Core GPU context — instance, adapter, device, and queue.
All resource creation goes through this context so that every allocated object is an agpu type with tracking metadata.
Implementations§
Source§impl GpuContext
impl GpuContext
Sourcepub async fn new(
surface: &Surface<'_>,
preference: BackendPreference,
) -> Result<Self, GpuError>
pub async fn new( surface: &Surface<'_>, preference: BackendPreference, ) -> Result<Self, GpuError>
Create a GPU context for the given surface.
Uses Vulkan-first backend selection: tries Backends::VULKAN,
and if no suitable adapter is found, falls back to the platform
default (Backends::PRIMARY).
Sourcepub async fn from_instance(
instance: Instance,
surface: &Surface<'_>,
preference: BackendPreference,
) -> Result<Self, GpuError>
pub async fn from_instance( instance: Instance, surface: &Surface<'_>, preference: BackendPreference, ) -> Result<Self, GpuError>
Create a GPU context reusing an existing wgpu::Instance and surface.
Use this when the caller already owns the instance that created the surface — avoids the “Surface does not exist” panic that occurs when a second instance tries to look up the surface.
Sourcepub fn device(&self) -> &Device
pub fn device(&self) -> &Device
The wgpu device (needed internally and for advanced escape-hatch).
Sourcepub fn adapter_name(&self) -> String
pub fn adapter_name(&self) -> String
Adapter name (e.g. “NVIDIA GeForce RTX 4090”).
Sourcepub fn device_type(&self) -> String
pub fn device_type(&self) -> String
Device type (discrete, integrated, software).
Sourcepub fn driver_info(&self) -> String
pub fn driver_info(&self) -> String
Driver info string.
Sourcepub fn max_texture_dimension(&self) -> u32
pub fn max_texture_dimension(&self) -> u32
Maximum 2D texture dimension.
Sourcepub fn max_buffer_size(&self) -> u64
pub fn max_buffer_size(&self) -> u64
Maximum buffer size in bytes.
Sourcepub fn backend_preference(&self) -> BackendPreference
pub fn backend_preference(&self) -> BackendPreference
Backend preference that was requested.
Sourcepub fn create_buffer(&self, desc: &GpuBufferDescriptor) -> GpuBuffer
pub fn create_buffer(&self, desc: &GpuBufferDescriptor) -> GpuBuffer
Create a GPU buffer.
Sourcepub fn create_texture(&self, desc: &GpuTextureDescriptor) -> GpuTexture
pub fn create_texture(&self, desc: &GpuTextureDescriptor) -> GpuTexture
Create a GPU texture.
Sourcepub fn create_sampler(&self, desc: &GpuSamplerDescriptor) -> GpuSampler
pub fn create_sampler(&self, desc: &GpuSamplerDescriptor) -> GpuSampler
Create a GPU sampler.
Sourcepub fn create_shader_wgsl(&self, label: &str, source: &str) -> GpuShaderModule
pub fn create_shader_wgsl(&self, label: &str, source: &str) -> GpuShaderModule
Create a shader module from WGSL source.
Sourcepub fn create_bind_group_layout(
&self,
label: &str,
entries: &[BindGroupLayoutEntry],
) -> GpuBindGroupLayout
pub fn create_bind_group_layout( &self, label: &str, entries: &[BindGroupLayoutEntry], ) -> GpuBindGroupLayout
Create a bind group layout.
Sourcepub fn create_bind_group(
&self,
label: &str,
layout: &GpuBindGroupLayout,
entries: &[BindGroupEntry<'_>],
) -> GpuBindGroup
pub fn create_bind_group( &self, label: &str, layout: &GpuBindGroupLayout, entries: &[BindGroupEntry<'_>], ) -> GpuBindGroup
Create a bind group.
Sourcepub fn create_pipeline_layout(
&self,
label: &str,
bind_group_layouts: &[&GpuBindGroupLayout],
push_constant_ranges: &[PushConstantRange],
) -> GpuPipelineLayout
pub fn create_pipeline_layout( &self, label: &str, bind_group_layouts: &[&GpuBindGroupLayout], push_constant_ranges: &[PushConstantRange], ) -> GpuPipelineLayout
Create a pipeline layout.
Sourcepub fn create_render_pipeline(
&self,
desc: &RenderPipelineDescriptor<'_>,
) -> GpuRenderPipeline
pub fn create_render_pipeline( &self, desc: &RenderPipelineDescriptor<'_>, ) -> GpuRenderPipeline
Create a render pipeline.
Sourcepub fn create_compute_pipeline(
&self,
desc: &ComputePipelineDescriptor<'_>,
) -> GpuComputePipeline
pub fn create_compute_pipeline( &self, desc: &ComputePipelineDescriptor<'_>, ) -> GpuComputePipeline
Create a compute pipeline.
Sourcepub fn create_command_encoder(&self, label: &str) -> GpuCommandEncoder
pub fn create_command_encoder(&self, label: &str) -> GpuCommandEncoder
Create a command encoder.
Sourcepub fn create_query_set(
&self,
label: &str,
ty: QueryType,
count: u32,
) -> GpuQuerySet
pub fn create_query_set( &self, label: &str, ty: QueryType, count: u32, ) -> GpuQuerySet
Create a query set for timestamp or occlusion queries.
Sourcepub fn write_buffer(&self, buffer: &GpuBuffer, offset: u64, data: &[u8])
pub fn write_buffer(&self, buffer: &GpuBuffer, offset: u64, data: &[u8])
Write data to a buffer.
Sourcepub fn submit(&self, commands: impl IntoIterator<Item = GpuCommandBuffer>)
pub fn submit(&self, commands: impl IntoIterator<Item = GpuCommandBuffer>)
Submit finished command buffers to the GPU.
Sourcepub fn write_texture(
&self,
texture: TexelCopyTextureInfo<'_>,
data: &[u8],
data_layout: TexelCopyBufferLayout,
size: Extent3d,
)
pub fn write_texture( &self, texture: TexelCopyTextureInfo<'_>, data: &[u8], data_layout: TexelCopyBufferLayout, size: Extent3d, )
Write data directly to a texture.
Trait Implementations§
Source§impl Discoverable for GpuContext
impl Discoverable for GpuContext
Source§fn schema(&self) -> WidgetSchema
fn schema(&self) -> WidgetSchema
Source§fn capabilities(&self) -> Vec<AgentCapability>
fn capabilities(&self) -> Vec<AgentCapability>
Source§fn actions(&self) -> Vec<AgentAction>
fn actions(&self) -> Vec<AgentAction>
Source§fn semantic_role(&self) -> SemanticRole
fn semantic_role(&self) -> SemanticRole
Source§fn agent_state(&self) -> Value
fn agent_state(&self) -> Value
Source§fn execute_action(
&mut self,
action: &str,
_params: &Value,
) -> Result<Value, String>
fn execute_action( &mut self, action: &str, _params: &Value, ) -> Result<Value, String>
Source§fn agent_id(&self) -> Option<&str>
fn agent_id(&self) -> Option<&str>
Source§fn accessibility_label(&self) -> Option<String>
fn accessibility_label(&self) -> Option<String>
Auto Trait Implementations§
impl Freeze for GpuContext
impl !RefUnwindSafe for GpuContext
impl Send for GpuContext
impl Sync for GpuContext
impl Unpin for GpuContext
impl UnsafeUnpin for GpuContext
impl !UnwindSafe for GpuContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more