i965/fs: Disable CSE optimization for untyped & typed surface reads
authorJordan Justen <jordan.l.justen@intel.com>
Tue, 20 Oct 2015 06:13:09 +0000 (23:13 -0700)
committerJordan Justen <jordan.l.justen@intel.com>
Thu, 22 Oct 2015 07:36:37 +0000 (00:36 -0700)
An untyped surface read is volatile because it might be affected by a
write.

In the ES31-CTS.compute_shader.resources-max test, two back to back
read/modify/writes of an SSBO variable looked something like this:

  r1 = untyped_surface_read(ssbo_float)
  r2 = r1 + 1
  untyped_surface_write(ssbo_float, r2)
  r3 = untyped_surface_read(ssbo_float)
  r4 = r3 + 1
  untyped_surface_write(ssbo_float, r4)

And after CSE, we had:

  r1 = untyped_surface_read(ssbo_float)
  r2 = r1 + 1
  untyped_surface_write(ssbo_float, r2)
  r4 = r1 + 1
  untyped_surface_write(ssbo_float, r4)

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
src/mesa/drivers/dri/i965/brw_fs_cse.cpp
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/drivers/dri/i965/brw_shader.h

index c7628dcc2f456628d3b941996d1f04f06979b403..3a28c8d591d09e552e261d66aa694a4784437cc7 100644 (file)
@@ -93,7 +93,8 @@ is_expression(const fs_visitor *v, const fs_inst *const inst)
    case SHADER_OPCODE_LOAD_PAYLOAD:
       return !inst->is_copy_payload(v->alloc);
    default:
-      return inst->is_send_from_grf() && !inst->has_side_effects();
+      return inst->is_send_from_grf() && !inst->has_side_effects() &&
+         !inst->is_volatile();
    }
 }
 
index 6f6f77ab58396dad5bdfd37342a126744f35e7df..204935641f33a90850455487c4973f39b67756ee 100644 (file)
@@ -987,6 +987,20 @@ backend_instruction::has_side_effects() const
    }
 }
 
+bool
+backend_instruction::is_volatile() const
+{
+   switch (opcode) {
+   case SHADER_OPCODE_UNTYPED_SURFACE_READ:
+   case SHADER_OPCODE_UNTYPED_SURFACE_READ_LOGICAL:
+   case SHADER_OPCODE_TYPED_SURFACE_READ:
+   case SHADER_OPCODE_TYPED_SURFACE_READ_LOGICAL:
+      return true;
+   default:
+      return false;
+   }
+}
+
 #ifndef NDEBUG
 static bool
 inst_is_in_block(const bblock_t *block, const backend_instruction *inst)
index 51b059fcaa1af92ec1f711fb5a3818e8ae58ef32..6a2dfc9bbb63a3c7810c5d7e4485b0e9742de788 100644 (file)
@@ -115,6 +115,12 @@ struct backend_instruction : public exec_node {
     * optimize these out unless you know what you are doing.
     */
    bool has_side_effects() const;
+
+   /**
+    * True if the instruction might be affected by side effects of other
+    * instructions.
+    */
+   bool is_volatile() const;
 #else
 struct backend_instruction {
    struct exec_node link;