pub struct Device(_, _);
Expand description
Logical device, representation one or multiple physical devices (hardware or software).
This wraps an existing GL context and acts as the main API interface. It’s the responsibility of the user to keep the context alive.
Implementations
sourceimpl Device
impl Device
sourcepub fn create_buffer(&self, size: u64, memory: MemoryFlags) -> Result<Buffer>
pub fn create_buffer(&self, size: u64, memory: MemoryFlags) -> Result<Buffer>
Create a new empty buffer.
Parameters
size
: Length in bytes of the associated storage memory.memory
: Properties of the internal memory slice. Indicating the usage and locality of the allocation.
sourcepub fn create_buffer_from_host(
&self,
data: &[u8],
memory: MemoryFlags
) -> Result<Buffer>
pub fn create_buffer_from_host(
&self,
data: &[u8],
memory: MemoryFlags
) -> Result<Buffer>
Create a new buffer from host memory data.
Parameters
data
: Host data, which will copied into the buffer on creation.memory
: Properties of the internal memory slice. Indicating the usage and locality of the allocation.
sourcepub fn map_buffer<T>(
&self,
buffer: &Buffer,
range: Range<u64>,
mapping: MappingFlags
) -> &mut [T] ⓘ
pub fn map_buffer<T>(
&self,
buffer: &Buffer,
range: Range<u64>,
mapping: MappingFlags
) -> &mut [T] ⓘ
Persistently map memory to host accessible virtual memory.
Valid usage
range.end
may not be larger than the size of the buffer.range.start
must be smaller thanrange.end
buffer
must be created withCPU_MAP_READ
orCPU_MAP_WRITE
flags.range.end - range.start
must be a multiple of the size ofT
- If the buffer has not been created with
CPU_MAP_READ
the host should not read from the returned slice. - If the buffer has not been created with
CPU_MAP_WRITE
the host should not write to the returned slice. - A buffer can not be mapped multiple times.
Return
Returns a typed slice of the mapped memory range.
sourcepub fn unmap_buffer(&self, buffer: &Buffer) -> bool
pub fn unmap_buffer(&self, buffer: &Buffer) -> bool
Unmap a buffer from virtual host memory.
Valid usage
- The buffer must be currently mapped.
Return
Returns if the unmapping operation was successfull.
sourcepub fn delete_buffer(&self, buffer: Buffer)
pub fn delete_buffer(&self, buffer: Buffer)
Delete a buffer.
sourcepub fn delete_buffers(&self, buffers: &[Buffer])
pub fn delete_buffers(&self, buffers: &[Buffer])
Delete multiple buffers.
sourcepub fn copy_host_to_buffer(&self, buffer: &Buffer, offset: isize, data: &[u8])
pub fn copy_host_to_buffer(&self, buffer: &Buffer, offset: isize, data: &[u8])
Copy memory from the host into the buffer memory.
sourcepub fn copy_buffer(
&self,
src_buffer: &Buffer,
src_offset: isize,
dst_buffer: &Buffer,
dst_offset: isize,
size: u64
)
pub fn copy_buffer(
&self,
src_buffer: &Buffer,
src_offset: isize,
dst_buffer: &Buffer,
dst_offset: isize,
size: u64
)
Copy data from one buffer into another buffer.
sourcepub fn fill_buffer(
&self,
buffer: BufferRange<'_>,
buffer_format: Format,
base_format: BaseFormat,
format_layout: FormatLayout,
value: &[u8]
)
pub fn fill_buffer(
&self,
buffer: BufferRange<'_>,
buffer_format: Format,
base_format: BaseFormat,
format_layout: FormatLayout,
value: &[u8]
)
Fill buffer with data.
sourcepub fn bind_uniform_buffers(&self, first: u32, ranges: &[BufferRange<'_>])
pub fn bind_uniform_buffers(&self, first: u32, ranges: &[BufferRange<'_>])
Bind buffer ranges as uniform buffers.
Shader can access the buffer memory as readonly.
sourcepub fn bind_shader_storage_buffers(&self, first: u32, ranges: &[BufferRange<'_>])
pub fn bind_shader_storage_buffers(&self, first: u32, ranges: &[BufferRange<'_>])
Bind buffer ranges as shader storage buffers.
Shaders can access the buffer memory as readwrite.
sourcepub fn bind_draw_indirect_buffer(&self, buffer: &Buffer)
pub fn bind_draw_indirect_buffer(&self, buffer: &Buffer)
Bind indirect buffer for draw commands.
sourcepub fn bind_dispatch_indirect_buffer(&self, buffer: &Buffer)
pub fn bind_dispatch_indirect_buffer(&self, buffer: &Buffer)
Bind indirect buffer for dispatch commands.
sourceimpl Device
impl Device
sourcepub fn bind_uniform_constants(
&self,
pipeline: &Pipeline,
first: u32,
constants: &[Constant]
)
pub fn bind_uniform_constants(
&self,
pipeline: &Pipeline,
first: u32,
constants: &[Constant]
)
Set uniform constants for a pipeline.
sourcepub fn set_viewport(&self, first: u32, viewports: &[Viewport])
pub fn set_viewport(&self, first: u32, viewports: &[Viewport])
Set viewport transformation parameters.
The viewport determines the mapping from NDC (normalized device coordinates) into framebuffer coordinates.
See Viewport for more information about the viewport transformation.
sourcepub fn set_scissor(&self, first: u32, scissors: &[Region])
pub fn set_scissor(&self, first: u32, scissors: &[Region])
Set scissor rectangles for viewports.
Valid usage
- Every active viewport needs an associated scissor.
sourcepub fn draw(
&self,
primitive: Primitive,
vertices: Range<u32>,
instance: Range<u32>
)
pub fn draw(
&self,
primitive: Primitive,
vertices: Range<u32>,
instance: Range<u32>
)
Submit a (non-indexed) draw call.
Valid usage
- There must be a valid graphics pipeline currently bound.
- There must be a calid vertex array currently bound.
- For each attribute in the bound vertex array there must be a vertex buffer bound at the specified binding slot.
- For each attribute in the bound vertex array there must be a vertex attribute specified in the shader with matching format and location.
- The access vertices must be in bound of the vertex buffers bound.
vertices.end
must be larger thanvertices.start
.vertices.end - vertices.start
must be allow assembling complete primitives.instances.end
must be larger thaninstances.start
.
sourcepub fn draw_indexed(
&self,
primitive: Primitive,
index_ty: IndexTy,
indices: Range<u32>,
instance: Range<u32>,
base_vertex: i32
)
pub fn draw_indexed(
&self,
primitive: Primitive,
index_ty: IndexTy,
indices: Range<u32>,
instance: Range<u32>,
base_vertex: i32
)
Submit an indexed draw call.
Valid usage
- There must be a valid graphics pipeline currently bound.
- There must be a calid vertex array currently bound.
- For each attribute in the bound vertex array there must be a vertex buffer bound at the specified binding slot.
- For each attribute in the bound vertex array there must be a vertex attribute specified in the shader with matching format and location.
- The access vertices must be in bound of the vertex buffers bound.
indices.end
must be larger thanindices.start
.indices.end - indices.start
must allow to assemble complete primitives.instances.end
must be larger thaninstances.start
.
sourcepub fn draw_indirect(
&self,
primitive: Primitive,
offset: u64,
count: u32,
stride: u32
)
pub fn draw_indirect(
&self,
primitive: Primitive,
offset: u64,
count: u32,
stride: u32
)
Submit an indirect draw call.
Valid Usage
- There must be a valid graphics pipeline currently bound.
- There must be a valid draw indirect buffer currently bound.
sourcepub fn draw_indirect_from_host(
&self,
primitive: Primitive,
data: &[DrawIndirectCmd]
)
pub fn draw_indirect_from_host(
&self,
primitive: Primitive,
data: &[DrawIndirectCmd]
)
Submit an indirect draw call.
sourcepub fn draw_indexed_indirect(
&self,
primitive: Primitive,
index_ty: IndexTy,
offset: u64,
count: u32,
stride: u32
)
pub fn draw_indexed_indirect(
&self,
primitive: Primitive,
index_ty: IndexTy,
offset: u64,
count: u32,
stride: u32
)
Indirect draw call.
sourcepub fn draw_indexed_indirect_from_host(
&self,
primitive: Primitive,
index_ty: IndexTy,
data: &[DrawIndexedIndirectCmd]
)
pub fn draw_indexed_indirect_from_host(
&self,
primitive: Primitive,
index_ty: IndexTy,
data: &[DrawIndexedIndirectCmd]
)
Indirect (indexed) draw call.
sourcepub fn dispatch(&self, x: u32, y: u32, z: u32)
pub fn dispatch(&self, x: u32, y: u32, z: u32)
Dispatch a workgroup for computation.
Valid usage
- There must be a valid compute shader currently bound.
sourcepub fn dispatch_indirect(&self, offset: u64)
pub fn dispatch_indirect(&self, offset: u64)
sourceimpl Device
impl Device
sourcepub fn object_name<T: Object>(&self, object: &T, name: &str)
pub fn object_name<T: Object>(&self, object: &T, name: &str)
Associate a name with an object.
pub fn enable_debug_message(
&self,
src: Filter<DebugSource>,
ty: Filter<DebugType>,
flags: DebugReport,
ids: Option<&[u32]>
)
pub fn disable_debug_message(
&self,
src: Filter<DebugSource>,
ty: Filter<DebugType>,
flags: DebugReport,
ids: Option<&[u32]>
)
pub fn begin_debug_marker(&self, src: DebugSource, id: u32, msg: &str)
pub fn end_debug_marker(&self)
sourceimpl Device
impl Device
sourcepub fn new<F>(
loader: F,
debug: Debug<fn(_: DebugReport, _: DebugSource, _: DebugType, _: u32, _: &str)>
) -> Selfwhere
F: FnMut(&str) -> *const c_void,
pub fn new<F>(
loader: F,
debug: Debug<fn(_: DebugReport, _: DebugSource, _: DebugType, _: u32, _: &str)>
) -> Selfwhere
F: FnMut(&str) -> *const c_void,
Create a new device from an existing context.
The context must be initialized with GL 4.5+ core profile.
The passed loader
is used to obtain the function pointers from the context.
pub fn limits(&self) -> DeviceLimits
pub fn features(&self) -> DeviceFeatures
sourceimpl Device
impl Device
sourcepub fn create_framebuffer(&self) -> Result<Framebuffer>
pub fn create_framebuffer(&self) -> Result<Framebuffer>
Create a new framebuffer.
sourcepub fn delete_framebuffer(&self, framebuffer: Framebuffer)
pub fn delete_framebuffer(&self, framebuffer: Framebuffer)
Delete a framebuffer.
sourcepub fn delete_framebuffers(&self, framebuffers: &[Framebuffer])
pub fn delete_framebuffers(&self, framebuffers: &[Framebuffer])
Delete multiple framebuffers.
sourcepub fn create_renderbuffer(&self) -> Result<Renderbuffer>
pub fn create_renderbuffer(&self) -> Result<Renderbuffer>
Create a new framebuffer.
sourcepub fn delete_renderbuffer(&self, renderbuffer: Renderbuffer)
pub fn delete_renderbuffer(&self, renderbuffer: Renderbuffer)
Delete a renderbuffer.
sourcepub fn delete_renderbuffers(&self, renderbuffers: &[Renderbuffer])
pub fn delete_renderbuffers(&self, renderbuffers: &[Renderbuffer])
Delete multiple renderbuffers.
sourcepub fn clear_attachment(&self, fb: &Framebuffer, cv: ClearAttachment)
pub fn clear_attachment(&self, fb: &Framebuffer, cv: ClearAttachment)
Clear framebuffer attachment.
sourcepub fn invalidate_attachments(
&self,
framebuffer: &Framebuffer,
attachments: &[Attachment],
region: Region
)
pub fn invalidate_attachments(
&self,
framebuffer: &Framebuffer,
attachments: &[Attachment],
region: Region
)
sourcepub fn bind_framebuffer(&self, framebuffer: &Framebuffer)
pub fn bind_framebuffer(&self, framebuffer: &Framebuffer)
Bind a framebuffer for draw commands.
sourcepub fn bind_attachments(
&self,
framebuffer: &Framebuffer,
color_attachments: &[AttachmentView<'_>],
depth_stencil_attachment: Option<AttachmentView<'_>>
)
pub fn bind_attachments(
&self,
framebuffer: &Framebuffer,
color_attachments: &[AttachmentView<'_>],
depth_stencil_attachment: Option<AttachmentView<'_>>
)
Bind attachments to the framebuffer.
All previously bound attachments become invalid.
sourcepub fn set_color_attachments(
&self,
framebuffer: &Framebuffer,
attachments: &[u32]
)
pub fn set_color_attachments(
&self,
framebuffer: &Framebuffer,
attachments: &[u32]
)
Specify color attachments.
Defines the color render targets for the next draw calls. This builds the link between fragment outputs in the fragment shader and attachments bound on the framebuffer.
sourceimpl Device
impl Device
sourcepub fn delete_image(&self, image: Image)
pub fn delete_image(&self, image: Image)
Delete an images.
sourcepub fn delete_images(&self, images: &[Image])
pub fn delete_images(&self, images: &[Image])
Delete multiple images.
sourcepub fn copy_host_to_image<T>(
&self,
image: &Image,
subresource: SubresourceLevel,
offset: Offset,
extent: Extent,
data: &[T],
layout: SubresourceLayout
)
pub fn copy_host_to_image<T>(
&self,
image: &Image,
subresource: SubresourceLevel,
offset: Offset,
extent: Extent,
data: &[T],
layout: SubresourceLayout
)
Copy image data from host memory to device memory.
sourcepub fn create_image_view(
&self,
image: &Image,
ty: ImageViewType,
format: Format,
range: SubresourceRange
) -> Result<ImageView>
pub fn create_image_view(
&self,
image: &Image,
ty: ImageViewType,
format: Format,
range: SubresourceRange
) -> Result<ImageView>
Create an image view from an image.
sourcepub fn delete_image_view(&self, view: ImageView)
pub fn delete_image_view(&self, view: ImageView)
Delete an image views.
sourcepub fn delete_image_views(&self, views: &[ImageView])
pub fn delete_image_views(&self, views: &[ImageView])
Delete multipe image views.
sourcepub fn bind_image_views(&self, first: u32, views: &[&ImageView])
pub fn bind_image_views(&self, first: u32, views: &[&ImageView])
Bind image views to texture units.
sourcepub fn generate_mipmaps(&self, image: &Image)
pub fn generate_mipmaps(&self, image: &Image)
Generate mipmaps.
This generates the remaining mipmap levels using the base layer via downscaling. The number of levels are determined on resource creation.
The downscaling filter is implementation dependent!
sourceimpl Device
impl Device
sourcepub fn create_shader(&self, stage: ShaderStage, source: &[u8]) -> Result<Shader>
pub fn create_shader(&self, stage: ShaderStage, source: &[u8]) -> Result<Shader>
Create a new shader from GLSL.
Valid usage
source
must be a NULL-terminated C-String.- The GLSL shader version must be
450 core
or higher. - The
stage
parameter must be a valid stage of the passed shader source.
sourcepub fn delete_shader(&self, shader: Shader)
pub fn delete_shader(&self, shader: Shader)
Delete a shader.
sourcepub fn delete_shaders(&self, shaders: &[Shader])
pub fn delete_shaders(&self, shaders: &[Shader])
Delete multiple shaders.
sourcepub fn create_graphics_pipeline(
&self,
desc: GraphicsPipelineDesc<'_>
) -> Result<Pipeline>
pub fn create_graphics_pipeline(
&self,
desc: GraphicsPipelineDesc<'_>
) -> Result<Pipeline>
Create a graphics pipeline.
This equals a Program
in GL terminology.
Valid usage
- The vertex shader in
desc
must be valid and created withShaderStage::Vertex
. - The tessellation control shader in
desc
must be valid and created withShaderStage::TessellationControl
if specified. - The tessellation evaluation shader in
desc
must be valid and created withShaderStage::TessellationEvalution
if specified. - The geometry shader in
desc
must be valid and created withShaderStage::Geometry
if specified. - The fragment shader in
desc
must be valid and created withShaderStage::Fragment
if specified.
sourcepub fn create_compute_pipeline(
&self,
compute_shader: &Shader
) -> Result<Pipeline>
pub fn create_compute_pipeline(
&self,
compute_shader: &Shader
) -> Result<Pipeline>
Create a compute pipeline.
This equals a Program
in GL terminology.
Valid usage
- The compute shader in must be valid and created with
ShaderStage::Compute
.
sourcepub fn delete_pipeline(&self, pipeline: Pipeline)
pub fn delete_pipeline(&self, pipeline: Pipeline)
Delete a pipeline.
sourcepub fn delete_pipelines(&self, pipelines: &[Pipeline])
pub fn delete_pipelines(&self, pipelines: &[Pipeline])
Delete multiple pipelines.
sourcepub fn bind_input_assembly_state(&self, state: &InputAssembly)
pub fn bind_input_assembly_state(&self, state: &InputAssembly)
Bind input assembly pipeline state.
sourcepub fn bind_color_blend_state(&self, state: &ColorBlend)
pub fn bind_color_blend_state(&self, state: &ColorBlend)
Bind color blending pipeline state.
sourcepub fn bind_depth_stencil_state(&self, state: &DepthStencil)
pub fn bind_depth_stencil_state(&self, state: &DepthStencil)
Bind depth-stencil pipeline state.
Examples
Basic Less-Equal
depth test with write:
grr.bind_depth_stencil_state(&grr::DepthStencil {
depth_test: true,
depth_write: true,
depth_compare_op: grr::Compare::LessEqual,
stencil_test: false,
stencil_front: grr::StencilFace::KEEP,
stencil_back: grr::StencilFace::KEEP,
});
sourcepub fn bind_rasterization_state(&self, state: &Rasterization)
pub fn bind_rasterization_state(&self, state: &Rasterization)
Bind rasterization pipeline state.
pub fn bind_multisample_state(&self, state: Option<&Multisample>)
sourcepub fn bind_pipeline(&self, pipeline: &Pipeline)
pub fn bind_pipeline(&self, pipeline: &Pipeline)
Bind a pipeline for usage.
sourceimpl Device
impl Device
pub fn create_query(&self, ty: QueryType) -> Query
pub fn begin_query(&self, query: &Query)
pub fn end_query(&self, query: &Query)
pub fn write_timestamp(&self, query: &Query)
pub fn begin_conditional_rendering(&self, query: &Query, mode: ConditionalMode)
pub fn end_conditional_rendering(&self)
sourceimpl Device
impl Device
sourcepub fn create_sampler(&self, desc: SamplerDesc) -> Result<Sampler>
pub fn create_sampler(&self, desc: SamplerDesc) -> Result<Sampler>
Create a sampler object.
sourcepub fn bind_samplers(&self, first: u32, samplers: &[&Sampler])
pub fn bind_samplers(&self, first: u32, samplers: &[&Sampler])
Bind samplers to specific texture units.
pub fn delete_sampler(&self, sampler: Sampler)
sourcepub fn delete_samplers(&self, samplers: &[Sampler])
pub fn delete_samplers(&self, samplers: &[Sampler])
Delete multiple samplers.
sourceimpl Device
impl Device
sourcepub fn memory_barrier(&self, flags: Barrier)
pub fn memory_barrier(&self, flags: Barrier)
sourcepub fn memory_barrier_by_region(&self, flags: RegionBarrier)
pub fn memory_barrier_by_region(&self, flags: RegionBarrier)
sourceimpl Device
impl Device
sourcepub fn create_vertex_array(
&self,
attributes: &[VertexAttributeDesc]
) -> Result<VertexArray>
pub fn create_vertex_array(
&self,
attributes: &[VertexAttributeDesc]
) -> Result<VertexArray>
Create a new vertex array, storing information for the input assembler.
The vertex array specified the vertex attributes and their binding to vertex buffer objects.
sourcepub fn delete_vertex_array(&self, vao: VertexArray)
pub fn delete_vertex_array(&self, vao: VertexArray)
Delete a vertex array.
sourcepub fn delete_vertex_arrays(&self, vao: &[VertexArray])
pub fn delete_vertex_arrays(&self, vao: &[VertexArray])
Delete multiple vertex arrays.
sourcepub fn bind_vertex_array(&self, vao: &VertexArray)
pub fn bind_vertex_array(&self, vao: &VertexArray)
Bind a vertex array for usage.
sourcepub fn bind_vertex_buffers(
&self,
vao: &VertexArray,
first: u32,
views: &[VertexBufferView<'_>]
)
pub fn bind_vertex_buffers(
&self,
vao: &VertexArray,
first: u32,
views: &[VertexBufferView<'_>]
)
Bind vertex buffers to a vertex array.
sourcepub fn bind_index_buffer(&self, vao: &VertexArray, buffer: &Buffer)
pub fn bind_index_buffer(&self, vao: &VertexArray, buffer: &Buffer)
Bind a index buffer to a vertex array.