[gtk/wip/matthiasc/gsk-hdr: 6/7] ngl: Determine intermediate formats
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/gsk-hdr: 6/7] ngl: Determine intermediate formats
- Date: Wed, 6 Oct 2021 04:01:40 +0000 (UTC)
commit ca5565edcb0308def6b8318d829a5337b1fd45dd
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Oct 1 08:48:43 2021 -0400
ngl: Determine intermediate formats
Look at the framebuffer and the rendernode to
determine what format to use for intermediate
textures.
Our preference here is to use fp16, if we have it
and it makes sense for the framebuffer we're given.
gsk/ngl/gsknglrenderjob.c | 45 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 6 deletions(-)
---
diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c
index d285eb24b0..09135bc519 100644
--- a/gsk/ngl/gsknglrenderjob.c
+++ b/gsk/ngl/gsknglrenderjob.c
@@ -162,6 +162,11 @@ struct _GskNglRenderJob
/* If we should be rendering red zones over fallback nodes */
guint debug_fallback : 1;
+
+ /* Format of the framebuffer we are rendering on, used in
+ * determining the format for intermediate textures
+ */
+ int framebuffer_format;
};
typedef struct _GskNglRenderOffscreen
@@ -198,6 +203,16 @@ static gboolean gsk_ngl_render_job_visit_node_with_offscreen (GskNglRenderJob
const GskRenderNode *node,
GskNglRenderOffscreen *offscreen);
+static inline int
+get_target_format (GskNglRenderJob *job,
+ const GskRenderNode *node)
+{
+ if (!gsk_render_node_is_hdr (node))
+ return GL_RGBA8;
+
+ return job->framebuffer_format;
+}
+
static inline void
init_full_texture_region (GskNglRenderOffscreen *offscreen)
{
@@ -1258,7 +1273,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->framebuffer_format,
GL_NEAREST, GL_NEAREST,
&pass1))
return 0;
@@ -1269,7 +1284,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->framebuffer_format,
GL_NEAREST, GL_NEAREST,
&pass2))
return gsk_ngl_driver_release_render_target (job->driver, pass1, FALSE);
@@ -2181,7 +2196,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,
+ get_target_format (job, node),
GL_NEAREST, GL_NEAREST,
&render_target))
g_assert_not_reached ();
@@ -2452,7 +2467,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,
+ get_target_format (job, node),
GL_NEAREST, GL_NEAREST,
&render_target);
@@ -3860,7 +3875,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,
+ get_target_format (job, node),
filter, filter,
&render_target))
g_assert_not_reached ();
@@ -3959,7 +3974,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->framebuffer_format,
GL_NEAREST, GL_NEAREST,
&framebuffer_id, &texture_id))
return;
@@ -4050,6 +4065,23 @@ gsk_ngl_render_job_set_debug_fallback (GskNglRenderJob *job,
job->debug_fallback = !!debug_fallback;
}
+static int
+get_framebuffer_format (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,
@@ -4076,6 +4108,7 @@ gsk_ngl_render_job_new (GskNglDriver *driver,
job->scale_x = scale_factor;
job->scale_y = scale_factor;
job->viewport = *viewport;
+ job->framebuffer_format = get_framebuffer_format (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]