anv: add a memcpy compute internal kernel
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Wed, 16 Aug 2023 12:14:08 +0000 (15:14 +0300)
committerMarge Bot <emma+marge@anholt.net>
Mon, 25 Sep 2023 13:05:45 +0000 (13:05 +0000)
We'll use this memcpy utrace timestamp data.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24744>

src/intel/vulkan/anv_internal_kernels.c
src/intel/vulkan/anv_internal_kernels.h
src/intel/vulkan/anv_private.h
src/intel/vulkan/shaders/memcpy_compute.glsl [new file with mode: 0644]
src/intel/vulkan/shaders/meson.build

index 343f6bc..51b02ae 100644 (file)
@@ -37,6 +37,7 @@
 #include "shaders/gfx11_generated_draws_spv.h"
 #include "shaders/query_copy_compute_spv.h"
 #include "shaders/query_copy_fragment_spv.h"
+#include "shaders/memcpy_compute_spv.h"
 
 static bool
 lower_vulkan_descriptors_instr(nir_builder *b, nir_intrinsic_instr *intrin,
@@ -326,7 +327,7 @@ anv_device_init_internal_kernels(struct anv_device *device)
                                    false /* needs_slm */);
    device->internal_kernels_l3_config = intel_get_l3_config(device->info, w);
 
-   struct {
+   const struct {
       struct {
          char name[40];
       } key;
@@ -430,6 +431,34 @@ anv_device_init_internal_kernels(struct anv_device *device)
             .push_data_size = sizeof(struct anv_query_copy_params),
          },
       },
+      [ANV_INTERNAL_KERNEL_MEMCPY_COMPUTE] = {
+         .key        = {
+            .name    = "anv-memcpy-compute",
+         },
+         .stage      = MESA_SHADER_COMPUTE,
+         .spirv_data = memcpy_compute_spv_source,
+         .spirv_size = ARRAY_SIZE(memcpy_compute_spv_source),
+         .send_count = device->info->verx10 >= 125 ?
+                       10 /* 5 loads (1 pull constants) + 4 stores + 1 EOT */ :
+                       9 /* 4 loads + 4 stores + 1 EOT */,
+         .bind_map   = {
+            .num_bindings = 3,
+            .bindings     = {
+               {
+                  .address_offset = offsetof(struct anv_memcpy_params,
+                                             src_addr),
+               },
+               {
+                  .address_offset = offsetof(struct anv_memcpy_params,
+                                             dst_addr),
+               },
+               {
+                  .push_constant = true,
+               },
+            },
+            .push_data_size = sizeof(struct anv_memcpy_params),
+         },
+      },
    };
 
    for (uint32_t i = 0; i < ARRAY_SIZE(internal_kernels); i++) {
index de951d2..87445b8 100644 (file)
@@ -129,4 +129,20 @@ struct anv_query_copy_params {
    uint64_t destination_addr;
 };
 
+/* This needs to match memcpy_compute.glsl :
+ *
+ *    layout(set = 0, binding = 2) uniform block
+ */
+struct anv_memcpy_shader_params {
+   uint32_t num_dwords;
+};
+
+struct anv_memcpy_params {
+   struct anv_memcpy_shader_params copy;
+
+   uint64_t src_addr;
+
+   uint64_t dst_addr;
+};
+
 #endif /* ANV_GENERATED_INDIRECT_DRAWS_H */
index 32b0a33..5cd18fc 100644 (file)
@@ -1456,6 +1456,7 @@ enum anv_internal_kernel_name {
    ANV_INTERNAL_KERNEL_GENERATED_DRAWS,
    ANV_INTERNAL_KERNEL_COPY_QUERY_RESULTS_COMPUTE,
    ANV_INTERNAL_KERNEL_COPY_QUERY_RESULTS_FRAGMENT,
+   ANV_INTERNAL_KERNEL_MEMCPY_COMPUTE,
 
    ANV_INTERNAL_KERNEL_COUNT,
 };
diff --git a/src/intel/vulkan/shaders/memcpy_compute.glsl b/src/intel/vulkan/shaders/memcpy_compute.glsl
new file mode 100644 (file)
index 0000000..30b5e64
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2023 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#version 450
+#extension GL_ARB_gpu_shader_int64 : enable
+#extension GL_GOOGLE_include_directive : enable
+
+layout(local_size_x = 16, local_size_y = 1, local_size_z = 1) in;
+
+/* These 2 bindings will be accessed through A64 messages */
+layout(set = 0, binding = 0, std430) buffer Storage0 {
+   uint src[];
+};
+
+layout(set = 0, binding = 1, std430) buffer Storage1 {
+   uint dst[];
+};
+
+/* This data will be provided through push constants. */
+layout(set = 0, binding = 2) uniform block {
+   uint num_dwords;
+};
+
+void main()
+{
+   uint idx = gl_GlobalInvocationID.x * 4;
+   /* Try to do copies in single message as much as possible. */
+   if (idx + 4 <= num_dwords) {
+      dst[idx + 0] = src[idx + 0];
+      dst[idx + 1] = src[idx + 1];
+      dst[idx + 2] = src[idx + 2];
+      dst[idx + 3] = src[idx + 3];
+   } else if (idx + 3 <= num_dwords) {
+      dst[idx + 0] = src[idx + 0];
+      dst[idx + 1] = src[idx + 1];
+      dst[idx + 2] = src[idx + 2];
+   } else if (idx + 2 <= num_dwords) {
+      dst[idx + 0] = src[idx + 0];
+      dst[idx + 1] = src[idx + 1];
+   } else if (idx + 1 <= num_dwords) {
+      dst[idx + 0] = src[idx + 0];
+   }
+}
index f9653c1..d63c8af 100644 (file)
@@ -37,6 +37,7 @@ anv_internal_shaders = [
   [ 'gfx11_generated_draws.glsl', 'frag' ],
   [ 'query_copy_compute.glsl',    'comp' ],
   [ 'query_copy_fragment.glsl',   'frag' ],
+  [ 'memcpy_compute.glsl',        'comp' ],
 ]
 
 anv_internal_spvs = []