I have one DirectCtx with multiple canvases. With this, we only have access to flush in one place, and thus all canvases are flushed at once if their image is not manually transitioned with your own API.
none sk_sync() {
// the issue is the need to transition ALL skia canvas before a sync.
// that means we must gather handles to canvases intern
each(canvases, sk, cv) {
cv->tx->vk_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
transition(cv->tx, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
}
direct_ctx->flush(); // <--- affects all canvases in ctx
direct_ctx->submit();
each(canvases, sk, cv) {
cv->tx->vk_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
transition(cv->tx, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
}
//
That is how I get around the issue, but I can't imagine its performant to flush and submit all canvases in the app
I also register them as such
static array canvases;
none sk_init(sk a) {
if (!canvases) canvases = hold(array(32));
push(canvases, a);
and dealloc
none sk_dealloc(sk a) {
num i = index_of(canvases, a);
remove(canvases, i);
if (len(canvases) == 0)
drop(canvases);
SkSafeUnref((SkSurface*)a->sk_surface);
}
Is it better to have 1 DirectCtx per skia canvas instance? I never went about it that way before. It would also be great if Skia could perform the Vk transitions for us -- we would need to tell it if it were used in a Shader as a bound uniform texture, in which case you want SHADER_READ_ONLY before the user makes use of it.
I searched around the code prior and did not find a singular flush for a specific skia instance.
Regards
Kalen Novis White