clover: use pipe_image_view for images instead of set_compute_resources
authorKarol Herbst <kherbst@redhat.com>
Wed, 7 Oct 2020 21:08:43 +0000 (23:08 +0200)
committerKarol Herbst <kherbst@redhat.com>
Tue, 20 Oct 2020 21:46:42 +0000 (23:46 +0200)
Long term we want to git rid of set_compute_resources, this is just one
piece. The other bit would be to use the proper const buffer interfaces,
but because that path is only hit with r600/radeonsi I won't touch it.

Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7069>

src/gallium/frontends/clover/core/kernel.cpp
src/gallium/frontends/clover/core/kernel.hpp
src/gallium/frontends/clover/core/resource.cpp
src/gallium/frontends/clover/core/resource.hpp

index 4cc1214..76a03b1 100644 (file)
@@ -83,6 +83,8 @@ kernel::launch(command_queue &q,
 
    q.pipe->set_sampler_views(q.pipe, PIPE_SHADER_COMPUTE, 0,
                              exec.sviews.size(), exec.sviews.data());
+   q.pipe->set_shader_images(q.pipe, PIPE_SHADER_COMPUTE, 0,
+                             exec.iviews.size(), exec.iviews.data());
    q.pipe->set_compute_resources(q.pipe, 0, exec.resources.size(),
                                  exec.resources.data());
    q.pipe->set_global_binding(q.pipe, 0, exec.g_buffers.size(),
@@ -99,6 +101,8 @@ kernel::launch(command_queue &q,
 
    q.pipe->set_global_binding(q.pipe, 0, exec.g_buffers.size(), NULL, NULL);
    q.pipe->set_compute_resources(q.pipe, 0, exec.resources.size(), NULL);
+   q.pipe->set_shader_images(q.pipe, PIPE_SHADER_COMPUTE, 0,
+                             exec.iviews.size(), NULL);
    q.pipe->set_sampler_views(q.pipe, PIPE_SHADER_COMPUTE, 0,
                              exec.sviews.size(), NULL);
    q.pipe->bind_sampler_states(q.pipe, PIPE_SHADER_COMPUTE, 0,
@@ -279,6 +283,7 @@ kernel::exec_context::unbind() {
    input.clear();
    samplers.clear();
    sviews.clear();
+   iviews.clear();
    resources.clear();
    g_buffers.clear();
    g_handles.clear();
@@ -599,20 +604,17 @@ kernel::image_wr_argument::set(size_t size, const void *value) {
 void
 kernel::image_wr_argument::bind(exec_context &ctx,
                                 const module::argument &marg) {
-   auto v = bytes(ctx.resources.size());
+   auto v = bytes(ctx.iviews.size());
 
    extend(v, module::argument::zero_ext, marg.target_size);
    byteswap(v, ctx.q->device().endianness());
    align(ctx.input, marg.target_align);
    insert(ctx.input, v);
-
-   st = img->resource_in(*ctx.q).bind_surface(*ctx.q, true);
-   ctx.resources.push_back(st);
+   ctx.iviews.push_back(img->resource_in(*ctx.q).create_image_view(*ctx.q));
 }
 
 void
 kernel::image_wr_argument::unbind(exec_context &ctx) {
-   img->resource_in(*ctx.q).unbind_surface(*ctx.q, st);
 }
 
 void
index d7185bc..31967b6 100644 (file)
@@ -57,6 +57,7 @@ namespace clover {
          std::vector<uint8_t> input;
          std::vector<void *> samplers;
          std::vector<pipe_sampler_view *> sviews;
+         std::vector<pipe_image_view> iviews;
          std::vector<pipe_surface *> resources;
          std::vector<pipe_resource *> g_buffers;
          std::vector<size_t> g_handles;
@@ -226,9 +227,6 @@ namespace clover {
          virtual void bind(exec_context &ctx,
                            const module::argument &marg);
          virtual void unbind(exec_context &ctx);
-
-      private:
-         pipe_surface *st;
       };
 
       class sampler_argument : public argument {
index c21073e..4315204 100644 (file)
@@ -112,6 +112,26 @@ resource::unbind_sampler_view(command_queue &q,
    q.pipe->sampler_view_destroy(q.pipe, st);
 }
 
+pipe_image_view
+resource::create_image_view(command_queue &q) {
+   pipe_image_view view;
+   view.resource = pipe;
+   view.format = pipe->format;
+   view.access = 0;
+   view.shader_access = PIPE_IMAGE_ACCESS_WRITE;
+
+   if (pipe->target == PIPE_BUFFER) {
+      view.u.buf.offset = 0;
+      view.u.buf.size = obj.size();
+   } else {
+      view.u.tex.first_layer = 0;
+      view.u.tex.last_layer = 0;
+      view.u.tex.level = 0;
+   }
+
+   return view;
+}
+
 pipe_surface *
 resource::bind_surface(command_queue &q, bool rw) {
    pipe_surface info {};
index d4d7615..562f410 100644 (file)
@@ -75,6 +75,8 @@ namespace clover {
       pipe_surface *bind_surface(command_queue &q, bool rw);
       void unbind_surface(command_queue &q, pipe_surface *st);
 
+      pipe_image_view create_image_view(command_queue &q);
+
       pipe_resource *pipe;
       vector offset;