Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2020-03-08 16:21:29 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-03-11 22:45:39 +0300
commit6cf4861c3ac09fd65a765e8f8e3584713cc5303b (patch)
treeb2b104fbda65b67c56dd2a39ad812c89bc5b1ee2 /intern/cycles/render/image.h
parentd8aa613d94caf6a3d82a8f4e9e90b9b8f5c61a7d (diff)
Cleanup: refactor image loading to use abstract ImageLoader base class
Rather than passing around void pointers, various Blender image sources now subclass this. OIIO is also just another type of image loader. Also fixes T67718: Cycles viewport render crash editing point density settings
Diffstat (limited to 'intern/cycles/render/image.h')
-rw-r--r--intern/cycles/render/image.h172
1 files changed, 82 insertions, 90 deletions
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index b23bb7bed63..35e6d4dcb08 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -22,7 +22,6 @@
#include "render/colorspace.h"
-#include "util/util_image.h"
#include "util/util_string.h"
#include "util/util_thread.h"
#include "util/util_unique_ptr.h"
@@ -40,78 +39,89 @@ class RenderStats;
class Scene;
class ColorSpaceProcessor;
-/* Image MetaData
- *
- * Information about the image that is available before the image pxeisl are loaded. */
-class ImageMetaData {
+/* Image Parameters */
+class ImageParams {
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;
- ustring colorspace;
- bool compress_as_srgb;
-
- ImageMetaData()
- : is_float(false),
- is_half(false),
- channels(0),
- width(0),
- height(0),
- depth(0),
- builtin_free_cache(false),
- type(IMAGE_DATA_NUM_TYPES),
- colorspace(u_colorspace_raw),
- compress_as_srgb(false)
- {
- }
-
- bool operator==(const ImageMetaData &other) const
- {
- return is_float == other.is_float && is_half == other.is_half && channels == other.channels &&
- width == other.width && height == other.height && depth == other.depth &&
- type == other.type && colorspace == other.colorspace &&
- compress_as_srgb == other.compress_as_srgb;
- }
-};
-
-/* Image Key
- *
- * Image description that uniquely identifies and images. When adding images
- * with the same key, they will be internally deduplicated. */
-class ImageKey {
- public:
- string filename;
- void *builtin_data;
bool animated;
InterpolationType interpolation;
ExtensionType extension;
ImageAlphaType alpha_type;
ustring colorspace;
+ float frame;
- ImageKey()
- : builtin_data(NULL),
- animated(false),
+ ImageParams()
+ : animated(false),
interpolation(INTERPOLATION_LINEAR),
extension(EXTENSION_CLIP),
alpha_type(IMAGE_ALPHA_AUTO),
- colorspace(u_colorspace_raw)
+ colorspace(u_colorspace_raw),
+ frame(0.0f)
{
}
- bool operator==(const ImageKey &other) const
+ bool operator==(const ImageParams &other) const
{
- return (filename == other.filename && builtin_data == other.builtin_data &&
- animated == other.animated && interpolation == other.interpolation &&
+ return (animated == other.animated && interpolation == other.interpolation &&
extension == other.extension && alpha_type == other.alpha_type &&
- colorspace == other.colorspace);
+ colorspace == other.colorspace && frame == other.frame);
}
};
+/* Image MetaData
+ *
+ * Information about the image that is available before the image pxeisl are loaded. */
+class ImageMetaData {
+ public:
+ /* Set by ImageLoader.load_metadata(). */
+ int channels;
+ size_t width, height, depth;
+ ImageDataType type;
+
+ /* Optional color space, defaults to raw. */
+ ustring colorspace;
+ const char *colorspace_file_format;
+
+ /* Automatically set. */
+ bool compress_as_srgb;
+
+ ImageMetaData();
+ bool operator==(const ImageMetaData &other) const;
+ bool is_float() const;
+ void detect_colorspace();
+};
+
+/* Image loader base class, that can be subclassed to load image data
+ * from custom sources (file, memory, procedurally generated, etc). */
+class ImageLoader {
+ public:
+ ImageLoader();
+ virtual ~ImageLoader(){};
+
+ /* Load metadata without actual image yet, should be fast. */
+ virtual bool load_metadata(ImageMetaData &metadata) = 0;
+
+ /* Load actual image contents. */
+ virtual bool load_pixels(const ImageMetaData &metadata,
+ void *pixels,
+ const size_t pixels_size,
+ const bool associate_alpha) = 0;
+
+ /* Name for logs and stats. */
+ virtual string name() const = 0;
+
+ /* Optional for OSL texture cache. */
+ virtual ustring osl_filepath() const;
+
+ /* Free any memory used for loading metadata and pixels. */
+ virtual void cleanup(){};
+
+ /* Compare avoid loading the same image multiple times. */
+ virtual bool equals(const ImageLoader &other) const = 0;
+ static bool equals(const ImageLoader *a, const ImageLoader *b);
+
+ /* Work around for no RTTI. */
+};
+
/* Image Handle
*
* Access handle for image in the image manager. Multiple shader nodes may
@@ -123,17 +133,19 @@ class ImageHandle {
ImageHandle &operator=(const ImageHandle &other);
~ImageHandle();
+ bool operator==(const ImageHandle &other) const;
+
void clear();
bool empty();
int num_tiles();
ImageMetaData metadata();
- int svm_slot(const int tile_index = 0);
- device_memory *image_memory(const int tile_index = 0);
+ int svm_slot(const int tile_index = 0) const;
+ device_memory *image_memory(const int tile_index = 0) const;
protected:
- vector<int> slots;
+ vector<int> tile_slots;
ImageManager *manager;
friend class ImageManager;
@@ -148,8 +160,11 @@ class ImageManager {
explicit ImageManager(const DeviceInfo &info);
~ImageManager();
- ImageHandle add_image(const ImageKey &key, float frame);
- ImageHandle add_image(const ImageKey &key, float frame, const vector<int> &tiles);
+ ImageHandle add_image(const string &filename, const ImageParams &params);
+ ImageHandle add_image(const string &filename,
+ const ImageParams &params,
+ const vector<int> &tiles);
+ ImageHandle add_image(ImageLoader *loader, const ImageParams &params);
void device_update(Device *device, Scene *scene, Progress &progress);
void device_update_slot(Device *device, Scene *scene, int slot, Progress *progress);
@@ -165,40 +180,21 @@ class ImageManager {
bool need_update;
- /* 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, ImageMetaData &metadata)>
- builtin_image_info_cb;
- function<bool(const string &filename,
- void *data,
- int tile,
- unsigned char *pixels,
- const size_t pixels_size,
- const bool associate_alpha,
- const bool free_cache)>
- builtin_image_pixels_cb;
- function<bool(const string &filename,
- void *data,
- int tile,
- float *pixels,
- const size_t pixels_size,
- const bool associate_alpha,
- const bool free_cache)>
- builtin_image_float_pixels_cb;
-
struct Image {
- ImageKey key;
+ ImageParams params;
ImageMetaData metadata;
+ ImageLoader *loader;
float frame;
+ bool need_metadata;
bool need_load;
+ bool builtin;
string mem_name;
device_memory *mem;
int users;
+ thread_mutex mutex;
};
private:
@@ -210,19 +206,15 @@ class ImageManager {
vector<Image *> images;
void *osl_texture_system;
- int add_image_slot(const ImageKey &key, float frame);
+ int add_image_slot(ImageLoader *loader, const ImageParams &params, const bool builtin);
void add_image_user(int slot);
void remove_image_user(int slot);
- bool load_image_metadata(const ImageKey &key, ImageMetaData &metadata);
-
- bool file_load_image_generic(Image *img, unique_ptr<ImageInput> *in);
+ void load_image_metadata(Image *img);
template<TypeDesc::BASETYPE FileFormat, typename StorageType, typename DeviceType>
bool file_load_image(Image *img, int texture_limit, device_vector<DeviceType> &tex_img);
- void metadata_detect_colorspace(ImageMetaData &metadata, const char *file_format);
-
void device_load_image(Device *device, Scene *scene, int slot, Progress *progress);
void device_free_image(Device *device, int slot);