From dc9f0869b14067e27591dfcf043f37ff6b1ad911 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 19 Jul 2024 18:02:06 +0200 Subject: [PATCH] gpu: Pass used images to shader ops This by itself is just more work refcounting all those images, but there's actually a goal here, that will become visible in future commits. But this is split out for correctness and benchmarking purposes (the overhead from refcounting seems to be negligible on my computer). --- gsk/gpu/gskgpublendmodeop.c | 2 ++ gsk/gpu/gskgpublurop.c | 2 ++ gsk/gpu/gskgpuborderop.c | 2 ++ gsk/gpu/gskgpuboxshadowop.c | 2 ++ gsk/gpu/gskgpucolorizeop.c | 2 ++ gsk/gpu/gskgpucolormatrixop.c | 2 ++ gsk/gpu/gskgpucolorop.c | 2 ++ gsk/gpu/gskgpuconicgradientop.c | 2 ++ gsk/gpu/gskgpuconvertop.c | 2 ++ gsk/gpu/gskgpucrossfadeop.c | 2 ++ gsk/gpu/gskgpulineargradientop.c | 2 ++ gsk/gpu/gskgpumaskop.c | 2 ++ gsk/gpu/gskgpuradialgradientop.c | 2 ++ gsk/gpu/gskgpuroundedcolorop.c | 2 ++ gsk/gpu/gskgpushaderop.c | 20 ++++++++++++++++---- gsk/gpu/gskgpushaderopprivate.h | 4 ++++ gsk/gpu/gskgputextureop.c | 2 ++ 17 files changed, 50 insertions(+), 4 deletions(-) diff --git a/gsk/gpu/gskgpublendmodeop.c b/gsk/gpu/gskgpublendmodeop.c index e766e18f54..5fa68b5ec7 100644 --- a/gsk/gpu/gskgpublendmodeop.c +++ b/gsk/gpu/gskgpublendmodeop.c @@ -71,6 +71,8 @@ gsk_gpu_blend_mode_op (GskGpuFrame *frame, blend_mode, clip, desc, + (GskGpuImage *[2]) { bottom->image, top->image }, + (GskGpuSampler[2]) { bottom->sampler, top->sampler }, &instance); gsk_gpu_rect_to_float (rect, offset, instance->rect); diff --git a/gsk/gpu/gskgpublurop.c b/gsk/gpu/gskgpublurop.c index 425bebb631..390884fa17 100644 --- a/gsk/gpu/gskgpublurop.c +++ b/gsk/gpu/gskgpublurop.c @@ -72,6 +72,8 @@ gsk_gpu_blur_op_full (GskGpuFrame *frame, variation, clip, desc, + (GskGpuImage *[1]) { image->image }, + (GskGpuSampler[1]) { image->sampler }, &instance); gsk_gpu_rect_to_float (image->coverage, offset, instance->rect); diff --git a/gsk/gpu/gskgpuborderop.c b/gsk/gpu/gskgpuborderop.c index d1f80fe778..c8313724ec 100644 --- a/gsk/gpu/gskgpuborderop.c +++ b/gsk/gpu/gskgpuborderop.c @@ -113,6 +113,8 @@ gsk_gpu_border_op (GskGpuFrame *frame, 0, clip, NULL, + NULL, + NULL, &instance); gsk_rounded_rect_to_float (outline, offset, instance->outline); diff --git a/gsk/gpu/gskgpuboxshadowop.c b/gsk/gpu/gskgpuboxshadowop.c index 45933e92ba..92c8aa8a56 100644 --- a/gsk/gpu/gskgpuboxshadowop.c +++ b/gsk/gpu/gskgpuboxshadowop.c @@ -97,6 +97,8 @@ gsk_gpu_box_shadow_op (GskGpuFrame *frame, inset ? VARIATION_INSET : 0, clip, NULL, + NULL, + NULL, &instance); gsk_gpu_rect_to_float (bounds, offset, instance->bounds); diff --git a/gsk/gpu/gskgpucolorizeop.c b/gsk/gpu/gskgpucolorizeop.c index 0bf1d8c6a7..8e62bcc05b 100644 --- a/gsk/gpu/gskgpucolorizeop.c +++ b/gsk/gpu/gskgpucolorizeop.c @@ -66,6 +66,8 @@ gsk_gpu_colorize_op (GskGpuFrame *frame, 0, clip, descriptors, + (GskGpuImage *[1]) { image->image }, + (GskGpuSampler[1]) { image->sampler }, &instance); gsk_gpu_rect_to_float (image->coverage ? image->coverage : image->bounds, offset, instance->rect); diff --git a/gsk/gpu/gskgpucolormatrixop.c b/gsk/gpu/gskgpucolormatrixop.c index 354e48bc35..26a0fa553f 100644 --- a/gsk/gpu/gskgpucolormatrixop.c +++ b/gsk/gpu/gskgpucolormatrixop.c @@ -66,6 +66,8 @@ gsk_gpu_color_matrix_op (GskGpuFrame *frame, 0, clip, desc, + (GskGpuImage *[1]) { image->image }, + (GskGpuSampler[1]) { image->sampler }, &instance); gsk_gpu_rect_to_float (image->coverage, offset, instance->rect); diff --git a/gsk/gpu/gskgpucolorop.c b/gsk/gpu/gskgpucolorop.c index 78ab08bade..21930c76da 100644 --- a/gsk/gpu/gskgpucolorop.c +++ b/gsk/gpu/gskgpucolorop.c @@ -66,6 +66,8 @@ gsk_gpu_color_op (GskGpuFrame *frame, 0, clip, NULL, + NULL, + NULL, &instance); gsk_gpu_rect_to_float (rect, offset, instance->rect); diff --git a/gsk/gpu/gskgpuconicgradientop.c b/gsk/gpu/gskgpuconicgradientop.c index 372758780d..5c56cb49a5 100644 --- a/gsk/gpu/gskgpuconicgradientop.c +++ b/gsk/gpu/gskgpuconicgradientop.c @@ -73,6 +73,8 @@ gsk_gpu_conic_gradient_op (GskGpuFrame *frame, (gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_GRADIENTS) ? VARIATION_SUPERSAMPLING : 0), clip, NULL, + NULL, + NULL, &instance); gsk_gpu_rect_to_float (rect, offset, instance->rect); diff --git a/gsk/gpu/gskgpuconvertop.c b/gsk/gpu/gskgpuconvertop.c index a420d03a14..77aa1235ea 100644 --- a/gsk/gpu/gskgpuconvertop.c +++ b/gsk/gpu/gskgpuconvertop.c @@ -73,6 +73,8 @@ gsk_gpu_convert_op (GskGpuFrame *frame, (straight_alpha ? VARIATION_STRAIGHT_ALPHA : 0), clip, desc, + (GskGpuImage *[1]) { image->image }, + (GskGpuSampler[1]) { image->sampler }, &instance); gsk_gpu_rect_to_float (image->coverage, offset, instance->rect); diff --git a/gsk/gpu/gskgpucrossfadeop.c b/gsk/gpu/gskgpucrossfadeop.c index 70ee9eb3f5..f86a0c20af 100644 --- a/gsk/gpu/gskgpucrossfadeop.c +++ b/gsk/gpu/gskgpucrossfadeop.c @@ -70,6 +70,8 @@ gsk_gpu_cross_fade_op (GskGpuFrame *frame, 0, clip, desc, + (GskGpuImage *[2]) { start->image, end->image }, + (GskGpuSampler[2]) { start->sampler, end->sampler }, &instance); gsk_gpu_rect_to_float (rect, offset, instance->rect); diff --git a/gsk/gpu/gskgpulineargradientop.c b/gsk/gpu/gskgpulineargradientop.c index 8e2d41c459..8f0c0f064e 100644 --- a/gsk/gpu/gskgpulineargradientop.c +++ b/gsk/gpu/gskgpulineargradientop.c @@ -78,6 +78,8 @@ gsk_gpu_linear_gradient_op (GskGpuFrame *frame, (gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_GRADIENTS) ? VARIATION_SUPERSAMPLING : 0), clip, NULL, + NULL, + NULL, &instance); gsk_gpu_rect_to_float (rect, offset, instance->rect); diff --git a/gsk/gpu/gskgpumaskop.c b/gsk/gpu/gskgpumaskop.c index a6db7dbd1d..b58efe0a12 100644 --- a/gsk/gpu/gskgpumaskop.c +++ b/gsk/gpu/gskgpumaskop.c @@ -70,6 +70,8 @@ gsk_gpu_mask_op (GskGpuFrame *frame, mask_mode, clip, desc, + (GskGpuImage *[2]) { source->image, mask->image }, + (GskGpuSampler[2]) { source->sampler, mask->sampler }, &instance); gsk_gpu_rect_to_float (rect, offset, instance->rect); diff --git a/gsk/gpu/gskgpuradialgradientop.c b/gsk/gpu/gskgpuradialgradientop.c index 621e06787d..c36892d4cc 100644 --- a/gsk/gpu/gskgpuradialgradientop.c +++ b/gsk/gpu/gskgpuradialgradientop.c @@ -80,6 +80,8 @@ gsk_gpu_radial_gradient_op (GskGpuFrame *frame, (gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_GRADIENTS) ? VARIATION_SUPERSAMPLING : 0), clip, NULL, + NULL, + NULL, &instance); gsk_gpu_rect_to_float (rect, offset, instance->rect); diff --git a/gsk/gpu/gskgpuroundedcolorop.c b/gsk/gpu/gskgpuroundedcolorop.c index 6b05ac5e75..d1b930b853 100644 --- a/gsk/gpu/gskgpuroundedcolorop.c +++ b/gsk/gpu/gskgpuroundedcolorop.c @@ -65,6 +65,8 @@ gsk_gpu_rounded_color_op (GskGpuFrame *frame, 0, clip, NULL, + NULL, + NULL, &instance); gsk_rounded_rect_to_float (outline, offset, instance->outline); diff --git a/gsk/gpu/gskgpushaderop.c b/gsk/gpu/gskgpushaderop.c index cf3694bf94..599f7a20da 100644 --- a/gsk/gpu/gskgpushaderop.c +++ b/gsk/gpu/gskgpushaderop.c @@ -27,6 +27,8 @@ gsk_gpu_shader_op_finish (GskGpuOp *op) GskGpuShaderOp *self = (GskGpuShaderOp *) op; g_clear_object (&self->desc); + g_clear_object (&self->images[0]); + g_clear_object (&self->images[1]); } void @@ -192,7 +194,9 @@ gsk_gpu_shader_op_gl_command_n (GskGpuOp *op, next_shader->color_states != self->color_states || next_shader->variation != self->variation || next_shader->clip != self->clip || - next_shader->vertex_offset != self->vertex_offset + n_ops * shader_op_class->vertex_size) + next_shader->vertex_offset != self->vertex_offset + n_ops * shader_op_class->vertex_size || + (shader_op_class->n_textures > 0 && (next_shader->images[0] != self->images[0] || next_shader->samplers[0] != self->samplers[0])) || + (shader_op_class->n_textures > 1 && (next_shader->images[1] != self->images[1] || next_shader->samplers[1] != self->samplers[1]))) break; n_ops += next_shader->n_ops; @@ -238,11 +242,13 @@ gsk_gpu_shader_op_alloc (GskGpuFrame *frame, guint32 variation, GskGpuShaderClip clip, GskGpuDescriptors *desc, + GskGpuImage **images, + GskGpuSampler *samplers, gpointer out_vertex_data) { GskGpuOp *last; GskGpuShaderOp *last_shader; - gsize vertex_offset; + gsize i, vertex_offset; vertex_offset = gsk_gpu_frame_reserve_vertex_data (frame, op_class->vertex_size); @@ -251,11 +257,12 @@ gsk_gpu_shader_op_alloc (GskGpuFrame *frame, last_shader = (GskGpuShaderOp *) last; if (last && last->op_class == (const GskGpuOpClass *) op_class && - last_shader->desc == desc && last_shader->color_states == color_states && last_shader->variation == variation && last_shader->clip == clip && - last_shader->vertex_offset + last_shader->n_ops * op_class->vertex_size == vertex_offset) + last_shader->vertex_offset + last_shader->n_ops * op_class->vertex_size == vertex_offset && + (op_class->n_textures < 1 || (last_shader->images[0] == images[0] && last_shader->samplers[0] == samplers[0])) && + (op_class->n_textures < 2 || (last_shader->images[1] == images[1] && last_shader->samplers[1] == samplers[1]))) { last_shader->n_ops++; } @@ -273,6 +280,11 @@ gsk_gpu_shader_op_alloc (GskGpuFrame *frame, else self->desc = NULL; self->n_ops = 1; + for (i = 0; i < op_class->n_textures; i++) + { + self->images[i] = g_object_ref (images[i]); + self->samplers[i] = samplers[i]; + } } *((gpointer *) out_vertex_data) = gsk_gpu_frame_get_vertex_data (frame, vertex_offset); diff --git a/gsk/gpu/gskgpushaderopprivate.h b/gsk/gpu/gskgpushaderopprivate.h index 1131c1eae8..4a88124062 100644 --- a/gsk/gpu/gskgpushaderopprivate.h +++ b/gsk/gpu/gskgpushaderopprivate.h @@ -23,6 +23,8 @@ struct _GskGpuShaderOp GskGpuOp parent_op; GskGpuDescriptors *desc; + GskGpuImage *images[2]; + GskGpuSampler samplers[2]; GskGpuColorStates color_states; guint32 variation; GskGpuShaderClip clip; @@ -53,6 +55,8 @@ void gsk_gpu_shader_op_alloc (GskGpuF guint32 variation, GskGpuShaderClip clip, GskGpuDescriptors *desc, + GskGpuImage **images, + GskGpuSampler *samplers, gpointer out_vertex_data); void gsk_gpu_shader_op_finish (GskGpuOp *op); diff --git a/gsk/gpu/gskgputextureop.c b/gsk/gpu/gskgputextureop.c index 828c75d013..5dd4e605c1 100644 --- a/gsk/gpu/gskgputextureop.c +++ b/gsk/gpu/gskgputextureop.c @@ -63,6 +63,8 @@ gsk_gpu_texture_op (GskGpuFrame *frame, 0, clip, desc, + (GskGpuImage *[1]) { image->image }, + (GskGpuSampler[1]) { image->sampler }, &instance); gsk_gpu_rect_to_float (image->coverage ? image->coverage : image->bounds, offset, instance->rect);