Closed Bug 2072784 Opened 2 months ago Closed 1 month ago

Split the WebRender device layer into a backend-neutral Device and a GL backend

Categories

(Core :: Graphics: WebRender, task)

task

Tracking

()

RESOLVED FIXED
158 Branch
Tracking Status
firefox158 --- fixed

People

(Reporter: gw, Assigned: gw)

Details

Attachments

(8 external files)

No description provided.

Texture, ExternalTexture, Program, VAO, TransferBuffer and the framebuffer
and buffer id newtypes now hold plain integers rather than gleam types, and
Texture holds the ImageBufferKind it was created from rather than a GL enum,
converting at the call sites that issue GL. DepthFunction becomes a plain
enum with the GL mapping in to_gl. This lets the resource types be shared
with another backend without depending on gleam.

No behaviour change: from_gl_target, which could not tell
TextureExternalBT709 from TextureExternal, is no longer needed.

Assignee: nobody → mozilla
Status: NEW → ASSIGNED

Remove UniformLocation, get_uniform_location and draw_triangles_u16, none of
which had callers, and the phantom type parameter of reuse_render_target.
Privatise the helpers only called from inside the device: bind_read_target,
bind_external_draw_target, reset_draw_target, depth_bits, compile_shader,
invalidate_depth_target, create_transfer_buffer and
required_upload_size_and_stride.

What remains is what a backend trait will have to express, so it should be
as small as possible. No behaviour change.

UploadBufferPool and TextureUploader reached into the GL context to
allocate, map, flush and orphan pixel buffers, to create and poll sync
objects, and to issue texture updates. Express those as Device operations
any backend can provide: allocate, map, flush and orphan_upload_buffer,
upload_texture_region, and create, poll and delete_fence over Fence and
FenceStatus. UploadChunk becomes the public description of one copy from an
upload buffer into a texture, and flush_upload_buffer performs a batch of
them, which is the shape of a staging buffer copy in explicit graphics APIs.
The pool and uploader then use only Device and Capabilities, so they can
move out of the GL backend.

GL calls are the same except that the pixel unpack buffer is unbound at the
end of each flush and orphan rather than once per returned buffer, adding a
rebind when an oversized buffer is orphaned, and that a recycled
persistently mapped buffer is no longer bound while being handed out, since
nothing used the binding.

The GPU profiler held its own GL context handle for timer and occlusion
queries and for debug marker groups, and picked the GL debug extension
itself. Give it a GpuQueryBackend trait with the operations it needs,
implemented for GL by GlQueries in the device, which also owns the extension
choice. The file is renamed query_gl.rs to query.rs; its module path
device::query is unchanged. No behaviour change.

Explicit graphics APIs bake blend, depth test, depth write and color write
mask into a pipeline object together with the shader, so a backend needs to
see them when the program is bound rather than as separate GL-style toggles.
Add RenderState holding those four settings and bind_pipeline(program,
state). The set_blend_mode, set_depth_test, set_depth_write and
set_color_write methods now only record the requested state and bind_program
applies it, so renderer call sites are unchanged. Debug builds still assert
that a draw follows the program bind, which is what makes the state known at
bind time.

The GL device caches the state the context holds and issues calls only for
the parts that differ, invalidating the cache in reset_state, which the
renderer already calls after external code may have used the context. The
color mask is the exception, assumed untouched by external code as it always
has been, because SWGL does not implement glColorMask and it must not be
issued unless the renderer asks for it. Clears set the depth write mask they
need themselves, being independent of pipeline state in explicit APIs, and
the stencil test is disabled once in begin_frame instead of through a
separate disable_stencil call. The GL calls issued are otherwise the same or
fewer.

Device becomes a thin wrapper around Box<dyn GpuBackend>, the trait a
graphics API backend implements, and the GL implementation is renamed
GlDevice. The trait covers resource creation and destruction, render passes,
bind_pipeline, texture and vertex binding, uploads, readback, fences,
queries and draws, with vertex, instance and texel data passed as bytes so
that it is object safe.

The wrapper derefs to the backend, so renderer call sites are unchanged, and
owns what is backend independent: the requested RenderState and its set_*
methods, bind_program, the debug check that a draw follows a program bind,
the typed helpers over sampler types and typed slices, create_program_linked,
blit_render_target_invert_y and upload_texture. MappedTransferBuffer holds
the backend and unmaps through a new unmap_transfer_buffer, and the texture
counters become accessors.

Most of the diff is GlDevice's methods splitting into a trait impl block and
a private one; review with --color-moved. The GL calls issued are unchanged.

Move the resource types, state and descriptor structs, targets and the
program binary cache from device/gl.rs to device/types.rs, and the upload
buffer pool and texture uploader to device/upload.rs, so that gl.rs holds
only the GL backend. The moved code is unchanged apart from imports and the
fields and helpers the GL backend fills in becoming pub(super). Methods that
need GL, such as DepthFunction::to_gl and ProgramSourceInfo::new, stay in
gl.rs as inherent impls on the moved types.

The gl_leaks test now scans everything except device/gl.rs. device/mod.rs
joins the allowlist because Device::new still takes the GL context, which
Pt 8 replaces with a backend selection. No behaviour change.

create_webrender_instance and Device::new took the GL context directly,
which tied the embedder API to gleam. They now take GpuBackendConfig, an
enum with one variant per backend carrying what that backend needs from the
embedder; Gl carries the GL context. Gecko, wrench and the examples wrap
their context in GpuBackendConfig::Gl.

With that, renderer/init.rs and lib.rs no longer mention GL, so the gl_leaks
allowlist is empty. device/mod.rs is permanently allowed, since selecting a
backend means naming each one's native context type. No behaviour change.

Pushed by gwatson@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/1f2fb4e38302 https://hg.mozilla.org/integration/autoland/rev/28d6ee4697ad Pt 1 - Give WebRender device resources backend-neutral handles r=gfx-reviewers,nical https://github.com/mozilla-firefox/firefox/commit/e5dfbe0e75c7 https://hg.mozilla.org/integration/autoland/rev/2e82a5313a09 Pt 2 - Trim the WebRender Device API to what the renderer uses r=gfx-reviewers,nical https://github.com/mozilla-firefox/firefox/commit/ae2ee4182231 https://hg.mozilla.org/integration/autoland/rev/07a7a0922e20 Pt 3 - Drive WebRender texture uploads through device primitives r=gfx-reviewers,nical https://github.com/mozilla-firefox/firefox/commit/efb88336ab01 https://hg.mozilla.org/integration/autoland/rev/3878799c78e1 Pt 4 - Drive the WebRender GPU profiler through a query trait r=gfx-reviewers,nical https://github.com/mozilla-firefox/firefox/commit/20c65f421f7f https://hg.mozilla.org/integration/autoland/rev/0a48ebae16fa Pt 5 - Bundle WebRender blend, depth and color-write state into a pipeline bind r=gfx-reviewers,nical https://github.com/mozilla-firefox/firefox/commit/32fba8b922d1 https://hg.mozilla.org/integration/autoland/rev/0cb7d640b527 Pt 6 - Carve the GpuBackend trait out of the WebRender Device r=gfx-reviewers,nical https://github.com/mozilla-firefox/firefox/commit/610425bffda8 https://hg.mozilla.org/integration/autoland/rev/d146346fdc03 Pt 7 - Move the backend-neutral WebRender device types out of the GL backend r=gfx-reviewers,nical https://github.com/mozilla-firefox/firefox/commit/4e9e72bf38a2 https://hg.mozilla.org/integration/autoland/rev/a6fcce2bb53d Pt 8 - Select the WebRender GPU backend through GpuBackendConfig r=gfx-reviewers,nical
QA Whiteboard: [qa-triage-done-c159/b158]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: