diff --git a/src/shaders.c b/src/shaders.c
index 58c2ab3412ca3ea509f10c1a03062c520171cd87..2584c49f42652cabfc6926dca7ee15e396c63cb7 100644
--- a/src/shaders.c
+++ b/src/shaders.c
@@ -369,13 +369,11 @@ ident_t sh_subpass(struct pl_shader *sh, const struct pl_shader *sub)
         return NULL;
     }
 
-    // Check for shader compatibility
-    int res_w = PL_DEF(sh->output_w, sub->output_w),
-        res_h = PL_DEF(sh->output_h, sub->output_h);
+    int sub_w = PL_DEF(sub->output_w, sh->output_w),
+        sub_h = PL_DEF(sub->output_h, sh->output_h);
 
-    if ((sub->output_w && res_w != sub->output_w) ||
-        (sub->output_h && res_h != sub->output_h))
-    {
+    // Check for shader compatibility
+    if (sh->output_w != sub_w || sh->output_h != sub_h) {
         PL_TRACE(sh, "Can't merge shaders: incompatible sizes: %dx%d and %dx%d",
                  sh->output_w, sh->output_h, sub->output_w, sub->output_h);
         return NULL;
@@ -393,9 +391,6 @@ ident_t sh_subpass(struct pl_shader *sh, const struct pl_shader *sub)
         }
     }
 
-    sh->output_w = res_w;
-    sh->output_h = res_h;
-
     // Append the prelude and header
     bstr_xappend(sh, &sh->buffers[SH_BUF_PRELUDE], sub->buffers[SH_BUF_PRELUDE]);
     bstr_xappend(sh, &sh->buffers[SH_BUF_HEADER],  sub->buffers[SH_BUF_HEADER]);