meson: drop duplicate inc_nir from libglsl
[mesa.git] / src / compiler / glsl / lower_blend_equation_advanced.cpp
index 1d033924159f3a46db4891c5e15bb9d4a6bf18c3..c85b39bcaa343691b4c83737a77f9fb562988e02 100644 (file)
@@ -28,6 +28,8 @@
 #include "program/prog_instruction.h"
 #include "program/prog_statevars.h"
 #include "util/bitscan.h"
+#include "builtin_functions.h"
+#include "main/mtypes.h"
 
 using namespace ir_builder;
 
@@ -308,12 +310,18 @@ calc_blend_result(ir_factory f,
    f.emit(assign(dst_alpha, swizzle_w(fb)));
    f.emit(if_tree(equal(dst_alpha, imm1(0)),
                      assign(dst_rgb, imm3(0)),
-                     assign(dst_rgb, div(swizzle_xyz(fb), dst_alpha))));
+                     assign(dst_rgb, csel(equal(swizzle_xyz(fb),
+                                                swizzle(fb, SWIZZLE_WWWW, 3)),
+                                          imm3(1),
+                                          div(swizzle_xyz(fb), dst_alpha)))));
 
    f.emit(assign(src_alpha, swizzle_w(src)));
    f.emit(if_tree(equal(src_alpha, imm1(0)),
                      assign(src_rgb, imm3(0)),
-                     assign(src_rgb, div(swizzle_xyz(src), src_alpha))));
+                     assign(src_rgb, csel(equal(swizzle_xyz(src),
+                                                swizzle(src, SWIZZLE_WWWW, 3)),
+                                          imm3(1),
+                                          div(swizzle_xyz(src), src_alpha)))));
 
    ir_variable *factor = f.make_temp(glsl_type::vec3_type, "__blend_factor");
 
@@ -455,9 +463,9 @@ get_main(gl_linked_shader *sh)
 }
 
 bool
-lower_blend_equation_advanced(struct gl_linked_shader *sh)
+lower_blend_equation_advanced(struct gl_linked_shader *sh, bool coherent)
 {
-   if (sh->info.BlendSupport == 0)
+   if (sh->Program->sh.fs.BlendSupport == 0)
       return false;
 
    /* Lower early returns in main() so there's a single exit point
@@ -473,6 +481,7 @@ lower_blend_equation_advanced(struct gl_linked_shader *sh)
    fb->data.location = FRAG_RESULT_DATA0;
    fb->data.read_only = 1;
    fb->data.fb_fetch_output = 1;
+   fb->data.memory_coherent = coherent;
    fb->data.how_declared = ir_var_hidden;
 
    ir_variable *mode = new(mem_ctx) ir_variable(glsl_type::uint_type,
@@ -541,7 +550,8 @@ lower_blend_equation_advanced(struct gl_linked_shader *sh)
    ir_factory f(&main->body, mem_ctx);
 
    ir_variable *result_dest =
-      calc_blend_result(f, mode, fb, blend_source, sh->info.BlendSupport);
+      calc_blend_result(f, mode, fb, blend_source,
+                        sh->Program->sh.fs.BlendSupport);
 
    /* Copy the result back to the original values.  It would be simpler
     * to demote the program's output variables, and create a new vec4