ui/gpu_view.rs#
Source: lib/ui/gpu_view.rs
gpu_view -- GPU content in a window: a 3D view between widgets (G5e1; docs/GPU.md "3D-Ansicht")
The framebuffer stays the truth: a view is drawn into it like any canvas, its command's Draw copies the view's
last frame there. What is new is where that frame comes from: the app's content (GpuContent; a render3d Renderer
and Scene, or anything else on lib/gpu: lib/ui knows nothing of render3d) draws it on the UI's own device into a
texture of the view's size, and the frame is read back from there.
ui.gpu_view(id, &content, ver) -> &UiInput the view in the layout's next rectangle (next_size), its input
as ui.canvas's; a new ver (or size, or device) draws a frame
GpuContent::attach(dev) / detach() a device for the view: the first one, a new one after a loss /
it goes; build and drop what the frames need there
GpuContent::draw(e, target, size) a frame into target (GPU_VIEW_FORMAT, the view's size)
GpuContent::submitted(id) the frame went to the queue
GpuContent::paint(g, r) what the view shows without a device
GpuContent::paints() paint draws what a frame would (render2d's CPU path): without a
device the view paints, not the last frame of a device that is gone
ui.gpu_view_info(win, id) what a view does now (tests, measurements)
AF_GPU_3D the app shows views: the UI's device at level Voll on the
fastest adapter (without it, as ever: Basis, the frugal one)
Where a frame shows (gpu_out.rs "views"):
- the window on its swapchain and the view on top in its cells: the output's render pass draws the texture
there (a quad, as an image's), the framebuffer lacks those pixels (Split::owed) until somebody reads it:
gp_settle runs the Draw, which reads the texture back. At rest (REST after the last frame) gp_tick does
that once, so the framebuffer holds the picture again without anybody asking. A layer over the view gets
the frame below it the same way; cells with something of the base over the view are drawn by the CPU over
the frame read back.
- anywhere else (the CPU path: before the switch, a new size, minimised, the inspector, right to left,
jfgui_GPU_OUTPUT=0, jfgui_GPU_VIEWS=0, a script without `gpu on`): the frame is read back at once and the
Draw copies it into the framebuffer, in the cells the CPU draws.
- no device (jfgui_GPU=0, no Vulkan or no usable adapter, a static Linux program, a lost device not back
yet): the last frame read back, else GpuContent::paint (a content that paints itself, GpuContent::paints:
always its painting).
The device is the UI output's (one for all windows); without an output in this run (not wanted, never
possible) the views make one of their own on first use. A new device (generation) detaches the content from
the old one and attaches it to the new one; its next frame follows.
The browser cannot wait: a read-back there is answered later, the Draw shows the last frame that came back. When
the answer comes (gp_views_tick looks), the next render takes it to the framebuffer as it would a new frame, and at
rest it is settled again (G5e2: before, a view at rest or under a layer kept an older frame in the framebuffer).
A view's frame is bound to the display (G5e3): while its window is on its swapchain and the window's last frame has
not been shown yet (gpu_out.rs Win::pending: no free image, the display has not answered, less than 4 ms since the
last present), a new ver does not ask the content to draw; renders in between take the view's last frame. Once the
window's frame is shown gp_views_wake asks for a render, which draws the newest ver; a frame that is never shown
holds the view at most VIEW_HOLD_US, then it draws one anyway. GpuViewInfo::held counts the frames that waited.
/// the format of a view's target: what the output samples and what is read back byte for byte into the
/// framebuffer (B, G, R, x). The content's colours go in as it writes them, as sRGB codes like the framebuffer's:
/// no hardware encodes them (G5e2: render3d's fragment shaders do, RendererDesc::encode_srgb)
GPU_VIEW_FORMAT: gpu::Format = gpu::Format::Bgra8Unorm
trait GpuContentwhat a view (ui.gpu_view) shows: content drawn on the UI's GPU device. The app keeps it in anRc<RefCell<..>>and hands the same one every frame; lib/ui keeps a Weak and calls these at render timefn attach(&mut self, dev: &gpu::Device) -> gpu::Result<()>a device for the view: the first, or a new one after the last was lost (what was built on an earlier one is dead). Build what the frames need on it. Err: the view paints until the next devicefn detach(&mut self)the device goes (lost, the output ended, another content took the view's id): drop what was built on itfn draw<'a>(&'a mut self, e: &mut gpu::CommandEncoder<'a>, target: gpu::ColorAttachment<'a>, size: (u32, u32)) -> gpu::Result<()>one frame: record into e a render pass into target (GPU_VIEW_FORMAT, size w x h px). Keep its view, before and after (the pass may set its own load and clear:ColorAttachment { clear: .., ..target }); passes that split it (render3d's occlusion test) begin with its before and end with its after. lib/ui submits efn submitted(&mut self, id: gpu::SubmitId)the frame went to the queue as id (render3d: Scene::submitted)fn paint(&self, g: &mut Gfx, r: [i32; 4])what the view shows without a device (no GPU, jfgui_GPU=0, before the first frame): painted on the CPU into g, clipped to r (x, y, w, h); a dark grey unless the content says otherwisefn paints(&self) -> boolpaint draws what a frame would (render2d's CPU path, G6e1): without a device the view paints, also where it holds a frame read back from an earlier device (a lost one); false (the default): that last frame stays until a device draws again
struct GpuViewInfowhat a view does now (Ui::gpu_view_info; tests and measurements)device: bool-- its content is attached to a device: its frames come from the GPUoutput: bool-- that device is the UI output's (else the views' own: no output in this run)level: Option<gpu::Level>-- the device's levelgeneration: u32-- the device's generation (a new one after a lost device; 0: none)apart: bool-- the output's render pass drew it in the window's last frame (else the CPU copies the frame read back)attaches: u32-- the content attached and detached so fardetaches: u32frames: u64-- frames drawn, the CPU time recording and submitting them took (us)draw_us: u64reads: u64-- frames read back into the CPU's copy, the time that took (us: submit, wait, copy)read_us: u64read_frame: u64-- (G5e2) the newest frame read back into the CPU's copy (1, 2, ..; 0: none): the framebuffer can hold the view's newest frame once it equalsframes(in the browser a read-back comes later)held: u64-- (G5e3) frames that had to wait: a new ver (size, device) came while the view's window had not shown its last frame yet, so the content was not asked to draw then (each ver counted once; the newest is drawn when the window's frame has arrived)size: (u32, u32)-- the size of its target (px)error: Option<String>-- what the last failure said
impl Ui
fn gpu_view<C: GpuContent + 'static>(&mut self, id: u32, content: &Rc<RefCell<C>>, ver: u32) -> &UiInputa view of GPU content (gpu_view.rs): the layout's next rectangle (next_size) shows whatcontentdraws on the UI's device, between the widgets, under popups and tooltips; its input is ui.canvas's.verstands for everything the view shows (scene, camera, an animation's time): another value draws a frame, the same one none (an animation asks for passes itself, ui.invalidate). Hand the same content every framefn gpu_view_info(&self, win: u32, id: u32) -> Option<GpuViewInfo>what viewidof windowwin(0 = main) does now; None: no such view