blob: 2ffd9f2ffcbe34e51f0d4a59bb26ebda2425a0a9 [file] [log] [blame]
Georgios Pinitasdf310362018-11-14 13:16:56 +00001/*
Georgios Pinitas74ef1db2020-01-20 17:01:15 +00002 * Copyright (c) 2018-2020 ARM Limited.
Georgios Pinitasdf310362018-11-14 13:16:56 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/runtime/GLES_COMPUTE/GCMemoryRegion.h"
25
26#include "arm_compute/core/Error.h"
27
28namespace arm_compute
29{
30IGCMemoryRegion::IGCMemoryRegion(size_t size)
31 : IMemoryRegion(size), _mapping(nullptr), _ssbo_name(0)
32{
33}
34
35const GLuint &IGCMemoryRegion::gc_ssbo_name() const
36{
37 return _ssbo_name;
38}
39
40void *IGCMemoryRegion::buffer()
41{
42 return _mapping;
43}
44
Georgios Pinitas74ef1db2020-01-20 17:01:15 +000045const void *IGCMemoryRegion::buffer() const
Georgios Pinitasdf310362018-11-14 13:16:56 +000046{
47 return _mapping;
48}
49
50GCBufferMemoryRegion::GCBufferMemoryRegion(size_t size)
51 : IGCMemoryRegion(size)
52{
53 ARM_COMPUTE_GL_CHECK(glGenBuffers(1, &_ssbo_name));
54 ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, _ssbo_name));
55 ARM_COMPUTE_GL_CHECK(glBufferData(GL_SHADER_STORAGE_BUFFER, static_cast<GLsizeiptr>(size), nullptr, GL_STATIC_DRAW));
56 ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0));
57}
58
59GCBufferMemoryRegion::~GCBufferMemoryRegion()
60{
61 ARM_COMPUTE_GL_CHECK(glDeleteBuffers(1, &_ssbo_name));
62}
63
64void *GCBufferMemoryRegion::ptr()
65{
66 return nullptr;
67}
68
69void *GCBufferMemoryRegion::map(bool blocking)
70{
71 ARM_COMPUTE_ERROR_ON(_mapping != nullptr);
72 ARM_COMPUTE_UNUSED(blocking);
73
74 ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, _ssbo_name));
75 void *p = ARM_COMPUTE_GL_CHECK(glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, static_cast<GLsizeiptr>(size()), GL_MAP_READ_BIT | GL_MAP_WRITE_BIT));
76 _mapping = reinterpret_cast<uint8_t *>(p);
77
78 return _mapping;
79}
80
81void GCBufferMemoryRegion::unmap()
82{
83 ARM_COMPUTE_ERROR_ON(_mapping == nullptr);
84
85 ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, _ssbo_name));
86 ARM_COMPUTE_GL_CHECK(glUnmapBuffer(GL_SHADER_STORAGE_BUFFER));
87 ARM_COMPUTE_GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0));
88 _mapping = nullptr;
89}
90
91std::unique_ptr<IMemoryRegion> GCBufferMemoryRegion::extract_subregion(size_t offset, size_t size)
92{
93 ARM_COMPUTE_UNUSED(offset, size);
94 return nullptr;
95}
96} // namespace arm_compute