[Mesa-dev] [PATCH] r600g/compute: Fix Warnings

2014-08-07 Thread Bruno Jiménez
I have followed the following convention:
- Positions in the pool are now 'int' (start_in_dw and related)
- Sizes are 'unsigned' (size_in_dw and related)
- IDs are 'unsigned'

The pool and item's status are left as uint32_t
The shadow has been also left as a pointer to an uint32_t
---
 src/gallium/drivers/r600/compute_memory_pool.c | 56 +-
 src/gallium/drivers/r600/compute_memory_pool.h | 26 ++--
 2 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 0ee8ceb..8bcab00 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -76,7 +76,7 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
unsigned initial_size_in_dw)
 {
 
-   COMPUTE_DBG(pool-screen, * compute_memory_pool_init() 
initial_size_in_dw = %ld\n,
+   COMPUTE_DBG(pool-screen, * compute_memory_pool_init() 
initial_size_in_dw = %u\n,
initial_size_in_dw);
 
pool-size_in_dw = initial_size_in_dw;
@@ -104,9 +104,9 @@ void compute_memory_pool_delete(struct compute_memory_pool* 
pool)
  * \param size_in_dw   The size of the space we are looking for.
  * \return -1 on failure
  */
-int64_t compute_memory_prealloc_chunk(
+int compute_memory_prealloc_chunk(
struct compute_memory_pool* pool,
-   int64_t size_in_dw)
+   unsigned size_in_dw)
 {
struct compute_memory_item *item;
 
@@ -114,7 +114,7 @@ int64_t compute_memory_prealloc_chunk(
 
assert(size_in_dw = pool-size_in_dw);
 
-   COMPUTE_DBG(pool-screen, * compute_memory_prealloc_chunk() size_in_dw 
= %ld\n,
+   COMPUTE_DBG(pool-screen, * compute_memory_prealloc_chunk() size_in_dw 
= %u\n,
size_in_dw);
 
LIST_FOR_EACH_ENTRY(item, pool-item_list, link) {
@@ -139,13 +139,13 @@ int64_t compute_memory_prealloc_chunk(
  */
 struct list_head *compute_memory_postalloc_chunk(
struct compute_memory_pool* pool,
-   int64_t start_in_dw)
+   int start_in_dw)
 {
struct compute_memory_item *item;
struct compute_memory_item *next;
struct list_head *next_link;
 
-   COMPUTE_DBG(pool-screen, * compute_memory_postalloc_chunck() 
start_in_dw = %ld\n,
+   COMPUTE_DBG(pool-screen, * compute_memory_postalloc_chunck() 
start_in_dw = %i\n,
start_in_dw);
 
/* Check if we can insert it in the front of the list */
@@ -181,12 +181,12 @@ struct list_head *compute_memory_postalloc_chunk(
  * \see compute_memory_finalize_pending
  */
 int compute_memory_grow_defrag_pool(struct compute_memory_pool *pool,
-   struct pipe_context *pipe, int new_size_in_dw)
+   struct pipe_context *pipe, unsigned new_size_in_dw)
 {
new_size_in_dw = align(new_size_in_dw, ITEM_ALIGNMENT);
 
COMPUTE_DBG(pool-screen, * compute_memory_grow_defrag_pool() 
-   new_size_in_dw = %d (%d bytes)\n,
+   new_size_in_dw = %u (%u bytes)\n,
new_size_in_dw, new_size_in_dw * 4);
 
assert(new_size_in_dw = pool-size_in_dw);
@@ -274,17 +274,17 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 {
struct compute_memory_item *item, *next;
 
-   int64_t allocated = 0;
-   int64_t unallocated = 0;
-   int64_t last_pos;
+   unsigned allocated = 0;
+   unsigned unallocated = 0;
+   int last_pos;
 
int err = 0;
 
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
 
LIST_FOR_EACH_ENTRY(item, pool-item_list, link) {
-   COMPUTE_DBG(pool-screen,   + list: offset = %i id = %i size = 
%i 
-   (%i bytes)\n,item-start_in_dw, item-id,
+   COMPUTE_DBG(pool-screen,   + list: offset = %i id = %u size = 
%u 
+   (%u bytes)\n, item-start_in_dw, item-id,
item-size_in_dw, item-size_in_dw * 4);
}
 
@@ -347,7 +347,7 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
struct pipe_context *pipe)
 {
struct compute_memory_item *item;
-   int64_t last_pos;
+   int last_pos;
 
COMPUTE_DBG(pool-screen, * compute_memory_defrag()\n);
 
@@ -374,7 +374,7 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
  */
 int compute_memory_promote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe,
-   int64_t start_in_dw)
+   int start_in_dw)
 {
struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
struct r600_context *rctx = (struct r600_context *)pipe;
@@ -383,8 +383,8 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
struct pipe_box box;
 
COMPUTE_DBG(pool-screen, * compute_memory_promote_item()\n
- + Promoting Item: %i , starting at: %u (%u 

[Mesa-dev] [PATCH 2/2] r600g/compute: Decrement map_count when unmapping items

2014-08-07 Thread Bruno Jiménez
This patch adds a new struct: r600_transfer_global. It will
act as a wrapper around an r600_resource_global and an r600_transfer.

It will be used for calling r600_compute_global_transfer_unmap when
transfer_unmap is called. And at the same time, keep all the transfer
information, so we can call r600_buffer_transfer_unmap with the
'real' transfer.
---
 src/gallium/drivers/r600/evergreen_compute.c | 46 +---
 src/gallium/drivers/r600/evergreen_compute.h |  5 +++
 2 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index f50f94a..ac72256 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -970,10 +970,16 @@ void *r600_compute_global_transfer_map(
struct r600_resource_global* buffer =
(struct r600_resource_global*)resource;
 
+   struct r600_transfer_global *trans = NULL;
+   uint8_t *data;
+
struct compute_memory_item *item = buffer-chunk;
struct pipe_resource *dst = NULL;
unsigned offset = box-x;
 
+   trans = CALLOC(1, sizeof(struct r600_transfer_global));
+   trans-resource = resource;
+
if (is_item_in_pool(item)) {
compute_memory_demote_item(pool, item, ctx_);
}
@@ -1004,8 +1010,11 @@ void *r600_compute_global_transfer_map(
assert(box-z == 0);
 
///TODO: do it better, mapping is not possible if the pool is too big
-   return pipe_buffer_map_range(ctx_, dst,
-   offset, box-width, usage, ptransfer);
+   data = pipe_buffer_map_range(ctx_, dst,
+   offset, box-width, usage, trans-ptransfer);
+
+   *ptransfer = (struct pipe_transfer *)trans;
+   return data;
 }
 
 void r600_compute_global_transfer_unmap(
@@ -1013,16 +1022,31 @@ void r600_compute_global_transfer_unmap(
struct pipe_transfer* transfer)
 {
/* struct r600_resource_global are not real resources, they just map
-* to an offset within the compute memory pool.  The function
-* r600_compute_global_transfer_map() maps the memory pool
-* resource rather than the struct r600_resource_global passed to
-* it as an argument and then initalizes ptransfer-resource with
-* the memory pool resource (via pipe_buffer_map_range).
-* When transfer_unmap is called it uses the memory pool's
-* vtable which calls r600_buffer_transfer_map() rather than
-* this function.
+* to an offset within the compute memory pool. The function
+* r600_compute_global_transfer_map() creates a struct
+* r600_transfer_global, which has as resource an r600_global_resource
+* and an r600_transfer which will act as the 'real' pipe_transfer
+* that will be passed to pipe_buffer_map_range.
+*
+* This allows us to use an r600_resource_global vtable when 
transfer_unmap
+* is called, and still have the full information about the transfer,
+* which will be used to actually unmap the resource.
 */
-   assert (!This function should not be called);
+
+   struct r600_context *rctx = (struct r600_context *)ctx_;
+   struct r600_transfer_global *trans =
+   (struct r600_transfer_global *)transfer;
+   struct r600_resource_global *buffer =
+   (struct r600_resource_global *)trans-resource;
+   struct compute_memory_item *item = buffer-chunk;
+
+   COMPUTE_DBG(rctx-screen, * r600_compute_global_transfer_unmap()\n
+   Unmaping Buffer: %u\n, item-id);
+
+   ctx_-transfer_unmap(ctx_, trans-ptransfer);
+   item-map_count--;
+
+   FREE(trans);
 }
 
 void r600_compute_global_transfer_flush_region(
diff --git a/src/gallium/drivers/r600/evergreen_compute.h 
b/src/gallium/drivers/r600/evergreen_compute.h
index 4fb53a1..842e5e4 100644
--- a/src/gallium/drivers/r600/evergreen_compute.h
+++ b/src/gallium/drivers/r600/evergreen_compute.h
@@ -38,6 +38,11 @@ struct r600_resource_global {
struct compute_memory_item *chunk;
 };
 
+struct r600_transfer_global {
+   struct pipe_resource *resource;
+   struct pipe_transfer *ptransfer;
+};
+
 void *evergreen_create_compute_state(struct pipe_context *ctx, const struct 
pipe_compute_state *cso);
 void evergreen_delete_compute_state(struct pipe_context *ctx, void *state);
 void evergreen_compute_upload_input(struct pipe_context *context, const uint 
*block_layout, const uint *grid_layout, const void *input);
-- 
2.0.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 0/2] [RFC] r600g/compute: Track better how items are mapped

2014-08-07 Thread Bruno Jiménez
Hi,

This series adds support for actually knowing when an item is not
mapped. Previously, when an item was marked as 'MAPPED_FOR_READING'
we couldn't really remove that status because although we controlled
how items were mapped, we didn't control how they were unmapped.

Patch 1 modifies how items track how they are mapped. As an item can
be mapped multiple times for reading/writing, we should also
know how many times the item is mapped.

Patch 2 adds a new structure that will be used to actually make possible
that r600_compute_global_transfer_unmap is called when we try to unmap
an item, so we can decrement the map count.

Patch 2 is a bit of hack that seems to work, but any suggestions about
it are welcomed.

Thanks in advance!
Bruno

Bruno Jiménez (2):
  r600g/compute: Add a member to the items to track how many maps it has
  r600g/compute: Decrement map_count when unmapping items

 src/gallium/drivers/r600/compute_memory_pool.c |  5 +--
 src/gallium/drivers/r600/compute_memory_pool.h |  1 +
 src/gallium/drivers/r600/evergreen_compute.c   | 49 +++---
 src/gallium/drivers/r600/evergreen_compute.h   |  5 +++
 4 files changed, 45 insertions(+), 15 deletions(-)

-- 
2.0.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/2] r600g/compute: Add a member to the items to track how many maps it has

2014-08-07 Thread Bruno Jiménez
This will be necessary to know how many mappings for read it has, as
the spec allows to have as many as desired.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 5 +++--
 src/gallium/drivers/r600/compute_memory_pool.h | 1 +
 src/gallium/drivers/r600/evergreen_compute.c   | 3 +--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 0ee8ceb..497ff90 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -403,11 +403,12 @@ int compute_memory_promote_item(struct 
compute_memory_pool *pool,
dst, 0, item-start_in_dw * 4, 0 ,0,
src, 0, box);
 
-   /* We check if the item is mapped for reading.
+   /* We check if the item is mapped. At this point, only
+* buffers mapped for reading should still be mapped.
 * In this case, we need to keep the temporary buffer 'alive'
 * because it is possible to keep a map active for reading
 * while a kernel (that reads from it) executes */
-   if (!(item-status  ITEM_MAPPED_FOR_READING)) {
+   if (item-map_count == 0) {
pool-screen-b.b.resource_destroy(screen, src);
item-real_buffer = NULL;
}
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 161ddd5..8fcd75b 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -41,6 +41,7 @@ struct compute_memory_item
int64_t id; /** ID of the memory chunk */
 
uint32_t status;/** Will track the status of the item */
+   uint32_t map_count; /** Will track the number of maps done to the 
item */
 
/** Start pointer in dwords relative in the pool bo. If an item
 * is unallocated, then this value must be -1 to indicate this. */
diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index 1970414..f50f94a 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -986,8 +986,7 @@ void *r600_compute_global_transfer_map(
 
dst = (struct pipe_resource*)item-real_buffer;
 
-   if (usage  PIPE_TRANSFER_READ)
-   buffer-chunk-status |= ITEM_MAPPED_FOR_READING;
+   item-map_count++;
 
COMPUTE_DBG(rctx-screen, * r600_compute_global_transfer_map()\n
level = %u, usage = %u, box(x = %u, y = %u, z = %u 
-- 
2.0.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] r600g/compute: Add information about how compute_memory_pool works

2014-08-07 Thread Bruno Jiménez
---
NOTE: if the two patches I have just send for tracking how buffers are mapped
are good, we may drop the last item from the TODO list.

 src/gallium/drivers/r600/compute_memory_pool.c | 47 ++
 1 file changed, 47 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 0ee8ceb..58f07c0 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -22,6 +22,53 @@
  *  Adam Rak adam@streamnovation.com
  */
 
+/**
+ * \file compute_memory_pool.c
+ * Pool for computation resources
+ *
+ * Summary of how it works:
+ *  First, items are added to the pool by compute_memory_alloc. These
+ *  items aren't allocated yet, don't have a position at the pool
+ *  and are added to the \a unallocated_list.
+ *  Now, when this items are actually used in a kernel, they are
+ *  promoted to the pool by compute_memory_promote_item. This means
+ *  that they will be placed somewhere in the pool and they will be
+ *  moved from the \a unallocated_list to the \a item_list.
+ *  The process of ensuring that there's enough memory for all the items
+ *  and that everything goes to its correct place is done by
+ *  compute_memory_finalize_pending. This function first sums the
+ *  size of all the items that are already in the pool and of those
+ *  that will be added. If the size is more than the total of the pool
+ *  then it will be grown so that all the items will fit. After this
+ *  if the pool is fragmented (meaning that there may be gaps between
+ *  items) it will be defragmented. Finally, all the items marked
+ *  for promotion are promoted to the pool.
+ *  For now, the defragmentation is very simple: it just loops for all
+ *  the allocated items checking where they should start, and if any
+ *  item starts further back than where it should, it is moved forward.
+ *
+ *  Mapping buffers is done in an inefficient way, result of the limitation
+ *  of not being able to have buffers mapped when a pool is grown,
+ *  which should only happen at the moment of launching kernels.
+ *  When a buffer is going to be mapped, first it is demoted from the
+ *  pool, so we can assure that its position will never change, even
+ *  if the pool gets relocated as a result of it being grown.
+ *  This means that we have to actually copy the whole buffer to a new
+ *  resource before mapping it.
+ *  As an example of why we have to do this imagine this case:
+ *  Pool with a size of 16 with buffers A, B, C and D (size 4 each)
+ *  We map buffer A and launch a kernel that needs of a new item E.
+ *  As we need to add a new item, the pool will grow, possibly
+ *  geting relocated in the process. This means that the mapping
+ *  for buffer A won't be valid any more.
+ *
+ * Things still TODO:
+ *  - Find a better way of having items mapped when a kernel is launched
+ *  - Find a better way of adding items to the pool when it is fragmented
+ *  - Decide what to do with '{post,pre}alloc_chunk' now that they aren't used
+ *  - Actually be able to remove the 'ITEM_MAPPED_FOR_READING' status
+ */
+
 #include pipe/p_defines.h
 #include pipe/p_state.h
 #include pipe/p_context.h
-- 
2.0.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] clover: Add support for CL_MAP_WRITE_INVALIDATE_REGION

2014-08-07 Thread Bruno Jiménez
OpenCL 1.2 CL_MAP_WRITE_INVALIDATE_REGION sounds a lot like
PIPE_TRANSFER_DISCARD_RANGE:

From OpenCL 1.2 spec:
The contents of the region being mapped are to be discarded.

From p_defines.h:
Discards the memory within the mapped region.
---
 src/gallium/state_trackers/clover/core/resource.cpp | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/gallium/state_trackers/clover/core/resource.cpp 
b/src/gallium/state_trackers/clover/core/resource.cpp
index 7b8a40a..f7d24ef 100644
--- a/src/gallium/state_trackers/clover/core/resource.cpp
+++ b/src/gallium/state_trackers/clover/core/resource.cpp
@@ -172,8 +172,14 @@ mapping::mapping(command_queue q, resource r,
  const resource::vector origin,
  const resource::vector region) :
pctx(q.pipe) {
+   if (((flags  CL_MAP_WRITE) || (flags  CL_MAP_READ)) 
+(flags  CL_MAP_WRITE_INVALIDATE_REGION))
+   throw error(CL_INVALID_VALUE);
+
unsigned usage = ((flags  CL_MAP_WRITE ? PIPE_TRANSFER_WRITE : 0 ) |
  (flags  CL_MAP_READ ? PIPE_TRANSFER_READ : 0 ) |
+ (flags  CL_MAP_WRITE_INVALIDATE_REGION ?
+PIPE_TRANSFER_DISCARD_RANGE : 0) |
  (!blocking ? PIPE_TRANSFER_UNSYNCHRONIZED : 0));
 
p = pctx-transfer_map(pctx, r.pipe, 0, usage,
-- 
2.0.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2] clover: Add support for CL_MAP_WRITE_INVALIDATE_REGION

2014-08-07 Thread Bruno Jiménez
OpenCL 1.2 CL_MAP_WRITE_INVALIDATE_REGION sounds a lot like
PIPE_TRANSFER_DISCARD_RANGE:

From OpenCL 1.2 spec:
The contents of the region being mapped are to be discarded.

From p_defines.h:
Discards the memory within the mapped region.

v2: Move the code for validating flags to the front-end as
suggested by Francisco Jerez
---
 src/gallium/state_trackers/clover/api/transfer.cpp  | 13 +
 src/gallium/state_trackers/clover/core/resource.cpp |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp 
b/src/gallium/state_trackers/clover/api/transfer.cpp
index 07d8a73..37c3074 100644
--- a/src/gallium/state_trackers/clover/api/transfer.cpp
+++ b/src/gallium/state_trackers/clover/api/transfer.cpp
@@ -168,6 +168,17 @@ namespace {
}
 
///
+   /// Checks that the mapping flags are correct
+   ///
+   void
+   validate_flags(const cl_map_flags flags) {
+  if (((flags  CL_MAP_WRITE) || (flags  CL_MAP_READ)) 
+   (flags  CL_MAP_WRITE_INVALIDATE_REGION))
+ throw error(CL_INVALID_VALUE);
+   }
+
+
+   ///
/// Class that encapsulates the task of mapping an object of type
/// \a T.  The return value of get() should be implicitly
/// convertible to \a void *.
@@ -629,6 +640,7 @@ clEnqueueMapBuffer(cl_command_queue d_q, cl_mem d_mem, 
cl_bool blocking,
 
validate_common(q, deps);
validate_object(q, mem, obj_origin, obj_pitch, region);
+   validate_flags(flags);
 
void *map = mem.resource(q).add_map(q, flags, blocking, obj_origin, region);
 
@@ -656,6 +668,7 @@ clEnqueueMapImage(cl_command_queue d_q, cl_mem d_mem, 
cl_bool blocking,
 
validate_common(q, deps);
validate_object(q, img, origin, region);
+   validate_flags(flags);
 
void *map = img.resource(q).add_map(q, flags, blocking, origin, region);
 
diff --git a/src/gallium/state_trackers/clover/core/resource.cpp 
b/src/gallium/state_trackers/clover/core/resource.cpp
index 7b8a40a..34c0cd5 100644
--- a/src/gallium/state_trackers/clover/core/resource.cpp
+++ b/src/gallium/state_trackers/clover/core/resource.cpp
@@ -174,6 +174,8 @@ mapping::mapping(command_queue q, resource r,
pctx(q.pipe) {
unsigned usage = ((flags  CL_MAP_WRITE ? PIPE_TRANSFER_WRITE : 0 ) |
  (flags  CL_MAP_READ ? PIPE_TRANSFER_READ : 0 ) |
+ (flags  CL_MAP_WRITE_INVALIDATE_REGION ?
+PIPE_TRANSFER_DISCARD_RANGE : 0) |
  (!blocking ? PIPE_TRANSFER_UNSYNCHRONIZED : 0));
 
p = pctx-transfer_map(pctx, r.pipe, 0, usage,
-- 
2.0.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 1/2] r600g/compute: Add documentation to compute_memory_pool

2014-07-27 Thread Bruno Jiménez
v2: Rebased on top of master
---
 src/gallium/drivers/r600/compute_memory_pool.c | 59 +-
 src/gallium/drivers/r600/compute_memory_pool.h | 58 -
 2 files changed, 86 insertions(+), 31 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index d53587f..928618c 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -44,7 +44,7 @@
 
 #define ITEM_ALIGNMENT 1024
 /**
- * Creates a new pool
+ * Creates a new pool.
  */
 struct compute_memory_pool* compute_memory_pool_new(
struct r600_screen * rscreen)
@@ -66,6 +66,12 @@ struct compute_memory_pool* compute_memory_pool_new(
return pool;
 }
 
+/**
+ * Initializes the pool with a size of \a initial_size_in_dw.
+ * \param pool The pool to be initialized.
+ * \param initial_size_in_dw   The initial size.
+ * \see compute_memory_grow_defrag_pool
+ */
 static void compute_memory_pool_init(struct compute_memory_pool * pool,
unsigned initial_size_in_dw)
 {
@@ -79,7 +85,7 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
 }
 
 /**
- * Frees all stuff in the pool and the pool struct itself too
+ * Frees all stuff in the pool and the pool struct itself too.
  */
 void compute_memory_pool_delete(struct compute_memory_pool* pool)
 {
@@ -94,7 +100,9 @@ void compute_memory_pool_delete(struct compute_memory_pool* 
pool)
 
 /**
  * Searches for an empty space in the pool, return with the pointer to the
- * allocatable space in the pool, returns -1 on failure.
+ * allocatable space in the pool.
+ * \param size_in_dw   The size of the space we are looking for.
+ * \return -1 on failure
  */
 int64_t compute_memory_prealloc_chunk(
struct compute_memory_pool* pool,
@@ -126,6 +134,8 @@ int64_t compute_memory_prealloc_chunk(
 
 /**
  *  Search for the chunk where we can link our new chunk after it.
+ *  \param start_in_dw The position of the item we want to add to the pool.
+ *  \return The item that is just before the passed position
  */
 struct list_head *compute_memory_postalloc_chunk(
struct compute_memory_pool* pool,
@@ -166,8 +176,9 @@ struct list_head *compute_memory_postalloc_chunk(
 }
 
 /**
- * Reallocates pool, conserves data.
- * @returns -1 if it fails, 0 otherwise
+ * Reallocates and defragments the pool, conserves data.
+ * \returns -1 if it fails, 0 otherwise
+ * \see compute_memory_finalize_pending
  */
 int compute_memory_grow_defrag_pool(struct compute_memory_pool *pool,
struct pipe_context *pipe, int new_size_in_dw)
@@ -234,6 +245,8 @@ int compute_memory_grow_defrag_pool(struct 
compute_memory_pool *pool,
 
 /**
  * Copy pool from device to host, or host to device.
+ * \param device_to_host 1 for device-host, 0 for host-device
+ * \see compute_memory_grow_defrag_pool
  */
 void compute_memory_shadow(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host)
@@ -251,8 +264,10 @@ void compute_memory_shadow(struct compute_memory_pool* 
pool,
 }
 
 /**
- * Allocates pending allocations in the pool
- * @returns -1 if it fails, 0 otherwise
+ * Moves all the items marked for promotion from the \a unallocated_list
+ * to the \a item_list.
+ * \return -1 if it fails, 0 otherwise
+ * \see evergreen_set_global_binding
  */
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
@@ -323,6 +338,9 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 /**
  * Defragments the pool, so that there's no gap between items.
  * \param pool The pool to be defragmented
+ * \param src  The origin resource
+ * \param dst  The destination resource
+ * \see compute_memory_grow_defrag_pool and compute_memory_finalize_pending
  */
 void compute_memory_defrag(struct compute_memory_pool *pool,
struct pipe_resource *src, struct pipe_resource *dst,
@@ -348,6 +366,12 @@ void compute_memory_defrag(struct compute_memory_pool 
*pool,
pool-status = ~POOL_FRAGMENTED;
 }
 
+/**
+ * Moves an item from the \a unallocated_list to the \a item_list.
+ * \param item The item that will be promoted.
+ * \return -1 if it fails, 0 otherwise
+ * \see compute_memory_finalize_pending
+ */
 int compute_memory_promote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe,
int64_t start_in_dw)
@@ -390,6 +414,11 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
return 0;
 }
 
+/**
+ * Moves an item from the \a item_list to the \a unallocated_list.
+ * \param item The item that will be demoted
+ * \see r600_compute_global_transfer_map
+ */
 void compute_memory_demote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe)
 {
@@ -434,7 +463,7 @@ void compute_memory_demote_item(struct 

[Mesa-dev] [PATCH v3 2/2] r600g/compute: Add debug information to promote and demote functions

2014-07-27 Thread Bruno Jiménez
v2: Add information about the item's starting point and size
v3: Rebased on top of master
---
 src/gallium/drivers/r600/compute_memory_pool.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 928618c..0ee8ceb 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -382,10 +382,12 @@ int compute_memory_promote_item(struct 
compute_memory_pool *pool,
struct pipe_resource *dst = (struct pipe_resource *)pool-bo;
struct pipe_box box;
 
-   COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
-   start_in_dw = %u (%u bytes) size_in_dw = %u (%u 
bytes)\n,
-   item, item-id, start_in_dw, start_in_dw * 4,
-   item-size_in_dw, item-size_in_dw * 4);
+   COMPUTE_DBG(pool-screen, * compute_memory_promote_item()\n
+ + Promoting Item: %i , starting at: %u (%u bytes) 
+   size: %u (%u bytes)\n\t\t\tnew start: %u (%u bytes)\n,
+   item-id, item-start_in_dw, item-start_in_dw * 4,
+   item-size_in_dw, item-size_in_dw * 4,
+   start_in_dw, start_in_dw * 4);
 
/* Remove the item from the unallocated list */
list_del(item-link);
@@ -427,6 +429,11 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
struct pipe_resource *dst;
struct pipe_box box;
 
+   COMPUTE_DBG(pool-screen, * compute_memory_demote_item()\n
+ + Demoting Item: %i, starting at: %u (%u bytes) 
+   size: %u (%u bytes)\n, item-id, item-start_in_dw,
+   item-start_in_dw * 4, item-size_in_dw, 
item-size_in_dw * 4);
+
/* First, we remove the item from the item_list */
list_del(item-link);
 
-- 
2.0.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 1/3] r600g/compute: Allow compute_memory_move_item to move items between resources

2014-07-24 Thread Bruno Jiménez
v2: Remove unnecesary variables
---
 src/gallium/drivers/r600/compute_memory_pool.c | 31 +-
 src/gallium/drivers/r600/compute_memory_pool.h |  1 +
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 254c1d7..b2b9ad6 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -331,6 +331,7 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
struct pipe_context *pipe)
 {
struct compute_memory_item *item;
+   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
int64_t last_pos;
 
COMPUTE_DBG(pool-screen, * compute_memory_defrag()\n);
@@ -340,7 +341,8 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
if (item-start_in_dw != last_pos) {
assert(last_pos  item-start_in_dw);
 
-   compute_memory_move_item(pool, item, last_pos, pipe);
+   compute_memory_move_item(pool, src, src,
+   item, last_pos, pipe);
}
 
last_pos += align(item-size_in_dw, ITEM_ALIGNMENT);
@@ -431,7 +433,8 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
 }
 
 /**
- * Moves the item \a item forward in the pool to \a new_start_in_dw
+ * Moves the item \a item forward from the resource \a src to the
+ * resource \a dst at \a new_start_in_dw
  *
  * This function assumes two things:
  * 1) The item is \b only moved forward
@@ -442,13 +445,12 @@ void compute_memory_demote_item(struct 
compute_memory_pool *pool,
  * \see compute_memory_defrag
  */
 void compute_memory_move_item(struct compute_memory_pool *pool,
+   struct pipe_resource *src, struct pipe_resource *dst,
struct compute_memory_item *item, uint64_t new_start_in_dw,
struct pipe_context *pipe)
 {
struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
struct r600_context *rctx = (struct r600_context *)pipe;
-   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
-   struct pipe_resource *dst;
struct pipe_box box;
 
struct compute_memory_item *prev;
@@ -465,9 +467,9 @@ void compute_memory_move_item(struct compute_memory_pool 
*pool,
 
u_box_1d(item-start_in_dw * 4, item-size_in_dw * 4, box);
 
-   /* If the ranges don't overlap, we can just copy the item directly */
-   if (new_start_in_dw + item-size_in_dw = item-start_in_dw) {
-   dst = (struct pipe_resource *)pool-bo;
+   /* If the ranges don't overlap, or we are copying from one resource
+* to another, we can just copy the item directly */
+   if (src != dst || new_start_in_dw + item-size_in_dw = 
item-start_in_dw) {
 
rctx-b.b.resource_copy_region(pipe,
dst, 0, new_start_in_dw * 4, 0, 0,
@@ -475,24 +477,21 @@ void compute_memory_move_item(struct compute_memory_pool 
*pool,
} else {
/* The ranges overlap, we will try first to use an intermediate
 * resource to move the item */
-   dst = (struct pipe_resource *)r600_compute_buffer_alloc_vram(
-   pool-screen, item-size_in_dw * 4);
+   struct pipe_resource *tmp = (struct pipe_resource *)
+   r600_compute_buffer_alloc_vram(pool-screen, 
item-size_in_dw * 4);
 
-   if (dst != NULL) {
+   if (tmp != NULL) {
rctx-b.b.resource_copy_region(pipe,
-   dst, 0, 0, 0, 0,
+   tmp, 0, 0, 0, 0,
src, 0, box);
 
-   src = dst;
-   dst = (struct pipe_resource *)pool-bo;
-
box.x = 0;
 
rctx-b.b.resource_copy_region(pipe,
dst, 0, new_start_in_dw * 4, 0, 0,
-   src, 0, box);
+   tmp, 0, box);
 
-   pool-screen-b.b.resource_destroy(screen, src);
+   pool-screen-b.b.resource_destroy(screen, tmp);
 
} else {
/* The allocation of the temporary resource failed,
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 5a1b33b..822bfbe 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -101,6 +101,7 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
struct compute_memory_item *item, struct pipe_context *pipe);
 
 void compute_memory_move_item(struct compute_memory_pool *pool,
+   struct pipe_resource *src, struct pipe_resource *dst,
struct compute_memory_item *item, 

[Mesa-dev] [PATCH 3/3] r600g/compute: Defrag the pool at the same time as we grow it

2014-07-19 Thread Bruno Jiménez
This allows us two things: we now need less item copies when we have
to defrag+grow the pool (to just one copy per item) and, even in the
case where we don't need to defrag the pool, we reduce the data copied
to just the useful data that the items use.

Note: The fallback path is a bit ugly now, but hopefully we won't need
it much.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 40 --
 src/gallium/drivers/r600/compute_memory_pool.h |  2 +-
 2 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index ca36240..32f5892 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -169,10 +169,12 @@ struct list_head *compute_memory_postalloc_chunk(
  * Reallocates pool, conserves data.
  * @returns -1 if it fails, 0 otherwise
  */
-int compute_memory_grow_pool(struct compute_memory_pool* pool,
-   struct pipe_context * pipe, int new_size_in_dw)
+int compute_memory_grow_defrag_pool(struct compute_memory_pool *pool,
+   struct pipe_context *pipe, int new_size_in_dw)
 {
-   COMPUTE_DBG(pool-screen, * compute_memory_grow_pool() 
+   new_size_in_dw = align(new_size_in_dw, ITEM_ALIGNMENT);
+
+   COMPUTE_DBG(pool-screen, * compute_memory_grow_defrag_pool() 
new_size_in_dw = %d (%d bytes)\n,
new_size_in_dw, new_size_in_dw * 4);
 
@@ -183,27 +185,17 @@ int compute_memory_grow_pool(struct compute_memory_pool* 
pool,
} else {
struct r600_resource *temp = NULL;
 
-   new_size_in_dw = align(new_size_in_dw, ITEM_ALIGNMENT);
-
-   COMPUTE_DBG(pool-screen,   Aligned size = %d (%d bytes)\n,
-   new_size_in_dw, new_size_in_dw * 4);
-
temp = (struct r600_resource *)r600_compute_buffer_alloc_vram(
pool-screen, 
new_size_in_dw * 4);
 
if (temp != NULL) {
-   struct r600_context *rctx = (struct r600_context *)pipe;
struct pipe_resource *src = (struct pipe_resource 
*)pool-bo;
struct pipe_resource *dst = (struct pipe_resource 
*)temp;
-   struct pipe_box box;
 
-   COMPUTE_DBG(pool-screen,   Growing the pool using a 
temporary resource\n);
+   COMPUTE_DBG(pool-screen,   Growing and defragmenting 
the pool 
+   using a temporary resource\n);
 
-   u_box_1d(0, pool-size_in_dw * 4, box);
-
-   rctx-b.b.resource_copy_region(pipe,
-   dst, 0, 0, 0 ,0,
-   src, 0, box);
+   compute_memory_defrag(pool, src, dst, pipe);
 
pool-screen-b.b.resource_destroy(
(struct pipe_screen *)pool-screen,
@@ -229,6 +221,11 @@ int compute_memory_grow_pool(struct compute_memory_pool* 
pool,
pool-screen,
pool-size_in_dw * 4);
compute_memory_shadow(pool, pipe, 0);
+
+   if (pool-status  POOL_FRAGMENTED) {
+   struct pipe_resource *src = (struct 
pipe_resource *)pool-bo;
+   compute_memory_defrag(pool, src, src, pipe);
+   }
}
}
 
@@ -292,16 +289,15 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
return 0;
}
 
-   if (pool-status  POOL_FRAGMENTED) {
-   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
-   compute_memory_defrag(pool, src, src, pipe);
-   }
-
if (pool-size_in_dw  allocated + unallocated) {
-   err = compute_memory_grow_pool(pool, pipe, allocated + 
unallocated);
+   err = compute_memory_grow_defrag_pool(pool, pipe, allocated + 
unallocated);
if (err == -1)
return -1;
}
+   else if (pool-status  POOL_FRAGMENTED) {
+   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
+   compute_memory_defrag(pool, src, src, pipe);
+   }
 
/* After defragmenting the pool, allocated is equal to the first 
available
 * position for new items in the pool */
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 5f1d72b..c7eb237 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -81,7 +81,7 @@ int64_t compute_memory_prealloc_chunk(struct 
compute_memory_pool* pool, int64_t
 
 struct list_head *compute_memory_postalloc_chunk(struct 

[Mesa-dev] [PATCH 1/3] r600g/compute: Allow compute_memory_move_item to move items between resources

2014-07-19 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 43 ++
 src/gallium/drivers/r600/compute_memory_pool.h |  1 +
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 254c1d7..1ad77ad 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -331,6 +331,7 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
struct pipe_context *pipe)
 {
struct compute_memory_item *item;
+   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
int64_t last_pos;
 
COMPUTE_DBG(pool-screen, * compute_memory_defrag()\n);
@@ -340,7 +341,8 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
if (item-start_in_dw != last_pos) {
assert(last_pos  item-start_in_dw);
 
-   compute_memory_move_item(pool, item, last_pos, pipe);
+   compute_memory_move_item(pool, src, src,
+   item, last_pos, pipe);
}
 
last_pos += align(item-size_in_dw, ITEM_ALIGNMENT);
@@ -431,7 +433,8 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
 }
 
 /**
- * Moves the item \a item forward in the pool to \a new_start_in_dw
+ * Moves the item \a item forward from the resource \a src to the
+ * resource \a dst at \a new_start_in_dw
  *
  * This function assumes two things:
  * 1) The item is \b only moved forward
@@ -442,13 +445,14 @@ void compute_memory_demote_item(struct 
compute_memory_pool *pool,
  * \see compute_memory_defrag
  */
 void compute_memory_move_item(struct compute_memory_pool *pool,
+   struct pipe_resource *src, struct pipe_resource *dst,
struct compute_memory_item *item, uint64_t new_start_in_dw,
struct pipe_context *pipe)
 {
struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
struct r600_context *rctx = (struct r600_context *)pipe;
-   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
-   struct pipe_resource *dst;
+   struct pipe_resource *src_ = src;
+   struct pipe_resource *dst_;
struct pipe_box box;
 
struct compute_memory_item *prev;
@@ -465,34 +469,35 @@ void compute_memory_move_item(struct compute_memory_pool 
*pool,
 
u_box_1d(item-start_in_dw * 4, item-size_in_dw * 4, box);
 
-   /* If the ranges don't overlap, we can just copy the item directly */
-   if (new_start_in_dw + item-size_in_dw = item-start_in_dw) {
-   dst = (struct pipe_resource *)pool-bo;
+   /* If the ranges don't overlap, or we are copying from one resource
+* to another, we can just copy the item directly */
+   if (src != dst || new_start_in_dw + item-size_in_dw = 
item-start_in_dw) {
+   dst_ = dst;
 
rctx-b.b.resource_copy_region(pipe,
-   dst, 0, new_start_in_dw * 4, 0, 0,
-   src, 0, box);
+   dst_, 0, new_start_in_dw * 4, 0, 0,
+   src_, 0, box);
} else {
/* The ranges overlap, we will try first to use an intermediate
 * resource to move the item */
-   dst = (struct pipe_resource *)r600_compute_buffer_alloc_vram(
+   dst_ = (struct pipe_resource *)r600_compute_buffer_alloc_vram(
pool-screen, item-size_in_dw * 4);
 
-   if (dst != NULL) {
+   if (dst_ != NULL) {
rctx-b.b.resource_copy_region(pipe,
-   dst, 0, 0, 0, 0,
-   src, 0, box);
+   dst_, 0, 0, 0, 0,
+   src_, 0, box);
 
-   src = dst;
-   dst = (struct pipe_resource *)pool-bo;
+   src_ = dst_;
+   dst_ = dst;
 
box.x = 0;
 
rctx-b.b.resource_copy_region(pipe,
-   dst, 0, new_start_in_dw * 4, 0, 0,
-   src, 0, box);
+   dst_, 0, new_start_in_dw * 4, 0, 0,
+   src_, 0, box);
 
-   pool-screen-b.b.resource_destroy(screen, src);
+   pool-screen-b.b.resource_destroy(screen, src_);
 
} else {
/* The allocation of the temporary resource failed,
@@ -505,7 +510,7 @@ void compute_memory_move_item(struct compute_memory_pool 
*pool,
 
u_box_1d(new_start_in_dw * 4, (offset + 
item-size_in_dw) * 4, box);
 
-   map = pipe-transfer_map(pipe, src, 0, 
PIPE_TRANSFER_READ_WRITE,
+   map = pipe-transfer_map(pipe, src_, 0, 

[Mesa-dev] [PATCH 2/3] r600g/compute: Allow compute_memory_defrag to defragment between resources

2014-07-19 Thread Bruno Jiménez
This will be used in the following patch to avoid duplicated code
---
 src/gallium/drivers/r600/compute_memory_pool.c | 11 ++-
 src/gallium/drivers/r600/compute_memory_pool.h |  1 +
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 1ad77ad..ca36240 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -293,7 +293,8 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
}
 
if (pool-status  POOL_FRAGMENTED) {
-   compute_memory_defrag(pool, pipe);
+   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
+   compute_memory_defrag(pool, src, src, pipe);
}
 
if (pool-size_in_dw  allocated + unallocated) {
@@ -328,20 +329,20 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
  * \param pool The pool to be defragmented
  */
 void compute_memory_defrag(struct compute_memory_pool *pool,
+   struct pipe_resource *src, struct pipe_resource *dst,
struct pipe_context *pipe)
 {
struct compute_memory_item *item;
-   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
int64_t last_pos;
 
COMPUTE_DBG(pool-screen, * compute_memory_defrag()\n);
 
last_pos = 0;
LIST_FOR_EACH_ENTRY(item, pool-item_list, link) {
-   if (item-start_in_dw != last_pos) {
-   assert(last_pos  item-start_in_dw);
+   if (src != dst || item-start_in_dw != last_pos) {
+   assert(last_pos = item-start_in_dw);
 
-   compute_memory_move_item(pool, src, src,
+   compute_memory_move_item(pool, src, dst,
item, last_pos, pipe);
}
 
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 822bfbe..5f1d72b 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -91,6 +91,7 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
struct pipe_context * pipe);
 
 void compute_memory_defrag(struct compute_memory_pool *pool,
+   struct pipe_resource *src, struct pipe_resource *dst,
struct pipe_context *pipe);
 
 int compute_memory_promote_item(struct compute_memory_pool *pool,
-- 
2.0.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 0/3] r600g/compute: Implement grow+defrag for compute_memory_pool

2014-07-19 Thread Bruno Jiménez
Hi,

This series is a follow up for the 'Adding support for defragmenting
compute_memory_pool' series. It also sits on top of the patch I sent
here: http://lists.freedesktop.org/archives/mesa-dev/2014-July/062923.html

It modifies the function 'compute_memory_grow_pool' so it can defrag
the pool at the same time as it grows it, thus reducing the total amount
of copies to one per item in the case grow+defrag. In the case where
the pool needs to grow, but it's not fragmented, then we copy only
the 'real' data that the items have, instead of copying the whole
resource, data and garbage at the same time.

The fallback path for grow+defrag isn't very good, but hopefully
it won't be used much.

As usual, if you have any doubt about any of the patches, just ask.

Thanks in advance!
Bruno

Bruno Jiménez (3):
  r600g/compute: Allow compute_memory_move_item to move items between
resources
  r600g/compute: Allow compute_memory_defrag to defragment between
resources
  r600g/compute: Defrag the pool at the same time as we grow it

 src/gallium/drivers/r600/compute_memory_pool.c | 86 +-
 src/gallium/drivers/r600/compute_memory_pool.h |  4 +-
 2 files changed, 47 insertions(+), 43 deletions(-)

-- 
2.0.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/5] r600g/compute: Defrag the pool if it's necesary

2014-07-16 Thread Bruno Jiménez
This patch adds a new member to the pool to track its status.
For now it is used only for the 'fragmented' status, but if
needed it could be used for more statuses.

The pool will be considered fragmented if: An item that isn't
the last is freed or demoted.

This 'strategy' has a problem, although it shouldn't cause any bug.
If for example we have two items, A and B. We choose to free A first,
now the pool will have the 'fragmented' status. If we now free B,
the pool will retain its 'fragmented' status even if it isn't
fragmented.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 32 --
 src/gallium/drivers/r600/compute_memory_pool.h |  4 
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 00b28bc..b158f5e 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -262,23 +262,10 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
-   /* If we require more space than the size of the pool, then grow the
-* pool.
-*
-* XXX: I'm pretty sure this won't work.  Imagine this scenario:
-*
-* Offset Item Size
-*   0A50
-* 200B50
-* 400C50
-*
-* Total size = 450
-* Allocated size = 150
-* Pending Item D Size = 200
-*
-* In this case, there are 300 units of free space in the pool, but
-* they aren't contiguous, so it will be impossible to allocate Item D.
-*/
+   if (pool-status  POOL_FRAGMENTED) {
+   compute_memory_defrag(pool, pipe);
+   }
+
if (pool-size_in_dw  allocated + unallocated) {
err = compute_memory_grow_pool(pool, pipe, allocated + 
unallocated);
if (err == -1)
@@ -324,6 +311,8 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
 
last_pos += align(item-size_in_dw, ITEM_ALIGNMENT);
}
+
+   pool-status = ~POOL_FRAGMENTED;
 }
 
 int compute_memory_promote_item(struct compute_memory_pool *pool,
@@ -430,6 +419,10 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
 
/* Remember to mark the buffer as 'pending' by setting start_in_dw to 
-1 */
item-start_in_dw = -1;
+
+   if (item-link.next != pool-item_list) {
+   pool-status |= POOL_FRAGMENTED;
+   }
 }
 
 /**
@@ -533,6 +526,11 @@ void compute_memory_free(struct compute_memory_pool* pool, 
int64_t id)
LIST_FOR_EACH_ENTRY_SAFE(item, next, pool-item_list, link) {
 
if (item-id == id) {
+
+   if (item-link.next != pool-item_list) {
+   pool-status |= POOL_FRAGMENTED;
+   }
+
list_del(item-link);
 
if (item-real_buffer) {
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 5d18777..acc68ea 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -32,6 +32,8 @@
 #define ITEM_FOR_PROMOTING  (12)
 #define ITEM_FOR_DEMOTING   (13)
 
+#define POOL_FRAGMENTED (10)
+
 struct compute_memory_pool;
 
 struct compute_memory_item
@@ -60,6 +62,8 @@ struct compute_memory_pool
 
uint32_t *shadow; ///host copy of the pool, used for defragmentation
 
+   uint32_t status;/** Status of the pool */
+
struct list_head *item_list; ///Allocated memory chunks in the 
buffer,they must be ordered by start_in_dw
struct list_head *unallocated_list; ///Unallocated memory chunks
 };
-- 
2.0.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/5] r600g/compute: Add a function for defragmenting the pool

2014-07-16 Thread Bruno Jiménez
This new function will move items forward in the pool, so that
there's no gap between them, effectively defragmenting the pool.

For now this function is a bit dumb as it just moves items
forward without trying to see if other items in the pool could
fit in the gaps.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 25 +
 src/gallium/drivers/r600/compute_memory_pool.h |  3 +++
 2 files changed, 28 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 0b41318..00b28bc 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -302,6 +302,30 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
return 0;
 }
 
+/**
+ * Defragments the pool, so that there's no gap between items.
+ * \param pool The pool to be defragmented
+ */
+void compute_memory_defrag(struct compute_memory_pool *pool,
+   struct pipe_context *pipe)
+{
+   struct compute_memory_item *item;
+   int64_t last_pos;
+
+   COMPUTE_DBG(pool-screen, * compute_memory_defrag()\n);
+
+   last_pos = 0;
+   LIST_FOR_EACH_ENTRY(item, pool-item_list, link) {
+   if (item-start_in_dw != last_pos) {
+   assert(last_pos  item-start_in_dw);
+
+   compute_memory_move_item(pool, item, last_pos, pipe);
+   }
+
+   last_pos += align(item-size_in_dw, ITEM_ALIGNMENT);
+   }
+}
+
 int compute_memory_promote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe,
int64_t allocated)
@@ -417,6 +441,7 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
  *
  * \param item The item that will be moved
  * \param new_start_in_dw  The new position of the item in \a item_list
+ * \see compute_memory_defrag
  */
 void compute_memory_move_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, uint64_t new_start_in_dw,
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 7332010..5d18777 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -86,6 +86,9 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe);
 
+void compute_memory_defrag(struct compute_memory_pool *pool,
+   struct pipe_context *pipe);
+
 int compute_memory_promote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe,
int64_t allocated);
-- 
2.0.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 5/5] r600g/compute: Remove unneeded code from compute_memory_promote_item

2014-07-16 Thread Bruno Jiménez
Now that we know that the pool is defragmented, we positively know
that allocated + unallocated will be the total size of the
current pool plus all the items that will be promoted. So we only
need to grow the pool once.

This will allow us to just add the new items to the end of the
item_list without the need of looking for a place to the new item.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 46 ++
 src/gallium/drivers/r600/compute_memory_pool.h |  2 +-
 2 files changed, 12 insertions(+), 36 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 75a8bd3..04aaac9 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -239,6 +239,7 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
int64_t allocated = 0;
int64_t unallocated = 0;
+   int64_t last_pos;
 
int err = 0;
 
@@ -276,14 +277,18 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
return -1;
}
 
+   /* After defragmenting the pool, allocated is equal to the first 
available
+* position for new items in the pool */
+   last_pos = allocated;
+
/* Loop through all the unallocated items, check if they are marked
 * for promoting, allocate space for them and add them to the 
item_list. */
LIST_FOR_EACH_ENTRY_SAFE(item, next, pool-unallocated_list, link) {
if (item-status  ITEM_FOR_PROMOTING) {
-   err = compute_memory_promote_item(pool, item, pipe, 
allocated);
-   item-status ^= ITEM_FOR_PROMOTING;
+   err = compute_memory_promote_item(pool, item, pipe, 
last_pos);
+   item-status = ~ITEM_FOR_PROMOTING;
 
-   allocated += align(item-size_in_dw, ITEM_ALIGNMENT);
+   last_pos += align(item-size_in_dw, ITEM_ALIGNMENT);
 
if (err == -1)
return -1;
@@ -321,42 +326,14 @@ void compute_memory_defrag(struct compute_memory_pool 
*pool,
 
 int compute_memory_promote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe,
-   int64_t allocated)
+   int64_t start_in_dw)
 {
struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
struct r600_context *rctx = (struct r600_context *)pipe;
struct pipe_resource *src = (struct pipe_resource *)item-real_buffer;
-   struct pipe_resource *dst = NULL;
+   struct pipe_resource *dst = (struct pipe_resource *)pool-bo;
struct pipe_box box;
 
-   struct list_head *pos;
-   int64_t start_in_dw;
-   int err = 0;
-
-
-   /* Search for free space in the pool for this item. */
-   while ((start_in_dw=compute_memory_prealloc_chunk(pool,
-   item-size_in_dw)) == -1) {
-   int64_t need = item-size_in_dw + 2048 -
-   (pool-size_in_dw - allocated);
-
-   if (need = 0) {
-   /* There's enough free space, but it's too
-* fragmented. Assume half of the item can fit
-* int the last chunk */
-   need = (item-size_in_dw / 2) + ITEM_ALIGNMENT;
-   }
-
-   need = align(need, ITEM_ALIGNMENT);
-
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
-
-   if (err == -1)
-   return -1;
-   }
-   dst = (struct pipe_resource *)pool-bo;
COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
start_in_dw = %u (%u bytes) size_in_dw = %u (%u 
bytes)\n,
item, item-id, start_in_dw, start_in_dw * 4,
@@ -366,8 +343,7 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
list_del(item-link);
 
/* Add it back to the item_list */
-   pos = compute_memory_postalloc_chunk(pool, start_in_dw);
-   list_add(item-link, pos);
+   list_addtail(item-link, pool-item_list);
item-start_in_dw = start_in_dw;
 
if (src != NULL) {
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index acc68ea..5a1b33b 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -95,7 +95,7 @@ void compute_memory_defrag(struct compute_memory_pool *pool,
 
 int compute_memory_promote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe,
-   int64_t allocated);
+   int64_t start_in_dw);
 
 void 

[Mesa-dev] [PATCH 0/5] [RFC] r600g/compute: Adding support for defragmenting compute_memory_pool

2014-07-16 Thread Bruno Jiménez
Hi,

This series finally adds support for defragmenting the pool for
OpenCL buffers in the r600g driver. It is mostly a rewritten of
the series that I wrote some months ago.

For defragmenting the pool I have thought of two different
possibilities:

- Creating a new pool and moving every item here in the correct
position. This has the advantage of being very simple to
implement and that it allows the pool to be grown at the
same time. But it has a couple of problems, namely that it
has a high memory peak usage (sum of current pool + new pool)
and that in the case of having a pool not very fragmented you
have to copy every item to its new place.
- Using the same pool by moving the items in it. This has the
advantage of using less memory (sum of current pool + biggest
item in it) and that it is easier to handle the case of
only having few elements out of place. The disadvantages
are that it doesn't allow growing the pool at the same time
and that it may involve twice the number of item-copies in 
the worst case.

I have chosen to implement the second option, but if you think
that it is better the first one I can rewrite the series for it.
(^_^)

The worst case I have mentioned is this: Imagine that you have
a series of items in which the first is, at least, 1 'unit'
smaller than the rest. You now free this item and create a new
one with the same size [why would anyone do this? I don't know]
For now, the defragmenter code is so dumb that it will move
every item to the front of the pool without trying first to
put this new item in the available space.

Hopefully situations like this won't be very common.

If you want me to explain any detail about any of the patches
just ask. And as said, if you prefer the first version of the
defragmenter, just ask. [In fact, after having written this,
I may add it for the case grow+defrag]

Also, no regressions found in piglit.

Thanks in advance!
Bruno

Bruno Jiménez (5):
  r600g/compute: Add a function for moving items in the pool
  r600g/compute: Add a function for defragmenting the pool
  r600g/compute: Defrag the pool if it's necesary
  r600g/compute: Quick exit if there's nothing to add to the pool
  r600g/compute: Remove unneeded code from compute_memory_promote_item

 src/gallium/drivers/r600/compute_memory_pool.c | 196 ++---
 src/gallium/drivers/r600/compute_memory_pool.h |  13 +-
 2 files changed, 156 insertions(+), 53 deletions(-)

-- 
2.0.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 4/5] r600g/compute: Quick exit if there's nothing to add to the pool

2014-07-16 Thread Bruno Jiménez
This way we can avoid defragmenting the pool, even if it is needed
to defragment it, and looping again through the list of unallocated
items.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index b158f5e..75a8bd3 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -262,6 +262,10 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
+   if (unallocated == 0) {
+   return 0;
+   }
+
if (pool-status  POOL_FRAGMENTED) {
compute_memory_defrag(pool, pipe);
}
-- 
2.0.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev



[Mesa-dev] [PATCH 1/5] r600g/compute: Add a function for moving items in the pool

2014-07-16 Thread Bruno Jiménez
This function will be used in the future by compute_memory_defrag
to move items forward in the pool.

It does so by first checking for overlaping ranges, if the ranges
don't overlap it will copy the contents directly. If they overlap
it will try first to make a temporary buffer, if this buffer fails
to allocate, it will finally fall back to a mapping.

Note that it will only be needed to move items forward, it only
checks for overlapping ranges in that case. If needed, it can
easily be added by changing the first if.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 89 ++
 src/gallium/drivers/r600/compute_memory_pool.h |  4 ++
 2 files changed, 93 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index fe19d9e..0b41318 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -408,6 +408,95 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
item-start_in_dw = -1;
 }
 
+/**
+ * Moves the item \a item forward in the pool to \a new_start_in_dw
+ *
+ * This function assumes two things:
+ * 1) The item is \b only moved forward
+ * 2) The item \b won't change it's position inside the \a item_list
+ *
+ * \param item The item that will be moved
+ * \param new_start_in_dw  The new position of the item in \a item_list
+ */
+void compute_memory_move_item(struct compute_memory_pool *pool,
+   struct compute_memory_item *item, uint64_t new_start_in_dw,
+   struct pipe_context *pipe)
+{
+   struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
+   struct r600_context *rctx = (struct r600_context *)pipe;
+   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
+   struct pipe_resource *dst;
+   struct pipe_box box;
+
+   struct compute_memory_item *prev;
+
+   COMPUTE_DBG(pool-screen, * compute_memory_move_item()\n
+ + Moving item %i from %u (%u bytes) to %u (%u 
bytes)\n,
+   item-id, item-start_in_dw, item-start_in_dw * 4,
+   new_start_in_dw, new_start_in_dw * 4);
+
+   if (pool-item_list != item-link.prev) {
+   prev = container_of(item-link.prev, item, link);
+   assert(prev-start_in_dw + prev-size_in_dw = new_start_in_dw);
+   }
+
+   u_box_1d(item-start_in_dw * 4, item-size_in_dw * 4, box);
+
+   /* If the ranges don't overlap, we can just copy the item directly */
+   if (new_start_in_dw + item-size_in_dw = item-start_in_dw) {
+   dst = (struct pipe_resource *)pool-bo;
+
+   rctx-b.b.resource_copy_region(pipe,
+   dst, 0, new_start_in_dw * 4, 0, 0,
+   src, 0, box);
+   } else {
+   /* The ranges overlap, we will try first to use an intermediate
+* resource to move the item */
+   dst = (struct pipe_resource *)r600_compute_buffer_alloc_vram(
+   pool-screen, item-size_in_dw * 4);
+
+   if (dst != NULL) {
+   rctx-b.b.resource_copy_region(pipe,
+   dst, 0, 0, 0, 0,
+   src, 0, box);
+
+   src = dst;
+   dst = (struct pipe_resource *)pool-bo;
+
+   box.x = 0;
+
+   rctx-b.b.resource_copy_region(pipe,
+   dst, 0, new_start_in_dw * 4, 0, 0,
+   src, 0, box);
+
+   pool-screen-b.b.resource_destroy(screen, src);
+
+   } else {
+   /* The allocation of the temporary resource failed,
+* falling back to use mappings */
+   uint32_t *map;
+   int64_t offset;
+   struct pipe_transfer *trans;
+
+   offset = item-start_in_dw - new_start_in_dw;
+
+   u_box_1d(new_start_in_dw * 4, (offset + 
item-size_in_dw) * 4, box);
+
+   map = pipe-transfer_map(pipe, src, 0, 
PIPE_TRANSFER_READ_WRITE,
+   box, trans);
+
+   assert(map);
+   assert(trans);
+
+   memmove(map, map + offset, item-size_in_dw * 4);
+
+   pipe-transfer_unmap(pipe, trans);
+   }
+   }
+
+   item-start_in_dw = new_start_in_dw;
+}
+
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id)
 {
struct compute_memory_item *item, *next;
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 259474a..7332010 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -93,6 +93,10 @@ int 

[Mesa-dev] [PATCH v2 2/2] r600g/compute: Add debug information to promote and demote functions

2014-07-11 Thread Bruno Jiménez
v2: Add information about the item's starting point and size
---
 src/gallium/drivers/r600/compute_memory_pool.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 1d0ec85..6a525cf 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -339,6 +339,10 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
int64_t start_in_dw;
int err = 0;
 
+   COMPUTE_DBG(pool-screen, * compute_memory_promote_item()\n
+ + Promoting Item: %i , starting at: %u (%u bytes) 
+   size: %u (%u bytes)\n, item-id, item-start_in_dw,
+   item-start_in_dw * 4, item-size_in_dw, 
item-size_in_dw * 4);
 
/* Search for free space in the pool for this item. */
while ((start_in_dw=compute_memory_prealloc_chunk(pool,
@@ -409,6 +413,11 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
struct pipe_resource *dst;
struct pipe_box box;
 
+   COMPUTE_DBG(pool-screen, * compute_memory_demote_item()\n
+ + Demoting Item: %i, starting at: %u (%u bytes) 
+   size: %u (%u bytes)\n, item-id, item-start_in_dw,
+   item-start_in_dw * 4, item-size_in_dw, 
item-size_in_dw * 4);
+
/* First, we remove the item from the item_list */
list_del(item-link);
 
-- 
2.0.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/2] r600g/compute: Add debug information to promote and demote functions

2014-07-10 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 1d0ec85..6d47b1a 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -339,6 +339,8 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
int64_t start_in_dw;
int err = 0;
 
+   COMPUTE_DBG(pool-screen, * compute_memory_promote_item()\n
+ + Promoting Item: %i\n, item-id);
 
/* Search for free space in the pool for this item. */
while ((start_in_dw=compute_memory_prealloc_chunk(pool,
@@ -409,6 +411,9 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
struct pipe_resource *dst;
struct pipe_box box;
 
+   COMPUTE_DBG(pool-screen, * compute_memory_demote_item()\n
+ + Demoting Item: %i\n, item-id);
+
/* First, we remove the item from the item_list */
list_del(item-link);
 
-- 
2.0.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/2] r600g/compute: Add documentation to compute_memory_pool

2014-07-10 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 54 
 src/gallium/drivers/r600/compute_memory_pool.h | 58 --
 2 files changed, 83 insertions(+), 29 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index fe19d9e..1d0ec85 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -44,7 +44,7 @@
 
 #define ITEM_ALIGNMENT 1024
 /**
- * Creates a new pool
+ * Creates a new pool.
  */
 struct compute_memory_pool* compute_memory_pool_new(
struct r600_screen * rscreen)
@@ -66,6 +66,12 @@ struct compute_memory_pool* compute_memory_pool_new(
return pool;
 }
 
+/**
+ * Initializes the pool with a size of \a initial_size_in_dw.
+ * \param pool The pool to be initialized.
+ * \param initial_size_in_dw   The initial size.
+ * \see compute_memory_grow_pool
+ */
 static void compute_memory_pool_init(struct compute_memory_pool * pool,
unsigned initial_size_in_dw)
 {
@@ -83,7 +89,7 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
 }
 
 /**
- * Frees all stuff in the pool and the pool struct itself too
+ * Frees all stuff in the pool and the pool struct itself too.
  */
 void compute_memory_pool_delete(struct compute_memory_pool* pool)
 {
@@ -98,7 +104,10 @@ void compute_memory_pool_delete(struct compute_memory_pool* 
pool)
 
 /**
  * Searches for an empty space in the pool, return with the pointer to the
- * allocatable space in the pool, returns -1 on failure.
+ * allocatable space in the pool.
+ * \param size_in_dw   The size of the space we are looking for.
+ * \return -1 on failure
+ * \see compute_memory_promote_item
  */
 int64_t compute_memory_prealloc_chunk(
struct compute_memory_pool* pool,
@@ -130,6 +139,9 @@ int64_t compute_memory_prealloc_chunk(
 
 /**
  *  Search for the chunk where we can link our new chunk after it.
+ *  \param start_in_dw The position of the item we want to add to the pool.
+ *  \return The item that is just before the passed position
+ *  \see compute_memory_promote_item
  */
 struct list_head *compute_memory_postalloc_chunk(
struct compute_memory_pool* pool,
@@ -171,7 +183,8 @@ struct list_head *compute_memory_postalloc_chunk(
 
 /**
  * Reallocates pool, conserves data.
- * @returns -1 if it fails, 0 otherwise
+ * \returns -1 if it fails, 0 otherwise
+ * \see compute_memory_finalize_pending and compute_memory_promote_item
  */
 int compute_memory_grow_pool(struct compute_memory_pool* pool,
struct pipe_context * pipe, int new_size_in_dw)
@@ -212,6 +225,8 @@ int compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
 /**
  * Copy pool from device to host, or host to device.
+ * \param device_to_host 1 for device-host, 0 for host-device
+ * \see compute_memory_grow_pool
  */
 void compute_memory_shadow(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host)
@@ -229,8 +244,10 @@ void compute_memory_shadow(struct compute_memory_pool* 
pool,
 }
 
 /**
- * Allocates pending allocations in the pool
- * @returns -1 if it fails, 0 otherwise
+ * Moves all the items marked for promotion from the \a unallocated_list
+ * to the \a item_list.
+ * \return -1 if it fails, 0 otherwise
+ * \see evergreen_set_global_binding
  */
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
@@ -302,6 +319,12 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
return 0;
 }
 
+/**
+ * Moves an item from the \a unallocated_list to the \a item_list.
+ * \param item The item that will be promoted.
+ * \return -1 if it fails, 0 otherwise
+ * \see compute_memory_finalize_pending
+ */
 int compute_memory_promote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe,
int64_t allocated)
@@ -373,6 +396,11 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
return 0;
 }
 
+/**
+ * Moves an item from the \a item_list to the \a unallocated_list.
+ * \param item The item that will be demoted
+ * \see r600_compute_global_transfer_map
+ */
 void compute_memory_demote_item(struct compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe)
 {
@@ -408,6 +436,10 @@ void compute_memory_demote_item(struct compute_memory_pool 
*pool,
item-start_in_dw = -1;
 }
 
+/**
+ * Frees the memory asociated to the item with id \a id from the pool.
+ * \param id   The id of the item to be freed.
+ */
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id)
 {
struct compute_memory_item *item, *next;
@@ -457,7 +489,11 @@ void compute_memory_free(struct compute_memory_pool* pool, 
int64_t id)
 }
 
 /**
- * Creates pending allocations
+ * Creates pending allocations for new items, these items 

[Mesa-dev] [PATCH] r600g/compute: Try to use a temporary resource when growing the pool

2014-07-07 Thread Bruno Jiménez
Now, before moving everything to host memory, we try to create a
new resource to use as a pool. I we succeed we just use this resource
and delete the previous one. If we fail we fallback to using the
shadow.

This should make growing the pool faster, and we can also save
64KB of memory that were allocated for the 'shadow', even if they
weren't used.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 61 ++
 1 file changed, 43 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index fe19d9e..db6d937 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -73,10 +73,6 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
COMPUTE_DBG(pool-screen, * compute_memory_pool_init() 
initial_size_in_dw = %ld\n,
initial_size_in_dw);
 
-   pool-shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
-   if (pool-shadow == NULL)
-   return;
-
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
pool-size_in_dw * 4);
@@ -184,27 +180,56 @@ int compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
if (!pool-bo) {
compute_memory_pool_init(pool, MAX2(new_size_in_dw, 1024 * 16));
-   if (pool-shadow == NULL)
-   return -1;
} else {
+   struct r600_resource *temp = NULL;
+
new_size_in_dw = align(new_size_in_dw, ITEM_ALIGNMENT);
 
COMPUTE_DBG(pool-screen,   Aligned size = %d (%d bytes)\n,
new_size_in_dw, new_size_in_dw * 4);
 
-   compute_memory_shadow(pool, pipe, 1);
-   pool-shadow = realloc(pool-shadow, new_size_in_dw*4);
-   if (pool-shadow == NULL)
-   return -1;
+   temp = (struct r600_resource *)r600_compute_buffer_alloc_vram(
+   pool-screen, 
new_size_in_dw * 4);
 
-   pool-size_in_dw = new_size_in_dw;
-   pool-screen-b.b.resource_destroy(
-   (struct pipe_screen *)pool-screen,
-   (struct pipe_resource *)pool-bo);
-   pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(
-   pool-screen,
-   pool-size_in_dw * 4);
-   compute_memory_shadow(pool, pipe, 0);
+   if (temp != NULL) {
+   struct r600_context *rctx = (struct r600_context *)pipe;
+   struct pipe_resource *src = (struct pipe_resource 
*)pool-bo;
+   struct pipe_resource *dst = (struct pipe_resource 
*)temp;
+   struct pipe_box box;
+
+   COMPUTE_DBG(pool-screen,   Growing the pool using a 
temporary resource\n);
+
+   u_box_1d(0, pool-size_in_dw * 4, box);
+
+   rctx-b.b.resource_copy_region(pipe,
+   dst, 0, 0, 0 ,0,
+   src, 0, box);
+
+   pool-screen-b.b.resource_destroy(
+   (struct pipe_screen *)pool-screen,
+   src);
+
+   pool-bo = temp;
+   pool-size_in_dw = new_size_in_dw;
+   }
+   else {
+   COMPUTE_DBG(pool-screen,   The creation of the 
temporary resource failed\n
+ Falling back to using 'shadow'\n);
+
+   compute_memory_shadow(pool, pipe, 1);
+   pool-shadow = realloc(pool-shadow, new_size_in_dw * 
4);
+   if (pool-shadow == NULL)
+   return -1;
+
+   pool-size_in_dw = new_size_in_dw;
+   pool-screen-b.b.resource_destroy(
+   (struct pipe_screen *)pool-screen,
+   (struct pipe_resource *)pool-bo);
+   pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(
+   pool-screen,
+   pool-size_in_dw * 4);
+   compute_memory_shadow(pool, pipe, 0);
+   }
}
 
return 0;
-- 
2.0.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 12/12] r600g/compute: Defer the creation of the temporary resource

2014-06-19 Thread Bruno Jiménez
For the first use of a buffer, we will only need the temporary
resource in the case that a user wants to write/map to this buffer.

But in the cases where the user creates a buffer to act as an
output of a kernel, then we were creating an unneeded resource,
because it will contain garbage, and would be copied to the pool,
and destroyed when promoting.

This patch avoids the creation and copies of resources in
this case.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 31 +-
 src/gallium/drivers/r600/evergreen_compute.c   | 17 +-
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index a78ff1e..7540f14 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -352,19 +352,21 @@ int compute_memory_promote_item(struct 
compute_memory_pool *pool,
list_add(item-link, pos);
item-start_in_dw = start_in_dw;
 
-   u_box_1d(0, item-size_in_dw * 4, box);
-
-   rctx-b.b.resource_copy_region(pipe,
-   dst, 0, item-start_in_dw * 4, 0 ,0,
-   src, 0, box);
-
-   /* We check if the item is mapped for reading.
-* In this case, we need to keep the temporary buffer 'alive'
-* because it is possible to keep a map active for reading
-* while a kernel (that reads from it) executes */
-   if (!(item-status  ITEM_MAPPED_FOR_READING)) {
-   pool-screen-b.b.resource_destroy(screen, src);
-   item-real_buffer = NULL;
+   if (src != NULL) {
+   u_box_1d(0, item-size_in_dw * 4, box);
+
+   rctx-b.b.resource_copy_region(pipe,
+   dst, 0, item-start_in_dw * 4, 0 ,0,
+   src, 0, box);
+
+   /* We check if the item is mapped for reading.
+* In this case, we need to keep the temporary buffer 'alive'
+* because it is possible to keep a map active for reading
+* while a kernel (that reads from it) executes */
+   if (!(item-status  ITEM_MAPPED_FOR_READING)) {
+   pool-screen-b.b.resource_destroy(screen, src);
+   item-real_buffer = NULL;
+   }
}
 
return 0;
@@ -474,8 +476,7 @@ struct compute_memory_item* compute_memory_alloc(
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
new_item-pool = pool;
-   new_item-real_buffer = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(
-   pool-screen, 
size_in_dw * 4);
+   new_item-real_buffer = NULL;
 
list_addtail(new_item-link, pool-unallocated_list);
 
diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index 5c115dc..12e9c85 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -970,14 +970,21 @@ void *r600_compute_global_transfer_map(
struct r600_resource_global* buffer =
(struct r600_resource_global*)resource;
 
-   struct pipe_resource *dst;
+   struct compute_memory_item *item = buffer-chunk;
+   struct pipe_resource *dst = NULL;
unsigned offset = box-x;
 
-   if (is_item_in_pool(buffer-chunk)) {
-   compute_memory_demote_item(pool, buffer-chunk, ctx_);
+   if (is_item_in_pool(item)) {
+   compute_memory_demote_item(pool, item, ctx_);
+   }
+   else {
+   if (item-real_buffer == NULL) {
+   item-real_buffer = (struct r600_resource*)
+   
r600_compute_buffer_alloc_vram(pool-screen, item-size_in_dw * 4);
+   }
}
 
-   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
+   dst = (struct pipe_resource*)item-real_buffer;
 
if (usage  PIPE_TRANSFER_READ)
buffer-chunk-status |= ITEM_MAPPED_FOR_READING;
@@ -988,7 +995,7 @@ void *r600_compute_global_transfer_map(
box-x, box-y, box-z, box-width, box-height,
box-depth);
COMPUTE_DBG(rctx-screen, Buffer id = %u offset = 
-   %u (box.x)\n, buffer-chunk-id, box-x);
+   %u (box.x)\n, item-id, box-x);
 
 
assert(resource-target == PIPE_BUFFER);
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 10/12] r600g/compute: Fix possible endless loop in compute_memory_pool allocations.

2014-06-19 Thread Bruno Jiménez
From: Jan Vesely jan.ves...@rutgers.edu

The important part is the change of the condition to = 0. Otherwise the loop
gets stuck never actually growing the pool.

The change in the aux-need calculation guarantees max 2 iterations, and
avoids wasting memory in case a smaller item can't fit into a relatively larger
pool.

Signed-off-by: Jan Vesely jan.ves...@rutgers.edu
CC: Bruno Jimenez brunoji...@gmail.com
---
 src/gallium/drivers/r600/compute_memory_pool.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 518ea65..a78ff1e 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -323,8 +323,11 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
int64_t need = item-size_in_dw + 2048 -
(pool-size_in_dw - allocated);
 
-   if (need  0) {
-   need = pool-size_in_dw / 10;
+   if (need = 0) {
+   /* There's enough free space, but it's too
+* fragmented. Assume half of the item can fit
+* int the last chunk */
+   need = (item-size_in_dw / 2) + ITEM_ALIGNMENT;
}
 
need = align(need, ITEM_ALIGNMENT);
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 11/12] r600g/compute: Handle failures in compute_memory_pool_finalize

2014-06-19 Thread Bruno Jiménez
From: Jan Vesely jan.ves...@rutgers.edu

Signed-off-by: Jan Vesely jan.ves...@rutgers.edu
CC: Bruno Jimenez brunoji...@gmail.com
---
 src/gallium/drivers/r600/evergreen_compute.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index c0dd0f3..5c115dc 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -668,7 +668,10 @@ static void evergreen_set_global_binding(
buffers[i]-chunk-status |= ITEM_FOR_PROMOTING;
}
 
-   compute_memory_finalize_pending(pool, ctx_);
+   if (compute_memory_finalize_pending(pool, ctx_) == -1) {
+   /* XXX: Unset */
+   return;
+   }
 
for (int i = 0; i  n; i++)
{
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 09/11] r600g/compute: Use gallium util functions for double lists

2014-06-18 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 147 +++--
 src/gallium/drivers/r600/compute_memory_pool.h |  10 +-
 2 files changed, 46 insertions(+), 111 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 6409b34..518ea65 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -57,6 +57,12 @@ struct compute_memory_pool* compute_memory_pool_new(
COMPUTE_DBG(rscreen, * compute_memory_pool_new()\n);
 
pool-screen = rscreen;
+   pool-item_list = (struct list_head *)
+   CALLOC(sizeof(struct list_head), 1);
+   pool-unallocated_list = (struct list_head *)
+   CALLOC(sizeof(struct list_head), 1);
+   list_inithead(pool-item_list);
+   list_inithead(pool-unallocated_list);
return pool;
 }
 
@@ -107,7 +113,7 @@ int64_t compute_memory_prealloc_chunk(
COMPUTE_DBG(pool-screen, * compute_memory_prealloc_chunk() size_in_dw 
= %ld\n,
size_in_dw);
 
-   for (item = pool-item_list; item; item = item-next) {
+   LIST_FOR_EACH_ENTRY(item, pool-item_list, link) {
if (last_end + size_in_dw = item-start_in_dw) {
return last_end;
}
@@ -125,31 +131,37 @@ int64_t compute_memory_prealloc_chunk(
 /**
  *  Search for the chunk where we can link our new chunk after it.
  */
-struct compute_memory_item* compute_memory_postalloc_chunk(
+struct list_head *compute_memory_postalloc_chunk(
struct compute_memory_pool* pool,
int64_t start_in_dw)
 {
-   struct compute_memory_item* item;
+   struct compute_memory_item *item;
+   struct compute_memory_item *next;
+   struct list_head *next_link;
 
COMPUTE_DBG(pool-screen, * compute_memory_postalloc_chunck() 
start_in_dw = %ld\n,
start_in_dw);
 
/* Check if we can insert it in the front of the list */
-   if (pool-item_list  pool-item_list-start_in_dw  start_in_dw) {
-   return NULL;
+   item = LIST_ENTRY(struct compute_memory_item, pool-item_list-next, 
link);
+   if (LIST_IS_EMPTY(pool-item_list) || item-start_in_dw  start_in_dw) {
+   return pool-item_list;
}
 
-   for (item = pool-item_list; item; item = item-next) {
-   if (item-next) {
+   LIST_FOR_EACH_ENTRY(item, pool-item_list, link) {
+   next_link = item-link.next;
+
+   if (next_link != pool-item_list) {
+   next = container_of(next_link, item, link);
if (item-start_in_dw  start_in_dw
-item-next-start_in_dw  start_in_dw) {
-   return item;
+next-start_in_dw  start_in_dw) {
+   return item-link;
}
}
else {
/* end of chain */
assert(item-start_in_dw  start_in_dw);
-   return item;
+   return item-link;
}
}
 
@@ -212,7 +224,6 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
chunk.id = 0;
chunk.start_in_dw = 0;
chunk.size_in_dw = pool-size_in_dw;
-   chunk.prev = chunk.next = NULL;
compute_memory_transfer(pool, pipe, device_to_host, chunk,
pool-shadow, 0, pool-size_in_dw*4);
 }
@@ -233,22 +244,20 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
 
-   for (item = pool-item_list; item; item = item-next) {
+   LIST_FOR_EACH_ENTRY(item, pool-item_list, link) {
COMPUTE_DBG(pool-screen,   + list: offset = %i id = %i size = 
%i 
(%i bytes)\n,item-start_in_dw, item-id,
item-size_in_dw, item-size_in_dw * 4);
}
 
/* Calculate the total allocated size */
-   for (item = pool-item_list; item; item = next) {
-   next = item-next;
+   LIST_FOR_EACH_ENTRY(item, pool-item_list, link) {
allocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
/* Calculate the total unallocated size of the items that
 * will be promoted to the pool */
-   for (item = pool-unallocated_list; item; item = next) {
-   next = item-next;
+   LIST_FOR_EACH_ENTRY(item, pool-unallocated_list, link) {
if (item-status  ITEM_FOR_PROMOTING)
unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
@@ -278,9 +287,7 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
/* Loop through all the unallocated items, check if they are marked
 * 

[Mesa-dev] [PATCH 02/11] r600g/compute: Add an util function to know if an item is in the pool

2014-06-18 Thread Bruno Jiménez
Every item that has been placed in the pool must have start_in_dw
different from -1.
---
 src/gallium/drivers/r600/compute_memory_pool.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index e94159c..d8201c4 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -59,6 +59,11 @@ struct compute_memory_pool
 };
 
 
+static inline int is_item_in_pool(struct compute_memory_item *item)
+{
+   return item-start_in_dw != -1;
+}
+
 struct compute_memory_pool* compute_memory_pool_new(struct r600_screen 
*rscreen); ///Creates a new pool
 void compute_memory_pool_delete(struct compute_memory_pool* pool); ///Frees 
all stuff in the pool and the pool struct itself too
 
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 05/11] r600g/compute: Only move to the pool the buffers marked for promoting

2014-06-18 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 146 +++--
 src/gallium/drivers/r600/compute_memory_pool.h |   5 +
 2 files changed, 91 insertions(+), 60 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 96769e5..5b1ee14 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -229,8 +229,6 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
int64_t allocated = 0;
int64_t unallocated = 0;
 
-   int64_t start_in_dw = 0;
-
int err = 0;
 
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
@@ -247,10 +245,12 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
allocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
-   /* Calculate the total unallocated size */
+   /* Calculate the total unallocated size of the items that
+* will be promoted to the pool */
for (item = pool-unallocated_list; item; item = next) {
next = item-next;
-   unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
+   if (item-status  ITEM_FOR_PROMOTING)
+   unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
/* If we require more space than the size of the pool, then grow the
@@ -276,87 +276,113 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
return -1;
}
 
-   /* Loop through all the unallocated items, allocate space for them
-* and add them to the item_list. */
+   /* Loop through all the unallocated items, check if they are marked
+* for promoting, allocate space for them and add them to the 
item_list. */
for (item = pool-unallocated_list; item; item = next) {
next = item-next;
 
-   struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
-   struct r600_context *rctx = (struct r600_context *)pipe;
-   struct pipe_resource *dst = (struct pipe_resource *)pool-bo;
-   struct pipe_resource *src = (struct pipe_resource 
*)item-real_buffer;
-   struct pipe_box box;
+   if (item-status  ITEM_FOR_PROMOTING) {
+   err = compute_memory_promote_item(pool, item, pipe, 
allocated);
+   item-status ^= ITEM_FOR_PROMOTING;
 
-   u_box_1d(0, item-size_in_dw * 4, box);
+   allocated += align(item-size_in_dw, ITEM_ALIGNMENT);
 
-   /* Search for free space in the pool for this item. */
-   while ((start_in_dw=compute_memory_prealloc_chunk(pool,
-   item-size_in_dw)) == -1) {
-   int64_t need = item-size_in_dw+2048 -
-   (pool-size_in_dw - allocated);
+   if (err == -1)
+   return -1;
+   }
+   }
 
-   if (need  0) {
-   need = pool-size_in_dw / 10;
-   }
+   return 0;
+}
+
+int compute_memory_promote_item(struct compute_memory_pool *pool,
+   struct compute_memory_item *item, struct pipe_context *pipe,
+   int64_t allocated)
+{
+   struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
+   struct r600_context *rctx = (struct r600_context *)pipe;
+   struct pipe_resource *dst = (struct pipe_resource *)pool-bo;
+   struct pipe_resource *src = (struct pipe_resource *)item-real_buffer;
+   struct pipe_box box;
 
-   need = align(need, ITEM_ALIGNMENT);
+   int64_t start_in_dw;
+   int err = 0;
 
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
 
-   if (err == -1)
-   return -1;
+   /* Search for free space in the pool for this item. */
+   while ((start_in_dw=compute_memory_prealloc_chunk(pool,
+   item-size_in_dw)) == -1) {
+   int64_t need = item-size_in_dw + 2048 -
+   (pool-size_in_dw - allocated);
+
+   if (need  0) {
+   need = pool-size_in_dw / 10;
}
-   COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
+
+   need = align(need, ITEM_ALIGNMENT);
+
+   err = compute_memory_grow_pool(pool,
+   pipe,
+   pool-size_in_dw + need);
+
+   if (err == -1)
+   return -1;
+   }
+   COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
 

[Mesa-dev] [PATCH 10/11] r600g/compute: Map directly the pool in some cases

2014-06-18 Thread Bruno Jiménez
All the *Enqueue* functions that read/write buffers (except
clEnqueueCopyBuffer) would map the associated resource, making
it to be demoted if it was in the pool.

But we possitively know that this transfer will end before
any kernel is launched, so there's no need to demote it.
---
 src/gallium/drivers/r600/evergreen_compute.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index c0dd0f3..2d6b9d3 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -967,18 +967,28 @@ void *r600_compute_global_transfer_map(
struct r600_resource_global* buffer =
(struct r600_resource_global*)resource;
 
-   struct pipe_resource *dst;
+   struct pipe_resource *dst =
+   (struct pipe_resource *) buffer-chunk-real_buffer;
unsigned offset = box-x;
 
+   /* If the item is already in the pool, and we are going
+* to read/write it, map it directly without demoting it */
if (is_item_in_pool(buffer-chunk)) {
-   compute_memory_demote_item(pool, buffer-chunk, ctx_);
+   if (usage  PIPE_TRANSFER_MAP_DIRECTLY) {
+   dst = (struct pipe_resource *) buffer-chunk-pool-bo;
+   offset += (buffer-chunk-start_in_dw * 4);
+   }
+   else {
+   compute_memory_demote_item(pool, buffer-chunk, ctx_);
+   dst = (struct pipe_resource *) 
buffer-chunk-real_buffer;
+   }
}
 
-   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
-
-   if (usage  PIPE_TRANSFER_READ)
+   if ((usage  PIPE_TRANSFER_READ)  !(usage  
PIPE_TRANSFER_MAP_DIRECTLY))
buffer-chunk-status |= ITEM_MAPPED_FOR_READING;
 
+   usage = ~PIPE_TRANSFER_MAP_DIRECTLY;
+
COMPUTE_DBG(rctx-screen, * r600_compute_global_transfer_map()\n
level = %u, usage = %u, box(x = %u, y = %u, z = %u 
width = %u, height = %u, depth = %u)\n, level, usage,
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 07/11] r600g/compute: Implement compute_memory_demote_item

2014-06-18 Thread Bruno Jiménez
This function will be used when we want to map an item
that it's already in the pool.

v2: Use temporary variables to avoid so many castings in functions,
as suggested by Tom Stellard
---
 src/gallium/drivers/r600/compute_memory_pool.c | 51 ++
 src/gallium/drivers/r600/compute_memory_pool.h |  3 ++
 2 files changed, 54 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index f232f9f..6409b34 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -387,6 +387,57 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
return 0;
 }
 
+void compute_memory_demote_item(struct compute_memory_pool *pool,
+   struct compute_memory_item *item, struct pipe_context *pipe)
+{
+   struct r600_context *rctx = (struct r600_context *)pipe;
+   struct pipe_resource *src = (struct pipe_resource *)pool-bo;
+   struct pipe_resource *dst;
+   struct pipe_box box;
+
+   /* First, we remove the item from the item_list */
+   if (item-prev == NULL)
+   pool-item_list = item-next;
+   else
+   item-prev-next = item-next;
+
+   if (item-next != NULL)
+   item-next-prev = item-prev;
+
+
+   /* Now we add it to the beginning of the unallocated list
+* NOTE: we could also add it to the end, but this is easier */
+   item-next = NULL;
+   item-prev = NULL;
+   if (pool-unallocated_list) {
+   item-next = pool-unallocated_list;
+   item-next-prev = item;
+   pool-unallocated_list = item;
+   }
+   else
+   pool-unallocated_list = item;
+
+   /* We check if the intermediate buffer exists, and if it
+* doesn't, we create it again */
+   if (item-real_buffer == NULL) {
+   item-real_buffer = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(
+   pool-screen, item-size_in_dw * 4);
+   }
+
+   dst = (struct pipe_resource *)item-real_buffer;
+
+   /* We transfer the memory from the item in the pool to the
+* temporary buffer */
+   u_box_1d(item-start_in_dw * 4, item-size_in_dw * 4, box);
+
+   rctx-b.b.resource_copy_region(pipe,
+   dst, 0, 0, 0, 0,
+   src, 0, box);
+
+   /* Remember to mark the buffer as 'pending' by setting start_in_dw to 
-1 */
+   item-start_in_dw = -1;
+}
+
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id)
 {
struct compute_memory_item *item, *next;
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index faadeea..0bb695c 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -90,6 +90,9 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
struct compute_memory_item *item, struct pipe_context *pipe,
int64_t allocated);
 
+void compute_memory_demote_item(struct compute_memory_pool *pool,
+   struct compute_memory_item *item, struct pipe_context *pipe);
+
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id);
 struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* 
pool, int64_t size_in_dw); ///Creates pending allocations
 
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 04/11] r600g/compute: divide the item list in two

2014-06-18 Thread Bruno Jiménez
Now we will have a list with the items that are in the pool
(item_list) and the items that are outside it (unallocated_list)
---
 src/gallium/drivers/r600/compute_memory_pool.c | 99 +-
 src/gallium/drivers/r600/compute_memory_pool.h |  1 +
 2 files changed, 49 insertions(+), 51 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 0b126a8..96769e5 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -108,13 +108,11 @@ int64_t compute_memory_prealloc_chunk(
size_in_dw);
 
for (item = pool-item_list; item; item = item-next) {
-   if (item-start_in_dw  -1) {
-   if (last_end + size_in_dw = item-start_in_dw) {
-   return last_end;
-   }
-
-   last_end = item-start_in_dw + align(item-size_in_dw, 
ITEM_ALIGNMENT);
+   if (last_end + size_in_dw = item-start_in_dw) {
+   return last_end;
}
+
+   last_end = item-start_in_dw + align(item-size_in_dw, 
ITEM_ALIGNMENT);
}
 
if (pool-size_in_dw - last_end  size_in_dw) {
@@ -226,7 +224,6 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
 {
-   struct compute_memory_item *pending_list = NULL, *end_p = NULL;
struct compute_memory_item *item, *next;
 
int64_t allocated = 0;
@@ -244,45 +241,16 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
item-size_in_dw, item-size_in_dw * 4);
}
 
-   /* Search through the list of memory items in the pool */
+   /* Calculate the total allocated size */
for (item = pool-item_list; item; item = next) {
next = item-next;
+   allocated += align(item-size_in_dw, ITEM_ALIGNMENT);
+   }
 
-   /* Check if the item is pending. */
-   if (item-start_in_dw == -1) {
-   /* It is pending, so add it to the pending_list... */
-   if (end_p) {
-   end_p-next = item;
-   }
-   else {
-   pending_list = item;
-   }
-
-   /* ... and then remove it from the item list. */
-   if (item-prev) {
-   item-prev-next = next;
-   }
-   else {
-   pool-item_list = next;
-   }
-
-   if (next) {
-   next-prev = item-prev;
-   }
-
-   /* This sequence makes the item be at the end of the 
list */
-   item-prev = end_p;
-   item-next = NULL;
-   end_p = item;
-
-   /* Update the amount of space we will need to allocate. 
*/
-   unallocated += item-size_in_dw+1024;
-   }
-   else {
-   /* The item is not pending, so update the amount of 
space
-* that has already been allocated. */
-   allocated += item-size_in_dw;
-   }
+   /* Calculate the total unallocated size */
+   for (item = pool-unallocated_list; item; item = next) {
+   next = item-next;
+   unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
/* If we require more space than the size of the pool, then grow the
@@ -302,15 +270,15 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 * In this case, there are 300 units of free space in the pool, but
 * they aren't contiguous, so it will be impossible to allocate Item D.
 */
-   if (pool-size_in_dw  allocated+unallocated) {
-   err = compute_memory_grow_pool(pool, pipe, 
allocated+unallocated);
+   if (pool-size_in_dw  allocated + unallocated) {
+   err = compute_memory_grow_pool(pool, pipe, allocated + 
unallocated);
if (err == -1)
return -1;
}
 
-   /* Loop through all the pending items, allocate space for them and
-* add them back to the item_list. */
-   for (item = pending_list; item; item = next) {
+   /* Loop through all the unallocated items, allocate space for them
+* and add them to the item_list. */
+   for (item = pool-unallocated_list; item; item = next) {
next = item-next;
 
struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
@@ -383,6 +351,8 @@ int compute_memory_finalize_pending(struct 

[Mesa-dev] [PATCH 06/11] r600g/compute: Avoid problems when promoting items mapped for reading

2014-06-18 Thread Bruno Jiménez
Acording to the OpenCL spec, it is possible to have a buffer mapped
for reading and at read from it using commands or buffers.

With this we can keep the mapping (that exists against the
temporary item) and read with a kernel (from the item we have
just added to the pool) without problems.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 5b1ee14..f232f9f 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -375,10 +375,14 @@ int compute_memory_promote_item(struct 
compute_memory_pool *pool,
dst, 0, item-start_in_dw * 4, 0 ,0,
src, 0, box);
 
-   pool-screen-b.b.resource_destroy(
-   screen, src);
-
-   item-real_buffer = NULL;
+   /* We check if the item is mapped for reading.
+* In this case, we need to keep the temporary buffer 'alive'
+* because it is possible to keep a map active for reading
+* while a kernel (that reads from it) executes */
+   if (!(item-status  ITEM_MAPPED_FOR_READING)) {
+   pool-screen-b.b.resource_destroy(screen, src);
+   item-real_buffer = NULL;
+   }
 
return 0;
 }
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 11/11] clover: Use PIPE_TRANSFER_MAP_DIRECTLY when writing/reading buffers

2014-06-18 Thread Bruno Jiménez
Note: This is just a proof of concept.
---
 src/gallium/state_trackers/clover/api/transfer.cpp  | 4 ++--
 src/gallium/state_trackers/clover/core/object.hpp   | 4 
 src/gallium/state_trackers/clover/core/resource.cpp | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp 
b/src/gallium/state_trackers/clover/api/transfer.cpp
index 404ceb0..f34ae8b 100644
--- a/src/gallium/state_trackers/clover/api/transfer.cpp
+++ b/src/gallium/state_trackers/clover/api/transfer.cpp
@@ -174,8 +174,8 @@ namespace {
   static mapping
   get(command_queue q, T obj, cl_map_flags flags,
   size_t offset, size_t size) {
- return { q, obj-resource(q), flags, true,
-  {{ offset }}, {{ size, 1, 1 }} };
+ return { q, obj-resource(q), flags | CLOVER_TRANSFER_MAP_DIRECTLY,
+  true, {{ offset }}, {{ size, 1, 1 }} };
   }
};
 
diff --git a/src/gallium/state_trackers/clover/core/object.hpp 
b/src/gallium/state_trackers/clover/core/object.hpp
index 697565c..7d5adf9 100644
--- a/src/gallium/state_trackers/clover/core/object.hpp
+++ b/src/gallium/state_trackers/clover/core/object.hpp
@@ -33,6 +33,10 @@
 #include core/property.hpp
 #include api/dispatch.hpp
 
+#ifndef CLOVER_TRANSFER_MAP_DIRECTLY
+#define CLOVER_TRANSFER_MAP_DIRECTLY (18)
+#endif
+
 ///
 /// Main namespace of the CL state tracker.
 ///
diff --git a/src/gallium/state_trackers/clover/core/resource.cpp 
b/src/gallium/state_trackers/clover/core/resource.cpp
index 7b8a40a..c8e97db 100644
--- a/src/gallium/state_trackers/clover/core/resource.cpp
+++ b/src/gallium/state_trackers/clover/core/resource.cpp
@@ -174,6 +174,8 @@ mapping::mapping(command_queue q, resource r,
pctx(q.pipe) {
unsigned usage = ((flags  CL_MAP_WRITE ? PIPE_TRANSFER_WRITE : 0 ) |
  (flags  CL_MAP_READ ? PIPE_TRANSFER_READ : 0 ) |
+ (flags  CLOVER_TRANSFER_MAP_DIRECTLY ?
+  PIPE_TRANSFER_MAP_DIRECTLY : 0 ) |
  (!blocking ? PIPE_TRANSFER_UNSYNCHRONIZED : 0));
 
p = pctx-transfer_map(pctx, r.pipe, 0, usage,
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 08/11] r600g/compute: Map only against intermediate buffers

2014-06-18 Thread Bruno Jiménez
With this we can assure that mapped buffers will never change
its position when relocating the pool.

This patch should finally solve the mapping bug.

v2: Use the new is_item_in_pool util function,
as suggested by Tom Stellard
---
 src/gallium/drivers/r600/evergreen_compute.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index 8657071..c0dd0f3 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -970,14 +970,12 @@ void *r600_compute_global_transfer_map(
struct pipe_resource *dst;
unsigned offset = box-x;
 
-   if (buffer-chunk-real_buffer) {
-   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
-   }
-   else {
-   dst = (struct pipe_resource*)buffer-chunk-pool-bo;
-   offset += (buffer-chunk-start_in_dw * 4);
+   if (is_item_in_pool(buffer-chunk)) {
+   compute_memory_demote_item(pool, buffer-chunk, ctx_);
}
 
+   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
+
if (usage  PIPE_TRANSFER_READ)
buffer-chunk-status |= ITEM_MAPPED_FOR_READING;
 
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 00/11] [RFC v2] Solve the mapping bug

2014-06-18 Thread Bruno Jiménez
Hi,

This is my second attempt to fix the mapping bug adding all the
suggestions that Tom Stellard sent, and, so far, it seems that
it is resolved.

This series changes completely how OpenCL buffers are handled
by the r600g driver. Before this, we would add them directly to
a pool, and this pool would grow whenever we needed more space.
But this process implied destroying the pool and creating a new
one. There could be cases where a buffer would be mapped and
the pool would grow, leaving one side of the mapping pointed
to where the item was. This is the 'mapping bug'

Now, Items will have an intermediate resource, where all mappings
can be done, and when a buffer is going to be used with a kernel
it is promoted to the pool. In the case where a promoted item
is going to be mapped, it is previously demoted, so even if
the pool changes its location due to growing, the map remains
valid. In the case of a buffer mapped for reading, and used
by a kernel to read from it, we will duplicate this buffer,
having the intermediate buffer, where the user has its map, and
an item in the pool, which is the one that the kernel is going
to use.

As a summary for v2:
Patches 1-8: These are the main part of the series, and solve
the mapping bug.
Patches 1 and 7 now use less explicit castings
Patch 2 is new and introduces the 'is_item_in_pool'
function, which is used in patches 3 and 8

Patch 9: Is a complete rewrite of v1 patch 8 using gallium
utils for double lists

Patches 10 and 11: These are just a proof of concept for avoiding
transfers GPU - GPU when using all CL Read/Write functions.
They are v1 patch 9 splited in two to separate r600g changes
from clover changes.
Now, in clover's side it introduces and uses
'CLOVER_TRANSFER_MAP_DIRECTLY' so it doesen't collide with
any other OpenCL flag.

Please review and Thanks :)

Bruno Jiménez (11):
  r600g/compute: Add an intermediate resource for OpenCL buffers
  r600g/compute: Add an util function to know if an item is in the pool
  r600g/compute: Add statuses to the compute_memory_items
  r600g/compute: divide the item list in two
  r600g/compute: Only move to the pool the buffers marked for promoting
  r600g/compute: Avoid problems when promoting items mapped for reading
  r600g/compute: Implement compute_memory_demote_item
  r600g/compute: Map only against intermediate buffers
  r600g/compute: Use gallium util functions for double lists
  r600g/compute: Map directly the pool in some cases
  clover: Use PIPE_TRANSFER_MAP_DIRECTLY when writing/reading buffers

 src/gallium/drivers/r600/compute_memory_pool.c | 294 -
 src/gallium/drivers/r600/compute_memory_pool.h |  31 ++-
 src/gallium/drivers/r600/evergreen_compute.c   |  38 ++-
 src/gallium/state_trackers/clover/api/transfer.cpp |   4 +-
 src/gallium/state_trackers/clover/core/object.hpp  |   4 +
 .../state_trackers/clover/core/resource.cpp|   2 +
 6 files changed, 233 insertions(+), 140 deletions(-)

-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 01/11] r600g/compute: Add an intermediate resource for OpenCL buffers

2014-06-18 Thread Bruno Jiménez
This patch changes completely the way buffers are added to the
compute_memory_pool. Before this, whenever we were going to
map a buffer or write to or read from it, it would get placed
into the pool. Now, every unallocated buffer has its own
r600_resource until it is allocated in the pool.

NOTE: This patch also increase the GPU memory usage at the moment
of putting every buffer in it's place. More or less, the memory
usage is ~2x(sum of every buffer size)

v2: Cleanup

v3: Use temporary variables to avoid so many castings in functions,
as suggested by Tom Stellard
---
 src/gallium/drivers/r600/compute_memory_pool.c | 27 +-
 src/gallium/drivers/r600/compute_memory_pool.h |  2 ++
 src/gallium/drivers/r600/evergreen_compute.c   | 18 -
 3 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index ec8c470..0b126a8 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -71,7 +71,6 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
if (pool-shadow == NULL)
return;
 
-   pool-next_id = 1;
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
pool-size_in_dw * 4);
@@ -314,6 +313,14 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
for (item = pending_list; item; item = next) {
next = item-next;
 
+   struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
+   struct r600_context *rctx = (struct r600_context *)pipe;
+   struct pipe_resource *dst = (struct pipe_resource *)pool-bo;
+   struct pipe_resource *src = (struct pipe_resource 
*)item-real_buffer;
+   struct pipe_box box;
+
+   u_box_1d(0, item-size_in_dw * 4, box);
+
/* Search for free space in the pool for this item. */
while ((start_in_dw=compute_memory_prealloc_chunk(pool,
item-size_in_dw)) == -1) {
@@ -365,6 +372,14 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
pool-item_list = item;
}
 
+   rctx-b.b.resource_copy_region(pipe,
+   dst, 0, item-start_in_dw * 4, 0 ,0,
+   src, 0, box);
+
+   pool-screen-b.b.resource_destroy(
+   screen, src);
+   item-real_buffer = NULL;
+
allocated += item-size_in_dw;
}
 
@@ -375,6 +390,8 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id)
 {
struct compute_memory_item *item, *next;
+   struct pipe_screen *screen = (struct pipe_screen *)pool-screen;
+   struct pipe_resource *res;
 
COMPUTE_DBG(pool-screen, * compute_memory_free() id + %ld \n, id);
 
@@ -393,6 +410,12 @@ void compute_memory_free(struct compute_memory_pool* pool, 
int64_t id)
item-next-prev = item-prev;
}
 
+   if (item-real_buffer) {
+   res = (struct pipe_resource *)item-real_buffer;
+   pool-screen-b.b.resource_destroy(
+   screen, res);
+   }
+
free(item);
 
return;
@@ -426,6 +449,8 @@ struct compute_memory_item* compute_memory_alloc(
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
new_item-pool = pool;
+   new_item-real_buffer = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(
+   pool-screen, 
size_in_dw * 4);
 
if (pool-item_list) {
for (last_item = pool-item_list; last_item-next;
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index c711c59..e94159c 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -38,6 +38,8 @@ struct compute_memory_item
int64_t start_in_dw; ///Start pointer in dwords relative in the pool bo
int64_t size_in_dw; ///Size of the chunk in dwords
 
+   struct r600_resource *real_buffer;
+
struct compute_memory_pool* pool;
 
struct compute_memory_item* prev;
diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index a2abf15..c152e54 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ 

[Mesa-dev] [PATCH 03/11] r600g/compute: Add statuses to the compute_memory_items

2014-06-18 Thread Bruno Jiménez
These statuses will help track whether the items are mapped
or if they should be promoted to or demoted from the pool

v2: Use the new is_item_in_pool util function,
as suggested by Tom Stellard
---
 src/gallium/drivers/r600/compute_memory_pool.h |  7 ++-
 src/gallium/drivers/r600/evergreen_compute.c   | 12 
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index d8201c4..cd93a19 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -27,13 +27,18 @@
 
 #include stdlib.h
 
+#define ITEM_MAPPED_FOR_READING (10)
+#define ITEM_MAPPED_FOR_WRITING (11)
+#define ITEM_FOR_PROMOTING  (12)
+#define ITEM_FOR_DEMOTING   (13)
+
 struct compute_memory_pool;
 
 struct compute_memory_item
 {
int64_t id; ///ID of the memory chunk
 
-   int untouched; ///True if the memory contains only junk, no need to 
save it for defrag
+   uint32_t status; ///Will track the status of the item
 
int64_t start_in_dw; ///Start pointer in dwords relative in the pool bo
int64_t size_in_dw; ///Size of the chunk in dwords
diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index c152e54..8657071 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -659,6 +659,15 @@ static void evergreen_set_global_binding(
return;
}
 
+   /* We mark these items for promotion to the pool if they
+* aren't already there */
+   for (int i = 0; i  n; i++) {
+   struct compute_memory_item *item = buffers[i]-chunk;
+
+   if (!is_item_in_pool(item))
+   buffers[i]-chunk-status |= ITEM_FOR_PROMOTING;
+   }
+
compute_memory_finalize_pending(pool, ctx_);
 
for (int i = 0; i  n; i++)
@@ -969,6 +978,9 @@ void *r600_compute_global_transfer_map(
offset += (buffer-chunk-start_in_dw * 4);
}
 
+   if (usage  PIPE_TRANSFER_READ)
+   buffer-chunk-status |= ITEM_MAPPED_FOR_READING;
+
COMPUTE_DBG(rctx-screen, * r600_compute_global_transfer_map()\n
level = %u, usage = %u, box(x = %u, y = %u, z = %u 
width = %u, height = %u, depth = %u)\n, level, usage,
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/3] radeon/compute: Implement PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS

2014-06-13 Thread Bruno Jiménez
v2:
Add RADEON_INFO_ACTIVE_CU_COUNT as a define, as suggested by
Tom Stellard
---
 src/gallium/drivers/radeon/r600_pipe_common.c | 7 +++
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 7 +++
 src/gallium/winsys/radeon/drm/radeon_winsys.h | 1 +
 3 files changed, 15 insertions(+)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c 
b/src/gallium/drivers/radeon/r600_pipe_common.c
index 70c4d1a..e7d33a0 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -519,6 +519,13 @@ static int r600_get_compute_param(struct pipe_screen 
*screen,
}
return sizeof(uint32_t);
 
+   case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
+   if (ret) {
+   uint32_t *max_compute_units = ret;
+   *max_compute_units = rscreen-info.max_compute_units;
+   }
+   return sizeof(uint32_t);
+
default:
fprintf(stderr, unknown PIPE_COMPUTE_CAP %d\n, param);
return 0;
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c 
b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index e54e79e..576fea5 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -45,6 +45,10 @@
 #include sys/stat.h
 #include unistd.h
 
+#ifndef RADEON_INFO_ACTIVE_CU_COUNT
+#define RADEON_INFO_ACTIVE_CU_COUNT 0x20
+#endif
+
 static struct util_hash_table *fd_tab = NULL;
 pipe_static_mutex(fd_tab_mutex);
 
@@ -382,6 +386,9 @@ static boolean do_winsys_init(struct radeon_drm_winsys *ws)
 radeon_get_drm_value(ws-fd, RADEON_INFO_MAX_PIPES, NULL,
  ws-info.r600_max_pipes);
 
+radeon_get_drm_value(ws-fd, RADEON_INFO_ACTIVE_CU_COUNT, NULL,
+ ws-info.max_compute_units);
+
 if (radeon_get_drm_value(ws-fd, RADEON_INFO_SI_TILE_MODE_ARRAY, NULL,
  ws-info.si_tile_mode_array)) {
 ws-info.si_tile_mode_array_valid = TRUE;
diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h 
b/src/gallium/winsys/radeon/drm/radeon_winsys.h
index 2d13550..6df1987 100644
--- a/src/gallium/winsys/radeon/drm/radeon_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h
@@ -198,6 +198,7 @@ struct radeon_info {
 uint32_tgart_size;
 uint32_tvram_size;
 uint32_tmax_sclk;
+uint32_tmax_compute_units;
 
 uint32_tdrm_major; /* version */
 uint32_tdrm_minor;
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 5/9] r600g/compute: avoid problems when promoting items mapped for reading

2014-06-13 Thread Bruno Jiménez
Acording to the OpenCL spec, it is possible to have a buffer mapped
for reading and at read from it using commands or buffers.

With this we can keep the mapping (that exists against the
temporary item) and read with a kernel (from the item we have
just added to the pool) without problems.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 1da4609..e1f9c88 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -369,10 +369,16 @@ int compute_memory_promote_item(struct 
compute_memory_pool *pool,
0, (struct pipe_box) {.width = item-size_in_dw * 4,
.height = 1, .depth = 1});
 
-   pool-screen-b.b.resource_destroy(
-   (struct pipe_screen *)pool-screen,
-   (struct pipe_resource *)item-real_buffer);
-   item-real_buffer = NULL;
+   /* We check if the item is mapped for reading.
+* In this case, we need to keep the temporary buffer 'alive'
+* because it is possible to keep a map active for reading
+* while a kernel (that reads from it) executes */
+   if (!(item-status  ITEM_MAPPED_FOR_READING)) {
+   pool-screen-b.b.resource_destroy(
+   (struct pipe_screen *)pool-screen,
+   (struct pipe_resource *)item-real_buffer);
+   item-real_buffer = NULL;
+   }
 
return 0;
 }
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/9] r600g/compute: Add an intermediate resource for OpenCL buffers

2014-06-13 Thread Bruno Jiménez
This patch changes completely the way buffers are added to the
compute_memory_pool. Before this, whenever we were going to
map a buffer or write to or read from it, it would get placed
into the pool. Now, every unallocated buffer has its own
r600_resource until it is allocated in the pool.

NOTE: This patch also increase the GPU memory usage at the moment
of putting every buffer in it's place. More or less, the memory
usage is ~2x(sum of every buffer size)

v2: Cleanup
---
 src/gallium/drivers/r600/compute_memory_pool.c | 21 -
 src/gallium/drivers/r600/compute_memory_pool.h |  2 ++
 src/gallium/drivers/r600/evergreen_compute.c   | 18 +-
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index ec8c470..94ddcde 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -71,7 +71,6 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
if (pool-shadow == NULL)
return;
 
-   pool-next_id = 1;
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
pool-size_in_dw * 4);
@@ -365,6 +364,18 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
pool-item_list = item;
}
 
+   ((struct r600_context *)pipe)-b.b.resource_copy_region(pipe,
+   (struct pipe_resource *)pool-bo,
+   0, item-start_in_dw * 4, 0 ,0,
+   (struct pipe_resource *)item-real_buffer,
+   0, (struct pipe_box) {.width = 
item-size_in_dw * 4,
+   .height = 1, .depth = 1});
+
+   pool-screen-b.b.resource_destroy(
+   (struct pipe_screen *)pool-screen,
+   (struct pipe_resource *)item-real_buffer);
+   item-real_buffer = NULL;
+
allocated += item-size_in_dw;
}
 
@@ -393,6 +404,12 @@ void compute_memory_free(struct compute_memory_pool* pool, 
int64_t id)
item-next-prev = item-prev;
}
 
+   if (item-real_buffer) {
+   pool-screen-b.b.resource_destroy(
+   (struct pipe_screen 
*)pool-screen,
+   (struct pipe_resource 
*)item-real_buffer);
+   }
+
free(item);
 
return;
@@ -426,6 +443,8 @@ struct compute_memory_item* compute_memory_alloc(
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
new_item-pool = pool;
+   new_item-real_buffer = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(
+   pool-screen, 
size_in_dw * 4);
 
if (pool-item_list) {
for (last_item = pool-item_list; last_item-next;
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index c711c59..e94159c 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -38,6 +38,8 @@ struct compute_memory_item
int64_t start_in_dw; ///Start pointer in dwords relative in the pool bo
int64_t size_in_dw; ///Size of the chunk in dwords
 
+   struct r600_resource *real_buffer;
+
struct compute_memory_pool* pool;
 
struct compute_memory_item* prev;
diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index a2abf15..c152e54 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -958,6 +958,17 @@ void *r600_compute_global_transfer_map(
struct r600_resource_global* buffer =
(struct r600_resource_global*)resource;
 
+   struct pipe_resource *dst;
+   unsigned offset = box-x;
+
+   if (buffer-chunk-real_buffer) {
+   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
+   }
+   else {
+   dst = (struct pipe_resource*)buffer-chunk-pool-bo;
+   offset += (buffer-chunk-start_in_dw * 4);
+   }
+
COMPUTE_DBG(rctx-screen, * r600_compute_global_transfer_map()\n
level = %u, usage = %u, box(x = %u, y = %u, z = %u 
width = %u, height = %u, depth = %u)\n, level, usage,
@@ -967,8 +978,6 @@ void *r600_compute_global_transfer_map(
%u (box.x)\n, buffer-chunk-id, box-x);
 
 
-   compute_memory_finalize_pending(pool, ctx_);
-
assert(resource-target 

[Mesa-dev] [PATCH 3/9] r600g/compute: divide the item list in two

2014-06-13 Thread Bruno Jiménez
Now we will have a list with the items that are in the pool
(item_list) and the items that are outside it (unallocated_list)
---
 src/gallium/drivers/r600/compute_memory_pool.c | 99 +-
 src/gallium/drivers/r600/compute_memory_pool.h |  1 +
 2 files changed, 49 insertions(+), 51 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 94ddcde..5a5ef12 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -108,13 +108,11 @@ int64_t compute_memory_prealloc_chunk(
size_in_dw);
 
for (item = pool-item_list; item; item = item-next) {
-   if (item-start_in_dw  -1) {
-   if (last_end + size_in_dw = item-start_in_dw) {
-   return last_end;
-   }
-
-   last_end = item-start_in_dw + align(item-size_in_dw, 
ITEM_ALIGNMENT);
+   if (last_end + size_in_dw = item-start_in_dw) {
+   return last_end;
}
+
+   last_end = item-start_in_dw + align(item-size_in_dw, 
ITEM_ALIGNMENT);
}
 
if (pool-size_in_dw - last_end  size_in_dw) {
@@ -226,7 +224,6 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
 {
-   struct compute_memory_item *pending_list = NULL, *end_p = NULL;
struct compute_memory_item *item, *next;
 
int64_t allocated = 0;
@@ -244,45 +241,16 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
item-size_in_dw, item-size_in_dw * 4);
}
 
-   /* Search through the list of memory items in the pool */
+   /* Calculate the total allocated size */
for (item = pool-item_list; item; item = next) {
next = item-next;
+   allocated += align(item-size_in_dw, ITEM_ALIGNMENT);
+   }
 
-   /* Check if the item is pending. */
-   if (item-start_in_dw == -1) {
-   /* It is pending, so add it to the pending_list... */
-   if (end_p) {
-   end_p-next = item;
-   }
-   else {
-   pending_list = item;
-   }
-
-   /* ... and then remove it from the item list. */
-   if (item-prev) {
-   item-prev-next = next;
-   }
-   else {
-   pool-item_list = next;
-   }
-
-   if (next) {
-   next-prev = item-prev;
-   }
-
-   /* This sequence makes the item be at the end of the 
list */
-   item-prev = end_p;
-   item-next = NULL;
-   end_p = item;
-
-   /* Update the amount of space we will need to allocate. 
*/
-   unallocated += item-size_in_dw+1024;
-   }
-   else {
-   /* The item is not pending, so update the amount of 
space
-* that has already been allocated. */
-   allocated += item-size_in_dw;
-   }
+   /* Calculate the total unallocated size */
+   for (item = pool-unallocated_list; item; item = next) {
+   next = item-next;
+   unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
/* If we require more space than the size of the pool, then grow the
@@ -302,15 +270,15 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 * In this case, there are 300 units of free space in the pool, but
 * they aren't contiguous, so it will be impossible to allocate Item D.
 */
-   if (pool-size_in_dw  allocated+unallocated) {
-   err = compute_memory_grow_pool(pool, pipe, 
allocated+unallocated);
+   if (pool-size_in_dw  allocated + unallocated) {
+   err = compute_memory_grow_pool(pool, pipe, allocated + 
unallocated);
if (err == -1)
return -1;
}
 
-   /* Loop through all the pending items, allocate space for them and
-* add them back to the item_list. */
-   for (item = pending_list; item; item = next) {
+   /* Loop through all the unallocated items, allocate space for them
+* and add them to the item_list. */
+   for (item = pool-unallocated_list; item; item = next) {
next = item-next;
 
/* Search for free space in the pool for this item. */
@@ -379,6 +347,8 @@ int compute_memory_finalize_pending(struct 

[Mesa-dev] [PATCH 0/9] [RFC] Solve the mapping bug

2014-06-13 Thread Bruno Jiménez
Hi,

This is my latest attempt to fix the mapping bug and, so far,
it seems that it is resolved.

This series changes completely how OpenCL buffers are handled
by the r600g driver. Before this, we would add them directly to
a pool, and this pool would grow whenever we needed more space.
But this process implied destroying the pool and creating a new
one. There could be cases where a buffer would be mapped and
the pool would grow, leaving one side of the mapping pointed
to where the item was. This is the 'mapping bug'

Now, Items will have an intermediate resource, where all mappings
can be done, and when a buffer is going to be used with a kernel
it is promoted to the pool. In the case where a promoted item
is going to be mapped, it is previously demoted, so even if
the pool changes its location due to growing, the map remains
valid. In the case of a buffer mapped for reading, and used
by a kernel to read from it, we will duplicate this buffer,
having the intermediate buffer, where the user has its map, and
an item in the pool, which is the one that the kernel is going
to use.

As a summary:
Patches 1-7: These are the main part of the series, and solve
the mapping bug.
Patch 8: Introduces some utils for managing the pool's lists

Patch 9: This is just a proof of concept for avoiding transfers
GPU - GPU when using all CL Read/Write functions.
In fact, it CAN'T land as it is because PIPE_TRANSFER_MAP_DIRECTLY
collides with CL_MAP_WRITE_INVALIDATE_REGION

Please review and Thanks :)

Bruno Jiménez (9):
  r600g/compute: Add an intermediate resource for OpenCL buffers
  r600g/compute: Add statuses to the compute_memory_items
  r600g/compute: divide the item list in two
  r600g/compute: only move to the pool the buffers marked for promoting
  r600g/compute: avoid problems when promoting items mapped for reading
  r600g/compute: implement compute_memory_demote_item
  r600g/compute: map only against intermediate buffers
  r600g/compute: add util functions to add and remove items from lists
  r600g/compute: avoid demoting items when reading/writing

 src/gallium/drivers/r600/compute_memory_pool.c | 313 +
 src/gallium/drivers/r600/compute_memory_pool.h |  18 +-
 src/gallium/drivers/r600/evergreen_compute.c   |  38 ++-
 src/gallium/state_trackers/clover/api/transfer.cpp |   4 +-
 .../state_trackers/clover/core/resource.cpp|   2 +
 5 files changed, 255 insertions(+), 120 deletions(-)

-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 8/9] r600g/compute: add util functions to add and remove items from lists

2014-06-13 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 158 -
 1 file changed, 78 insertions(+), 80 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 624b50d..26b9f98 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -43,6 +43,73 @@
 #include inttypes.h
 
 #define ITEM_ALIGNMENT 1024
+
+static inline void list_add_item_front(struct compute_memory_item **list,
+struct compute_memory_item *item)
+{
+   if (*list != NULL) {
+   item-next = *list;
+   (*list)-prev = item;
+   }
+   else {
+   item-next = NULL;
+   }
+
+   *list = item;
+   item-prev = NULL;
+}
+
+static inline void list_add_item_tail(struct compute_memory_item **list,
+struct compute_memory_item *item)
+{
+   struct compute_memory_item *last_item = NULL;
+
+   if (*list != NULL) {
+   for (last_item = *list; last_item-next != NULL; last_item = 
last_item-next);
+
+   last_item-next = item;
+   item-prev = last_item;
+   }
+   else {
+   *list = item;
+   item-prev = NULL;
+   }
+
+   item-next = NULL;
+}
+
+static inline void list_add_item_after(struct compute_memory_item **list,
+   struct compute_memory_item *item, struct compute_memory_item 
*pos)
+{
+   if (pos == NULL) {
+   list_add_item_front(list, item);
+   }
+   else {
+   if (pos-next != NULL) {
+   pos-next-prev = item;
+   }
+
+   item-prev = pos;
+   item-next = pos-next;
+   pos-next = item;
+   }
+}
+
+static inline void list_remove_item(struct compute_memory_item **list,
+   struct compute_memory_item *item)
+{
+   if (item-prev == NULL) {
+   *list = item-next;
+   }
+   else {
+   item-prev-next = item-next;
+   }
+
+   if (item-next != NULL) {
+   item-next-prev = item-prev;
+   }
+}
+
 /**
  * Creates a new pool
  */
@@ -299,6 +366,7 @@ int compute_memory_promote_item(struct compute_memory_pool 
*pool,
struct compute_memory_item *item, struct pipe_context *pipe,
int64_t allocated)
 {
+   struct compute_memory_item *pos;
int64_t start_in_dw;
int err = 0;
 
@@ -327,40 +395,12 @@ int compute_memory_promote_item(struct 
compute_memory_pool *pool,
item-size_in_dw, item-size_in_dw * 4);
 
/* Remove the item from the unallocated list */
-   if (item-prev == NULL)
-   pool-unallocated_list = item-next;
-   else
-   item-prev-next = item-next;
-
-   if (item-next != NULL)
-   item-next-prev = item-prev;
+   list_remove_item(pool-unallocated_list, item);
 
+   /* Add it back to the item_list */
+   pos = compute_memory_postalloc_chunk(pool, start_in_dw);
+   list_add_item_after(pool-item_list, item, pos);
item-start_in_dw = start_in_dw;
-   item-next = NULL;
-   item-prev = NULL;
-
-   if (pool-item_list) {
-   struct compute_memory_item *pos;
-
-   pos = compute_memory_postalloc_chunk(pool, start_in_dw);
-   if (pos) {
-   item-prev = pos;
-   item-next = pos-next;
-   pos-next = item;
-   if (item-next) {
-   item-next-prev = item;
-   }
-   } else {
-   /* Add item to the front of the list */
-   item-next = pool-item_list;
-   item-prev = pool-item_list-prev;
-   pool-item_list-prev = item;
-   pool-item_list = item;
-   }
-   }
-   else {
-   pool-item_list = item;
-   }
 
((struct r600_context *)pipe)-b.b.resource_copy_region(pipe,
(struct pipe_resource *)pool-bo,
@@ -387,26 +427,11 @@ void compute_memory_demote_item(struct 
compute_memory_pool *pool,
struct compute_memory_item *item, struct pipe_context *pipe)
 {
/* First, we remove the item from the item_list */
-   if (item-prev == NULL)
-   pool-item_list = item-next;
-   else
-   item-prev-next = item-next;
-
-   if (item-next != NULL)
-   item-next-prev = item-prev;
-
+   list_remove_item(pool-item_list, item);
 
/* Now we add it to the beginning of the unallocated list
 * NOTE: we could also add it to the end, but this is easier */
-   item-next = NULL;
-   item-prev = NULL;
-   if (pool-unallocated_list) {
-   item-next = pool-unallocated_list;
-   item-next-prev = item;
-   

[Mesa-dev] [PATCH 9/9] r600g/compute: avoid demoting items when reading/writing

2014-06-13 Thread Bruno Jiménez
All the *Enqueue* functions that read/write buffers (except
clEnqueueCopyBuffer) would map the associated resource, making
it to be demoted if it was in the pool.

But we possitively know that this transfer will end before
any kernel is launched, so there's no need to demote it.

NOTE: As a proof of concept I have used PIPE_TRANSFER_MAP_DIRECTLY,
but it collides with OpenCL 1.2 CL_MAP_WRITE_INVALIDATE_REGION,
so we will have to find another bitfield to use.
---
 src/gallium/drivers/r600/evergreen_compute.c| 20 +++-
 src/gallium/state_trackers/clover/api/transfer.cpp  |  4 ++--
 src/gallium/state_trackers/clover/core/resource.cpp |  2 ++
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index e5967b5..794cbe6 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -967,18 +967,28 @@ void *r600_compute_global_transfer_map(
struct r600_resource_global* buffer =
(struct r600_resource_global*)resource;
 
-   struct pipe_resource *dst;
+   struct pipe_resource *dst =
+   (struct pipe_resource *) buffer-chunk-real_buffer;
unsigned offset = box-x;
 
+   /* If the item is already in the pool, and we are going
+* to read/write it, map it directly without demoting it */
if (buffer-chunk-start_in_dw != -1) {
-   compute_memory_demote_item(pool, buffer-chunk, ctx_);
+   if (usage  PIPE_TRANSFER_MAP_DIRECTLY) {
+   dst = (struct pipe_resource *) buffer-chunk-pool-bo;
+   offset += (buffer-chunk-start_in_dw * 4);
+   }
+   else {
+   compute_memory_demote_item(pool, buffer-chunk, ctx_);
+   dst = (struct pipe_resource *) 
buffer-chunk-real_buffer;
+   }
}
 
-   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
-
-   if (usage  PIPE_TRANSFER_READ)
+   if ((usage  PIPE_TRANSFER_READ)  !(usage  
PIPE_TRANSFER_MAP_DIRECTLY))
buffer-chunk-status |= ITEM_MAPPED_FOR_READING;
 
+   usage = ~PIPE_TRANSFER_MAP_DIRECTLY;
+
COMPUTE_DBG(rctx-screen, * r600_compute_global_transfer_map()\n
level = %u, usage = %u, box(x = %u, y = %u, z = %u 
width = %u, height = %u, depth = %u)\n, level, usage,
diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp 
b/src/gallium/state_trackers/clover/api/transfer.cpp
index 404ceb0..032542e 100644
--- a/src/gallium/state_trackers/clover/api/transfer.cpp
+++ b/src/gallium/state_trackers/clover/api/transfer.cpp
@@ -174,8 +174,8 @@ namespace {
   static mapping
   get(command_queue q, T obj, cl_map_flags flags,
   size_t offset, size_t size) {
- return { q, obj-resource(q), flags, true,
-  {{ offset }}, {{ size, 1, 1 }} };
+ return { q, obj-resource(q), flags | PIPE_TRANSFER_MAP_DIRECTLY,
+  true, {{ offset }}, {{ size, 1, 1 }} };
   }
};
 
diff --git a/src/gallium/state_trackers/clover/core/resource.cpp 
b/src/gallium/state_trackers/clover/core/resource.cpp
index 7b8a40a..bda9847 100644
--- a/src/gallium/state_trackers/clover/core/resource.cpp
+++ b/src/gallium/state_trackers/clover/core/resource.cpp
@@ -174,6 +174,8 @@ mapping::mapping(command_queue q, resource r,
pctx(q.pipe) {
unsigned usage = ((flags  CL_MAP_WRITE ? PIPE_TRANSFER_WRITE : 0 ) |
  (flags  CL_MAP_READ ? PIPE_TRANSFER_READ : 0 ) |
+ (flags  PIPE_TRANSFER_MAP_DIRECTLY ?
+  PIPE_TRANSFER_MAP_DIRECTLY : 0 ) |
  (!blocking ? PIPE_TRANSFER_UNSYNCHRONIZED : 0));
 
p = pctx-transfer_map(pctx, r.pipe, 0, usage,
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/9] r600g/compute: Add statuses to the compute_memory_items

2014-06-13 Thread Bruno Jiménez
These statuses will help track whether the items are mapped
or if they should be promoted to or demoted from the pool
---
 src/gallium/drivers/r600/compute_memory_pool.h |  7 ++-
 src/gallium/drivers/r600/evergreen_compute.c   | 12 
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index e94159c..166093d 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -27,13 +27,18 @@
 
 #include stdlib.h
 
+#define ITEM_MAPPED_FOR_READING (10)
+#define ITEM_MAPPED_FOR_WRITING (11)
+#define ITEM_FOR_PROMOTING  (12)
+#define ITEM_FOR_DEMOTING   (13)
+
 struct compute_memory_pool;
 
 struct compute_memory_item
 {
int64_t id; ///ID of the memory chunk
 
-   int untouched; ///True if the memory contains only junk, no need to 
save it for defrag
+   uint32_t status; ///Will track the status of the item
 
int64_t start_in_dw; ///Start pointer in dwords relative in the pool bo
int64_t size_in_dw; ///Size of the chunk in dwords
diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index c152e54..9123a40 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -659,6 +659,15 @@ static void evergreen_set_global_binding(
return;
}
 
+   /* We mark these items for promotion to the pool if they
+* aren't already there */
+   for (int i = 0; i  n; i++) {
+   struct compute_memory_item *item = buffers[i]-chunk;
+
+   if (item-start_in_dw == -1)
+   buffers[i]-chunk-status |= ITEM_FOR_PROMOTING;
+   }
+
compute_memory_finalize_pending(pool, ctx_);
 
for (int i = 0; i  n; i++)
@@ -969,6 +978,9 @@ void *r600_compute_global_transfer_map(
offset += (buffer-chunk-start_in_dw * 4);
}
 
+   if (usage  PIPE_TRANSFER_READ)
+   buffer-chunk-status |= ITEM_MAPPED_FOR_READING;
+
COMPUTE_DBG(rctx-screen, * r600_compute_global_transfer_map()\n
level = %u, usage = %u, box(x = %u, y = %u, z = %u 
width = %u, height = %u, depth = %u)\n, level, usage,
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 4/9] r600g/compute: only move to the pool the buffers marked for promoting

2014-06-13 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 140 +++--
 src/gallium/drivers/r600/compute_memory_pool.h |   5 +
 2 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 5a5ef12..1da4609 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -229,8 +229,6 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
int64_t allocated = 0;
int64_t unallocated = 0;
 
-   int64_t start_in_dw = 0;
-
int err = 0;
 
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
@@ -247,10 +245,12 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
allocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
-   /* Calculate the total unallocated size */
+   /* Calculate the total unallocated size of the items that
+* will be promoted to the pool */
for (item = pool-unallocated_list; item; item = next) {
next = item-next;
-   unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
+   if (item-status  ITEM_FOR_PROMOTING)
+   unallocated += align(item-size_in_dw, ITEM_ALIGNMENT);
}
 
/* If we require more space than the size of the pool, then grow the
@@ -276,83 +276,107 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
return -1;
}
 
-   /* Loop through all the unallocated items, allocate space for them
-* and add them to the item_list. */
+   /* Loop through all the unallocated items, check if they are marked
+* for promoting, allocate space for them and add them to the 
item_list. */
for (item = pool-unallocated_list; item; item = next) {
next = item-next;
 
-   /* Search for free space in the pool for this item. */
-   while ((start_in_dw=compute_memory_prealloc_chunk(pool,
-   item-size_in_dw)) == -1) {
-   int64_t need = item-size_in_dw+2048 -
-   (pool-size_in_dw - allocated);
-
-   if (need  0) {
-   need = pool-size_in_dw / 10;
-   }
+   if (item-status  ITEM_FOR_PROMOTING) {
+   err = compute_memory_promote_item(pool, item, pipe, 
allocated);
+   item-status ^= ITEM_FOR_PROMOTING;
 
-   need = align(need, ITEM_ALIGNMENT);
-
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
+   allocated += align(item-size_in_dw, ITEM_ALIGNMENT);
 
if (err == -1)
return -1;
}
-   COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
+   }
+
+   return 0;
+}
+
+int compute_memory_promote_item(struct compute_memory_pool *pool,
+   struct compute_memory_item *item, struct pipe_context *pipe,
+   int64_t allocated)
+{
+   int64_t start_in_dw;
+   int err = 0;
+
+   /* Search for free space in the pool for this item. */
+   while ((start_in_dw=compute_memory_prealloc_chunk(pool,
+   item-size_in_dw)) == -1) {
+   int64_t need = item-size_in_dw + 2048 -
+   (pool-size_in_dw - allocated);
+
+   if (need  0) {
+   need = pool-size_in_dw / 10;
+   }
+
+   need = align(need, ITEM_ALIGNMENT);
+
+   err = compute_memory_grow_pool(pool,
+   pipe,
+   pool-size_in_dw + need);
+
+   if (err == -1)
+   return -1;
+   }
+   COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
start_in_dw = %u (%u bytes) size_in_dw = %u (%u 
bytes)\n,
item, item-id, start_in_dw, start_in_dw * 4,
item-size_in_dw, item-size_in_dw * 4);
 
-   item-start_in_dw = start_in_dw;
-   item-next = NULL;
-   item-prev = NULL;
-
-   if (pool-item_list) {
-   struct compute_memory_item *pos;
-
-   pos = compute_memory_postalloc_chunk(pool, start_in_dw);
-   if (pos) {
-   item-prev = pos;
-   item-next = pos-next;
-   pos-next = item;
-   if (item-next) {
-   item-next-prev = item;

[Mesa-dev] [PATCH 7/9] r600g/compute: map only against intermediate buffers

2014-06-13 Thread Bruno Jiménez
With this we can assure that mapped buffers will never change
its position when relocating the pool.

This patch should finally solve the mapping bug.
---
 src/gallium/drivers/r600/evergreen_compute.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index 9123a40..e5967b5 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -970,14 +970,12 @@ void *r600_compute_global_transfer_map(
struct pipe_resource *dst;
unsigned offset = box-x;
 
-   if (buffer-chunk-real_buffer) {
-   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
-   }
-   else {
-   dst = (struct pipe_resource*)buffer-chunk-pool-bo;
-   offset += (buffer-chunk-start_in_dw * 4);
+   if (buffer-chunk-start_in_dw != -1) {
+   compute_memory_demote_item(pool, buffer-chunk, ctx_);
}
 
+   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
+
if (usage  PIPE_TRANSFER_READ)
buffer-chunk-status |= ITEM_MAPPED_FOR_READING;
 
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] r600g/compute: solve a bug introduced by 2e01b8b440c1402c88a2755d89f40292e1f36ce5

2014-06-11 Thread Bruno Jiménez
That commit made possible that the items could be one just
after the other when their size was a multiple of ITEM_ALIGNMENT.
But compute_memory_prealloc_chunk still looked to leave a gap
between items. Resulting in that we got an infinite loop when
trying to add an item which would left no space between itself and
the next item.

Fixes piglit test: cl-custom-r600-create-release-buffer-bug
And the test for alignment I have just sent:
http://lists.freedesktop.org/archives/piglit/2014-June/011135.html

Sorry about this.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 2050f28..ec8c470 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -110,7 +110,7 @@ int64_t compute_memory_prealloc_chunk(
 
for (item = pool-item_list; item; item = item-next) {
if (item-start_in_dw  -1) {
-   if (item-start_in_dw-last_end  size_in_dw) {
+   if (last_end + size_in_dw = item-start_in_dw) {
return last_end;
}
 
-- 
2.0.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] r600g/compute: solve the mapping bug

2014-05-30 Thread Bruno Jiménez
This patch changes completely the way buffers are added to the
compute_memory_pool. Before this, whenever we were going to
map a buffer or write to or read from it, it would get placed
into the pool. Now, every unallocated buffer has its own
r600_resource until it is allocated in the pool.

This allows us to ensure that the position of the buffers won't
change until a kernel is launched, and by that time, every buffer
must have been unmaped (if not, the OpenCL 1.1 spec says that
the behaviour is undefined)

NOTE: This patch also increase the GPU memory usage at the moment
of putting every buffer in it's place. More or less, the memory
usage is ~2x(sum of every buffer size)

v2: Cleanup
---
 src/gallium/drivers/r600/compute_memory_pool.c | 21 -
 src/gallium/drivers/r600/compute_memory_pool.h |  2 ++
 src/gallium/drivers/r600/evergreen_compute.c   | 18 +-
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 2f0d4c8..fd610b5 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -64,7 +64,6 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
initial_size_in_dw);
 
pool-shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
-   pool-next_id = 1;
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
pool-size_in_dw * 4);
@@ -348,6 +347,18 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
pool-item_list = item;
}
 
+   ((struct r600_context *)pipe)-b.b.resource_copy_region(pipe,
+   (struct pipe_resource *)pool-bo,
+   0, item-start_in_dw * 4, 0 ,0,
+   (struct pipe_resource *)item-real_buffer,
+   0, (struct pipe_box) {.width = 
item-size_in_dw * 4,
+   .height = 1, .depth = 1});
+
+   pool-screen-b.b.resource_destroy(
+   (struct pipe_screen *)pool-screen,
+   (struct pipe_resource *)item-real_buffer);
+   item-real_buffer = NULL;
+
allocated += item-size_in_dw;
}
 }
@@ -374,6 +385,12 @@ void compute_memory_free(struct compute_memory_pool* pool, 
int64_t id)
item-next-prev = item-prev;
}
 
+   if (item-real_buffer) {
+   pool-screen-b.b.resource_destroy(
+   (struct pipe_screen 
*)pool-screen,
+   (struct pipe_resource 
*)item-real_buffer);
+   }
+
free(item);
 
return;
@@ -404,6 +421,8 @@ struct compute_memory_item* compute_memory_alloc(
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
new_item-pool = pool;
+   new_item-real_buffer = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(
+   pool-screen, 
size_in_dw * 4);
 
if (pool-item_list) {
for (last_item = pool-item_list; last_item-next;
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 3777e3f..8083a11 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -38,6 +38,8 @@ struct compute_memory_item
int64_t start_in_dw; ///Start pointer in dwords relative in the pool bo
int64_t size_in_dw; ///Size of the chunk in dwords
 
+   struct r600_resource *real_buffer;
+
struct compute_memory_pool* pool;
 
struct compute_memory_item* prev;
diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index 701bb5c..e2f5b66 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -958,6 +958,17 @@ void *r600_compute_global_transfer_map(
struct r600_resource_global* buffer =
(struct r600_resource_global*)resource;
 
+   struct pipe_resource *dst;
+   unsigned offset = box-x;
+
+   if (buffer-chunk-real_buffer) {
+   dst = (struct pipe_resource*)buffer-chunk-real_buffer;
+   }
+   else {
+   dst = (struct pipe_resource*)buffer-chunk-pool-bo;
+   offset += (buffer-chunk-start_in_dw * 4);
+   }
+
COMPUTE_DBG(rctx-screen, * r600_compute_global_transfer_map()\n
level = %u, usage = %u, box(x = %u, y = %u, z = %u 
 

[Mesa-dev] [PATCH] [RFC] r600g/compute: Solving the mapping bug

2014-05-30 Thread Bruno Jiménez
Hi,

This is my first attempt to fix a bug that the r600g/compute
code has when handling mapped buffers in OpenCL.

I have written a small document explaining more or less what
is the bug I am trying to solve, and the approach I have chosen
to solve it with this patch:
https://www.dropbox.com/s/qwkpod33hg3uu07/mapping_bug.pdf

I sent a test for this bug to the piglit mailing list:
http://lists.freedesktop.org/archives/piglit/2014-May/010807.html
And this patch fixes it.

Unfortunately, a couple of days ago I reread the OpenCL 1.2 spec
and discovered that it allows buffers to be mapped for reading
and launch kernels that read from them. So, my patch has a bug
in this case.

I have also sent a test for this allowed behavior to the piglit
mailing list:
http://lists.freedesktop.org/archives/piglit/2014-May/010922.html
And as expected, this patch breaks it :(

I'll continue to think of some way of solving both bugs.

Thanks!
Bruno

Bruno Jiménez (1):
  r600g/compute: solve the mapping bug

 src/gallium/drivers/r600/compute_memory_pool.c | 21 -
 src/gallium/drivers/r600/compute_memory_pool.h |  2 ++
 src/gallium/drivers/r600/evergreen_compute.c   | 18 +-
 3 files changed, 35 insertions(+), 6 deletions(-)

-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 0/3] clover: Allow quering for the number of max compute units

2014-05-30 Thread Bruno Jiménez
This series allows clover to answer the query for the number of
max compute units of the devices.

The data has been extracted from:
AMD Accelerated Parallel Processing OpenCL Programming Guide (rev 2.7)
Appendix D: Device Parameters

For the rest of the devices I haven't found data.

Patch 2 is very big, and has a lot of comments about the data found in
said reference. For some of the chips, more than one number was listed
depending on the exact card, and I have chosen to return the lower one.

Thanks!
Bruno

Bruno Jiménez (3):
  gallium: Add PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS
  radeon/compute: Implement PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS
  clover: query driver for the max number of compute units

 src/gallium/docs/source/screen.rst|  2 +
 src/gallium/drivers/radeon/r600_pipe_common.c | 90 +++
 src/gallium/include/pipe/p_defines.h  |  3 +-
 src/gallium/state_trackers/clover/api/device.cpp  |  2 +-
 src/gallium/state_trackers/clover/core/device.cpp |  6 ++
 src/gallium/state_trackers/clover/core/device.hpp |  1 +
 6 files changed, 102 insertions(+), 2 deletions(-)

-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/3] gallium: Add PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS

2014-05-30 Thread Bruno Jiménez
---
 src/gallium/docs/source/screen.rst   | 2 ++
 src/gallium/include/pipe/p_defines.h | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index b292257..dde2c38 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -317,6 +317,8 @@ pipe_screen::get_compute_param.
   allocation in bytes.  Value type: ``uint64_t``.
 * ``PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY``: Maximum frequency of the GPU
   clock in MHz. Value type: ``uint32_t``
+* ``PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS``: Maximum number of compute units
+  Value type: ``uint32_t``
 
 .. _pipe_bind:
 
diff --git a/src/gallium/include/pipe/p_defines.h 
b/src/gallium/include/pipe/p_defines.h
index 4024470..5572bb6 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -644,7 +644,8 @@ enum pipe_compute_cap
PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE,
PIPE_COMPUTE_CAP_MAX_INPUT_SIZE,
PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
-   PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY
+   PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY,
+   PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS
 };
 
 /**
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/3] clover: query driver for the max number of compute units

2014-05-30 Thread Bruno Jiménez
---
 src/gallium/state_trackers/clover/api/device.cpp  | 2 +-
 src/gallium/state_trackers/clover/core/device.cpp | 6 ++
 src/gallium/state_trackers/clover/core/device.hpp | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/clover/api/device.cpp 
b/src/gallium/state_trackers/clover/api/device.cpp
index 1bc2692..97b2cf9 100644
--- a/src/gallium/state_trackers/clover/api/device.cpp
+++ b/src/gallium/state_trackers/clover/api/device.cpp
@@ -109,7 +109,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
   break;
 
case CL_DEVICE_MAX_COMPUTE_UNITS:
-  buf.as_scalarcl_uint() = 1;
+  buf.as_scalarcl_uint() = dev.max_compute_units();
   break;
 
case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:
diff --git a/src/gallium/state_trackers/clover/core/device.cpp 
b/src/gallium/state_trackers/clover/core/device.cpp
index bc3e3e6..b6078db 100644
--- a/src/gallium/state_trackers/clover/core/device.cpp
+++ b/src/gallium/state_trackers/clover/core/device.cpp
@@ -163,6 +163,12 @@ device::max_clock_frequency() const {
   PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY)[0];
 }
 
+cl_uint
+device::max_compute_units() const {
+   return get_compute_paramuint32_t(pipe,
+  PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS)[0];
+}
+
 std::vectorsize_t
 device::max_block_size() const {
auto v = get_compute_paramuint64_t(pipe, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
diff --git a/src/gallium/state_trackers/clover/core/device.hpp 
b/src/gallium/state_trackers/clover/core/device.hpp
index 3662c6b..731c31e 100644
--- a/src/gallium/state_trackers/clover/core/device.hpp
+++ b/src/gallium/state_trackers/clover/core/device.hpp
@@ -62,6 +62,7 @@ namespace clover {
   size_t max_threads_per_block() const;
   cl_ulong max_mem_alloc_size() const;
   cl_uint max_clock_frequency() const;
+  cl_uint max_compute_units() const;
 
   std::vectorsize_t max_block_size() const;
   std::string device_name() const;
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/3] radeon/compute: Implement PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS

2014-05-30 Thread Bruno Jiménez
The data has been extracted from:
AMD Accelerated Parallel Processing OpenCL Programming Guide (rev 2.7)
Appendix D: Device Parameters
---
 src/gallium/drivers/radeon/r600_pipe_common.c | 90 +++
 1 file changed, 90 insertions(+)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c 
b/src/gallium/drivers/radeon/r600_pipe_common.c
index 70c4d1a..c4abacd 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -422,6 +422,89 @@ const char *r600_get_llvm_processor_name(enum 
radeon_family family)
}
 }
 
+static uint32_t radeon_max_compute_units(enum radeon_family family)
+{
+   switch (family) {
+   case CHIP_CEDAR:
+   return 2;
+   
+   /* Redwood PRO2: 4
+* Redwood PRO:  5
+* Redwood XT:   5 */
+   case CHIP_REDWOOD:
+   return 4;
+   
+   /* Juniper LE:  9
+* Juniper XT: 10 */
+   case CHIP_JUNIPER:
+   return 9;
+
+   /* Cypress LE:  14
+* Cypress PRO: 18
+* Cypress XT:  20 */
+   case CHIP_CYPRESS:
+   return 14;
+
+   case CHIP_HEMLOCK:
+   return 40;
+   
+   /* XXX: is Zacate really equal to Ontario?
+* Zacate E-350: 2
+* Zacate E-240: 2
+* Ontario C-50: 2
+* Ontario C-30: 2 */
+   case CHIP_PALM:
+   return 2;
+   
+   /* Caicos:  2
+* Seymour LP:  2
+* Seymour PRO: 2
+* Seymour XT:  2
+* Seymour XTX: 2 */
+   case CHIP_CAICOS:
+   return 2;
+
+   /* Turks PRO:6
+* Turks XT: 6
+* Whistler LP:  6
+* Whistler PRO: 6
+* Whistler XT:  6 */
+   case CHIP_TURKS:
+   return 6;
+   
+   /* Barts LE:  10
+* Barts PRO: 12
+* Barts XT:  14
+* Blackcomb PRO: 12 */
+   case CHIP_BARTS:
+   return 10;
+
+   /* Cayman PRO: 22
+* Cayman XT:  24
+* Cayman Gemini: 48 */
+   case CHIP_CAYMAN:
+   return 22;
+
+   /* Verde PRO:  8
+* Verde XT:  10 */
+   case CHIP_VERDE:
+   return 8;
+
+   /* Pitcairn PRO: 16
+* Pitcairn XT:  20 */
+   case CHIP_PITCAIRN:
+   return 16;
+
+   /* Tahiti PRO: 28
+* Tahiti XT:  32 */
+   case CHIP_TAHITI:
+   return 28;
+
+   default:
+   return 1;
+   }
+}
+
 static int r600_get_compute_param(struct pipe_screen *screen,
 enum pipe_compute_cap param,
 void *ret)
@@ -519,6 +602,13 @@ static int r600_get_compute_param(struct pipe_screen 
*screen,
}
return sizeof(uint32_t);
 
+   case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
+   if (ret) {
+   uint32_t *max_compute_units = ret;
+   *max_compute_units = 
radeon_max_compute_units(rscreen-family);
+   }
+   return sizeof(uint32_t);
+
default:
fprintf(stderr, unknown PIPE_COMPUTE_CAP %d\n, param);
return 0;
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 0/7] r600g/compute: Some cleanup patches

2014-05-19 Thread Bruno Jiménez
Hi,

Firstly, I shall introduce myself (at least more formally than just
sending some patches). My name is Bruno Jiménez, I'm studying
physics at Zaragoza's University (Spain) and I am participating in
this year's Google Summer of Code, where I will try to improve
the compute_memory_pool, solve an annoying bug related to mappings
and anything else that I can do.

These patches are a little first cleanup. I sent the first five
some time ago, but weren't pushed. The sixth fixes the alignment
for items whose size is a multiple of 1024 dw and the last one
corrects the format type of an unsigned.

Thanks!
Bruno

Bruno Jiménez (7):
  r600g/compute: Fixing a typo and some indentation
  r600g/compute: Adding checks for NULL after CALLOC
  r600g/compute: Add more NULL checks
  r600g/compute: Tidy a bit compute_memory_finalize_pending
  r600g/compute: Cleanup of compute_memory_pool.h
  r600g/compute: align items correctly
  r600g/compute: Use %u as the unsigned format

 src/gallium/drivers/r600/compute_memory_pool.c | 64 +-
 src/gallium/drivers/r600/compute_memory_pool.h | 17 +--
 src/gallium/drivers/r600/evergreen_compute.c   |  2 +-
 3 files changed, 46 insertions(+), 37 deletions(-)

-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/7] r600g/compute: Fixing a typo and some indentation

2014-05-19 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 2f0d4c8..ccbb211 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -263,7 +263,7 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
unallocated += item-size_in_dw+1024;
}
else {
-   /* The item is not pendng, so update the amount of space
+   /* The item is not pending, so update the amount of 
space
 * that has already been allocated. */
allocated += item-size_in_dw;
}
@@ -451,7 +451,7 @@ void compute_memory_transfer(
map = pipe-transfer_map(pipe, gart, 0, PIPE_TRANSFER_READ,
(struct pipe_box) { .width = aligned_size * 4,
.height = 1, .depth = 1 }, xfer);
-assert(xfer);
+   assert(xfer);
assert(map);
memcpy(data, map + internal_offset, size);
pipe-transfer_unmap(pipe, xfer);
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 4/7] r600g/compute: Tidy a bit compute_memory_finalize_pending

2014-05-19 Thread Bruno Jiménez
Explanation of the changes, as requested by Tom Stellard:

Let's take need after is calculated as
item-size_in_dw+2048 - (pool-size_in_dw - allocated)

BEFORE:
If need is positive or 0:
we calculate need += 1024 - (need % 1024), which is like
cealing to the nearest multiple of 1024, for example
0 goes to 1024, 512 goes to 1024 as well, 1025 goes
to 2048 and so on. So now need is always possitive,
we do compute_memory_grow_pool, check its output
and continue.

If need is negative:
we calculate need += 1024 - (need % 1024), in this case
we will have negative numbers, and if need is
[-1024:-1] 0, so now we take the else, recalculate
need as need = pool-size_in_dw / 10 and
need += 1024 - (need % 1024), we do
compute_memory_grow_pool, check its output and continue.

AFTER:
If need is positive or 0:
we jump the if, calculate need += 1024 - (need % 1024)
compute_memory_grow_pool, check its output and continue.

If need is negative:
we enter the if, and need is now pool-size_in_dw / 10.
Now we calculate need += 1024 - (need % 1024)
compute_memory_grow_pool, check its output and continue.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index e959a6d..01851ad 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -319,21 +319,16 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
int64_t need = item-size_in_dw+2048 -
(pool-size_in_dw - allocated);
 
-   need += 1024 - (need % 1024);
-
-   if (need  0) {
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
-   }
-   else {
+   if (need  0) {
need = pool-size_in_dw / 10;
-   need += 1024 - (need % 1024);
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
}
 
+   need += 1024 - (need % 1024);
+
+   err = compute_memory_grow_pool(pool,
+   pipe,
+   pool-size_in_dw + need);
+
if (err == -1)
return -1;
}
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/7] r600g/compute: Adding checks for NULL after CALLOC

2014-05-19 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index ccbb211..7143545 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -49,6 +49,8 @@ struct compute_memory_pool* compute_memory_pool_new(
 {
struct compute_memory_pool* pool = (struct compute_memory_pool*)
CALLOC(sizeof(struct compute_memory_pool), 1);
+   if (pool == NULL)
+   return NULL;
 
COMPUTE_DBG(rscreen, * compute_memory_pool_new()\n);
 
@@ -64,6 +66,9 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
initial_size_in_dw);
 
pool-shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
+   if (pool-shadow == NULL)
+   return;
+
pool-next_id = 1;
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
@@ -400,6 +405,9 @@ struct compute_memory_item* compute_memory_alloc(
 
new_item = (struct compute_memory_item *)
CALLOC(sizeof(struct compute_memory_item), 1);
+   if (new_item == NULL)
+   return NULL;
+
new_item-size_in_dw = size_in_dw;
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 6/7] r600g/compute: align items correctly

2014-05-19 Thread Bruno Jiménez
Now, items whose size is a multiple of 1024 dw won't leave
1024 dw between itself and the following item

The rest of the cases is left as it was
---
 src/gallium/drivers/r600/compute_memory_pool.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 01851ad..2050f28 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -30,6 +30,7 @@
 #include util/u_transfer.h
 #include util/u_surface.h
 #include util/u_pack_color.h
+#include util/u_math.h
 #include util/u_memory.h
 #include util/u_inlines.h
 #include util/u_framebuffer.h
@@ -41,6 +42,7 @@
 #include evergreen_compute_internal.h
 #include inttypes.h
 
+#define ITEM_ALIGNMENT 1024
 /**
  * Creates a new pool
  */
@@ -112,8 +114,7 @@ int64_t compute_memory_prealloc_chunk(
return last_end;
}
 
-   last_end = item-start_in_dw + item-size_in_dw;
-   last_end += (1024 - last_end % 1024);
+   last_end = item-start_in_dw + align(item-size_in_dw, 
ITEM_ALIGNMENT);
}
}
 
@@ -177,7 +178,7 @@ int compute_memory_grow_pool(struct compute_memory_pool* 
pool,
if (pool-shadow == NULL)
return -1;
} else {
-   new_size_in_dw += 1024 - (new_size_in_dw % 1024);
+   new_size_in_dw = align(new_size_in_dw, ITEM_ALIGNMENT);
 
COMPUTE_DBG(pool-screen,   Aligned size = %d (%d bytes)\n,
new_size_in_dw, new_size_in_dw * 4);
@@ -323,7 +324,7 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
need = pool-size_in_dw / 10;
}
 
-   need += 1024 - (need % 1024);
+   need = align(need, ITEM_ALIGNMENT);
 
err = compute_memory_grow_pool(pool,
pipe,
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/7] r600g/compute: Add more NULL checks

2014-05-19 Thread Bruno Jiménez
In this case, NULL checks are added to compute_memory_grow_pool,
so it returns -1 when it fails. This makes necesary
to handle such cases in compute_memory_finalize_pending
when it is needed to grow the pool
---
 src/gallium/drivers/r600/compute_memory_pool.c | 30 --
 src/gallium/drivers/r600/compute_memory_pool.h |  6 --
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 7143545..e959a6d 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -160,9 +160,10 @@ struct compute_memory_item* compute_memory_postalloc_chunk(
 }
 
 /**
- * Reallocates pool, conserves data
+ * Reallocates pool, conserves data.
+ * @returns -1 if it fails, 0 otherwise
  */
-void compute_memory_grow_pool(struct compute_memory_pool* pool,
+int compute_memory_grow_pool(struct compute_memory_pool* pool,
struct pipe_context * pipe, int new_size_in_dw)
 {
COMPUTE_DBG(pool-screen, * compute_memory_grow_pool() 
@@ -173,6 +174,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
if (!pool-bo) {
compute_memory_pool_init(pool, MAX2(new_size_in_dw, 1024 * 16));
+   if (pool-shadow == NULL)
+   return -1;
} else {
new_size_in_dw += 1024 - (new_size_in_dw % 1024);
 
@@ -181,6 +184,9 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
compute_memory_shadow(pool, pipe, 1);
pool-shadow = realloc(pool-shadow, new_size_in_dw*4);
+   if (pool-shadow == NULL)
+   return -1;
+
pool-size_in_dw = new_size_in_dw;
pool-screen-b.b.resource_destroy(
(struct pipe_screen *)pool-screen,
@@ -190,6 +196,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
pool-size_in_dw * 4);
compute_memory_shadow(pool, pipe, 0);
}
+
+   return 0;
 }
 
 /**
@@ -213,8 +221,9 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
 
 /**
  * Allocates pending allocations in the pool
+ * @returns -1 if it fails, 0 otherwise
  */
-void compute_memory_finalize_pending(struct compute_memory_pool* pool,
+int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
 {
struct compute_memory_item *pending_list = NULL, *end_p = NULL;
@@ -225,6 +234,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
int64_t start_in_dw = 0;
 
+   int err = 0;
+
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
 
for (item = pool-item_list; item; item = item-next) {
@@ -292,7 +303,9 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 * they aren't contiguous, so it will be impossible to allocate Item D.
 */
if (pool-size_in_dw  allocated+unallocated) {
-   compute_memory_grow_pool(pool, pipe, allocated+unallocated);
+   err = compute_memory_grow_pool(pool, pipe, 
allocated+unallocated);
+   if (err == -1)
+   return -1;
}
 
/* Loop through all the pending items, allocate space for them and
@@ -309,17 +322,20 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
need += 1024 - (need % 1024);
 
if (need  0) {
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
else {
need = pool-size_in_dw / 10;
need += 1024 - (need % 1024);
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
+
+   if (err == -1)
+   return -1;
}
COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
start_in_dw = %u (%u bytes) size_in_dw = %u (%u 
bytes)\n,
@@ -355,6 +371,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
allocated += item-size_in_dw;
}
+
+   return 0;
 }
 
 
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 3777e3f..e61c003 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ 

[Mesa-dev] [PATCH 7/7] r600g/compute: Use %u as the unsigned format

2014-05-19 Thread Bruno Jiménez
This fixes an issue when running cl-program-bitcoin-phatk
piglit test where some of the inputs have negative values
---
 src/gallium/drivers/r600/evergreen_compute.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
b/src/gallium/drivers/r600/evergreen_compute.c
index 701bb5c..a2abf15 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -323,7 +323,7 @@ void evergreen_compute_upload_input(
memcpy(kernel_parameters_start, input, shader-input_size);
 
for (i = 0; i  (input_size / 4); i++) {
-   COMPUTE_DBG(ctx-screen, input %i : %i\n, i,
+   COMPUTE_DBG(ctx-screen, input %i : %u\n, i,
((unsigned*)num_work_groups_start)[i]);
}
 
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 5/7] r600g/compute: Cleanup of compute_memory_pool.h

2014-05-19 Thread Bruno Jiménez
Removed compute_memory_defrag declaration because it seems
to be unimplemented.

I think that this function would have been the one that solves
the problem with fragmentation that compute_memory_finalize_pending has.

Also removed comments that are already at compute_memory_pool.c
---
 src/gallium/drivers/r600/compute_memory_pool.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index e61c003..c711c59 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -64,32 +64,17 @@ int64_t compute_memory_prealloc_chunk(struct 
compute_memory_pool* pool, int64_t
 
 struct compute_memory_item* compute_memory_postalloc_chunk(struct 
compute_memory_pool* pool, int64_t start_in_dw); ///search for the chunk where 
we can link our new chunk after it
 
-/** 
- * reallocates pool, conserves data
- * @returns -1 if it fails, 0 otherwise
- */
 int compute_memory_grow_pool(struct compute_memory_pool* pool, struct 
pipe_context * pipe,
int new_size_in_dw);
 
-/**
- * Copy pool from device to host, or host to device
- */
 void compute_memory_shadow(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host);
 
-/**
- * Allocates pending allocations in the pool
- * @returns -1 if it fails, 0 otherwise
- */
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe);
-void compute_memory_defrag(struct compute_memory_pool* pool); ///Defragment 
the memory pool, always heavy memory usage
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id);
 struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* 
pool, int64_t size_in_dw); ///Creates pending allocations
 
-/**
- * Transfer data host-device, offset and size is in bytes
- */
 void compute_memory_transfer(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host,
struct compute_memory_item* chunk, void* data,
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 0/3] clover: Add support for quering CL_DEVICE_MAX_CLOCK_FREQUENCY

2014-04-18 Thread Bruno Jiménez
This series is based in Tom Stellard's 'clover-clock' branch:
http://cgit.freedesktop.org/~tstellar/mesa/log/?h=clover-clock
And should fix this bug report:
https://bugs.freedesktop.org/show_bug.cgi?id=73511

The only changes from the original branch are in patches 2 and 3.
Patch 2 has been updated so that it applies to current master.
Patch 3 has been updated so that it returns the frequency in MHz,
not in kHz.

v2: Updated docs in patch 1, the frequency is returned in MHz in
patch 2, and patch 3 is returned to it's original form.

Tom Stellard (3):
  gallium: Add PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY
  radeon/compute: Implement PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY
  clover: Query drivers for max clock frequency

 src/gallium/docs/source/screen.rst| 2 ++
 src/gallium/drivers/radeon/r600_pipe_common.c | 7 +++
 src/gallium/include/pipe/p_defines.h  | 3 ++-
 src/gallium/state_trackers/clover/api/device.cpp  | 2 +-
 src/gallium/state_trackers/clover/core/device.cpp | 6 ++
 src/gallium/state_trackers/clover/core/device.hpp | 1 +
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 5 +
 src/gallium/winsys/radeon/drm/radeon_winsys.h | 1 +
 8 files changed, 25 insertions(+), 2 deletions(-)

-- 
1.9.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/3] gallium: Add PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY

2014-04-18 Thread Bruno Jiménez
From: Tom Stellard thomas.stell...@amd.com

v2: Updated the docs
---
 src/gallium/docs/source/screen.rst   | 2 ++
 src/gallium/include/pipe/p_defines.h | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 5c255d0..3f38b28 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -310,6 +310,8 @@ pipe_screen::get_compute_param.
   resource.  Value type: ``uint64_t``.
 * ``PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE``: Maximum size of a memory object
   allocation in bytes.  Value type: ``uint64_t``.
+* ``PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY``: Maximum frequency of the GPU
+  clock in MHz. Value type: ``uint32_t``
 
 .. _pipe_bind:
 
diff --git a/src/gallium/include/pipe/p_defines.h 
b/src/gallium/include/pipe/p_defines.h
index a3a1ae1..93f9642 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -641,7 +641,8 @@ enum pipe_compute_cap
PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE,
PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE,
PIPE_COMPUTE_CAP_MAX_INPUT_SIZE,
-   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE
+   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
+   PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY,
 };
 
 /**
-- 
1.9.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/3] clover: Query drivers for max clock frequency

2014-04-18 Thread Bruno Jiménez
From: Tom Stellard thomas.stell...@amd.com

v2: PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY instead of
PIPE_COMPUTE_MAX_CLOCK_FREQUENCY

Signed-off-by: Igor Gnatenko i.gnatenko.br...@gmail.com

clover: Correct the returned value for max_clock_frequency

According to OpenCL 1.1 spec, the returned value must be in MHz, and we
were returning it in kHz

v3: Now the conversion is done in patch 2.
---
 src/gallium/state_trackers/clover/api/device.cpp  | 2 +-
 src/gallium/state_trackers/clover/core/device.cpp | 6 ++
 src/gallium/state_trackers/clover/core/device.hpp | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/clover/api/device.cpp 
b/src/gallium/state_trackers/clover/api/device.cpp
index 7bc8d0a..f980845 100644
--- a/src/gallium/state_trackers/clover/api/device.cpp
+++ b/src/gallium/state_trackers/clover/api/device.cpp
@@ -122,7 +122,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
   break;
 
case CL_DEVICE_MAX_CLOCK_FREQUENCY:
-  buf.as_scalarcl_uint() = 0;
+  buf.as_scalarcl_uint() = dev.max_clock_frequency();
   break;
 
case CL_DEVICE_ADDRESS_BITS:
diff --git a/src/gallium/state_trackers/clover/core/device.cpp 
b/src/gallium/state_trackers/clover/core/device.cpp
index 2c5f9b7..2f84677 100644
--- a/src/gallium/state_trackers/clover/core/device.cpp
+++ b/src/gallium/state_trackers/clover/core/device.cpp
@@ -154,6 +154,12 @@ device::max_mem_alloc_size() const {
   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE)[0];
 }
 
+cl_uint
+device::max_clock_frequency() const {
+   return get_compute_paramuint32_t(pipe,
+  PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY)[0];
+}
+
 std::vectorsize_t
 device::max_block_size() const {
auto v = get_compute_paramuint64_t(pipe, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
diff --git a/src/gallium/state_trackers/clover/core/device.hpp 
b/src/gallium/state_trackers/clover/core/device.hpp
index 433ac81..3662c6b 100644
--- a/src/gallium/state_trackers/clover/core/device.hpp
+++ b/src/gallium/state_trackers/clover/core/device.hpp
@@ -61,6 +61,7 @@ namespace clover {
   cl_uint max_const_buffers() const;
   size_t max_threads_per_block() const;
   cl_ulong max_mem_alloc_size() const;
+  cl_uint max_clock_frequency() const;
 
   std::vectorsize_t max_block_size() const;
   std::string device_name() const;
-- 
1.9.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/3] radeon/compute: Implement PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY

2014-04-18 Thread Bruno Jiménez
From: Tom Stellard thomas.stell...@amd.com

v2: in define RADEON_INFO_MAX_SCLK use 0x1a instead of 0x19 (upstream changes)

Signed-off-by: Igor Gnatenko i.gnatenko.br...@gmail.com

r600: Correct the case MAX_CLOCK_FREQUENCY in get_compute_param

v3: Convert the frequency to MHz from kHz after getting it in
'do_winsys_init'
---
 src/gallium/drivers/radeon/r600_pipe_common.c | 7 +++
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 5 +
 src/gallium/winsys/radeon/drm/radeon_winsys.h | 1 +
 3 files changed, 13 insertions(+)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c 
b/src/gallium/drivers/radeon/r600_pipe_common.c
index 7508865..957186a 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -505,6 +505,13 @@ static int r600_get_compute_param(struct pipe_screen 
*screen,
}
return sizeof(uint64_t);
 
+   case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
+   if (ret) {
+   uint32_t *max_clock_frequency = ret;
+   *max_clock_frequency = rscreen-info.max_sclk;
+   }
+   return sizeof(uint32_t);
+
default:
fprintf(stderr, unknown PIPE_COMPUTE_CAP %d\n, param);
return 0;
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c 
b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index 0eb0c6a..92fbc7f 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -316,6 +316,11 @@ static boolean do_winsys_init(struct radeon_drm_winsys *ws)
 ws-info.gart_size = gem_info.gart_size;
 ws-info.vram_size = gem_info.vram_size;
 
+/* Get max clock frequency info and convert it to MHz */
+radeon_get_drm_value(ws-fd, RADEON_INFO_MAX_SCLK, NULL,
+ ws-info.max_sclk);
+ws-info.max_sclk /= 1000;
+
 ws-num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
 /* Generation-specific queries. */
diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h 
b/src/gallium/winsys/radeon/drm/radeon_winsys.h
index fe0617b..1cb17bb 100644
--- a/src/gallium/winsys/radeon/drm/radeon_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h
@@ -196,6 +196,7 @@ struct radeon_info {
 enum chip_class chip_class;
 uint32_tgart_size;
 uint32_tvram_size;
+uint32_tmax_sclk;
 
 uint32_tdrm_major; /* version */
 uint32_tdrm_minor;
-- 
1.9.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/3] gallium: Add PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY

2014-04-18 Thread Bruno Jiménez
From: Tom Stellard thomas.stell...@amd.com

v2: Updated the docs
v3: Remove trailing comma
---
 src/gallium/docs/source/screen.rst   | 2 ++
 src/gallium/include/pipe/p_defines.h | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 5c255d0..3f38b28 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -310,6 +310,8 @@ pipe_screen::get_compute_param.
   resource.  Value type: ``uint64_t``.
 * ``PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE``: Maximum size of a memory object
   allocation in bytes.  Value type: ``uint64_t``.
+* ``PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY``: Maximum frequency of the GPU
+  clock in MHz. Value type: ``uint32_t``
 
 .. _pipe_bind:
 
diff --git a/src/gallium/include/pipe/p_defines.h 
b/src/gallium/include/pipe/p_defines.h
index a3a1ae1..93f9642 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -641,7 +641,8 @@ enum pipe_compute_cap
PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE,
PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE,
PIPE_COMPUTE_CAP_MAX_INPUT_SIZE,
-   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE
+   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
+   PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY
 };
 
 /**
-- 
1.9.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] clover: Add support for quering CL_DEVICE_MAX_CLOCK_FREQUENCY

2014-04-17 Thread Bruno Jiménez
This series is based in Tom Stellard's 'clover-clock' branch:
http://cgit.freedesktop.org/~tstellar/mesa/log/?h=clover-clock
And should fix this bug report:
https://bugs.freedesktop.org/show_bug.cgi?id=73511

The only changes from the original branch are in patches 2 and 3.
Patch 2 has been updated so that it applies to current master.
Patch 3 has been updated so that it returns the frequency in MHz,
not in kHz.

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/3] gallium: Add PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY

2014-04-17 Thread Bruno Jiménez
From: Tom Stellard thomas.stell...@amd.com

---
 src/gallium/include/pipe/p_defines.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/gallium/include/pipe/p_defines.h 
b/src/gallium/include/pipe/p_defines.h
index a3a1ae1..93f9642 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -641,7 +641,8 @@ enum pipe_compute_cap
PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE,
PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE,
PIPE_COMPUTE_CAP_MAX_INPUT_SIZE,
-   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE
+   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
+   PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY,
 };
 
 /**
-- 
1.9.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/3] radeon/compute: Implement PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY

2014-04-17 Thread Bruno Jiménez
From: Tom Stellard thomas.stell...@amd.com

v2: in define RADEON_INFO_MAX_SCLK use 0x1a instead of 0x19 (upstream changes)

Signed-off-by: Igor Gnatenko i.gnatenko.br...@gmail.com

r600: Correct the case MAX_CLOCK_FREQUENCY in get_compute_param
---
 src/gallium/drivers/radeon/r600_pipe_common.c | 7 +++
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 3 +++
 src/gallium/winsys/radeon/drm/radeon_winsys.h | 1 +
 3 files changed, 11 insertions(+)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c 
b/src/gallium/drivers/radeon/r600_pipe_common.c
index 7508865..957186a 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -505,6 +505,13 @@ static int r600_get_compute_param(struct pipe_screen 
*screen,
}
return sizeof(uint64_t);
 
+   case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
+   if (ret) {
+   uint32_t *max_clock_frequency = ret;
+   *max_clock_frequency = rscreen-info.max_sclk;
+   }
+   return sizeof(uint32_t);
+
default:
fprintf(stderr, unknown PIPE_COMPUTE_CAP %d\n, param);
return 0;
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c 
b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index 0eb0c6a..a7f0d9e 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -316,6 +316,9 @@ static boolean do_winsys_init(struct radeon_drm_winsys *ws)
 ws-info.gart_size = gem_info.gart_size;
 ws-info.vram_size = gem_info.vram_size;
 
+radeon_get_drm_value(ws-fd, RADEON_INFO_MAX_SCLK, NULL,
+ ws-info.max_sclk);
+
 ws-num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
 /* Generation-specific queries. */
diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h 
b/src/gallium/winsys/radeon/drm/radeon_winsys.h
index fe0617b..1cb17bb 100644
--- a/src/gallium/winsys/radeon/drm/radeon_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h
@@ -196,6 +196,7 @@ struct radeon_info {
 enum chip_class chip_class;
 uint32_tgart_size;
 uint32_tvram_size;
+uint32_tmax_sclk;
 
 uint32_tdrm_major; /* version */
 uint32_tdrm_minor;
-- 
1.9.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/3] clover: Query drivers for max clock frequency

2014-04-17 Thread Bruno Jiménez
From: Tom Stellard thomas.stell...@amd.com

v2: PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY instead of
PIPE_COMPUTE_MAX_CLOCK_FREQUENCY

Signed-off-by: Igor Gnatenko i.gnatenko.br...@gmail.com

clover: Correct the returned value for max_clock_frequency

According to OpenCL 1.1 spec, the returned value must be in MHz, and we
were returning it in kHz
---
 src/gallium/state_trackers/clover/api/device.cpp  | 2 +-
 src/gallium/state_trackers/clover/core/device.cpp | 6 ++
 src/gallium/state_trackers/clover/core/device.hpp | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/clover/api/device.cpp 
b/src/gallium/state_trackers/clover/api/device.cpp
index 7bc8d0a..f980845 100644
--- a/src/gallium/state_trackers/clover/api/device.cpp
+++ b/src/gallium/state_trackers/clover/api/device.cpp
@@ -122,7 +122,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
   break;
 
case CL_DEVICE_MAX_CLOCK_FREQUENCY:
-  buf.as_scalarcl_uint() = 0;
+  buf.as_scalarcl_uint() = dev.max_clock_frequency();
   break;
 
case CL_DEVICE_ADDRESS_BITS:
diff --git a/src/gallium/state_trackers/clover/core/device.cpp 
b/src/gallium/state_trackers/clover/core/device.cpp
index 2c5f9b7..4ae575f 100644
--- a/src/gallium/state_trackers/clover/core/device.cpp
+++ b/src/gallium/state_trackers/clover/core/device.cpp
@@ -154,6 +154,12 @@ device::max_mem_alloc_size() const {
   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE)[0];
 }
 
+cl_uint
+device::max_clock_frequency() const {
+   return get_compute_paramuint32_t(pipe,
+  PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY)[0] 
/ 1000;
+}
+
 std::vectorsize_t
 device::max_block_size() const {
auto v = get_compute_paramuint64_t(pipe, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
diff --git a/src/gallium/state_trackers/clover/core/device.hpp 
b/src/gallium/state_trackers/clover/core/device.hpp
index 433ac81..3662c6b 100644
--- a/src/gallium/state_trackers/clover/core/device.hpp
+++ b/src/gallium/state_trackers/clover/core/device.hpp
@@ -61,6 +61,7 @@ namespace clover {
   cl_uint max_const_buffers() const;
   size_t max_threads_per_block() const;
   cl_ulong max_mem_alloc_size() const;
+  cl_uint max_clock_frequency() const;
 
   std::vectorsize_t max_block_size() const;
   std::string device_name() const;
-- 
1.9.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/2] clover: Fix building with latest llvm

2014-03-02 Thread Bruno Jiménez
---
 src/gallium/state_trackers/clover/Makefile.am | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/gallium/state_trackers/clover/Makefile.am 
b/src/gallium/state_trackers/clover/Makefile.am
index ece2b38..75eae86 100644
--- a/src/gallium/state_trackers/clover/Makefile.am
+++ b/src/gallium/state_trackers/clover/Makefile.am
@@ -37,9 +37,8 @@ libcltgsi_la_SOURCES = \
tgsi/compiler.cpp
 
 libclllvm_la_CXXFLAGS = \
-   -std=c++98 \
$(VISIBILITY_CXXFLAGS) \
-   $(LLVM_CPPFLAGS) \
+   $(LLVM_CXXFLAGS) \
$(DEFINES) \
-DLIBCLC_INCLUDEDIR=\$(LIBCLC_INCLUDEDIR)/\ \
-DLIBCLC_LIBEXECDIR=\$(LIBCLC_LIBEXECDIR)/\ \
@@ -49,7 +48,7 @@ libclllvm_la_SOURCES = \
llvm/invocation.cpp
 
 libclover_la_CXXFLAGS = \
-   -std=c++0x \
+   -std=c++11 \
$(VISIBILITY_CXXFLAGS)
 
 libclover_la_LIBADD = \
-- 
1.9.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] clover: Fix building with latest llvm

2014-03-01 Thread Bruno Jiménez
Recently, llvm has changed to use c++11, so we also should use it
---
 src/gallium/state_trackers/clover/Makefile.am | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/clover/Makefile.am 
b/src/gallium/state_trackers/clover/Makefile.am
index ece2b38..cc9311c 100644
--- a/src/gallium/state_trackers/clover/Makefile.am
+++ b/src/gallium/state_trackers/clover/Makefile.am
@@ -37,7 +37,7 @@ libcltgsi_la_SOURCES = \
tgsi/compiler.cpp
 
 libclllvm_la_CXXFLAGS = \
-   -std=c++98 \
+   -std=c++11 \
$(VISIBILITY_CXXFLAGS) \
$(LLVM_CPPFLAGS) \
$(DEFINES) \
@@ -49,7 +49,7 @@ libclllvm_la_SOURCES = \
llvm/invocation.cpp
 
 libclover_la_CXXFLAGS = \
-   -std=c++0x \
+   -std=c++11 \
$(VISIBILITY_CXXFLAGS)
 
 libclover_la_LIBADD = \
-- 
1.9.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] Cleaning compute_memory_pool from gallium/drivers/r600

2014-01-19 Thread Bruno Jiménez
Hope I got everything right this time.

Thanks a lot to Marek Olšák for all the help!

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/5] r600g/compute: Fixing a typo and some indentation

2014-01-19 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index fd3a04c..7a7b057 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -264,7 +264,7 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
unallocated += item-size_in_dw+1024;
}
else {
-   /* The item is not pendng, so update the amount of space
+   /* The item is not pending, so update the amount of 
space
 * that has already been allocated. */
allocated += item-size_in_dw;
}
@@ -452,7 +452,7 @@ void compute_memory_transfer(
map = pipe-transfer_map(pipe, gart, 0, PIPE_TRANSFER_READ,
(struct pipe_box) { .width = aligned_size,
.height = 1, .depth = 1 }, xfer);
-assert(xfer);
+   assert(xfer);
assert(map);
memcpy(data, map + internal_offset, size);
pipe-transfer_unmap(pipe, xfer);
-- 
1.8.5.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/5] r600g/compute: Adding checks for NULL after CALLOC

2014-01-19 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 7a7b057..da351d8 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -50,6 +50,8 @@ struct compute_memory_pool* compute_memory_pool_new(
 {
struct compute_memory_pool* pool = (struct compute_memory_pool*)
CALLOC(sizeof(struct compute_memory_pool), 1);
+   if (pool == NULL)
+   return NULL;
 
COMPUTE_DBG(rscreen, * compute_memory_pool_new()\n);
 
@@ -65,6 +67,9 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
initial_size_in_dw);
 
pool-shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
+   if (pool-shadow == NULL)
+   return;
+
pool-next_id = 1;
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
@@ -401,6 +406,9 @@ struct compute_memory_item* compute_memory_alloc(
 
new_item = (struct compute_memory_item *)
CALLOC(sizeof(struct compute_memory_item), 1);
+   if (new_item == NULL)
+   return NULL;
+
new_item-size_in_dw = size_in_dw;
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
-- 
1.8.5.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/5] r600g/compute: Add more NULL checks

2014-01-19 Thread Bruno Jiménez
In this case, NULL checks are added to compute_memory_grow_pool,
so it returns -1 when it fails. This makes necesary
to handle such cases in compute_memory_finalize_pending
when it is needed to grow the pool
---
 src/gallium/drivers/r600/compute_memory_pool.c | 30 --
 src/gallium/drivers/r600/compute_memory_pool.h |  6 --
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index da351d8..1e04639 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -161,9 +161,10 @@ struct compute_memory_item* compute_memory_postalloc_chunk(
 }
 
 /**
- * Reallocates pool, conserves data
+ * Reallocates pool, conserves data.
+ * @returns -1 if it fails, 0 otherwise
  */
-void compute_memory_grow_pool(struct compute_memory_pool* pool,
+int compute_memory_grow_pool(struct compute_memory_pool* pool,
struct pipe_context * pipe, int new_size_in_dw)
 {
COMPUTE_DBG(pool-screen, * compute_memory_grow_pool() 
@@ -174,6 +175,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
if (!pool-bo) {
compute_memory_pool_init(pool, MAX2(new_size_in_dw, 1024 * 16));
+   if (pool-shadow == NULL)
+   return -1;
} else {
new_size_in_dw += 1024 - (new_size_in_dw % 1024);
 
@@ -182,6 +185,9 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
compute_memory_shadow(pool, pipe, 1);
pool-shadow = realloc(pool-shadow, new_size_in_dw*4);
+   if (pool-shadow == NULL)
+   return -1;
+
pool-size_in_dw = new_size_in_dw;
pool-screen-b.b.resource_destroy(
(struct pipe_screen *)pool-screen,
@@ -191,6 +197,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
pool-size_in_dw * 4);
compute_memory_shadow(pool, pipe, 0);
}
+
+   return 0;
 }
 
 /**
@@ -214,8 +222,9 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
 
 /**
  * Allocates pending allocations in the pool
+ * @returns -1 if it fails, 0 otherwise
  */
-void compute_memory_finalize_pending(struct compute_memory_pool* pool,
+int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
 {
struct compute_memory_item *pending_list = NULL, *end_p = NULL;
@@ -226,6 +235,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
int64_t start_in_dw = 0;
 
+   int err = 0;
+
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
 
for (item = pool-item_list; item; item = item-next) {
@@ -293,7 +304,9 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 * they aren't contiguous, so it will be impossible to allocate Item D.
 */
if (pool-size_in_dw  allocated+unallocated) {
-   compute_memory_grow_pool(pool, pipe, allocated+unallocated);
+   err = compute_memory_grow_pool(pool, pipe, 
allocated+unallocated);
+   if (err == -1)
+   return -1;
}
 
/* Loop through all the pending items, allocate space for them and
@@ -310,17 +323,20 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
need += 1024 - (need % 1024);
 
if (need  0) {
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
else {
need = pool-size_in_dw / 10;
need += 1024 - (need % 1024);
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
+
+   if (err == -1)
+   return -1;
}
COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
start_in_dw = %u (%u bytes) size_in_dw = %u (%u 
bytes)\n,
@@ -356,6 +372,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
allocated += item-size_in_dw;
}
+
+   return 0;
 }
 
 
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 3777e3f..e61c003 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ 

[Mesa-dev] [PATCH 4/5] r600g/compute: Tidy a bit compute_memory_finalize_pending

2014-01-19 Thread Bruno Jiménez
Explanation of the changes, as requested by Tom Stellard:

Let's take need after is calculated as
item-size_in_dw+2048 - (pool-size_in_dw - allocated)

BEFORE:
If need is positive or 0:
we calculate need += 1024 - (need % 1024), which is like
cealing to the nearest multiple of 1024, for example
0 goes to 1024, 512 goes to 1024 as well, 1025 goes
to 2048 and so on. So now need is always possitive,
we do compute_memory_grow_pool, check its output
and continue.

If need is negative:
we calculate need += 1024 - (need % 1024), in this case
we will have negative numbers, and if need is
[-1024:-1] 0, so now we take the else, recalculate
need as need = pool-size_in_dw / 10 and
need += 1024 - (need % 1024), we do
compute_memory_grow_pool, check its output and continue.

AFTER:
If need is positive or 0:
we jump the if, calculate need += 1024 - (need % 1024)
compute_memory_grow_pool, check its output and continue.

If need is negative:
we enter the if, and need is now pool-size_in_dw / 10.
Now we calculate need += 1024 - (need % 1024)
compute_memory_grow_pool, check its output and continue.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 1e04639..7a3b92c 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -320,21 +320,16 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
int64_t need = item-size_in_dw+2048 -
(pool-size_in_dw - allocated);
 
-   need += 1024 - (need % 1024);
-
-   if (need  0) {
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
-   }
-   else {
+   if (need  0) {
need = pool-size_in_dw / 10;
-   need += 1024 - (need % 1024);
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
}
 
+   need += 1024 - (need % 1024);
+
+   err = compute_memory_grow_pool(pool,
+   pipe,
+   pool-size_in_dw + need);
+
if (err == -1)
return -1;
}
-- 
1.8.5.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 5/5] r600g/compute: Cleanup of compute_memory_pool.h

2014-01-19 Thread Bruno Jiménez
Removed compute_memory_defrag declaration because it seems
to be unimplemented.

I think that this function would have been the one that solves
the problem with fragmentation that compute_memory_finalize_pending has.

Also removed comments that are already at compute_memory_pool.c
---
 src/gallium/drivers/r600/compute_memory_pool.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index e61c003..c711c59 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -64,32 +64,17 @@ int64_t compute_memory_prealloc_chunk(struct 
compute_memory_pool* pool, int64_t
 
 struct compute_memory_item* compute_memory_postalloc_chunk(struct 
compute_memory_pool* pool, int64_t start_in_dw); ///search for the chunk where 
we can link our new chunk after it
 
-/** 
- * reallocates pool, conserves data
- * @returns -1 if it fails, 0 otherwise
- */
 int compute_memory_grow_pool(struct compute_memory_pool* pool, struct 
pipe_context * pipe,
int new_size_in_dw);
 
-/**
- * Copy pool from device to host, or host to device
- */
 void compute_memory_shadow(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host);
 
-/**
- * Allocates pending allocations in the pool
- * @returns -1 if it fails, 0 otherwise
- */
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe);
-void compute_memory_defrag(struct compute_memory_pool* pool); ///Defragment 
the memory pool, always heavy memory usage
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id);
 struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* 
pool, int64_t size_in_dw); ///Creates pending allocations
 
-/**
- * Transfer data host-device, offset and size is in bytes
- */
 void compute_memory_transfer(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host,
struct compute_memory_item* chunk, void* data,
-- 
1.8.5.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/5] Fixing a typo and some indentation

2014-01-06 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index fd3a04c..7a7b057 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -264,7 +264,7 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
unallocated += item-size_in_dw+1024;
}
else {
-   /* The item is not pendng, so update the amount of space
+   /* The item is not pending, so update the amount of 
space
 * that has already been allocated. */
allocated += item-size_in_dw;
}
@@ -452,7 +452,7 @@ void compute_memory_transfer(
map = pipe-transfer_map(pipe, gart, 0, PIPE_TRANSFER_READ,
(struct pipe_box) { .width = aligned_size,
.height = 1, .depth = 1 }, xfer);
-assert(xfer);
+   assert(xfer);
assert(map);
memcpy(data, map + internal_offset, size);
pipe-transfer_unmap(pipe, xfer);
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [v2] Cleaning compute_memory_pool from gallium/drivers/r600

2014-01-06 Thread Bruno Jiménez
Hi,

This is the second version of my previous patches.
I have cleaned a bit compute_memory_pool.c, added some
NULL checks to the code, corrected a typo and removed
an unneeded decraration of a function.

Patches 1 and 2 are the same.
Patch 3 changes Returns to @returns so doxygen can
parse it correctly.
Patch 4 is a correction of my anterior patch, as
it changed the behaviour of the code. It
also contain an explanation of the change
Patch 5 now, apart from removing the declaration
compute_memory_defrag, also removes some
comments that are already in
compute_memory_pool.c

[PATCH 1/5] Fixing a typo and some indentation
[PATCH 2/5] Adding checks for NULL after CALLOC
[PATCH 3/5] Add more NULL checks
[PATCH 4/5] Tidy a bit compute_memory_finalize_pending
[PATCH 5/5] Cleanup of compute_memory_pool.h
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/5] Adding checks for NULL after CALLOC

2014-01-06 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 7a7b057..62d1a5c 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -50,6 +50,8 @@ struct compute_memory_pool* compute_memory_pool_new(
 {
struct compute_memory_pool* pool = (struct compute_memory_pool*)
CALLOC(sizeof(struct compute_memory_pool), 1);
+   if(pool == NULL)
+   return NULL;
 
COMPUTE_DBG(rscreen, * compute_memory_pool_new()\n);
 
@@ -65,6 +67,9 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
initial_size_in_dw);
 
pool-shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
+   if(pool-shadow == NULL)
+   return;
+   
pool-next_id = 1;
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
@@ -401,6 +406,9 @@ struct compute_memory_item* compute_memory_alloc(
 
new_item = (struct compute_memory_item *)
CALLOC(sizeof(struct compute_memory_item), 1);
+   if(new_item == NULL)
+   return NULL;
+
new_item-size_in_dw = size_in_dw;
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 4/5] Tidy a bit compute_memory_finalize_pending

2014-01-06 Thread Bruno Jiménez
Explanation of the changes, as requested by Tom Stellard:

Let's take need after is calculated as
item-size_in_dw+2048 - (pool-size_in_dw - allocated)

BEFORE:
If need is positive or 0:
we calculate need += 1024 - (need % 1024), which is like
cealing to the nearest multiple of 1024, for example
0 goes to 1024, 512 goes to 1024 as well, 1025 goes
to 2048 and so on. So now need is always possitive,
we do compute_memory_grow_pool, check its output
and continue.

If need is negative:
we calculate need += 1024 - (need % 1024), in this case
we will have negative numbers, and if need is
[-1024:-1] 0, so now we take the else, recalculate
need as need = pool-size_in_dw / 10 and
need += 1024 - (need % 1024), we do
compute_memory_grow_pool, check its output and continue.

AFTER:
If need is positive or 0:
we jump the if, calculate need += 1024 - (need % 1024)
compute_memory_grow_pool, check its output and continue.

If need is negative:
we enter the if, and need is now pool-size_in_dw / 10.
Now we calculate need += 1024 - (need % 1024)
compute_memory_grow_pool, check its output and continue.
---
 src/gallium/drivers/r600/compute_memory_pool.c | 19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 4f4bad2..cf183cd 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -320,21 +320,16 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
int64_t need = item-size_in_dw+2048 -
(pool-size_in_dw - allocated);
 
-   need += 1024 - (need % 1024);
-
-   if (need  0) {
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
-   }
-   else {
+   if (need  0) {
need = pool-size_in_dw / 10;
-   need += 1024 - (need % 1024);
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
}
 
+   need += 1024 - (need % 1024);
+
+   err = compute_memory_grow_pool(pool,
+   pipe,
+   pool-size_in_dw + need);
+
if(err == -1)
return -1;
}
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 5/5] Cleanup of compute_memory_pool.h

2014-01-06 Thread Bruno Jiménez
Removed compute_memory_defrag declaration
because it seems to be unimplemented.

I think that this function would have been the one that
solves the problem with fragmentation that
compute_memory_finalize_pending has.

Also removed comments that are already at
compute_memory_pool.c
---
 src/gallium/drivers/r600/compute_memory_pool.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index e61c003..c711c59 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -64,32 +64,17 @@ int64_t compute_memory_prealloc_chunk(struct 
compute_memory_pool* pool, int64_t
 
 struct compute_memory_item* compute_memory_postalloc_chunk(struct 
compute_memory_pool* pool, int64_t start_in_dw); ///search for the chunk where 
we can link our new chunk after it
 
-/** 
- * reallocates pool, conserves data
- * @returns -1 if it fails, 0 otherwise
- */
 int compute_memory_grow_pool(struct compute_memory_pool* pool, struct 
pipe_context * pipe,
int new_size_in_dw);
 
-/**
- * Copy pool from device to host, or host to device
- */
 void compute_memory_shadow(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host);
 
-/**
- * Allocates pending allocations in the pool
- * @returns -1 if it fails, 0 otherwise
- */
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe);
-void compute_memory_defrag(struct compute_memory_pool* pool); ///Defragment 
the memory pool, always heavy memory usage
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id);
 struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* 
pool, int64_t size_in_dw); ///Creates pending allocations
 
-/**
- * Transfer data host-device, offset and size is in bytes
- */
 void compute_memory_transfer(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host,
struct compute_memory_item* chunk, void* data,
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/5] Add more NULL checks

2014-01-06 Thread Bruno Jiménez
In this case, NULL checks are added to compute_memory_grow_pool,
so it returns -1 when it fails. This makes necesary
to handle such cases in compute_memory_finalize_pending
when it is needed to grow the pool
---
 src/gallium/drivers/r600/compute_memory_pool.c | 30 --
 src/gallium/drivers/r600/compute_memory_pool.h |  6 --
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 62d1a5c..4f4bad2 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -161,9 +161,10 @@ struct compute_memory_item* compute_memory_postalloc_chunk(
 }
 
 /**
- * Reallocates pool, conserves data
+ * Reallocates pool, conserves data.
+ * @returns -1 if it fails, 0 otherwise
  */
-void compute_memory_grow_pool(struct compute_memory_pool* pool,
+int compute_memory_grow_pool(struct compute_memory_pool* pool,
struct pipe_context * pipe, int new_size_in_dw)
 {
COMPUTE_DBG(pool-screen, * compute_memory_grow_pool() 
@@ -174,6 +175,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
if (!pool-bo) {
compute_memory_pool_init(pool, MAX2(new_size_in_dw, 1024 * 16));
+   if(pool-shadow == NULL)
+   return -1;
} else {
new_size_in_dw += 1024 - (new_size_in_dw % 1024);
 
@@ -182,6 +185,9 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
compute_memory_shadow(pool, pipe, 1);
pool-shadow = realloc(pool-shadow, new_size_in_dw*4);
+   if(pool-shadow == NULL)
+   return -1;
+
pool-size_in_dw = new_size_in_dw;
pool-screen-b.b.resource_destroy(
(struct pipe_screen *)pool-screen,
@@ -191,6 +197,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
pool-size_in_dw * 4);
compute_memory_shadow(pool, pipe, 0);
}
+
+   return 0;
 }
 
 /**
@@ -214,8 +222,9 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
 
 /**
  * Allocates pending allocations in the pool
+ * @returns -1 if it fails, 0 otherwise
  */
-void compute_memory_finalize_pending(struct compute_memory_pool* pool,
+int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
 {
struct compute_memory_item *pending_list = NULL, *end_p = NULL;
@@ -226,6 +235,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
int64_t start_in_dw = 0;
 
+   int err = 0;
+
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
 
for (item = pool-item_list; item; item = item-next) {
@@ -293,7 +304,9 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 * they aren't contiguous, so it will be impossible to allocate Item D.
 */
if (pool-size_in_dw  allocated+unallocated) {
-   compute_memory_grow_pool(pool, pipe, allocated+unallocated);
+   err = compute_memory_grow_pool(pool, pipe, 
allocated+unallocated);
+   if(err == -1)
+   return -1;
}
 
/* Loop through all the pending items, allocate space for them and
@@ -310,17 +323,20 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
need += 1024 - (need % 1024);
 
if (need  0) {
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
else {
need = pool-size_in_dw / 10;
need += 1024 - (need % 1024);
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
+
+   if(err == -1)
+   return -1;
}
COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
start_in_dw = %u (%u bytes) size_in_dw = %u (%u 
bytes)\n,
@@ -356,6 +372,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
allocated += item-size_in_dw;
}
+
+   return 0;
 }
 
 
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 3777e3f..e61c003 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ 

[Mesa-dev] [PATCH 1/5] [r600g] Fixing a typo and some indentation

2014-01-06 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index fd3a04c..7a7b057 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -264,7 +264,7 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
unallocated += item-size_in_dw+1024;
}
else {
-   /* The item is not pendng, so update the amount of space
+   /* The item is not pending, so update the amount of 
space
 * that has already been allocated. */
allocated += item-size_in_dw;
}
@@ -452,7 +452,7 @@ void compute_memory_transfer(
map = pipe-transfer_map(pipe, gart, 0, PIPE_TRANSFER_READ,
(struct pipe_box) { .width = aligned_size,
.height = 1, .depth = 1 }, xfer);
-assert(xfer);
+   assert(xfer);
assert(map);
memcpy(data, map + internal_offset, size);
pipe-transfer_unmap(pipe, xfer);
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [v3][r600g] Cleaning compute_memory_pool from gallium/drivers/r600

2014-01-06 Thread Bruno Jiménez
Hi,

Third version of the patches.

Now with r600g in the commit messages.
Patches 2 and 3 have spaces between 'if' and '('.
Patches 1,4 and 5 are the same.

Thanks!

[PATCH 1/5] [r600g] Fixing a typo and some indentation
[PATCH 2/5] [r600g] Adding checks for NULL after CALLOC
[PATCH 3/5] [r600g] Add more NULL checks
[PATCH 4/5] [r600g] Tidy a bit compute_memory_finalize_pending
[PATCH 5/5] [r600g] Cleanup of compute_memory_pool.h
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/5] [r600g] Add more NULL checks

2014-01-06 Thread Bruno Jiménez
In this case, NULL checks are added to compute_memory_grow_pool,
so it returns -1 when it fails. This makes necesary
to handle such cases in compute_memory_finalize_pending
when it is needed to grow the pool
---
 src/gallium/drivers/r600/compute_memory_pool.c | 30 --
 src/gallium/drivers/r600/compute_memory_pool.h |  6 --
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index da351d8..1e04639 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -161,9 +161,10 @@ struct compute_memory_item* compute_memory_postalloc_chunk(
 }
 
 /**
- * Reallocates pool, conserves data
+ * Reallocates pool, conserves data.
+ * @returns -1 if it fails, 0 otherwise
  */
-void compute_memory_grow_pool(struct compute_memory_pool* pool,
+int compute_memory_grow_pool(struct compute_memory_pool* pool,
struct pipe_context * pipe, int new_size_in_dw)
 {
COMPUTE_DBG(pool-screen, * compute_memory_grow_pool() 
@@ -174,6 +175,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
if (!pool-bo) {
compute_memory_pool_init(pool, MAX2(new_size_in_dw, 1024 * 16));
+   if (pool-shadow == NULL)
+   return -1;
} else {
new_size_in_dw += 1024 - (new_size_in_dw % 1024);
 
@@ -182,6 +185,9 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
compute_memory_shadow(pool, pipe, 1);
pool-shadow = realloc(pool-shadow, new_size_in_dw*4);
+   if (pool-shadow == NULL)
+   return -1;
+
pool-size_in_dw = new_size_in_dw;
pool-screen-b.b.resource_destroy(
(struct pipe_screen *)pool-screen,
@@ -191,6 +197,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
pool-size_in_dw * 4);
compute_memory_shadow(pool, pipe, 0);
}
+
+   return 0;
 }
 
 /**
@@ -214,8 +222,9 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
 
 /**
  * Allocates pending allocations in the pool
+ * @returns -1 if it fails, 0 otherwise
  */
-void compute_memory_finalize_pending(struct compute_memory_pool* pool,
+int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
 {
struct compute_memory_item *pending_list = NULL, *end_p = NULL;
@@ -226,6 +235,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
int64_t start_in_dw = 0;
 
+   int err = 0;
+
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
 
for (item = pool-item_list; item; item = item-next) {
@@ -293,7 +304,9 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 * they aren't contiguous, so it will be impossible to allocate Item D.
 */
if (pool-size_in_dw  allocated+unallocated) {
-   compute_memory_grow_pool(pool, pipe, allocated+unallocated);
+   err = compute_memory_grow_pool(pool, pipe, 
allocated+unallocated);
+   if (err == -1)
+   return -1;
}
 
/* Loop through all the pending items, allocate space for them and
@@ -310,17 +323,20 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
need += 1024 - (need % 1024);
 
if (need  0) {
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
else {
need = pool-size_in_dw / 10;
need += 1024 - (need % 1024);
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
+
+   if (err == -1)
+   return -1;
}
COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
start_in_dw = %u (%u bytes) size_in_dw = %u (%u 
bytes)\n,
@@ -356,6 +372,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
allocated += item-size_in_dw;
}
+
+   return 0;
 }
 
 
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 3777e3f..e61c003 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ 

[Mesa-dev] [PATCH 5/5] [r600g] Cleanup of compute_memory_pool.h

2014-01-06 Thread Bruno Jiménez
Removed compute_memory_defrag declaration because it seems
to be unimplemented.

I think that this function would have been the one that solves
the problem with fragmentation that compute_memory_finalize_pending has.

Also removed comments that are already at compute_memory_pool.c
---
 src/gallium/drivers/r600/compute_memory_pool.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index e61c003..c711c59 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -64,32 +64,17 @@ int64_t compute_memory_prealloc_chunk(struct 
compute_memory_pool* pool, int64_t
 
 struct compute_memory_item* compute_memory_postalloc_chunk(struct 
compute_memory_pool* pool, int64_t start_in_dw); ///search for the chunk where 
we can link our new chunk after it
 
-/** 
- * reallocates pool, conserves data
- * @returns -1 if it fails, 0 otherwise
- */
 int compute_memory_grow_pool(struct compute_memory_pool* pool, struct 
pipe_context * pipe,
int new_size_in_dw);
 
-/**
- * Copy pool from device to host, or host to device
- */
 void compute_memory_shadow(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host);
 
-/**
- * Allocates pending allocations in the pool
- * @returns -1 if it fails, 0 otherwise
- */
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe);
-void compute_memory_defrag(struct compute_memory_pool* pool); ///Defragment 
the memory pool, always heavy memory usage
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id);
 struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* 
pool, int64_t size_in_dw); ///Creates pending allocations
 
-/**
- * Transfer data host-device, offset and size is in bytes
- */
 void compute_memory_transfer(struct compute_memory_pool* pool,
struct pipe_context * pipe, int device_to_host,
struct compute_memory_item* chunk, void* data,
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/5] [r600g] Adding checks for NULL after CALLOC

2014-01-06 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 7a7b057..da351d8 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -50,6 +50,8 @@ struct compute_memory_pool* compute_memory_pool_new(
 {
struct compute_memory_pool* pool = (struct compute_memory_pool*)
CALLOC(sizeof(struct compute_memory_pool), 1);
+   if (pool == NULL)
+   return NULL;
 
COMPUTE_DBG(rscreen, * compute_memory_pool_new()\n);
 
@@ -65,6 +67,9 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
initial_size_in_dw);
 
pool-shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
+   if (pool-shadow == NULL)
+   return;
+
pool-next_id = 1;
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
@@ -401,6 +406,9 @@ struct compute_memory_item* compute_memory_alloc(
 
new_item = (struct compute_memory_item *)
CALLOC(sizeof(struct compute_memory_item), 1);
+   if (new_item == NULL)
+   return NULL;
+
new_item-size_in_dw = size_in_dw;
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/5] Adding checks for NULL after CALLOC

2014-01-03 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 7a7b057..62d1a5c 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -50,6 +50,8 @@ struct compute_memory_pool* compute_memory_pool_new(
 {
struct compute_memory_pool* pool = (struct compute_memory_pool*)
CALLOC(sizeof(struct compute_memory_pool), 1);
+   if(pool == NULL)
+   return NULL;
 
COMPUTE_DBG(rscreen, * compute_memory_pool_new()\n);
 
@@ -65,6 +67,9 @@ static void compute_memory_pool_init(struct 
compute_memory_pool * pool,
initial_size_in_dw);
 
pool-shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
+   if(pool-shadow == NULL)
+   return;
+   
pool-next_id = 1;
pool-size_in_dw = initial_size_in_dw;
pool-bo = (struct 
r600_resource*)r600_compute_buffer_alloc_vram(pool-screen,
@@ -401,6 +406,9 @@ struct compute_memory_item* compute_memory_alloc(
 
new_item = (struct compute_memory_item *)
CALLOC(sizeof(struct compute_memory_item), 1);
+   if(new_item == NULL)
+   return NULL;
+
new_item-size_in_dw = size_in_dw;
new_item-start_in_dw = -1; /* mark pending */
new_item-id = pool-next_id++;
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 5/5] Remove compute_memory_defrag declaration

2014-01-03 Thread Bruno Jiménez
It seems to be unimplemented.

I think that this function would have been the one that
solves the problem with fragmentation that
compute_memory_finalize_pending has.
---
 src/gallium/drivers/r600/compute_memory_pool.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 5354b9a..8f1abdc 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++ b/src/gallium/drivers/r600/compute_memory_pool.h
@@ -83,7 +83,6 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
  */
 int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe);
-void compute_memory_defrag(struct compute_memory_pool* pool); ///Defragment 
the memory pool, always heavy memory usage
 void compute_memory_free(struct compute_memory_pool* pool, int64_t id);
 struct compute_memory_item* compute_memory_alloc(struct compute_memory_pool* 
pool, int64_t size_in_dw); ///Creates pending allocations
 
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/5] Fixing a typo and some indentation

2014-01-03 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index fd3a04c..7a7b057 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -264,7 +264,7 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
unallocated += item-size_in_dw+1024;
}
else {
-   /* The item is not pendng, so update the amount of space
+   /* The item is not pending, so update the amount of 
space
 * that has already been allocated. */
allocated += item-size_in_dw;
}
@@ -452,7 +452,7 @@ void compute_memory_transfer(
map = pipe-transfer_map(pipe, gart, 0, PIPE_TRANSFER_READ,
(struct pipe_box) { .width = aligned_size,
.height = 1, .depth = 1 }, xfer);
-assert(xfer);
+   assert(xfer);
assert(map);
memcpy(data, map + internal_offset, size);
pipe-transfer_unmap(pipe, xfer);
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 4/5] Tidy a bit compute_memory_finalize_pending

2014-01-03 Thread Bruno Jiménez
---
 src/gallium/drivers/r600/compute_memory_pool.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 5374a48..954c890 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -320,21 +320,17 @@ int compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
int64_t need = item-size_in_dw+2048 -
(pool-size_in_dw - allocated);
 
-   need += 1024 - (need % 1024);
 
-   if (need  0) {
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
-   }
-   else {
+   if (need = 0) {
need = pool-size_in_dw / 10;
-   need += 1024 - (need % 1024);
-   err = compute_memory_grow_pool(pool,
-   pipe,
-   pool-size_in_dw + need);
}
 
+   need += 1024 - (need % 1024);
+
+   err = compute_memory_grow_pool(pool,
+   pipe,
+   pool-size_in_dw + need);
+
if(err == -1)
return -1;
}
-- 
1.8.5.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] Cleaning compute_memory_pool from gallium/drivers/r600

2014-01-03 Thread Bruno Jiménez
Hi,

I have cleaned a bit compute_memory_pool.c, added some
NULL checks to the code, corrected a typo and removed
an unneeded decraration of a function.

Sorry if I got something wrong, this is the first
time I contribute to a project.

Thanks in advance!

[PATCH 1/5] Fixing a typo and some indentation
[PATCH 2/5] Adding checks for NULL after CALLOC
[PATCH 3/5] Add more NULL checks
[PATCH 4/5] Tidy a bit compute_memory_finalize_pending
[PATCH 5/5] Remove compute_memory_defrag declaration
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/5] Add more NULL checks

2014-01-03 Thread Bruno Jiménez
In this case, NULL checks are added to compute_memory_grow_pool,
so it returns -1 when it fails. This makes necesary
to handle such cases in compute_memory_finalize_pending
when it is needed to grow the pool
---
 src/gallium/drivers/r600/compute_memory_pool.c | 30 --
 src/gallium/drivers/r600/compute_memory_pool.h |  6 --
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c 
b/src/gallium/drivers/r600/compute_memory_pool.c
index 62d1a5c..5374a48 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -161,9 +161,10 @@ struct compute_memory_item* compute_memory_postalloc_chunk(
 }
 
 /**
- * Reallocates pool, conserves data
+ * Reallocates pool, conserves data.
+ * Returns -1 if it fails
  */
-void compute_memory_grow_pool(struct compute_memory_pool* pool,
+int compute_memory_grow_pool(struct compute_memory_pool* pool,
struct pipe_context * pipe, int new_size_in_dw)
 {
COMPUTE_DBG(pool-screen, * compute_memory_grow_pool() 
@@ -174,6 +175,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
if (!pool-bo) {
compute_memory_pool_init(pool, MAX2(new_size_in_dw, 1024 * 16));
+   if(pool-shadow == NULL)
+   return -1;
} else {
new_size_in_dw += 1024 - (new_size_in_dw % 1024);
 
@@ -182,6 +185,9 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
 
compute_memory_shadow(pool, pipe, 1);
pool-shadow = realloc(pool-shadow, new_size_in_dw*4);
+   if(pool-shadow == NULL)
+   return -1;
+
pool-size_in_dw = new_size_in_dw;
pool-screen-b.b.resource_destroy(
(struct pipe_screen *)pool-screen,
@@ -191,6 +197,8 @@ void compute_memory_grow_pool(struct compute_memory_pool* 
pool,
pool-size_in_dw * 4);
compute_memory_shadow(pool, pipe, 0);
}
+
+   return 0;
 }
 
 /**
@@ -214,8 +222,9 @@ void compute_memory_shadow(struct compute_memory_pool* pool,
 
 /**
  * Allocates pending allocations in the pool
+ * Returns -1 if it fails
  */
-void compute_memory_finalize_pending(struct compute_memory_pool* pool,
+int compute_memory_finalize_pending(struct compute_memory_pool* pool,
struct pipe_context * pipe)
 {
struct compute_memory_item *pending_list = NULL, *end_p = NULL;
@@ -226,6 +235,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
int64_t start_in_dw = 0;
 
+   int err = 0;
+
COMPUTE_DBG(pool-screen, * compute_memory_finalize_pending()\n);
 
for (item = pool-item_list; item; item = item-next) {
@@ -293,7 +304,9 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 * they aren't contiguous, so it will be impossible to allocate Item D.
 */
if (pool-size_in_dw  allocated+unallocated) {
-   compute_memory_grow_pool(pool, pipe, allocated+unallocated);
+   err = compute_memory_grow_pool(pool, pipe, 
allocated+unallocated);
+   if(err == -1)
+   return -1;
}
 
/* Loop through all the pending items, allocate space for them and
@@ -310,17 +323,20 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
need += 1024 - (need % 1024);
 
if (need  0) {
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
else {
need = pool-size_in_dw / 10;
need += 1024 - (need % 1024);
-   compute_memory_grow_pool(pool,
+   err = compute_memory_grow_pool(pool,
pipe,
pool-size_in_dw + need);
}
+
+   if(err == -1)
+   return -1;
}
COMPUTE_DBG(pool-screen,   + Found space for Item %p id = %u 
start_in_dw = %u (%u bytes) size_in_dw = %u (%u 
bytes)\n,
@@ -356,6 +372,8 @@ void compute_memory_finalize_pending(struct 
compute_memory_pool* pool,
 
allocated += item-size_in_dw;
}
+
+   return 0;
 }
 
 
diff --git a/src/gallium/drivers/r600/compute_memory_pool.h 
b/src/gallium/drivers/r600/compute_memory_pool.h
index 3777e3f..5354b9a 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.h
+++