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

SpecApi #3281

Merged
merged 62 commits into from
Oct 28, 2023
Merged

SpecApi #3281

Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
69ed953
add blockspec analogous to plotspec
SimonDanisch Oct 6, 2023
69100c0
correctly re-use plots
SimonDanisch Oct 6, 2023
66a7572
Merge branch 'master' of https://github.com/MakieOrg/Makie.jl into sd…
SimonDanisch Oct 10, 2023
8c3b9bf
add initial test example
SimonDanisch Oct 10, 2023
9c6790e
Merge branch 'sd/beta-20' into sd/blockspec
SimonDanisch Oct 17, 2023
6f8f127
Merge branch 'sd/blockspec' of https://github.com/MakieOrg/Makie.jl i…
SimonDanisch Oct 17, 2023
164358b
speed up marker lookup
SimonDanisch Oct 17, 2023
772688b
refactor requires_update to produce less leaks and less observables
SimonDanisch Oct 18, 2023
115b3bb
memoize more expensive operations to speed up plot creation
SimonDanisch Oct 18, 2023
c6c5fc7
cleanup state in WGLMakie
SimonDanisch Oct 18, 2023
fea2362
cleanup plot/scene deletion
SimonDanisch Oct 19, 2023
2985b8b
more clean up fixes
SimonDanisch Oct 20, 2023
7ccb85e
Merge branch 'sd/beta-20' into sd/blockspec
SimonDanisch Oct 20, 2023
c4f1751
fix spelling
SimonDanisch Oct 20, 2023
6ce78f3
Merge branch 'sd/blockspec' of https://github.com/MakieOrg/Makie.jl i…
SimonDanisch Oct 20, 2023
ff3b242
make things async safe
SimonDanisch Oct 20, 2023
326b989
cleanup and improve compile times
SimonDanisch Oct 20, 2023
521ceca
fix syntax error
SimonDanisch Oct 20, 2023
28bf675
cleanup
SimonDanisch Oct 20, 2023
620089d
try to recover precompile times
SimonDanisch Oct 20, 2023
6cd0d16
Merge branch 'sd/beta-20' into sd/blockspec
SimonDanisch Oct 20, 2023
7be2b10
try nightly
SimonDanisch Oct 21, 2023
27661eb
maybe this helsps!?
SimonDanisch Oct 21, 2023
df0aa2b
try nospecialize for plot
SimonDanisch Oct 22, 2023
6d9d00c
fix Electron invalidations
SimonDanisch Oct 23, 2023
dc5b6ca
a few more compile time improvements
SimonDanisch Oct 23, 2023
33b183e
What is going on with GLFramebuffer
SimonDanisch Oct 23, 2023
3058683
clean up
SimonDanisch Oct 23, 2023
8b21549
Merge branch 'sd/beta-20' into sd/blockspec
SimonDanisch Oct 24, 2023
04550b6
update v2
SimonDanisch Oct 24, 2023
1d1b31d
v6 texture atlas
SimonDanisch Oct 24, 2023
0a7704e
update download url
SimonDanisch Oct 24, 2023
f3fe41f
move cycler to scene
SimonDanisch Oct 24, 2023
66875eb
use plottype for plot
SimonDanisch Oct 24, 2023
58594ae
Merge branch 'sd/beta-20' into sd/blockspec
SimonDanisch Oct 24, 2023
4473f9f
Merge branch 'sd/blockspec' of https://github.com/MakieOrg/Makie.jl i…
SimonDanisch Oct 25, 2023
eb60638
refactor plot creation
SimonDanisch Oct 25, 2023
1ecdb4d
fix tests
SimonDanisch Oct 25, 2023
c2578cf
cycling now also happens in scenes
SimonDanisch Oct 25, 2023
e3c65f9
fix tests
SimonDanisch Oct 25, 2023
5b076b4
cleanup + legends
SimonDanisch Oct 25, 2023
53cb2f7
try docs
SimonDanisch Oct 25, 2023
bc8f227
fix makie tests
SimonDanisch Oct 25, 2023
e9a0377
fix tests
SimonDanisch Oct 25, 2023
11ef1c2
fix & cleanup
SimonDanisch Oct 26, 2023
7fd8ec2
add tests
SimonDanisch Oct 26, 2023
23189a0
Dont check in benchmark
SimonDanisch Oct 26, 2023
08915f0
fix legend
SimonDanisch Oct 26, 2023
bda6fd5
nightly doesn't like PNGFiles
SimonDanisch Oct 26, 2023
bd86530
include specapi tests
SimonDanisch Oct 26, 2023
359444e
fix test
SimonDanisch Oct 26, 2023
fdfc2dc
fix CairoMakie
SimonDanisch Oct 26, 2023
72ccdef
update tests for cycling
SimonDanisch Oct 26, 2023
fdf3bb3
update more cycle colros
SimonDanisch Oct 26, 2023
185f3eb
fix examples
SimonDanisch Oct 27, 2023
d06cc3e
polish, cleanup and fixes
SimonDanisch Oct 27, 2023
1523d65
try 'synchronizing'
SimonDanisch Oct 27, 2023
da7d9e7
fix tests maybe?!
SimonDanisch Oct 27, 2023
a2f653a
dont error
SimonDanisch Oct 28, 2023
2648216
dont do async in JSServe
SimonDanisch Oct 28, 2023
a576d34
hm
SimonDanisch Oct 28, 2023
0d148d9
take out test
SimonDanisch Oct 28, 2023
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
5 changes: 2 additions & 3 deletions GLMakie/src/GLAbstraction/AbstractGPUArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,11 @@ max_dim(t) = error("max_dim not implemented for: $(typeof(t)). This happen
function (::Type{GPUArrayType})(data::Observable; kw...) where GPUArrayType <: GPUArray
gpu_mem = GPUArrayType(data[]; kw...)
# TODO merge these and handle update tracking during contruction
obs1 = on(_-> gpu_mem.requires_update[] = true, data)
obs2 = on(new_data -> update!(gpu_mem, new_data), data)
if GPUArrayType <: TextureBuffer
push!(gpu_mem.buffer.observers, obs1, obs2)
push!(gpu_mem.buffer.observers, obs2)
else
push!(gpu_mem.observers, obs1, obs2)
push!(gpu_mem.observers, obs2)
end
return gpu_mem
end
Expand Down
5 changes: 1 addition & 4 deletions GLMakie/src/GLAbstraction/GLBuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mutable struct GLBuffer{T} <: GPUArray{T, 1}
usage::GLenum
context::GLContext
# TODO maybe also delay upload to when render happens?
requires_update::Observable{Bool}
observers::Vector{Observables.ObserverFunction}

function GLBuffer{T}(ptr::Ptr{T}, buff_length::Int, buffertype::GLenum, usage::GLenum) where T
Expand All @@ -18,8 +17,7 @@ mutable struct GLBuffer{T} <: GPUArray{T, 1}

obj = new(
id, (buff_length,), buffertype, usage, current_context(),
Observable(true), Observables.ObserverFunction[])

Observables.ObserverFunction[])
finalizer(free, obj)
obj
end
Expand Down Expand Up @@ -68,7 +66,6 @@ function GLBuffer(
au = ShaderAbstractions.updater(buffer)
obsfunc = on(au.update) do (f, args)
f(b, args...) # forward setindex! etc
b.requires_update[] = true
return
end
push!(b.observers, obsfunc)
Expand Down
2 changes: 0 additions & 2 deletions GLMakie/src/GLAbstraction/GLRender.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ So rewriting this function could get us a lot of performance for scenes with
a lot of objects.
"""
function render(renderobject::RenderObject, vertexarray=renderobject.vertexarray)
renderobject.requires_update = false

if renderobject.visible
renderobject.prerenderfunction()
program = vertexarray.program
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/GLAbstraction/GLShader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function gl_convert(cache::ShaderCache, lazyshader::AbstractLazyShader, data)
template_keys[i] = template
replacements[i] = String[mustache2replacement(t, v, data) for t in template]
end
program = get!(cache.program_cache, (paths, replacements)) do
return get!(cache.program_cache, (paths, replacements)) do
# when we're here, this means there were uncached shaders, meaning we definitely have
# to compile a new program
shaders = Vector{Shader}(undef, length(paths))
Expand Down
11 changes: 2 additions & 9 deletions GLMakie/src/GLAbstraction/GLTexture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mutable struct Texture{T <: GLArrayEltypes, NDIM} <: OpenglTexture{T, NDIM}
parameters ::TextureParameters{NDIM}
size ::NTuple{NDIM, Int}
context ::GLContext
requires_update ::Observable{Bool}
observers ::Vector{Observables.ObserverFunction}
function Texture{T, NDIM}(
id ::GLuint,
Expand All @@ -37,7 +36,6 @@ mutable struct Texture{T <: GLArrayEltypes, NDIM} <: OpenglTexture{T, NDIM}
parameters,
size,
current_context(),
Observable(true),
Observables.ObserverFunction[]
)
finalizer(free, tex)
Expand All @@ -49,11 +47,8 @@ end
mutable struct TextureBuffer{T <: GLArrayEltypes} <: OpenglTexture{T, 1}
texture::Texture{T, 1}
buffer::GLBuffer{T}
requires_update::Observable{Bool}

function TextureBuffer(texture::Texture{T, 1}, buffer::GLBuffer{T}) where T
x = map((_, _) -> true, buffer.requires_update, texture.requires_update)
new{T}(texture, buffer, x)
new{T}(texture, buffer)
end
end
Base.size(t::TextureBuffer) = size(t.buffer)
Expand All @@ -72,7 +67,6 @@ ShaderAbstractions.switch_context!(t::TextureBuffer) = switch_context!(t.texture
function unsafe_free(tb::TextureBuffer)
unsafe_free(tb.texture)
unsafe_free(tb.buffer)
Observables.clear(tb.requires_update)
end

is_texturearray(t::Texture) = t.texturetype == GL_TEXTURE_2D_ARRAY
Expand Down Expand Up @@ -148,8 +142,7 @@ function Texture(s::ShaderAbstractions.Sampler{T, N}; kwargs...) where {T, N}
anisotropic = s.anisotropic; kwargs...
)
obsfunc = ShaderAbstractions.connect!(s, tex)
obsfunc2 = on(x -> tex.requires_update[] = true, s.updates.update)
push!(tex.observers, obsfunc, obsfunc2)
push!(tex.observers, obsfunc)
return tex
end

Expand Down
76 changes: 8 additions & 68 deletions GLMakie/src/GLAbstraction/GLTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,8 @@ mutable struct GLVertexArray{T}
buffers::Dict{String,GLBuffer}
indices::T
context::GLContext
requires_update::Observable{Bool}

function GLVertexArray{T}(program, id, bufferlength, buffers, indices) where T
va = new(program, id, bufferlength, buffers, indices, current_context(), true)
if indices isa GLBuffer
on(indices.requires_update) do _ # only triggers true anyway
va.requires_update[] = true
end
end
for (name, buffer) in buffers
on(buffer.requires_update) do _ # only triggers true anyway
va.requires_update[] = true
end
end

va = new(program, id, bufferlength, buffers, indices, current_context())
return va
end
end
Expand Down Expand Up @@ -318,15 +305,14 @@ mutable struct RenderObject{Pre}
prerenderfunction::Pre
postrenderfunction
id::UInt32
requires_update::Bool
visible::Bool

function RenderObject{Pre}(
context,
uniforms::Dict{Symbol,Any}, observables::Vector{Observable},
vertexarray::GLVertexArray,
prerenderfunctions, postrenderfunctions,
visible, track_updates = true
visible
) where Pre
fxaa = Bool(to_value(get!(uniforms, :fxaa, true)))
RENDER_OBJECT_ID_COUNTER[] += one(UInt32)
Expand All @@ -340,57 +326,13 @@ mutable struct RenderObject{Pre}
context,
uniforms, observables, vertexarray,
prerenderfunctions, postrenderfunctions,
id, true, visible[]
id, visible[]
)

if track_updates
# visible changes should always trigger updates so that plots
# actually become invisible when visible is changed.
# Other uniforms and buffers don't need to trigger updates when
# visible = false
on(visible) do visible
robj.visible = visible
robj.requires_update = true
end

function request_update(_::Any)
if robj.visible
robj.requires_update = true
end
return
end

# gather update requests for polling in renderloop
for uniform in values(uniforms)
if uniform isa Observable
on(request_update, uniform)
elseif uniform isa GPUArray
on(request_update, uniform.requires_update)
end
end
on(request_update, vertexarray.requires_update)
else
on(visible) do visible
robj.visible = visible
end

# remove tracking from GPUArrays
for uniform in values(uniforms)
if uniform isa GPUArray
foreach(off, uniform.requires_update.inputs)
empty!(uniform.requires_update.inputs)
end
end
for buffer in vertexarray.buffers
if buffer isa GPUArray
foreach(off, buffer.requires_update.inputs)
empty!(buffer.requires_update.inputs)
end
end
foreach(off, vertexarray.requires_update.inputs)
empty!(vertexarray.requires_update.inputs)
push!(observables, visible)
on(visible) do visible
robj.visible = visible
return
end

return robj
end
end
Expand Down Expand Up @@ -474,8 +416,7 @@ function RenderObject(
vertexarray,
pre,
post,
visible,
track_updates
visible
)

# automatically integrate object ID, will be discarded if shader doesn't use it
Expand All @@ -502,7 +443,6 @@ function clean_up_observables(x::T) where T
foreach(off, x.observers)
empty!(x.observers)
end
Observables.clear(x.requires_update)
end

# OpenGL has the annoying habit of reusing id's when creating a new context
Expand Down
12 changes: 0 additions & 12 deletions GLMakie/src/GLAbstraction/GLUniforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,4 @@ function gl_convert(::Type{T}, a::Observable{<: AbstractArray{X, N}}; kw_args...
T(s; kw_args...)
end

lift_convert(a::AbstractArray, T, N) = lift(x -> convert(Array{T, N}, x), a)
function lift_convert(a::ShaderAbstractions.Sampler, T, N)
ShaderAbstractions.Sampler(
lift(x -> convert(Array{T, N}, x.data), a),
minfilter = a[].minfilter, magfilter = a[].magfilter,
x_repeat = a[].repeat[1],
y_repeat = a[].repeat[min(2, N)],
z_repeat = a[].repeat[min(3, N)],
anisotropic = a[].anisotropic, swizzle_mask = a[].swizzle_mask
)
end

gl_convert(f::Function, a) = f(a)
11 changes: 10 additions & 1 deletion GLMakie/src/GLMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ export Sampler, Buffer

const GL_ASSET_DIR = RelocatableFolders.@path joinpath(@__DIR__, "..", "assets")
const SHADER_DIR = RelocatableFolders.@path joinpath(GL_ASSET_DIR, "shader")
loadshader(name) = joinpath(SHADER_DIR, name)
const LOADED_SHADERS = Dict{String, String}()

function loadshader(name)
# Turns out, joinpath is so slow, that it actually makes sense
# To memoize it :-O
# when creating 1000 plots with the PlotSpec API, timing drop from 1.5s to 1s just from this change:
return get!(LOADED_SHADERS, name) do
return joinpath(SHADER_DIR, name)
end
end

gl_texture_atlas() = Makie.get_texture_atlas(2048, 64)

Expand Down
Loading
Loading