2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DEVICE_MEMORY_H__
|
|
|
|
#define __DEVICE_MEMORY_H__
|
|
|
|
|
|
|
|
/* Device Memory
|
|
|
|
*
|
2017-10-20 23:09:59 +00:00
|
|
|
* Data types for allocating, copying and freeing device memory. */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "util/util_debug.h"
|
|
|
|
#include "util/util_half.h"
|
2017-10-20 21:31:13 +00:00
|
|
|
#include "util/util_texture.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "util/util_types.h"
|
|
|
|
#include "util/util_vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
class Device;
|
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
enum MemoryType {
|
|
|
|
MEM_READ_ONLY,
|
2017-10-20 23:09:59 +00:00
|
|
|
MEM_READ_WRITE,
|
|
|
|
MEM_TEXTURE,
|
|
|
|
MEM_PIXELS
|
2012-01-04 18:06:32 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Supported Data Types */
|
|
|
|
|
|
|
|
enum DataType {
|
2017-09-26 21:42:36 +00:00
|
|
|
TYPE_UNKNOWN,
|
2011-04-27 11:58:34 +00:00
|
|
|
TYPE_UCHAR,
|
|
|
|
TYPE_UINT,
|
|
|
|
TYPE_INT,
|
2013-08-30 23:49:38 +00:00
|
|
|
TYPE_FLOAT,
|
2017-03-11 10:23:11 +00:00
|
|
|
TYPE_HALF,
|
|
|
|
TYPE_UINT64,
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline size_t datatype_size(DataType datatype)
|
|
|
|
{
|
|
|
|
switch(datatype) {
|
2017-09-26 21:42:36 +00:00
|
|
|
case TYPE_UNKNOWN: return 1;
|
2011-04-27 11:58:34 +00:00
|
|
|
case TYPE_UCHAR: return sizeof(uchar);
|
|
|
|
case TYPE_FLOAT: return sizeof(float);
|
|
|
|
case TYPE_UINT: return sizeof(uint);
|
|
|
|
case TYPE_INT: return sizeof(int);
|
2013-08-30 23:49:38 +00:00
|
|
|
case TYPE_HALF: return sizeof(half);
|
2017-03-11 10:23:11 +00:00
|
|
|
case TYPE_UINT64: return sizeof(uint64_t);
|
2011-04-27 11:58:34 +00:00
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Traits for data types */
|
|
|
|
|
|
|
|
template<typename T> struct device_type_traits {
|
2017-09-26 21:42:36 +00:00
|
|
|
static const DataType data_type = TYPE_UNKNOWN;
|
|
|
|
static const int num_elements = sizeof(T);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<uchar> {
|
|
|
|
static const DataType data_type = TYPE_UCHAR;
|
|
|
|
static const int num_elements = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<uchar2> {
|
|
|
|
static const DataType data_type = TYPE_UCHAR;
|
|
|
|
static const int num_elements = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<uchar3> {
|
|
|
|
static const DataType data_type = TYPE_UCHAR;
|
|
|
|
static const int num_elements = 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<uchar4> {
|
|
|
|
static const DataType data_type = TYPE_UCHAR;
|
|
|
|
static const int num_elements = 4;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<uint> {
|
|
|
|
static const DataType data_type = TYPE_UINT;
|
|
|
|
static const int num_elements = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<uint2> {
|
|
|
|
static const DataType data_type = TYPE_UINT;
|
|
|
|
static const int num_elements = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<uint3> {
|
|
|
|
static const DataType data_type = TYPE_UINT;
|
|
|
|
static const int num_elements = 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<uint4> {
|
|
|
|
static const DataType data_type = TYPE_UINT;
|
|
|
|
static const int num_elements = 4;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<int> {
|
|
|
|
static const DataType data_type = TYPE_INT;
|
|
|
|
static const int num_elements = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<int2> {
|
|
|
|
static const DataType data_type = TYPE_INT;
|
|
|
|
static const int num_elements = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<int3> {
|
|
|
|
static const DataType data_type = TYPE_INT;
|
|
|
|
static const int num_elements = 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<int4> {
|
|
|
|
static const DataType data_type = TYPE_INT;
|
|
|
|
static const int num_elements = 4;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<float> {
|
|
|
|
static const DataType data_type = TYPE_FLOAT;
|
|
|
|
static const int num_elements = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<float2> {
|
|
|
|
static const DataType data_type = TYPE_FLOAT;
|
|
|
|
static const int num_elements = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<float3> {
|
|
|
|
static const DataType data_type = TYPE_FLOAT;
|
2017-05-07 12:40:58 +00:00
|
|
|
static const int num_elements = 4;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct device_type_traits<float4> {
|
|
|
|
static const DataType data_type = TYPE_FLOAT;
|
|
|
|
static const int num_elements = 4;
|
|
|
|
};
|
|
|
|
|
2016-06-19 18:17:03 +00:00
|
|
|
template<> struct device_type_traits<half> {
|
|
|
|
static const DataType data_type = TYPE_HALF;
|
|
|
|
static const int num_elements = 1;
|
|
|
|
};
|
|
|
|
|
2013-08-30 23:49:38 +00:00
|
|
|
template<> struct device_type_traits<half4> {
|
|
|
|
static const DataType data_type = TYPE_HALF;
|
|
|
|
static const int num_elements = 4;
|
|
|
|
};
|
|
|
|
|
2017-03-11 10:23:11 +00:00
|
|
|
template<> struct device_type_traits<uint64_t> {
|
|
|
|
static const DataType data_type = TYPE_UINT64;
|
|
|
|
static const int num_elements = 1;
|
|
|
|
};
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Device Memory
|
|
|
|
*
|
|
|
|
* Base class for all device memory. This should not be allocated directly,
|
|
|
|
* instead the appropriate subclass can be used. */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
class device_memory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
size_t memory_size() { return data_size*data_elements*datatype_size(data_type); }
|
2017-05-07 12:40:58 +00:00
|
|
|
size_t memory_elements_size(int elements) {
|
|
|
|
return elements*data_elements*datatype_size(data_type);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Data information. */
|
2011-04-27 11:58:34 +00:00
|
|
|
DataType data_type;
|
|
|
|
int data_elements;
|
|
|
|
device_ptr data_pointer;
|
|
|
|
size_t data_size;
|
2014-09-04 11:22:40 +00:00
|
|
|
size_t device_size;
|
2011-04-27 11:58:34 +00:00
|
|
|
size_t data_width;
|
|
|
|
size_t data_height;
|
2014-03-29 12:03:48 +00:00
|
|
|
size_t data_depth;
|
2017-10-20 21:31:13 +00:00
|
|
|
MemoryType type;
|
|
|
|
const char *name;
|
|
|
|
InterpolationType interpolation;
|
|
|
|
ExtensionType extension;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Device pointer. */
|
2017-10-20 21:31:13 +00:00
|
|
|
Device *device;
|
2011-04-27 11:58:34 +00:00
|
|
|
device_ptr device_pointer;
|
|
|
|
|
2017-10-20 21:31:13 +00:00
|
|
|
virtual ~device_memory();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-02-22 12:32:57 +00:00
|
|
|
protected:
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Only create through subclasses. */
|
|
|
|
device_memory(Device *device, const char *name, MemoryType type);
|
|
|
|
|
|
|
|
/* No copying allowed. */
|
2011-04-27 11:58:34 +00:00
|
|
|
device_memory(const device_memory&);
|
|
|
|
device_memory& operator = (const device_memory&);
|
2017-10-20 23:09:59 +00:00
|
|
|
|
|
|
|
/* Host allocation on the device. All data_pointer memory should be
|
|
|
|
* allocated with these functions, for devices that support using
|
|
|
|
* the same pointer for host and device. */
|
|
|
|
device_ptr host_alloc(size_t size);
|
|
|
|
void host_free(device_ptr ptr, size_t size);
|
|
|
|
|
|
|
|
/* Device memory allocation and copying. */
|
|
|
|
void device_alloc();
|
|
|
|
void device_free();
|
|
|
|
void device_copy_to();
|
|
|
|
void device_copy_from(int y, int w, int h, int elem);
|
|
|
|
void device_zero();
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Device Only Memory
|
|
|
|
*
|
|
|
|
* Working memory only needed by the device, with no corresponding allocation
|
|
|
|
* on the host. Only used internally in the device implementations. */
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
template<typename T>
|
|
|
|
class device_only_memory : public device_memory
|
|
|
|
{
|
|
|
|
public:
|
2017-10-20 21:31:13 +00:00
|
|
|
device_only_memory(Device *device, const char *name)
|
|
|
|
: device_memory(device, name, MEM_READ_WRITE)
|
2017-05-07 12:40:58 +00:00
|
|
|
{
|
|
|
|
data_type = device_type_traits<T>::data_type;
|
|
|
|
data_elements = max(device_type_traits<T>::num_elements, 1);
|
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
virtual ~device_only_memory()
|
|
|
|
{
|
|
|
|
free();
|
|
|
|
}
|
|
|
|
|
|
|
|
void alloc_to_device(size_t num)
|
|
|
|
{
|
|
|
|
data_size = num*sizeof(T);
|
|
|
|
device_alloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
void free()
|
|
|
|
{
|
|
|
|
device_free();
|
|
|
|
}
|
|
|
|
|
|
|
|
void zero_to_device()
|
2017-05-07 12:40:58 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
device_zero();
|
2017-05-07 12:40:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Device Vector
|
|
|
|
*
|
|
|
|
* Data vector to exchange data between host and device. Memory will be
|
|
|
|
* allocated on the host first with alloc() and resize, and then filled
|
|
|
|
* in and copied to the device with copy_to_device(). Or alternatively
|
|
|
|
* allocated and set to zero on the device with zero_to_device().
|
|
|
|
*
|
|
|
|
* When using memory type MEM_TEXTURE, a pointer to this memory will be
|
|
|
|
* automatically attached to kernel globals, using the provided name
|
|
|
|
* matching an entry in kernel_textures.h. */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
template<typename T> class device_vector : public device_memory
|
|
|
|
{
|
|
|
|
public:
|
2017-10-20 23:09:59 +00:00
|
|
|
device_vector(Device *device, const char *name, MemoryType type)
|
2017-10-20 21:31:13 +00:00
|
|
|
: device_memory(device, name, type)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
data_type = device_type_traits<T>::data_type;
|
|
|
|
data_elements = device_type_traits<T>::num_elements;
|
|
|
|
|
|
|
|
assert(data_elements > 0);
|
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
virtual ~device_vector()
|
|
|
|
{
|
|
|
|
free();
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Host memory allocation. */
|
|
|
|
T *alloc(size_t width, size_t height = 0, size_t depth = 0)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
size_t new_size = size(width, height, depth);
|
|
|
|
|
|
|
|
if(new_size != data_size) {
|
|
|
|
device_free();
|
|
|
|
host_free(data_pointer, sizeof(T)*data_size);
|
|
|
|
data_pointer = host_alloc(sizeof(T)*new_size);
|
2017-10-24 23:22:16 +00:00
|
|
|
assert(device_pointer == 0);
|
2015-09-04 07:38:10 +00:00
|
|
|
}
|
2017-10-20 23:09:59 +00:00
|
|
|
|
|
|
|
data_size = new_size;
|
2011-04-27 11:58:34 +00:00
|
|
|
data_width = width;
|
|
|
|
data_height = height;
|
2014-03-29 12:03:48 +00:00
|
|
|
data_depth = depth;
|
2017-10-20 23:09:59 +00:00
|
|
|
|
|
|
|
return get_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Host memory resize. Only use this if the original data needs to be
|
|
|
|
* preserved, it is faster to call alloc() if it can be discarded. */
|
|
|
|
T *resize(size_t width, size_t height = 0, size_t depth = 0)
|
|
|
|
{
|
|
|
|
size_t new_size = size(width, height, depth);
|
|
|
|
|
|
|
|
if(new_size != data_size) {
|
|
|
|
device_ptr new_ptr = host_alloc(sizeof(T)*new_size);
|
|
|
|
|
|
|
|
if(new_size && data_size) {
|
|
|
|
size_t min_size = ((new_size < data_size)? new_size: data_size);
|
|
|
|
memcpy((T*)new_ptr, (T*)data_pointer, sizeof(T)*min_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_free();
|
|
|
|
host_free(data_pointer, sizeof(T)*data_size);
|
|
|
|
data_pointer = new_ptr;
|
2017-10-24 21:23:16 +00:00
|
|
|
assert(device_pointer == 0);
|
2015-06-30 21:23:38 +00:00
|
|
|
}
|
2017-10-20 23:09:59 +00:00
|
|
|
|
|
|
|
data_size = new_size;
|
|
|
|
data_width = width;
|
|
|
|
data_height = height;
|
|
|
|
data_depth = depth;
|
|
|
|
|
|
|
|
return get_data();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Take over data from an existing array. */
|
2017-10-20 02:32:29 +00:00
|
|
|
void steal_data(array<T>& from)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
device_free();
|
|
|
|
host_free(data_pointer, sizeof(T)*data_size);
|
|
|
|
|
|
|
|
data_size = from.size();
|
|
|
|
data_width = 0;
|
2017-10-20 02:32:29 +00:00
|
|
|
data_height = 0;
|
|
|
|
data_depth = 0;
|
2017-10-20 23:09:59 +00:00
|
|
|
data_pointer = (device_ptr)from.steal_pointer();
|
|
|
|
assert(device_pointer == 0);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Free device and host memory. */
|
|
|
|
void free()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
device_free();
|
|
|
|
host_free(data_pointer, sizeof(T)*data_size);
|
|
|
|
|
|
|
|
data_size = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
data_width = 0;
|
|
|
|
data_height = 0;
|
2014-03-29 12:03:48 +00:00
|
|
|
data_depth = 0;
|
2017-10-20 23:09:59 +00:00
|
|
|
data_pointer = 0;
|
|
|
|
assert(device_pointer == 0);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t size()
|
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
return data_size;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-10-03 08:52:04 +00:00
|
|
|
T* get_data()
|
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
return (T*)data_pointer;
|
2014-10-03 08:52:04 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 02:32:29 +00:00
|
|
|
T& operator[](size_t i)
|
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
assert(i < data_size);
|
|
|
|
return get_data()[i];
|
2017-10-20 02:32:29 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
void copy_to_device()
|
|
|
|
{
|
|
|
|
device_copy_to();
|
|
|
|
}
|
|
|
|
|
|
|
|
void copy_from_device(int y, int w, int h)
|
|
|
|
{
|
|
|
|
device_copy_from(y, w, h, sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
void zero_to_device()
|
|
|
|
{
|
|
|
|
device_zero();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t size(size_t width, size_t height, size_t depth)
|
|
|
|
{
|
|
|
|
return width * ((height == 0)? 1: height) * ((depth == 0)? 1: depth);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* Pixel Memory
|
|
|
|
*
|
|
|
|
* Device memory to efficiently draw as pixels to the screen in interactive
|
|
|
|
* rendering. Only copying pixels from the device is supported, not copying to. */
|
|
|
|
|
|
|
|
template<typename T> class device_pixels : public device_vector<T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
device_pixels(Device *device, const char *name)
|
|
|
|
: device_vector<T>(device, name, MEM_PIXELS)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void alloc_to_device(size_t width, size_t height, size_t depth = 0)
|
|
|
|
{
|
|
|
|
device_vector<T>::alloc(width, height, depth);
|
|
|
|
device_memory::device_alloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
T *copy_from_device(int y, int w, int h)
|
|
|
|
{
|
|
|
|
device_memory::device_copy_from(y, w, h, sizeof(T));
|
|
|
|
return device_vector<T>::get_data();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Device Sub Memory
|
|
|
|
*
|
|
|
|
* Pointer into existing memory. It is not allocated separately, but created
|
|
|
|
* from an already allocated base memory. It is freed automatically when it
|
|
|
|
* goes out of scope, which should happen before base memory is freed.
|
|
|
|
*
|
|
|
|
* Note: some devices require offset and size of the sub_ptr to be properly
|
|
|
|
* aligned to device->mem_address_alingment(). */
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
class device_sub_ptr
|
|
|
|
{
|
|
|
|
public:
|
2017-10-20 21:31:13 +00:00
|
|
|
device_sub_ptr(device_memory& mem, int offset, int size);
|
2017-05-07 12:40:58 +00:00
|
|
|
~device_sub_ptr();
|
|
|
|
|
|
|
|
device_ptr operator*() const
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
2017-10-20 23:09:59 +00:00
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
protected:
|
2017-10-20 23:09:59 +00:00
|
|
|
/* No copying. */
|
|
|
|
device_sub_ptr& operator = (const device_sub_ptr&);
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
Device *device;
|
|
|
|
device_ptr ptr;
|
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __DEVICE_MEMORY_H__ */
|
|
|
|
|