summaryrefslogtreecommitdiff
path: root/backend/src/driver/cl_gen_context.cpp
blob: 8a9f0c7bdffb80c03571561ec29228f25d05761f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright © 2012 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifdef __cplusplus
extern "C" {  // for the C header files
#endif /* __cplusplus */
#include "cl_gen_driver.h"
#ifdef __cplusplus
}
#endif /* __cplusplus */
#include "cl_gen_driver.hpp"
#include "sys/assert.hpp"
#include "sys/alloc.hpp"

GenGPUContext::GenGPUContext(dri_bufmgr *bufmgr)
{
  ctx = drm_intel_gem_context_create(bufmgr);
  GBE_ASSERT(ctx);
  this->bufmgr = bufmgr;
}

GenGPUContext::~GenGPUContext(void)
{
  if(ctx)
    drm_intel_gem_context_destroy(ctx);
}

extern "C"
cl_int GenCreateContext(cl_context context, const cl_device_id device,
                        const cl_context_properties* properties)
{
  GBE_ASSERT(getGenContextPrivate(context, device) == NULL);
  dri_bufmgr *bufmgr =
    (reinterpret_cast<GenGPUDevice*>(getGenDevicePrivate(device)))->bufmgr;
  GBE_ASSERT(bufmgr);
  GenGPUContext* gpuCtx = GBE_NEW(GenGPUContext, bufmgr);
  GBE_ASSERT(gpuCtx);
  setGenContextPrivate(context, device, gpuCtx);
  return CL_SUCCESS;
}

extern "C"
cl_int GenReleaseContext(cl_context context, const cl_device_id device)
{
  if (getGenContextPrivate(context, device) != NULL) {
    return CL_INVALID_VALUE;
  }

  GenGPUContext* gpuCtx = reinterpret_cast<GenGPUContext*>(getGenContextPrivate(context, device));
  GBE_DELETE(gpuCtx);
  setGenContextPrivate(context, device, NULL);
  return CL_SUCCESS;
}