2 * Copyright 2011, Blender Foundation.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "device_memory.h"
26 #include "util_string.h"
27 #include "util_thread.h"
28 #include "util_types.h"
29 #include "util_vector.h"
54 typedef enum { PATH_TRACE, TONEMAP, DISPLACE } Type;
64 device_ptr displace_input;
65 device_ptr displace_offset;
66 int displace_x, displace_w;
68 DeviceTask(Type type = PATH_TRACE);
69 void split(ThreadQueue<DeviceTask>& tasks, int num);
78 DeviceType device_type;
84 DeviceType type() { return device_type; }
87 virtual string description() = 0;
90 virtual void mem_alloc(device_memory& mem, MemoryType type) = 0;
91 virtual void mem_copy_to(device_memory& mem) = 0;
92 virtual void mem_copy_from(device_memory& mem,
93 size_t offset, size_t size) = 0;
94 virtual void mem_zero(device_memory& mem) = 0;
95 virtual void mem_free(device_memory& mem) = 0;
98 virtual void const_copy_to(const char *name, void *host, size_t size) = 0;
101 virtual void tex_alloc(const char *name, device_memory& mem,
102 bool interpolation = false, bool periodic = false) {};
103 virtual void tex_free(device_memory& mem) {};
106 virtual void pixels_alloc(device_memory& mem);
107 virtual void pixels_copy_from(device_memory& mem, int y, int w, int h);
108 virtual void pixels_free(device_memory& mem);
110 /* open shading language, only for CPU device */
111 virtual void *osl_memory() { return NULL; }
113 /* load/compile kernels, must be called before adding tasks */
114 virtual bool load_kernels() { return true; }
117 virtual void task_add(DeviceTask& task) = 0;
118 virtual void task_wait() = 0;
119 virtual void task_cancel() = 0;
122 virtual void draw_pixels(device_memory& mem, int y, int w, int h,
123 int width, int height, bool transparent);
131 static Device *create(DeviceType type, bool background = true, int threads = 0);
133 static DeviceType type_from_string(const char *name);
134 static string string_from_type(DeviceType type);
135 static vector<DeviceType> available_types();
140 #endif /* __DEVICE_H__ */