Skip to main content

GpuContext

Struct GpuContext 

Source
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

Source

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).

Source

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.

Source

pub fn device(&self) -> &Device

The wgpu device (needed internally and for advanced escape-hatch).

Source

pub fn queue(&self) -> &Queue

The wgpu queue.

Source

pub fn adapter(&self) -> &Adapter

The wgpu adapter.

Source

pub fn instance(&self) -> &Instance

The wgpu instance.

Source

pub fn adapter_name(&self) -> String

Adapter name (e.g. “NVIDIA GeForce RTX 4090”).

Source

pub fn backend(&self) -> String

Active backend (e.g. “Vulkan”, “DX12”, “Metal”).

Source

pub fn device_type(&self) -> String

Device type (discrete, integrated, software).

Source

pub fn driver(&self) -> String

Driver name.

Source

pub fn driver_info(&self) -> String

Driver info string.

Source

pub fn max_texture_dimension(&self) -> u32

Maximum 2D texture dimension.

Source

pub fn max_buffer_size(&self) -> u64

Maximum buffer size in bytes.

Source

pub fn features(&self) -> Features

Enabled GPU features.

Source

pub fn limits(&self) -> Limits

Device limits.

Source

pub fn backend_preference(&self) -> BackendPreference

Backend preference that was requested.

Source

pub fn create_buffer(&self, desc: &GpuBufferDescriptor) -> GpuBuffer

Create a GPU buffer.

Source

pub fn create_texture(&self, desc: &GpuTextureDescriptor) -> GpuTexture

Create a GPU texture.

Source

pub fn create_sampler(&self, desc: &GpuSamplerDescriptor) -> GpuSampler

Create a GPU sampler.

Source

pub fn create_shader_wgsl(&self, label: &str, source: &str) -> GpuShaderModule

Create a shader module from WGSL source.

Source

pub fn create_bind_group_layout( &self, label: &str, entries: &[BindGroupLayoutEntry], ) -> GpuBindGroupLayout

Create a bind group layout.

Source

pub fn create_bind_group( &self, label: &str, layout: &GpuBindGroupLayout, entries: &[BindGroupEntry<'_>], ) -> GpuBindGroup

Create a bind group.

Source

pub fn create_pipeline_layout( &self, label: &str, bind_group_layouts: &[&GpuBindGroupLayout], push_constant_ranges: &[PushConstantRange], ) -> GpuPipelineLayout

Create a pipeline layout.

Source

pub fn create_render_pipeline( &self, desc: &RenderPipelineDescriptor<'_>, ) -> GpuRenderPipeline

Create a render pipeline.

Source

pub fn create_compute_pipeline( &self, desc: &ComputePipelineDescriptor<'_>, ) -> GpuComputePipeline

Create a compute pipeline.

Source

pub fn create_command_encoder(&self, label: &str) -> GpuCommandEncoder

Create a command encoder.

Source

pub fn create_query_set( &self, label: &str, ty: QueryType, count: u32, ) -> GpuQuerySet

Create a query set for timestamp or occlusion queries.

Source

pub fn write_buffer(&self, buffer: &GpuBuffer, offset: u64, data: &[u8])

Write data to a buffer.

Source

pub fn submit(&self, commands: impl IntoIterator<Item = GpuCommandBuffer>)

Submit finished command buffers to the GPU.

Source

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

Source§

fn schema(&self) -> WidgetSchema

Returns the schema describing this widget type.
Source§

fn capabilities(&self) -> Vec<AgentCapability>

Returns the capabilities of this specific widget instance.
Source§

fn actions(&self) -> Vec<AgentAction>

Returns the actions available on this specific widget instance.
Source§

fn semantic_role(&self) -> SemanticRole

Returns the semantic role of this widget.
Source§

fn agent_state(&self) -> Value

Returns the current state as a JSON value for agent inspection.
Source§

fn execute_action( &mut self, action: &str, _params: &Value, ) -> Result<Value, String>

Attempt to execute a named action with the given JSON parameters.
Source§

fn agent_id(&self) -> Option<&str>

An optional unique identifier for this widget instance in the UI tree.
Source§

fn accessibility_label(&self) -> Option<String>

An optional accessibility label for screen readers and agents.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,