Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix low hanging fruits for render performance #4485

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ function cairo_draw(screen::Screen, scene::Scene)
draw_background(screen, scene)

allplots = Makie.collect_atomic_plots(scene; is_atomic_plot = is_cairomakie_atomic_plot)
zvals = Makie.zvalue2d.(allplots)
permute!(allplots, sortperm(zvals))

sort!(allplots; by=Makie.zvalue2d)
# If the backend is not a vector surface (i.e., PNG/ARGB),
# then there is no point in rasterizing twice.
should_rasterize = is_vector_backend(screen.surface)
Expand Down Expand Up @@ -120,7 +118,7 @@ function draw_background(screen::Screen, scene::Scene, root_h)
bg = scene.backgroundcolor[]
Cairo.set_source_rgba(cr, red(bg), green(bg), blue(bg), alpha(bg));
r = viewport(scene)[]
# Makie has (0,0) at bottom left, Cairo at top left. Makie extends up,
# Makie has (0,0) at bottom left, Cairo at top left. Makie extends up,
# Cairo down. Negative height breaks other backgrounds
x, y = origin(r); w, h = widths(r)
Cairo.rectangle(cr, x, root_h - y - h, w, h) # background
Expand Down
6 changes: 3 additions & 3 deletions GLMakie/src/GLAbstraction/GLRenderObject.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ function (sp::StandardPostrender)()
render(sp.vao, sp.primitive)
end

struct StandardPostrenderInstanced{T}
main::T
struct StandardPostrenderInstanced
n_instances::Observable{Int}
vao::GLVertexArray
primitive::GLenum
end

function (sp::StandardPostrenderInstanced)()
renderinstanced(sp.vao, to_value(sp.main), sp.primitive)
return renderinstanced(sp.vao, sp.n_instances[], sp.primitive)
end

struct EmptyPrerender end
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/postprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function to_screen_postprocessor(framebuffer, shader_cache, screen_fb_id = nothi
default_id = isnothing(screen_fb_id) ? 0 : screen_fb_id[]
# GLFW uses 0, Gtk uses a value that we have to probe at the beginning of rendering
glBindFramebuffer(GL_FRAMEBUFFER, default_id)
glViewport(0, 0, framebuffer_size(screen.glscreen)...)
glViewport(0, 0, framebuffer_size(screen)...)
glClear(GL_COLOR_BUFFER_BIT)
GLAbstraction.render(pass) # copy postprocess
end
Expand Down
10 changes: 4 additions & 6 deletions GLMakie/src/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ Renders a single frame of a `window`
function render_frame(screen::Screen; resize_buffers=true)
nw = to_native(screen)
ShaderAbstractions.switch_context!(nw)

function sortby(x)
robj = x[3]
plot = screen.cache2plot[robj.id]
# TODO, use actual boundingbox
return Makie.zvalue2d(plot)
return x[3][:model][][3, 4]
end
zvals = sortby.(screen.renderlist)
permute!(screen.renderlist, sortperm(zvals))

sort!(screen.renderlist; by=sortby)

# NOTE
# The transparent color buffer is reused by SSAO and FXAA. Changing the
Expand Down
4 changes: 3 additions & 1 deletion GLMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ mutable struct Screen{GLWindow} <: MakieScreen
renderlist::Vector{Tuple{ZIndex, ScreenID, RenderObject}}
postprocessors::Vector{PostProcessor}
cache::Dict{UInt64, RenderObject}
cache2plot::Dict{UInt32, AbstractPlot}
cache2plot::Dict{UInt32, Plot}
framecache::Matrix{RGB{N0f8}}
render_tick::Observable{Makie.TickState} # listeners must not Consume(true)
window_open::Observable{Bool}
Expand Down Expand Up @@ -218,6 +218,8 @@ mutable struct Screen{GLWindow} <: MakieScreen
end
end

framebuffer_size(screen::Screen) = screen.framebuffer.resolution[]

Makie.isvisible(screen::Screen) = screen.config.visible

# for e.g. closeall, track all created screens
Expand Down
Loading