[gtk/matthiasc/color-profiles: 5/9] ngl: Determine intermediate format
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profiles: 5/9] ngl: Determine intermediate format
- Date: Fri, 1 Oct 2021 18:24:22 +0000 (UTC)
commit 8c53871c548fc81fcf537b32c560b2ac05b52d73
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Oct 1 08:48:43 2021 -0400
ngl: Determine intermediate format
Look at the framebuffer we are given to determine
what format to use for intermediate textures.
Our preference here is to use fp16, if we can
and it makes sense for the framebuffer we're given.
gsk/ngl/gsknglrenderjob.c | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c
index ff13fce842..1e66ff5a1b 100644
--- a/gsk/ngl/gsknglrenderjob.c
+++ b/gsk/ngl/gsknglrenderjob.c
@@ -164,6 +164,9 @@ struct _GskNglRenderJob
/* If we should be rendering red zones over fallback nodes */
guint debug_fallback : 1;
+
+ /* Format to use for intermediate textures */
+ int format;
};
typedef struct _GskNglRenderOffscreen
@@ -1276,7 +1279,7 @@ blur_offscreen (GskNglRenderJob *job,
if (!gsk_ngl_driver_create_render_target (job->driver,
MAX (texture_to_blur_width, 1),
MAX (texture_to_blur_height, 1),
- GL_RGBA8,
+ job->format,
GL_NEAREST, GL_NEAREST,
&pass1))
return 0;
@@ -1287,7 +1290,7 @@ blur_offscreen (GskNglRenderJob *job,
if (!gsk_ngl_driver_create_render_target (job->driver,
texture_to_blur_width,
texture_to_blur_height,
- GL_RGBA8,
+ job->format,
GL_NEAREST, GL_NEAREST,
&pass2))
return gsk_ngl_driver_release_render_target (job->driver, pass1, FALSE);
@@ -2199,7 +2202,7 @@ gsk_ngl_render_job_visit_blurred_inset_shadow_node (GskNglRenderJob *job,
if (!gsk_ngl_driver_create_render_target (job->driver,
texture_width, texture_height,
- GL_RGBA8,
+ job->format,
GL_NEAREST, GL_NEAREST,
&render_target))
g_assert_not_reached ();
@@ -2470,7 +2473,7 @@ gsk_ngl_render_job_visit_blurred_outset_shadow_node (GskNglRenderJob *job,
gsk_ngl_driver_create_render_target (job->driver,
texture_width, texture_height,
- GL_RGBA8,
+ job->format,
GL_NEAREST, GL_NEAREST,
&render_target);
@@ -3879,7 +3882,7 @@ gsk_ngl_render_job_visit_node_with_offscreen (GskNglRenderJob *job,
if (!gsk_ngl_driver_create_render_target (job->driver,
scaled_width, scaled_height,
- GL_RGBA8,
+ job->format,
filter, filter,
&render_target))
g_assert_not_reached ();
@@ -3978,7 +3981,7 @@ gsk_ngl_render_job_render_flipped (GskNglRenderJob *job,
if (!gsk_ngl_command_queue_create_render_target (job->command_queue,
MAX (1, job->viewport.size.width),
MAX (1, job->viewport.size.height),
- GL_RGBA8,
+ job->format,
GL_NEAREST, GL_NEAREST,
&framebuffer_id, &texture_id))
return;
@@ -4050,7 +4053,7 @@ gsk_ngl_render_job_render (GskNglRenderJob *job,
gsk_ngl_driver_create_render_target (job->driver,
job->viewport.size.width,
job->viewport.size.height,
- GL_RGBA8,
+ job->format,
GL_NEAREST,
GL_NEAREST,
&render_target);
@@ -4098,6 +4101,24 @@ gsk_ngl_render_job_set_debug_fallback (GskNglRenderJob *job,
job->debug_fallback = !!debug_fallback;
}
+static int
+determine_format (GskNglDriver *driver,
+ guint framebuffer)
+{
+ int type, size;
+
+ glBindFramebuffer (GL_FRAMEBUFFER, framebuffer);
+ glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE, &type);
+ glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &size);
+
+ if (type == GL_FLOAT && size == 32)
+ return GL_RGBA32F;
+ else if (size > 8)
+ return GL_RGBA16F;
+ else
+ return GL_RGBA8;
+}
+
GskNglRenderJob *
gsk_ngl_render_job_new (GskNglDriver *driver,
const graphene_rect_t *viewport,
@@ -4124,6 +4145,7 @@ gsk_ngl_render_job_new (GskNglDriver *driver,
job->scale_x = scale_factor;
job->scale_y = scale_factor;
job->viewport = *viewport;
+ job->format = determine_format (driver, framebuffer);
gsk_ngl_render_job_set_alpha (job, 1.0f);
gsk_ngl_render_job_set_projection_from_rect (job, viewport, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]