diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2020-03-08 12:42:11 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-03-11 22:35:38 +0300 |
commit | d8aa613d94caf6a3d82a8f4e9e90b9b8f5c61a7d (patch) | |
tree | 7f85577ae4f37c9bdeba31fd65411b718b19b035 /intern/cycles/render/image.h | |
parent | ec3eeee46b4885b9167b0dc28d273993d77b8ce6 (diff) |
Cleanup: add ImageHandle to centralize image ownership logic
Diffstat (limited to 'intern/cycles/render/image.h')
-rw-r--r-- | intern/cycles/render/image.h | 63 |
1 files changed, 52 insertions, 11 deletions
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h index 49fef9f0de3..b23bb7bed63 100644 --- a/intern/cycles/render/image.h +++ b/intern/cycles/render/image.h @@ -31,11 +31,18 @@ CCL_NAMESPACE_BEGIN class Device; +class ImageHandle; +class ImageKey; +class ImageMetaData; +class ImageManager; class Progress; class RenderStats; class Scene; class ColorSpaceProcessor; +/* Image MetaData + * + * Information about the image that is available before the image pxeisl are loaded. */ class ImageMetaData { public: /* Must be set by image file or builtin callback. */ @@ -72,6 +79,10 @@ class ImageMetaData { } }; +/* 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; @@ -101,18 +112,44 @@ class ImageKey { } }; +/* Image Handle + * + * Access handle for image in the image manager. Multiple shader nodes may + * share the same image, and this class handles reference counting for that. */ +class ImageHandle { + public: + ImageHandle(); + ImageHandle(const ImageHandle &other); + ImageHandle &operator=(const ImageHandle &other); + ~ImageHandle(); + + 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); + + protected: + vector<int> slots; + ImageManager *manager; + + friend class ImageManager; +}; + +/* Image Manager + * + * Handles loading and storage of all images in the scene. This includes 2D + * texture images and 3D volume images. */ class ImageManager { public: explicit ImageManager(const DeviceInfo &info); ~ImageManager(); - int add_image(const ImageKey &key, float frame, ImageMetaData &metadata); - void add_image_user(int slot); - void remove_image(int slot); - void remove_image(const ImageKey &key); - void tag_reload_image(const ImageKey &key); - bool get_image_metadata(const ImageKey &key, ImageMetaData &metadata); - bool get_image_metadata(int slot, ImageMetaData &metadata); + ImageHandle add_image(const ImageKey &key, float frame); + ImageHandle add_image(const ImageKey &key, float frame, const vector<int> &tiles); void device_update(Device *device, Scene *scene, Progress &progress); void device_update_slot(Device *device, Scene *scene, int slot, Progress *progress); @@ -124,8 +161,6 @@ class ImageManager { void set_osl_texture_system(void *texture_system); bool set_animation_frame_update(int frame); - device_memory *image_memory(int slot); - void collect_statistics(RenderStats *stats); bool need_update; @@ -167,8 +202,6 @@ class ImageManager { }; private: - int tex_num_images; - int max_num_images; bool has_half_images; thread_mutex device_mutex; @@ -177,6 +210,12 @@ class ImageManager { vector<Image *> images; void *osl_texture_system; + int add_image_slot(const ImageKey &key, float frame); + 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); template<TypeDesc::BASETYPE FileFormat, typename StorageType, typename DeviceType> @@ -186,6 +225,8 @@ class ImageManager { void device_load_image(Device *device, Scene *scene, int slot, Progress *progress); void device_free_image(Device *device, int slot); + + friend class ImageHandle; }; CCL_NAMESPACE_END |