Struct webrender::Device

source ·
pub struct Device {
Show 41 fields gl: Rc<dyn Gl>, base_gl: Option<Rc<dyn Gl>>, bound_textures: [GLuint; 16], bound_program: GLuint, bound_program_name: Rc<CString>, bound_vao: GLuint, bound_read_fbo: (FBOId, DeviceIntPoint), bound_draw_fbo: FBOId, default_read_fbo: FBOId, default_draw_fbo: FBOId, depth_available: bool, upload_method: UploadMethod, use_batched_texture_uploads: bool, use_draw_calls_for_texture_copy: bool, batched_upload_threshold: i32, capabilities: Capabilities, color_formats: TextureFormatPair<ImageFormat>, bgra_formats: TextureFormatPair<GLuint>, bgra_pixel_type: GLuint, swizzle_settings: SwizzleSettings, depth_format: GLuint, depth_targets: FastHashMap<DeviceIntSize, SharedDepthTarget>, inside_frame: bool, crash_annotator: Option<Box<dyn CrashAnnotator>>, annotate_draw_call_crashes: bool, resource_override_path: Option<PathBuf>, use_optimized_shaders: bool, max_texture_size: i32, cached_programs: Option<Rc<ProgramCache>>, frame_id: GpuFrameId, texture_storage_usage: TexStorageUsage, required_pbo_stride: StrideAlignment, requires_null_terminated_shader_source: bool, requires_texture_external_unbind: bool, is_software_webrender: bool, extensions: Vec<String>, dump_shader_source: Option<String>, surface_origin_is_top_left: bool, shader_is_ready: bool, pub textures_created: u32, pub textures_deleted: u32,
}

Fields§

§gl: Rc<dyn Gl>§base_gl: Option<Rc<dyn Gl>>

If non-None, |gl| points to a profiling wrapper, and this points to the underling Gl instance.

§bound_textures: [GLuint; 16]§bound_program: GLuint§bound_program_name: Rc<CString>§bound_vao: GLuint§bound_read_fbo: (FBOId, DeviceIntPoint)§bound_draw_fbo: FBOId§default_read_fbo: FBOId§default_draw_fbo: FBOId§depth_available: bool

Track depth state for assertions. Note that the default FBO has depth, so this defaults to true.

§upload_method: UploadMethod§use_batched_texture_uploads: bool§use_draw_calls_for_texture_copy: bool

Whether to use draw calls instead of regular blitting commands.

Note: this currently only applies to the batched texture uploads path.

§batched_upload_threshold: i32

Number of pixels below which we prefer batched uploads.

§capabilities: Capabilities§color_formats: TextureFormatPair<ImageFormat>§bgra_formats: TextureFormatPair<GLuint>§bgra_pixel_type: GLuint§swizzle_settings: SwizzleSettings§depth_format: GLuint§depth_targets: FastHashMap<DeviceIntSize, SharedDepthTarget>

Map from texture dimensions to shared depth buffers for render targets.

Render targets often have the same width/height, so we can save memory by sharing these across targets.

§inside_frame: bool§crash_annotator: Option<Box<dyn CrashAnnotator>>§annotate_draw_call_crashes: bool§resource_override_path: Option<PathBuf>§use_optimized_shaders: bool

Whether to use shaders that have been optimized at build time.

§max_texture_size: i32§cached_programs: Option<Rc<ProgramCache>>§frame_id: GpuFrameId§texture_storage_usage: TexStorageUsage

When to use glTexStorage*. We prefer this over glTexImage* because it guarantees that mipmaps won’t be generated (which they otherwise are on some drivers, particularly ANGLE). However, it is not always supported at all, or for BGRA8 format. If it’s not supported for the required format, we fall back to glTexImage*.

§required_pbo_stride: StrideAlignment

Required stride alignment for pixel transfers. This may be required for correctness reasons due to driver bugs, or for performance reasons to ensure we remain on the fast-path for transfers.

§requires_null_terminated_shader_source: bool

Whether we must ensure the source strings passed to glShaderSource() are null-terminated, to work around driver bugs.

§requires_texture_external_unbind: bool

Whether we must unbind any texture from GL_TEXTURE_EXTERNAL_OES before binding to GL_TEXTURE_2D, to work around an android emulator bug.

§is_software_webrender: bool
§extensions: Vec<String>§dump_shader_source: Option<String>

Dumps the source of the shader with the given name

§surface_origin_is_top_left: bool§shader_is_ready: bool

A debug boolean for tracking if the shader program has been set after a blend mode change.

This is needed for compatibility with next-gen GPU APIs that switch states using “pipeline object” that bundles together the blending state with the shader.

Having the constraint of always binding the shader last would allow us to have the “pipeline object” bound at that time. Without this constraint, we’d either have to eagerly bind the “pipeline object” on changing either the shader or the blend more, or lazily bind it at draw call time, neither of which is desirable.

§textures_created: u32§textures_deleted: u32

Implementations§

source§

impl Device

source

pub fn new( gl: Rc<dyn Gl>, crash_annotator: Option<Box<dyn CrashAnnotator>>, resource_override_path: Option<PathBuf>, use_optimized_shaders: bool, upload_method: UploadMethod, batched_upload_threshold: i32, cached_programs: Option<Rc<ProgramCache>>, allow_texture_storage_support: bool, allow_texture_swizzling: bool, dump_shader_source: Option<String>, surface_origin_is_top_left: bool, panic_on_gl_error: bool ) -> Device

source

pub fn gl(&self) -> &dyn Gl

source

pub fn rc_gl(&self) -> &Rc<dyn Gl>

source

pub fn set_parameter(&mut self, param: &Parameter)

source

pub fn clamp_max_texture_size(&mut self, size: i32)

Ensures that the maximum texture size is less than or equal to the provided value. If the provided value is less than the value supported by the driver, the latter is used.

source

pub fn max_texture_size(&self) -> i32

Returns the limit on texture dimensions (width or height).

source

pub fn surface_origin_is_top_left(&self) -> bool

source

pub fn get_capabilities(&self) -> &Capabilities

source

pub fn preferred_color_formats(&self) -> TextureFormatPair<ImageFormat>

source

pub fn swizzle_settings(&self) -> Option<SwizzleSettings>

source

pub fn depth_bits(&self) -> i32

source

pub fn max_depth_ids(&self) -> i32

source

pub fn ortho_near_plane(&self) -> f32

source

pub fn ortho_far_plane(&self) -> f32

source

pub fn required_pbo_stride(&self) -> StrideAlignment

source

pub fn upload_method(&self) -> &UploadMethod

source

pub fn use_batched_texture_uploads(&self) -> bool

source

pub fn use_draw_calls_for_texture_copy(&self) -> bool

source

pub fn batched_upload_threshold(&self) -> i32

source

pub fn reset_state(&mut self)

source

fn print_shader_errors(source: &str, log: &str)

source

pub fn compile_shader( &self, name: &str, shader_type: GLenum, source: &String ) -> Result<GLuint, ShaderError>

source

pub fn begin_frame(&mut self) -> GpuFrameId

source

fn bind_texture_impl( &mut self, slot: TextureSlot, id: GLuint, target: GLenum, set_swizzle: Option<Swizzle>, image_rendering: Option<ImageRendering> )

source

pub fn bind_texture<S>(&mut self, slot: S, texture: &Texture, swizzle: Swizzle)where S: Into<TextureSlot>,

source

pub fn bind_external_texture<S>( &mut self, slot: S, external_texture: &ExternalTexture )where S: Into<TextureSlot>,

source

pub fn bind_read_target_impl(&mut self, fbo_id: FBOId, offset: DeviceIntPoint)

source

pub fn bind_read_target(&mut self, target: ReadTarget)

source

fn bind_draw_target_impl(&mut self, fbo_id: FBOId)

source

pub fn reset_read_target(&mut self)

source

pub fn reset_draw_target(&mut self)

source

pub fn bind_draw_target(&mut self, target: DrawTarget)

source

pub fn create_fbo(&mut self) -> FBOId

Creates an unbound FBO object. Additional attachment API calls are required to make it complete.

source

pub fn create_fbo_for_external_texture(&mut self, texture_id: u32) -> FBOId

Creates an FBO with the given texture bound as the color attachment.

source

pub fn delete_fbo(&mut self, fbo: FBOId)

source

pub fn bind_external_draw_target(&mut self, fbo_id: FBOId)

Link a program, attaching the supplied vertex format.

If create_program() finds a binary shader on disk, it will kick off linking immediately, which some drivers (notably ANGLE) run in parallel on background threads. As such, this function should ideally be run sometime later, to give the driver time to do that before blocking due to an API call accessing the shader.

This generally means that the first run of the application will have to do a bunch of blocking work to compile the shader from source, but subsequent runs should load quickly.

source

pub fn bind_program(&mut self, program: &Program) -> bool

source

pub fn create_texture( &mut self, target: ImageBufferKind, format: ImageFormat, width: i32, height: i32, filter: TextureFilter, render_target: Option<RenderTargetInfo> ) -> Texture

source

fn set_texture_parameters(&mut self, target: GLuint, filter: TextureFilter)

source

pub fn copy_entire_texture(&mut self, dst: &mut Texture, src: &Texture)

Copies the entire contents of one texture to another. The dest texture must be at least as large as the source texture in each dimension. No scaling is performed, so if the dest texture is larger than the source texture then some of its pixels will not be written to.

source

pub fn copy_texture_sub_region( &mut self, src_texture: &Texture, src_x: usize, src_y: usize, dest_texture: &Texture, dest_x: usize, dest_y: usize, width: usize, height: usize )

Copies the specified subregion from src_texture to dest_texture.

source

pub fn invalidate_render_target(&mut self, texture: &Texture)

Notifies the device that the contents of a render target are no longer needed.

source

pub fn invalidate_depth_target(&mut self)

Notifies the device that the contents of the current framebuffer’s depth attachment is no longer needed. Unlike invalidate_render_target, this can be called even when the contents of the colour attachment is still required. This should be called before unbinding the framebuffer at the end of a pass, to allow tiled GPUs to avoid writing the contents back to memory.

source

pub fn reuse_render_target<T: Texel>( &mut self, texture: &mut Texture, rt_info: RenderTargetInfo )

Notifies the device that a render target is about to be reused.

This method adds or removes a depth target as necessary.

source

fn init_fbos(&mut self, texture: &mut Texture, with_depth: bool)

source

fn acquire_depth_target(&mut self, dimensions: DeviceIntSize) -> RBOId

source

fn release_depth_target(&mut self, dimensions: DeviceIntSize)

source

fn blit_render_target_impl( &mut self, src_rect: FramebufferIntRect, dest_rect: FramebufferIntRect, filter: TextureFilter )

Perform a blit between self.bound_read_fbo and self.bound_draw_fbo.

source

pub fn blit_render_target( &mut self, src_target: ReadTarget, src_rect: FramebufferIntRect, dest_target: DrawTarget, dest_rect: FramebufferIntRect, filter: TextureFilter )

Perform a blit between src_target and dest_target. This will overwrite self.bound_read_fbo and self.bound_draw_fbo.

source

pub fn blit_render_target_invert_y( &mut self, src_target: ReadTarget, src_rect: FramebufferIntRect, dest_target: DrawTarget, dest_rect: FramebufferIntRect )

Performs a blit while flipping vertically. Useful for blitting textures (which use origin-bottom-left) to the main framebuffer (which uses origin-top-left).

source

pub fn delete_texture(&mut self, texture: Texture)

source

pub fn delete_program(&mut self, program: Program)

source

pub fn create_program_linked( &mut self, base_filename: &'static str, features: &[&'static str], descriptor: &VertexDescriptor ) -> Result<Program, ShaderError>

Create a shader program and link it immediately.

source

pub fn create_program( &mut self, base_filename: &'static str, features: &[&'static str] ) -> Result<Program, ShaderError>

Create a shader program. This does minimal amount of work to start loading a binary shader. If a binary shader is found, we invoke glProgramBinary, which, at least on ANGLE, will load and link the binary on a background thread. This can speed things up later when we invoke link_program().

source

fn build_shader_string<F: FnMut(&str)>( &self, features: &[&'static str], kind: ShaderKind, base_filename: &str, output: F )

source

pub fn bind_shader_samplers<S>( &mut self, program: &Program, bindings: &[(&'static str, S)] )where S: Into<TextureSlot> + Copy,

source

pub fn get_uniform_location( &self, program: &Program, name: &str ) -> UniformLocation

source

pub fn set_uniforms(&self, program: &Program, transform: &Transform3D<f32>)

source

pub fn set_shader_texture_size( &self, program: &Program, texture_size: DeviceSize )

Sets the uTextureSize uniform. Most shaders do not require this to be called as they use the textureSize GLSL function instead.

source

pub fn create_pbo(&mut self) -> PBO

source

pub fn create_pbo_with_size(&mut self, size: usize) -> PBO

source

pub fn read_pixels_into_pbo( &mut self, read_target: ReadTarget, rect: DeviceIntRect, format: ImageFormat, pbo: &PBO )

source

pub fn map_pbo_for_readback<'a>( &'a mut self, pbo: &'a PBO ) -> Option<BoundPBO<'a>>

source

pub fn delete_pbo(&mut self, pbo: PBO)

source

pub fn required_upload_size_and_stride( &self, size: DeviceIntSize, format: ImageFormat ) -> (usize, usize)

Returns the size and stride in bytes required to upload an area of pixels of the specified size, to a texture of the specified format.

source

pub fn upload_texture<'a>( &mut self, pbo_pool: &'a mut UploadPBOPool ) -> TextureUploader<'a>

Returns a TextureUploader which can be used to upload texture data to texture. Once uploads have been performed the uploader must be flushed with TextureUploader::flush().

source

pub fn upload_texture_immediate<T: Texel>( &mut self, texture: &Texture, pixels: &[T] )

Performs an immediate (non-PBO) texture upload.

source

pub fn read_pixels(&mut self, img_desc: &ImageDescriptor) -> Vec<u8>

source

pub fn read_pixels_into( &mut self, rect: FramebufferIntRect, format: ImageFormat, output: &mut [u8] )

Read rectangle of pixels into the specified output slice.

source

pub fn get_tex_image_into( &mut self, texture: &Texture, format: ImageFormat, output: &mut [u8] )

Get texels of a texture into the specified output slice.

source

fn attach_read_texture_raw(&mut self, texture_id: GLuint, target: GLuint)

Attaches the provided texture to the current Read FBO binding.

source

pub fn attach_read_texture_external( &mut self, texture_id: GLuint, target: ImageBufferKind )

source

pub fn attach_read_texture(&mut self, texture: &Texture)

source

fn bind_vao_impl(&mut self, id: GLuint)

source

pub fn bind_vao(&mut self, vao: &VAO)

source

pub fn bind_custom_vao(&mut self, vao: &CustomVAO)

source

fn create_vao_with_vbos( &mut self, descriptor: &VertexDescriptor, main_vbo_id: VBOId, instance_vbo_id: VBOId, instance_divisor: u32, ibo_id: IBOId, owns_vertices_and_indices: bool ) -> VAO

source

pub fn create_custom_vao(&mut self, streams: &[Stream<'_>]) -> CustomVAO

source

pub fn delete_custom_vao(&mut self, vao: CustomVAO)

source

pub fn create_vbo<T>(&mut self) -> VBO<T>

source

pub fn delete_vbo<T>(&mut self, vbo: VBO<T>)

source

pub fn create_vao( &mut self, descriptor: &VertexDescriptor, instance_divisor: u32 ) -> VAO

source

pub fn delete_vao(&mut self, vao: VAO)

source

pub fn allocate_vbo<V>( &mut self, vbo: &mut VBO<V>, count: usize, usage_hint: VertexUsageHint )

source

pub fn fill_vbo<V>(&mut self, vbo: &VBO<V>, data: &[V], offset: usize)

source

fn update_vbo_data<V>( &mut self, vbo: VBOId, vertices: &[V], usage_hint: VertexUsageHint )

source

pub fn create_vao_with_new_instances( &mut self, descriptor: &VertexDescriptor, base_vao: &VAO ) -> VAO

source

pub fn update_vao_main_vertices<V>( &mut self, vao: &VAO, vertices: &[V], usage_hint: VertexUsageHint )

source

pub fn update_vao_instances<V: Clone>( &mut self, vao: &VAO, instances: &[V], usage_hint: VertexUsageHint, repeat: Option<NonZeroUsize> )

source

pub fn update_vao_indices<I>( &mut self, vao: &VAO, indices: &[I], usage_hint: VertexUsageHint )

source

pub fn draw_triangles_u16(&mut self, first_vertex: i32, index_count: i32)

source

pub fn draw_triangles_u32(&mut self, first_vertex: i32, index_count: i32)

source

pub fn draw_nonindexed_points(&mut self, first_vertex: i32, vertex_count: i32)

source

pub fn draw_nonindexed_lines(&mut self, first_vertex: i32, vertex_count: i32)

source

pub fn draw_indexed_triangles(&mut self, index_count: i32)

source

pub fn draw_indexed_triangles_instanced_u16( &mut self, index_count: i32, instance_count: i32 )

source

pub fn end_frame(&mut self)

source

pub fn clear_target( &self, color: Option<[f32; 4]>, depth: Option<f32>, rect: Option<FramebufferIntRect> )

source

pub fn enable_depth(&self, depth_func: DepthFunction)

source

pub fn disable_depth(&self)

source

pub fn enable_depth_write(&self)

source

pub fn disable_depth_write(&self)

source

pub fn disable_stencil(&self)

source

pub fn set_scissor_rect(&self, rect: FramebufferIntRect)

source

pub fn enable_scissor(&self)

source

pub fn disable_scissor(&self)

source

pub fn enable_color_write(&self)

source

pub fn disable_color_write(&self)

source

pub fn set_blend(&mut self, enable: bool)

source

fn set_blend_factors( &mut self, color: (GLenum, GLenum), alpha: (GLenum, GLenum) )

source

pub fn set_blend_mode_alpha(&mut self)

source

pub fn set_blend_mode_premultiplied_alpha(&mut self)

source

pub fn set_blend_mode_premultiplied_dest_out(&mut self)

source

pub fn set_blend_mode_multiply(&mut self)

source

pub fn set_blend_mode_subpixel_pass0(&mut self)

source

pub fn set_blend_mode_subpixel_pass1(&mut self)

source

pub fn set_blend_mode_subpixel_dual_source(&mut self)

source

pub fn set_blend_mode_multiply_dual_source(&mut self)

source

pub fn set_blend_mode_screen(&mut self)

source

pub fn set_blend_mode_plus_lighter(&mut self)

source

pub fn set_blend_mode_exclusion(&mut self)

source

pub fn set_blend_mode_show_overdraw(&mut self)

source

pub fn set_blend_mode_max(&mut self)

source

pub fn set_blend_mode_min(&mut self)

source

pub fn set_blend_mode_advanced(&mut self, mode: MixBlendMode)

source

pub fn supports_extension(&self, extension: &str) -> bool

source

pub fn echo_driver_messages(&self)

source

fn log_driver_messages(gl: &dyn Gl)

source

pub fn gl_describe_format(&self, format: ImageFormat) -> FormatDesc

source

pub fn report_memory( &self, size_op_funs: &MallocSizeOfOps, swgl: *mut c_void ) -> MemoryReport

Generates a memory report for the resources managed by the device layer.

source

pub fn depth_targets_memory(&self) -> usize

Auto Trait Implementations§

§

impl !RefUnwindSafe for Device

§

impl !Send for Device

§

impl !Sync for Device

§

impl Unpin for Device

§

impl !UnwindSafe for Device

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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.
§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.