Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Maíra Canal" <mcanal@igalia.com>
To: "Melissa Wen" <mwen@igalia.com>,
	"André Almeida" <andrealmeid@igalia.com>,
	"Petri Latvala" <adrinael@adrinael.net>,
	"Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
	"Iago Toral Quiroga" <itoral@igalia.com>
Cc: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v4 1/3] lib/v3d: Add a helper to create a empty shader
Date: Wed, 15 Feb 2023 11:27:36 -0300	[thread overview]
Message-ID: <20230215142738.1121229-2-mcanal@igalia.com> (raw)
In-Reply-To: <20230215142738.1121229-1-mcanal@igalia.com>

In order to submit a compute dispatch job, a BO must contain the
assembly shader that corresponds to the job. Therefore, create a helper
to encapsulate a simple compute dispatch job. This helper sets the
configurations (cfg) needed for the job and has the assembled instructions
necessary to process an empty shader, just like the following one:

    #version 310 es
    layout (local_size_x = 1) in;
    void main (void) {}

Reviewed-by: Melissa Wen <mwen@igalia.com>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 lib/igt_v3d.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_v3d.h | 20 ++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/lib/igt_v3d.c b/lib/igt_v3d.c
index 41ea32fc..90274829 100644
--- a/lib/igt_v3d.c
+++ b/lib/igt_v3d.c
@@ -355,3 +355,79 @@ void igt_v3d_free_cl_job(int fd, struct v3d_cl_job *job)
 	free(job->submit);
 	free(job);
 }
+
+/**
+ * igt_v3d_empty_shader:
+ * @fd: device file descriptor
+ *
+ * This helper returns a simple compute dispatch job. It sets the
+ * configurations (cfg) needed for the job and has the assembled instructions
+ * necessary to process an empty shader.
+ */
+struct v3d_csd_job *igt_v3d_empty_shader(int fd)
+{
+	struct v3d_csd_job *job;
+	uint32_t *bos;
+
+	/* Reproduce an empty shader */
+	const uint32_t assembly[] = { 0xbb800000, 0x3c203186,
+				      0xbb800000, 0x3c003186,
+				      0xbb800000, 0x3c003186 };
+	const uint32_t group_count_x = 1, group_count_y = 1, group_count_z = 1;
+	const uint32_t num_batches = 1, wgs_per_sg = 1, batches_per_sg = 1, wg_size = 1;
+
+	job = calloc(1, sizeof(*job));
+
+	job->shader_assembly = igt_v3d_create_bo(fd, PAGE_SIZE);
+	job->cl = igt_v3d_create_bo(fd, PAGE_SIZE);
+	job->submit = calloc(1, sizeof(*job->submit));
+
+	igt_v3d_bo_mmap(fd, job->shader_assembly);
+	igt_v3d_bo_mmap(fd, job->cl);
+
+	memset(job->shader_assembly->map, 0, sizeof(*job->shader_assembly->map));
+	memcpy(job->shader_assembly->map, assembly, sizeof(assembly));
+	memset(job->cl->map, 0, sizeof(*job->cl->map));
+
+	job->submit->bo_handle_count = 2;
+	bos = malloc(sizeof(*bos) * job->submit->bo_handle_count);
+	bos[0] = job->shader_assembly->handle;
+	bos[1] = job->cl->handle;
+
+	job->submit->bo_handles = to_user_pointer(bos);
+
+	job->submit->cfg[0] |= group_count_x << V3D_CSD_CFG012_WG_COUNT_SHIFT;
+	job->submit->cfg[1] |= group_count_y << V3D_CSD_CFG012_WG_COUNT_SHIFT;
+	job->submit->cfg[2] |= group_count_z << V3D_CSD_CFG012_WG_COUNT_SHIFT;
+
+	job->submit->cfg[3] |= (wgs_per_sg & 0xf) << V3D_CSD_CFG3_WGS_PER_SG_SHIFT;
+	job->submit->cfg[3] |= (batches_per_sg - 1) << V3D_CSD_CFG3_BATCHES_PER_SG_M1_SHIFT;
+	job->submit->cfg[3] |= (wg_size & 0xff) << V3D_CSD_CFG3_WG_SIZE_SHIFT;
+
+	job->submit->cfg[4] = num_batches - 1;
+
+	job->submit->cfg[5] = job->shader_assembly->offset | V3D_CSD_CFG5_PROPAGATE_NANS;
+	job->submit->cfg[5] |= V3D_CSD_CFG5_SINGLE_SEG;
+	job->submit->cfg[5] |= V3D_CSD_CFG5_THREADING;
+
+	job->submit->cfg[6] = job->cl->offset;
+
+	return job;
+}
+
+/**
+ * igt_v3d_free_csd_job:
+ * @fd: device file descriptor
+ * @job: a compute shader dispatch job
+ *
+ * This helper frees all the fields of the struct v3d_csd_job and the
+ * alocatted job itself.
+ */
+void igt_v3d_free_csd_job(int fd, struct v3d_csd_job *job)
+{
+	free(from_user_pointer(job->submit->bo_handles));
+	igt_v3d_free_bo(fd, job->shader_assembly);
+	igt_v3d_free_bo(fd, job->cl);
+	free(job->submit);
+	free(job);
+}
diff --git a/lib/igt_v3d.h b/lib/igt_v3d.h
index 2cf7fbd8..b96a3b43 100644
--- a/lib/igt_v3d.h
+++ b/lib/igt_v3d.h
@@ -28,6 +28,17 @@
 
 #define PAGE_SIZE 4096
 
+#define V3D_CSD_CFG012_WG_COUNT_SHIFT 16
+/* Batches per supergroup minus 1.  8 bits. */
+#define V3D_CSD_CFG3_BATCHES_PER_SG_M1_SHIFT 12
+/* Workgroups per supergroup, 0 means 16 */
+#define V3D_CSD_CFG3_WGS_PER_SG_SHIFT 8
+#define V3D_CSD_CFG3_WG_SIZE_SHIFT 0
+
+#define V3D_CSD_CFG5_PROPAGATE_NANS (1 << 2)
+#define V3D_CSD_CFG5_SINGLE_SEG (1 << 1)
+#define V3D_CSD_CFG5_THREADING (1 << 0)
+
 struct v3d_cl;
 
 struct v3d_bo {
@@ -46,6 +57,12 @@ struct v3d_cl_job {
 	struct v3d_bo *tile_state;
 };
 
+struct v3d_csd_job {
+	struct drm_v3d_submit_csd *submit;
+	struct v3d_bo *shader_assembly;
+	struct v3d_bo *cl;
+};
+
 struct v3d_bo *igt_v3d_create_bo(int fd, size_t size);
 void igt_v3d_free_bo(int fd, struct v3d_bo *bo);
 
@@ -67,4 +84,7 @@ void igt_v3d_set_multisync(struct drm_v3d_multi_sync *ms, enum v3d_queue wait_st
 struct v3d_cl_job *igt_v3d_noop_job(int fd);
 void igt_v3d_free_cl_job(int fd, struct v3d_cl_job *job);
 
+struct v3d_csd_job *igt_v3d_empty_shader(int fd);
+void igt_v3d_free_csd_job(int fd, struct v3d_csd_job *job);
+
 #endif /* IGT_V3D_H */
-- 
2.39.1

  reply	other threads:[~2023-02-15 14:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 14:27 [igt-dev] [PATCH i-g-t v4 0/3] V3D Mixed Job Submission Tests Maíra Canal
2023-02-15 14:27 ` Maíra Canal [this message]
2023-02-15 14:27 ` [igt-dev] [PATCH i-g-t v4 2/3] tests/v3d_submit_csd: Create test for V3D's Submit CSD IOCTL Maíra Canal
2023-02-15 14:27 ` [igt-dev] [PATCH i-g-t v4 3/3] tests/v3d_job_submission: Create tests to mix CL and CSD jobs Maíra Canal
2023-02-15 17:15 ` [igt-dev] ✓ Fi.CI.BAT: success for V3D Mixed Job Submission Tests (rev5) Patchwork
2023-02-16 11:34 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230215142738.1121229-2-mcanal@igalia.com \
    --to=mcanal@igalia.com \
    --cc=adrinael@adrinael.net \
    --cc=andrealmeid@igalia.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=itoral@igalia.com \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=mwen@igalia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox