From e1ffb72a05f9b50ee47767aaadbab3e47896ee14 Mon Sep 17 00:00:00 2001
From: Karol Herbst <kherbst@redhat.com>
Date: Fri, 28 Feb 2020 15:54:08 +0100
Subject: gallium: make handles of set_global_binding 64 bit
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

needed by CL

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4072>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4072>
---
 src/gallium/auxiliary/driver_ddebug/dd_context.c  |  2 +-
 src/gallium/auxiliary/util/u_threaded_context.c   |  2 +-
 src/gallium/drivers/freedreno/freedreno_state.c   |  3 +--
 src/gallium/drivers/llvmpipe/lp_state_cs.c        |  4 ++--
 src/gallium/drivers/nouveau/nv50/nv50_state.c     | 13 +++----------
 src/gallium/drivers/nouveau/nvc0/nvc0_state.c     | 13 +++----------
 src/gallium/drivers/panfrost/pan_compute.c        |  2 +-
 src/gallium/drivers/r600/evergreen_compute.c      | 10 +++++-----
 src/gallium/drivers/radeonsi/si_compute.c         |  6 +++---
 src/gallium/drivers/tegra/tegra_context.c         |  2 +-
 src/gallium/include/pipe/p_context.h              |  2 +-
 src/gallium/state_trackers/clover/core/kernel.cpp |  4 ++--
 src/gallium/tests/trivial/compute.c               |  6 +++---
 13 files changed, 27 insertions(+), 42 deletions(-)

(limited to 'src')

diff --git a/src/gallium/auxiliary/driver_ddebug/dd_context.c b/src/gallium/auxiliary/driver_ddebug/dd_context.c
index 40da6cf41c7..fa70cb554b0 100644
--- a/src/gallium/auxiliary/driver_ddebug/dd_context.c
+++ b/src/gallium/auxiliary/driver_ddebug/dd_context.c
@@ -688,7 +688,7 @@ static void
 dd_context_set_global_binding(struct pipe_context *_pipe,
 			      unsigned first, unsigned count,
 			      struct pipe_resource **resources,
-			      uint32_t **handles)
+			      uint64_t **handles)
 {
    struct pipe_context *pipe = dd_context(_pipe)->pipe;
    pipe->set_global_binding(pipe, first, count, resources, handles);
diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c
index 30790949336..5002b762d3f 100644
--- a/src/gallium/auxiliary/util/u_threaded_context.c
+++ b/src/gallium/auxiliary/util/u_threaded_context.c
@@ -1066,7 +1066,7 @@ tc_set_compute_resources(struct pipe_context *_pipe, unsigned start,
 static void
 tc_set_global_binding(struct pipe_context *_pipe, unsigned first,
                       unsigned count, struct pipe_resource **resources,
-                      uint32_t **handles)
+                      uint64_t **handles)
 {
    struct threaded_context *tc = threaded_context(_pipe);
    struct pipe_context *pipe = tc->pipe;
diff --git a/src/gallium/drivers/freedreno/freedreno_state.c b/src/gallium/drivers/freedreno/freedreno_state.c
index d9c8f9f89a2..9fb1cb6e6b6 100644
--- a/src/gallium/drivers/freedreno/freedreno_state.c
+++ b/src/gallium/drivers/freedreno/freedreno_state.c
@@ -541,7 +541,7 @@ fd_set_compute_resources(struct pipe_context *pctx,
 static void
 fd_set_global_binding(struct pipe_context *pctx,
 		unsigned first, unsigned count, struct pipe_resource **prscs,
-		uint32_t **handles)
+		uint64_t **handles)
 {
 	struct fd_context *ctx = fd_context(pctx);
 	struct fd_global_bindings_stateobj *so = &ctx->global_bindings;
@@ -558,7 +558,6 @@ fd_set_global_binding(struct pipe_context *pctx,
 			if (so->buf[n]) {
 				struct fd_resource *rsc = fd_resource(so->buf[n]);
 				uint64_t iova = fd_bo_get_iova(rsc->bo);
-				// TODO need to scream if iova > 32b or fix gallium API..
 				*handles[i] += iova;
 			}
 
diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c
index 92e156b4111..81168be675f 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_cs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c
@@ -1279,7 +1279,7 @@ static void
 llvmpipe_set_global_binding(struct pipe_context *pipe,
                             unsigned first, unsigned count,
                             struct pipe_resource **resources,
-                            uint32_t **handles)
+                            uint64_t **handles)
 {
    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
    struct lp_compute_shader *cs = llvmpipe->cs;
@@ -1305,7 +1305,7 @@ llvmpipe_set_global_binding(struct pipe_context *pipe,
 
    for (i = 0; i < count; i++) {
       uint64_t va;
-      uint32_t offset;
+      uint64_t offset;
       pipe_resource_reference(&cs->global_buffers[first + i], resources[i]);
       struct llvmpipe_resource *lp_res = llvmpipe_resource(resources[i]);
       offset = *handles[i];
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_state.c b/src/gallium/drivers/nouveau/nv50/nv50_state.c
index 6488c71f4ad..f642b6bde90 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_state.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_state.c
@@ -1237,18 +1237,11 @@ nv50_set_compute_resources(struct pipe_context *pipe,
 }
 
 static inline void
-nv50_set_global_handle(uint32_t *phandle, struct pipe_resource *res)
+nv50_set_global_handle(uint64_t *phandle, struct pipe_resource *res)
 {
    struct nv04_resource *buf = nv04_resource(res);
    if (buf) {
-      uint64_t limit = (buf->address + buf->base.width0) - 1;
-      if (limit < (1ULL << 32)) {
-         *phandle = (uint32_t)buf->address;
-      } else {
-         NOUVEAU_ERR("Cannot map into TGSI_RESOURCE_GLOBAL: "
-                     "resource not contained within 32-bit address space !\n");
-         *phandle = 0;
-      }
+      *phandle = buf->address;
    } else {
       *phandle = 0;
    }
@@ -1258,7 +1251,7 @@ static void
 nv50_set_global_bindings(struct pipe_context *pipe,
                          unsigned start, unsigned nr,
                          struct pipe_resource **resources,
-                         uint32_t **handles)
+                         uint64_t **handles)
 {
    struct nv50_context *nv50 = nv50_context(pipe);
    struct pipe_resource **ptr;
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
index 49546e5de68..5a6af5df8c9 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
@@ -1354,18 +1354,11 @@ nvc0_set_shader_buffers(struct pipe_context *pipe,
 }
 
 static inline void
-nvc0_set_global_handle(uint32_t *phandle, struct pipe_resource *res)
+nvc0_set_global_handle(uint64_t *phandle, struct pipe_resource *res)
 {
    struct nv04_resource *buf = nv04_resource(res);
    if (buf) {
-      uint64_t limit = (buf->address + buf->base.width0) - 1;
-      if (limit < (1ULL << 32)) {
-         *phandle = (uint32_t)buf->address;
-      } else {
-         NOUVEAU_ERR("Cannot map into TGSI_RESOURCE_GLOBAL: "
-                     "resource not contained within 32-bit address space !\n");
-         *phandle = 0;
-      }
+      *phandle = buf->address;
    } else {
       *phandle = 0;
    }
@@ -1375,7 +1368,7 @@ static void
 nvc0_set_global_bindings(struct pipe_context *pipe,
                          unsigned start, unsigned nr,
                          struct pipe_resource **resources,
-                         uint32_t **handles)
+                         uint64_t **handles)
 {
    struct nvc0_context *nvc0 = nvc0_context(pipe);
    struct pipe_resource **ptr;
diff --git a/src/gallium/drivers/panfrost/pan_compute.c b/src/gallium/drivers/panfrost/pan_compute.c
index 2ebffdcfdc1..7bfabce7b96 100644
--- a/src/gallium/drivers/panfrost/pan_compute.c
+++ b/src/gallium/drivers/panfrost/pan_compute.c
@@ -149,7 +149,7 @@ static void
 panfrost_set_global_binding(struct pipe_context *pctx,
                       unsigned first, unsigned count,
                       struct pipe_resource **resources,
-                      uint32_t **handles)
+                      uint64_t **handles)
 {
         /* TODO */
 }
diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c
index 98d4b97d7fc..aa16596d126 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -986,7 +986,7 @@ static void evergreen_set_compute_resources(struct pipe_context *ctx,
 static void evergreen_set_global_binding(struct pipe_context *ctx,
 					 unsigned first, unsigned n,
 					 struct pipe_resource **resources,
-					 uint32_t **handles)
+					 uint64_t **handles)
 {
 	struct r600_context *rctx = (struct r600_context *)ctx;
 	struct compute_memory_pool *pool = rctx->screen->global_pool;
@@ -1018,15 +1018,15 @@ static void evergreen_set_global_binding(struct pipe_context *ctx,
 
 	for (i = first; i < first + n; i++)
 	{
-		uint32_t buffer_offset;
-		uint32_t handle;
+		uint64_t buffer_offset;
+		uint64_t handle;
 		assert(resources[i]->target == PIPE_BUFFER);
 		assert(resources[i]->bind & PIPE_BIND_GLOBAL);
 
-		buffer_offset = util_le32_to_cpu(*(handles[i]));
+		buffer_offset = util_le64_to_cpu(*(handles[i]));
 		handle = buffer_offset + buffers[i]->chunk->start_in_dw * 4;
 
-		*(handles[i]) = util_cpu_to_le32(handle);
+		*(handles[i]) = util_cpu_to_le64(handle);
 	}
 
 	/* globals for writing */
diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c
index 610c1333597..889f2f02cca 100644
--- a/src/gallium/drivers/radeonsi/si_compute.c
+++ b/src/gallium/drivers/radeonsi/si_compute.c
@@ -294,7 +294,7 @@ static void si_bind_compute_state(struct pipe_context *ctx, void *state)
 static void si_set_global_binding(
 	struct pipe_context *ctx, unsigned first, unsigned n,
 	struct pipe_resource **resources,
-	uint32_t **handles)
+	uint64_t **handles)
 {
 	unsigned i;
 	struct si_context *sctx = (struct si_context*)ctx;
@@ -326,10 +326,10 @@ static void si_set_global_binding(
 
 	for (i = 0; i < n; i++) {
 		uint64_t va;
-		uint32_t offset;
+		uint64_t offset;
 		pipe_resource_reference(&program->global_buffers[first + i], resources[i]);
 		va = si_resource(resources[i])->gpu_address;
-		offset = util_le32_to_cpu(*handles[i]);
+		offset = util_le64_to_cpu(*handles[i]);
 		va += offset;
 		va = util_cpu_to_le64(va);
 		memcpy(handles[i], &va, sizeof(va));
diff --git a/src/gallium/drivers/tegra/tegra_context.c b/src/gallium/drivers/tegra/tegra_context.c
index e91baf0be34..8c57a70b71d 100644
--- a/src/gallium/drivers/tegra/tegra_context.c
+++ b/src/gallium/drivers/tegra/tegra_context.c
@@ -1039,7 +1039,7 @@ tegra_set_compute_resources(struct pipe_context *pcontext,
 static void
 tegra_set_global_binding(struct pipe_context *pcontext, unsigned int first,
                          unsigned int count, struct pipe_resource **resources,
-                         uint32_t **handles)
+                         uint64_t **handles)
 {
    struct tegra_context *context = to_tegra_context(pcontext);
 
diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h
index 3a8b9eba462..3e3377a22e2 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -804,7 +804,7 @@ struct pipe_context {
    void (*set_global_binding)(struct pipe_context *context,
                               unsigned first, unsigned count,
                               struct pipe_resource **resources,
-                              uint32_t **handles);
+                              uint64_t **handles);
 
    /**
     * Launch the compute kernel starting from instruction \a pc of the
diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp
index 3cffec320e1..428229c0503 100644
--- a/src/gallium/state_trackers/clover/core/kernel.cpp
+++ b/src/gallium/state_trackers/clover/core/kernel.cpp
@@ -59,8 +59,8 @@ kernel::launch(command_queue &q,
 
    // The handles are created during exec_context::bind(), so we need make
    // sure to call exec_context::bind() before retrieving them.
-   std::vector<uint32_t *> g_handles = map([&](size_t h) {
-         return (uint32_t *)&exec.input[h];
+   std::vector<uint64_t *> g_handles = map([&](size_t h) {
+         return (uint64_t *)&exec.input[h];
       }, exec.g_handles);
 
    q.pipe->bind_compute_state(q.pipe, st);
diff --git a/src/gallium/tests/trivial/compute.c b/src/gallium/tests/trivial/compute.c
index cfdbdf1cc8d..2eaf6263392 100644
--- a/src/gallium/tests/trivial/compute.c
+++ b/src/gallium/tests/trivial/compute.c
@@ -403,7 +403,7 @@ static void destroy_sampler_states(struct context *ctx)
 }
 
 static void init_globals(struct context *ctx, const int *slots,
-                         uint32_t **handles)
+                         uint64_t **handles)
 {
         struct pipe_context *pipe = ctx->pipe;
         struct pipe_resource *res[MAX_RESOURCES];
@@ -651,7 +651,7 @@ static void test_input_global(struct context *ctx)
                 "       STORE RGLOBAL.x, TEMP[1].yyyy, TEMP[1]\n"
                 "       RET\n"
                 "    ENDSUB\n";
-        uint32_t input[8] = { 0x10001, 0x10002, 0x10003, 0x10004,
+        uint64_t input[8] = { 0x10001, 0x10002, 0x10003, 0x10004,
                               0x10005, 0x10006, 0x10007, 0x10008 };
 
         printf("- %s\n", __func__);
@@ -666,7 +666,7 @@ static void test_input_global(struct context *ctx)
         init_tex(ctx, 3, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
                  test_default_init);
         init_globals(ctx, (int []){ 0, 1, 2, 3, -1 },
-                     (uint32_t *[]){ &input[1], &input[3],
+                     (uint64_t *[]){ &input[1], &input[3],
                                      &input[5], &input[7] });
         launch_grid(ctx, (uint []){4, 1, 1}, (uint []){1, 1, 1}, 0, input);
         check_tex(ctx, 0, test_input_global_expect, NULL);
-- 
cgit v1.2.3