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 __IMAGE_H__
|
|
|
|
#define __IMAGE_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 "device/device.h"
|
|
|
|
#include "device/device_memory.h"
|
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_image.h"
|
|
|
|
#include "util/util_string.h"
|
|
|
|
#include "util/util_thread.h"
|
|
|
|
#include "util/util_vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class Device;
|
|
|
|
class Progress;
|
2018-07-27 13:46:13 +00:00
|
|
|
class RenderStats;
|
2016-11-17 11:13:22 +00:00
|
|
|
class Scene;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2018-02-27 21:16:45 +00:00
|
|
|
class ImageMetaData {
|
|
|
|
public:
|
|
|
|
/* Must be set by image file or builtin callback. */
|
|
|
|
bool is_float, is_half;
|
|
|
|
int channels;
|
|
|
|
size_t width, height, depth;
|
|
|
|
bool builtin_free_cache;
|
|
|
|
|
|
|
|
/* Automatically set. */
|
|
|
|
ImageDataType type;
|
|
|
|
bool is_linear;
|
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
class ImageManager {
|
|
|
|
public:
|
2016-05-11 14:50:10 +00:00
|
|
|
explicit ImageManager(const DeviceInfo& info);
|
2011-04-27 11:58:34 +00:00
|
|
|
~ImageManager();
|
|
|
|
|
2015-07-21 19:58:19 +00:00
|
|
|
int add_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
bool animated,
|
|
|
|
float frame,
|
|
|
|
InterpolationType interpolation,
|
|
|
|
ExtensionType extension,
|
2018-02-27 21:16:45 +00:00
|
|
|
bool use_alpha,
|
|
|
|
ImageMetaData& metadata);
|
2016-05-08 19:41:25 +00:00
|
|
|
void remove_image(int flat_slot);
|
2015-07-21 19:58:19 +00:00
|
|
|
void remove_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
InterpolationType interpolation,
|
2017-01-25 13:02:59 +00:00
|
|
|
ExtensionType extension,
|
|
|
|
bool use_alpha);
|
2015-07-21 19:58:19 +00:00
|
|
|
void tag_reload_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
InterpolationType interpolation,
|
2017-01-25 13:02:59 +00:00
|
|
|
ExtensionType extension,
|
|
|
|
bool use_alpha);
|
2018-02-27 21:16:45 +00:00
|
|
|
bool get_image_metadata(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
ImageMetaData& metadata);
|
2018-06-14 14:18:34 +00:00
|
|
|
bool get_image_metadata(int flat_slot,
|
|
|
|
ImageMetaData& metadata);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
void device_update(Device *device,
|
|
|
|
Scene *scene,
|
|
|
|
Progress& progress);
|
|
|
|
void device_update_slot(Device *device,
|
|
|
|
Scene *scene,
|
|
|
|
int flat_slot,
|
|
|
|
Progress *progress);
|
2017-10-20 02:20:37 +00:00
|
|
|
void device_free(Device *device);
|
|
|
|
void device_free_builtin(Device *device);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-31 16:21:30 +00:00
|
|
|
void set_osl_texture_system(void *texture_system);
|
2012-11-21 13:00:51 +00:00
|
|
|
bool set_animation_frame_update(int frame);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2018-03-01 10:54:01 +00:00
|
|
|
device_memory *image_memory(int flat_slot);
|
|
|
|
|
2018-07-27 13:46:13 +00:00
|
|
|
void collect_statistics(RenderStats *stats);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool need_update;
|
|
|
|
|
2016-11-29 10:03:11 +00:00
|
|
|
/* NOTE: Here pixels_size is a size of storage, which equals to
|
|
|
|
* width * height * depth.
|
|
|
|
* Use this to avoid some nasty memory corruptions.
|
|
|
|
*/
|
|
|
|
function<void(const string &filename,
|
|
|
|
void *data,
|
2018-02-27 21:16:45 +00:00
|
|
|
ImageMetaData& metadata)> builtin_image_info_cb;
|
2016-11-29 10:03:11 +00:00
|
|
|
function<bool(const string &filename,
|
|
|
|
void *data,
|
|
|
|
unsigned char *pixels,
|
2017-07-20 20:31:46 +00:00
|
|
|
const size_t pixels_size,
|
|
|
|
const bool free_cache)> builtin_image_pixels_cb;
|
2016-11-29 10:03:11 +00:00
|
|
|
function<bool(const string &filename,
|
|
|
|
void *data,
|
|
|
|
float *pixels,
|
2017-07-20 20:31:46 +00:00
|
|
|
const size_t pixels_size,
|
|
|
|
const bool free_cache)> builtin_image_float_pixels_cb;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
struct Image {
|
|
|
|
string filename;
|
2013-01-30 13:42:12 +00:00
|
|
|
void *builtin_data;
|
2018-06-14 14:18:34 +00:00
|
|
|
ImageMetaData metadata;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
bool use_alpha;
|
2011-04-27 11:58:34 +00:00
|
|
|
bool need_load;
|
2012-11-21 13:00:51 +00:00
|
|
|
bool animated;
|
2014-06-21 20:18:48 +00:00
|
|
|
float frame;
|
2014-03-07 22:16:09 +00:00
|
|
|
InterpolationType interpolation;
|
2015-07-21 19:58:19 +00:00
|
|
|
ExtensionType extension;
|
2014-03-07 22:16:09 +00:00
|
|
|
|
2018-01-02 21:56:07 +00:00
|
|
|
string mem_name;
|
2017-10-20 02:20:37 +00:00
|
|
|
device_memory *mem;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
int users;
|
|
|
|
};
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
private:
|
2016-05-06 09:57:30 +00:00
|
|
|
int tex_num_images[IMAGE_DATA_NUM_TYPES];
|
Unlimited number of textures for Cycles
This patch allows for an unlimited number of textures in Cycles where the hardware allows. It replaces a number static arrays with dynamic arrays and changes the way the flat_slot indices are calculated. Eventually, I'd like to get to a point where there are only flat slots left and textures off all kinds are stored in a single array.
Note that the arrays in DeviceScene are changed from containing device_vector<T> objects to device_vector<T>* pointers. Ideally, I'd like to store objects, but dynamic resizing of a std:vector in pre-C++11 calls the copy constructor, which for a good reason is not implemented for device_vector. Once we require C++11 for Cycles builds, we can implement a move constructor for device_vector and store objects again.
The limits for CUDA Fermi hardware still apply.
Reviewers: tod_baudais, InsigMathK, dingto, #cycles
Reviewed By: dingto, #cycles
Subscribers: dingto, smellslikedonkey
Differential Revision: https://developer.blender.org/D2650
2017-04-27 07:34:51 +00:00
|
|
|
int max_num_images;
|
|
|
|
bool has_half_images;
|
2016-05-27 21:35:29 +00:00
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
thread_mutex device_mutex;
|
|
|
|
int animation_frame;
|
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
vector<Image*> images[IMAGE_DATA_NUM_TYPES];
|
2011-05-31 16:21:30 +00:00
|
|
|
void *osl_texture_system;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-07-20 20:31:46 +00:00
|
|
|
bool file_load_image_generic(Image *img,
|
2018-06-14 14:18:34 +00:00
|
|
|
ImageInput **in);
|
2016-05-22 21:24:26 +00:00
|
|
|
|
2016-11-14 13:03:17 +00:00
|
|
|
template<TypeDesc::BASETYPE FileFormat,
|
|
|
|
typename StorageType,
|
|
|
|
typename DeviceType>
|
|
|
|
bool file_load_image(Image *img,
|
|
|
|
ImageDataType type,
|
2016-11-17 11:13:22 +00:00
|
|
|
int texture_limit,
|
2016-11-14 13:03:17 +00:00
|
|
|
device_vector<DeviceType>& tex_img);
|
2016-06-19 15:31:16 +00:00
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
void device_load_image(Device *device,
|
|
|
|
Scene *scene,
|
|
|
|
ImageDataType type,
|
|
|
|
int slot,
|
2018-07-27 08:30:10 +00:00
|
|
|
Progress *progress);
|
2016-11-17 11:13:22 +00:00
|
|
|
void device_free_image(Device *device,
|
|
|
|
ImageDataType type,
|
|
|
|
int slot);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
2018-11-09 10:34:54 +00:00
|
|
|
#endif /* __IMAGE_H__ */
|