[Mesa-dev] [PATCH] clover: use pipe_resource references

Jan Vesely jan.vesely at rutgers.edu
Wed Mar 8 01:30:24 UTC 2017


Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
Does this patch work as well?

 src/gallium/state_trackers/clover/core/resource.cpp | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/gallium/state_trackers/clover/core/resource.cpp b/src/gallium/state_trackers/clover/core/resource.cpp
index 06fd3f6..16525fa 100644
--- a/src/gallium/state_trackers/clover/core/resource.cpp
+++ b/src/gallium/state_trackers/clover/core/resource.cpp
@@ -25,6 +25,7 @@
 #include "pipe/p_screen.h"
 #include "util/u_sampler.h"
 #include "util/u_format.h"
+#include "util/u_inlines.h"
 
 using namespace clover;
 
@@ -118,6 +119,7 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj,
                              command_queue &q, const std::string &data) :
    resource(dev, obj) {
    pipe_resource info {};
+   pipe_resource *lpipe = NULL;
    const bool user_ptr_support = dev.pipe->get_param(dev.pipe,
          PIPE_CAP_RESOURCE_FROM_USER_MEMORY);
 
@@ -141,17 +143,19 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj,
    if (obj.flags() & CL_MEM_USE_HOST_PTR && user_ptr_support) {
       // Page alignment is normally required for this, just try, hope for the
       // best and fall back if it fails.
-      pipe = dev.pipe->resource_from_user_memory(dev.pipe, &info, obj.host_ptr());
-      if (pipe)
+      lpipe = dev.pipe->resource_from_user_memory(dev.pipe, &info, obj.host_ptr());
+      if (lpipe) {
+         pipe_resource_reference(&this->pipe, lpipe);
          return;
+      }
    }
 
    if (obj.flags() & (CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR)) {
       info.usage = PIPE_USAGE_STAGING;
    }
 
-   pipe = dev.pipe->resource_create(dev.pipe, &info);
-   if (!pipe)
+   lpipe = dev.pipe->resource_create(dev.pipe, &info);
+   if (!lpipe)
       throw error(CL_OUT_OF_RESOURCES);
 
    if (obj.flags() & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) {
@@ -159,14 +163,15 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj,
       box rect { {{ 0, 0, 0 }}, {{ info.width0, info.height0, info.depth0 }} };
       unsigned cpp = util_format_get_blocksize(info.format);
 
-      if (pipe->target == PIPE_BUFFER)
-         q.pipe->buffer_subdata(q.pipe, pipe, PIPE_TRANSFER_WRITE,
+      if (lpipe->target == PIPE_BUFFER)
+         q.pipe->buffer_subdata(q.pipe, lpipe, PIPE_TRANSFER_WRITE,
                                 0, info.width0, data_ptr);
       else
-         q.pipe->texture_subdata(q.pipe, pipe, 0, PIPE_TRANSFER_WRITE,
+         q.pipe->texture_subdata(q.pipe, lpipe, 0, PIPE_TRANSFER_WRITE,
                                  rect, data_ptr, cpp * info.width0,
                                  cpp * info.width0 * info.height0);
    }
+   pipe_resource_reference(&this->pipe, lpipe);
 }
 
 root_resource::root_resource(clover::device &dev, memory_obj &obj,
@@ -176,7 +181,7 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj,
 }
 
 root_resource::~root_resource() {
-   device().pipe->resource_destroy(device().pipe, pipe);
+   pipe_resource_reference(&pipe, NULL);
 }
 
 sub_resource::sub_resource(resource &r, const vector &offset) :
-- 
2.9.3



More information about the mesa-dev mailing list