r600/sfn: handle querying SSBO size
authorGert Wollny <gert.wollny@collabora.com>
Tue, 21 Jul 2020 09:57:52 +0000 (11:57 +0200)
committerGert Wollny <gw.fossdev@gmail.com>
Sun, 9 Aug 2020 13:45:35 +0000 (13:45 +0000)
Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6025>

src/gallium/drivers/r600/sfn/sfn_emitssboinstruction.cpp
src/gallium/drivers/r600/sfn/sfn_emitssboinstruction.h

index a65a187521a5bc35286164760fb02049e120387a..f5200405f7ad60ab71dafd35151615da0dd4cded 100644 (file)
@@ -98,6 +98,8 @@ bool EmitSSBOInstruction::do_emit(nir_instr* instr)
       return emit_image_load(intr);
    case nir_intrinsic_image_size:
       return emit_image_size(intr);
+   case nir_intrinsic_get_buffer_size:
+      return emit_buffer_size(intr);
    default:
       return false;
    }
@@ -586,6 +588,32 @@ bool EmitSSBOInstruction::emit_image_size(const nir_intrinsic_instr *intrin)
    return true;
 }
 
+bool EmitSSBOInstruction::emit_buffer_size(const nir_intrinsic_instr *intr)
+{
+   std::array<PValue,4> dst_elms;
+
+
+   for (uint16_t i = 0; i < 4; ++i) {
+      dst_elms[i] = from_nir(intr->dest, (i < intr->dest.ssa.num_components) ? i : 7);
+   }
+
+   GPRVector dst(dst_elms);
+   GPRVector src(0,{4,4,4,4});
+
+   auto const_offset = nir_src_as_const_value(intr->src[0]);
+   auto dyn_offset = PValue();
+   int res_id = R600_IMAGE_REAL_RESOURCE_OFFSET;
+   if (const_offset)
+      res_id += const_offset[0].u32;
+   else
+      assert(0 && "dynamic buffer offset not supported in buffer_size");
+
+   emit_instruction(new FetchInstruction(dst, PValue(new GPRValue(0, 7)),
+                    res_id, bim_none));
+
+   return true;
+}
+
 GPRVector EmitSSBOInstruction::make_dest(const nir_intrinsic_instr* ir)
 {
    GPRVector::Values v;
index 5064845d53040249f6d3a2ad58c5d92799242b81..4c742d0658da3c60dd38ae899af40fbae39bc7a4 100644 (file)
@@ -32,6 +32,7 @@ private:
    bool emit_image_load(const nir_intrinsic_instr *intrin);
    bool emit_image_store(const nir_intrinsic_instr *intrin);
    bool emit_ssbo_atomic_op(const nir_intrinsic_instr *intrin);
+   bool emit_buffer_size(const nir_intrinsic_instr *intrin);
 
    bool fetch_return_value(const nir_intrinsic_instr *intrin);