Georgios Pinitas | df31036 | 2018-11-14 13:16:56 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Georgios Pinitas | df31036 | 2018-11-14 13:16:56 +0000 | [diff] [blame] | 3 | * |
| 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_RUNTIME_GLES_COMPUTE_GC_MEMORY_REGION_H |
| 25 | #define ARM_COMPUTE_RUNTIME_GLES_COMPUTE_GC_MEMORY_REGION_H |
Georgios Pinitas | df31036 | 2018-11-14 13:16:56 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/GLES_COMPUTE/OpenGLES.h" |
| 28 | #include "arm_compute/runtime/IMemoryRegion.h" |
| 29 | |
| 30 | #include <cstddef> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | /** GLES memory region interface */ |
| 35 | class IGCMemoryRegion : public IMemoryRegion |
| 36 | { |
| 37 | public: |
| 38 | /** Constructor |
| 39 | * |
| 40 | * @param[in] size Region size |
| 41 | */ |
| 42 | IGCMemoryRegion(size_t size); |
| 43 | /** Default Destructor */ |
| 44 | virtual ~IGCMemoryRegion() = default; |
| 45 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 46 | IGCMemoryRegion(const IGCMemoryRegion &) = delete; |
| 47 | /** Default move constructor */ |
| 48 | IGCMemoryRegion(IGCMemoryRegion &&) = default; |
| 49 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 50 | IGCMemoryRegion &operator=(const IGCMemoryRegion &) = delete; |
| 51 | /** Default move assignment operator */ |
| 52 | IGCMemoryRegion &operator=(IGCMemoryRegion &&) = default; |
| 53 | /** Returns the underlying CL buffer |
| 54 | * |
| 55 | * @return CL memory buffer object |
| 56 | */ |
| 57 | const GLuint &gc_ssbo_name() const; |
| 58 | /** Host/SVM pointer accessor |
| 59 | * |
| 60 | * @return Host/SVM pointer base |
| 61 | */ |
| 62 | virtual void *ptr() = 0; |
| 63 | /** Enqueue a map operation of the allocated buffer on the given queue. |
| 64 | * |
| 65 | * @param[in] blocking If true, then the mapping will be ready to use by the time |
| 66 | * this method returns, else it is the caller's responsibility |
| 67 | * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer. |
| 68 | * |
| 69 | * @return The mapping address. |
| 70 | */ |
| 71 | virtual void *map(bool blocking) = 0; |
| 72 | /** Enqueue an unmap operation of the allocated buffer on the given queue. |
| 73 | * |
| 74 | * @note This method simply enqueue the unmap operation, it is the caller's responsibility to flush the queue and make sure the unmap is finished before |
| 75 | * the memory is accessed by the device. |
| 76 | * |
| 77 | */ |
| 78 | virtual void unmap() = 0; |
| 79 | |
| 80 | // Inherited methods overridden : |
Georgios Pinitas | 74ef1db | 2020-01-20 17:01:15 +0000 | [diff] [blame] | 81 | void *buffer() override; |
| 82 | const void *buffer() const override; |
Georgios Pinitas | df31036 | 2018-11-14 13:16:56 +0000 | [diff] [blame] | 83 | |
| 84 | protected: |
| 85 | void *_mapping; |
| 86 | GLuint _ssbo_name; |
| 87 | }; |
| 88 | |
| 89 | /** GLES buffer memory region implementation */ |
| 90 | class GCBufferMemoryRegion final : public IGCMemoryRegion |
| 91 | { |
| 92 | public: |
| 93 | /** Constructor |
| 94 | * |
| 95 | * @param[in] size Region size |
| 96 | */ |
| 97 | GCBufferMemoryRegion(size_t size); |
| 98 | /** Destructor */ |
| 99 | ~GCBufferMemoryRegion(); |
| 100 | |
| 101 | // Inherited methods overridden : |
| 102 | void *ptr() final; |
| 103 | void *map(bool blocking) final; |
| 104 | void unmap() final; |
| 105 | std::unique_ptr<IMemoryRegion> extract_subregion(size_t offset, size_t size) final; |
| 106 | }; |
| 107 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 108 | #endif /* ARM_COMPUTE_RUNTIME_GLES_COMPUTE_GC_MEMORY_REGION_H */ |