aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compute/skc/allocator_host.c
diff options
context:
space:
mode:
authorGravatar Allan MacKinnon <allanmac@google.com>2018-06-19 13:57:04 -0700
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-20 01:19:18 +0000
commit4359d529121fc1f39f882693d641c0133d138d41 (patch)
treed2c3239162e68d24d5c2cebc8a4f6659860cc2a0 /src/compute/skc/allocator_host.c
parent47c29fa64b3ffc1eec7723d40e9862b2d2a8443f (diff)
Skia Compute core files
Bug: skia: Change-Id: I4bba49cf20eff013e581800a3f114c85acd8498c Reviewed-on: https://skia-review.googlesource.com/135782 Reviewed-by: Mike Klein <mtklein@google.com> Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/compute/skc/allocator_host.c')
-rw-r--r--src/compute/skc/allocator_host.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/compute/skc/allocator_host.c b/src/compute/skc/allocator_host.c
new file mode 100644
index 0000000000..dbdcba0f51
--- /dev/null
+++ b/src/compute/skc/allocator_host.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can
+ * be found in the LICENSE file.
+ *
+ */
+
+//
+//
+//
+
+#include <stdlib.h>
+
+//
+//
+//
+
+#include "runtime_cl_12.h"
+#include "config_cl.h"
+
+//
+//
+//
+
+#define SKC_RUNTIME_HOST_CACHELINE_SIZE 64
+
+#define SKC_ALIGNED_MALLOC(size,alignment) _aligned_malloc(size,alignment)
+#define SKC_ALIGNED_FREE(p) _aligned_free(p)
+
+//
+// PERM
+//
+
+void *
+skc_runtime_host_perm_alloc(struct skc_runtime * const runtime,
+ skc_mem_flags_e const flags,
+ size_t const size)
+{
+ return SKC_ALIGNED_MALLOC(SKC_ROUND_UP(size,SKC_RUNTIME_HOST_CACHELINE_SIZE),
+ SKC_RUNTIME_HOST_CACHELINE_SIZE);
+}
+
+void
+skc_runtime_host_perm_free(struct skc_runtime * const runtime,
+ void * const mem)
+{
+ SKC_ALIGNED_FREE(mem);
+}
+
+//
+// TEMP
+//
+
+void *
+skc_runtime_host_temp_alloc(struct skc_runtime * const runtime,
+ skc_mem_flags_e const flags,
+ size_t const size,
+ skc_subbuf_id_t * const subbuf_id,
+ size_t * const subbuf_size)
+{
+ if (size == 0)
+ {
+ *subbuf_id = (skc_subbuf_id_t)-1;
+
+ if (subbuf_size != NULL)
+ *subbuf_size = 0;
+
+ return NULL;
+ }
+
+ return runtime->allocator.host.temp.extent +
+ skc_suballocator_subbuf_alloc(&runtime->allocator.host.temp.suballocator,
+ runtime->scheduler,
+ size,subbuf_id,subbuf_size);
+}
+
+
+void
+skc_runtime_host_temp_free(struct skc_runtime * const runtime,
+ void * const mem,
+ skc_subbuf_id_t const subbuf_id)
+{
+ if (mem == NULL)
+ return;
+
+ skc_suballocator_subbuf_free(&runtime->allocator.host.temp.suballocator,subbuf_id);
+}
+
+//
+//
+//
+
+void
+skc_allocator_host_create(struct skc_runtime * const runtime)
+{
+ skc_suballocator_create(runtime,
+ &runtime->allocator.host.temp.suballocator,
+ "HOST ",
+ runtime->config->suballocator.host.subbufs,
+ SKC_RUNTIME_HOST_CACHELINE_SIZE,
+ runtime->config->suballocator.host.size);
+
+ runtime->allocator.host.temp.extent =
+ skc_runtime_host_perm_alloc(runtime,
+ SKC_MEM_FLAGS_READ_WRITE,
+ runtime->config->suballocator.host.size);
+}
+
+void
+skc_allocator_host_dispose(struct skc_runtime * const runtime)
+{
+ skc_suballocator_dispose(runtime,&runtime->allocator.host.temp.suballocator);
+
+ skc_runtime_host_perm_free(runtime,runtime->allocator.host.temp.extent);
+}
+
+//
+//
+//