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
|
|
|
*/
|
|
|
|
|
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 "render/image.h"
|
|
|
|
#include "render/scene.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_foreach.h"
|
|
|
|
#include "util/util_logging.h"
|
|
|
|
#include "util/util_path.h"
|
|
|
|
#include "util/util_progress.h"
|
|
|
|
#include "util/util_texture.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-31 16:21:30 +00:00
|
|
|
#ifdef WITH_OSL
|
|
|
|
#include <OSL/oslexec.h>
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2017-05-17 15:23:32 +00:00
|
|
|
/* Some helpers to silence warning in templated function. */
|
|
|
|
static bool isfinite(uchar /*value*/)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static bool isfinite(half /*value*/)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-16 18:48:33 +00:00
|
|
|
ImageManager::ImageManager(const DeviceInfo& info)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
need_update = true;
|
2011-05-31 16:21:30 +00:00
|
|
|
osl_texture_system = NULL;
|
2012-11-21 13:00:51 +00:00
|
|
|
animation_frame = 0;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2016-05-24 14:57:13 +00:00
|
|
|
/* In case of multiple devices used we need to know type of an actual
|
|
|
|
* compute device.
|
|
|
|
*
|
|
|
|
* NOTE: We assume that all the devices are same type, otherwise we'll
|
|
|
|
* be screwed on so many levels..
|
|
|
|
*/
|
|
|
|
DeviceType device_type = info.type;
|
2016-10-24 10:26:12 +00:00
|
|
|
if(device_type == DEVICE_MULTI) {
|
2016-05-24 14:57:13 +00:00
|
|
|
device_type = info.multi_devices[0].type;
|
|
|
|
}
|
|
|
|
|
2016-04-16 18:48:33 +00:00
|
|
|
/* Set image limits */
|
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
|
|
|
max_num_images = TEX_NUM_MAX;
|
|
|
|
has_half_images = true;
|
|
|
|
cuda_fermi_limits = false;
|
2017-04-28 11:21:17 +00:00
|
|
|
|
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
|
|
|
if(device_type == DEVICE_CUDA) {
|
|
|
|
if(!info.has_bindless_textures) {
|
|
|
|
/* CUDA Fermi hardware (SM 2.x) has a hard limit on the number of textures */
|
|
|
|
cuda_fermi_limits = true;
|
|
|
|
has_half_images = false;
|
2016-05-24 14:57:13 +00:00
|
|
|
}
|
2016-04-16 18:48:33 +00:00
|
|
|
}
|
2016-05-24 14:57:13 +00:00
|
|
|
else if(device_type == DEVICE_OPENCL) {
|
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
|
|
|
has_half_images = false;
|
2016-04-16 18:48:33 +00:00
|
|
|
}
|
2017-04-28 11:21:17 +00:00
|
|
|
|
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
|
|
|
for(size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
|
|
|
tex_num_images[type] = 0;
|
2016-04-16 18:48:33 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageManager::~ImageManager()
|
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
for(size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
|
|
|
for(size_t slot = 0; slot < images[type].size(); slot++)
|
|
|
|
assert(!images[type][slot]);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-05-31 16:21:30 +00:00
|
|
|
void ImageManager::set_osl_texture_system(void *texture_system)
|
|
|
|
{
|
|
|
|
osl_texture_system = texture_system;
|
|
|
|
}
|
|
|
|
|
2012-11-21 13:00:51 +00:00
|
|
|
bool ImageManager::set_animation_frame_update(int frame)
|
|
|
|
{
|
|
|
|
if(frame != animation_frame) {
|
|
|
|
animation_frame = frame;
|
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
for(size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
|
|
|
for(size_t slot = 0; slot < images[type].size(); slot++) {
|
|
|
|
if(images[type][slot] && images[type][slot]->animated)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-11-21 13:00:51 +00:00
|
|
|
}
|
2016-05-06 09:57:30 +00:00
|
|
|
|
2012-11-21 13:00:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ImageDataType ImageManager::get_image_metadata(const string& filename,
|
2017-04-28 11:21:17 +00:00
|
|
|
void *builtin_data,
|
2017-07-20 20:31:46 +00:00
|
|
|
bool& is_linear,
|
|
|
|
bool& builtin_free_cache)
|
2012-03-07 12:27:18 +00:00
|
|
|
{
|
2016-06-19 15:31:16 +00:00
|
|
|
bool is_float = false, is_half = false;
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = false;
|
2017-07-20 20:31:46 +00:00
|
|
|
builtin_free_cache = false;
|
2016-05-09 10:51:42 +00:00
|
|
|
int channels = 4;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2013-01-30 13:42:12 +00:00
|
|
|
if(builtin_data) {
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(builtin_image_info_cb) {
|
2016-05-09 10:51:42 +00:00
|
|
|
int width, height, depth;
|
2017-07-20 20:31:46 +00:00
|
|
|
builtin_image_info_cb(filename, builtin_data, is_float, width, height, depth, channels, builtin_free_cache);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
if(is_float) {
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = true;
|
2016-05-22 20:47:37 +00:00
|
|
|
return (channels > 1) ? IMAGE_DATA_TYPE_FLOAT4 : IMAGE_DATA_TYPE_FLOAT;
|
2016-05-09 10:51:42 +00:00
|
|
|
}
|
2016-05-12 12:51:42 +00:00
|
|
|
else {
|
2016-05-22 20:47:37 +00:00
|
|
|
return (channels > 1) ? IMAGE_DATA_TYPE_BYTE4 : IMAGE_DATA_TYPE_BYTE;
|
2016-05-12 12:51:42 +00:00
|
|
|
}
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 13:47:12 +00:00
|
|
|
/* Perform preliminary checks, with meaningful logging. */
|
|
|
|
if(!path_exists(filename)) {
|
|
|
|
VLOG(1) << "File '" << filename << "' does not exist.";
|
|
|
|
return IMAGE_DATA_TYPE_BYTE4;
|
|
|
|
}
|
|
|
|
if(path_is_directory(filename)) {
|
|
|
|
VLOG(1) << "File '" << filename << "' is a directory, can't use as image.";
|
|
|
|
return IMAGE_DATA_TYPE_BYTE4;
|
|
|
|
}
|
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
ImageInput *in = ImageInput::create(filename);
|
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
if(in) {
|
|
|
|
ImageSpec spec;
|
|
|
|
|
|
|
|
if(in->open(filename, spec)) {
|
|
|
|
/* check the main format, and channel formats;
|
2012-06-09 17:22:52 +00:00
|
|
|
* if any take up more than one byte, we'll need a float texture slot */
|
2013-02-14 21:40:29 +00:00
|
|
|
if(spec.format.basesize() > 1) {
|
2012-03-07 12:27:18 +00:00
|
|
|
is_float = true;
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = true;
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
for(size_t channel = 0; channel < spec.channelformats.size(); channel++) {
|
2013-02-14 21:40:29 +00:00
|
|
|
if(spec.channelformats[channel].basesize() > 1) {
|
2012-03-07 12:27:18 +00:00
|
|
|
is_float = true;
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 15:31:16 +00:00
|
|
|
/* check if it's half float */
|
2016-08-14 23:01:43 +00:00
|
|
|
if(spec.format == TypeDesc::HALF)
|
2016-06-19 15:31:16 +00:00
|
|
|
is_half = true;
|
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
channels = spec.nchannels;
|
|
|
|
|
2013-02-14 21:40:29 +00:00
|
|
|
/* basic color space detection, not great but better than nothing
|
|
|
|
* before we do OpenColorIO integration */
|
|
|
|
if(is_float) {
|
|
|
|
string colorspace = spec.get_string_attribute("oiio:ColorSpace");
|
|
|
|
|
|
|
|
is_linear = !(colorspace == "sRGB" ||
|
|
|
|
colorspace == "GammaCorrected" ||
|
2013-08-29 20:53:20 +00:00
|
|
|
(colorspace == "" &&
|
|
|
|
(strcmp(in->format_name(), "png") == 0 ||
|
|
|
|
strcmp(in->format_name(), "tiff") == 0 ||
|
2014-08-22 17:52:29 +00:00
|
|
|
strcmp(in->format_name(), "dpx") == 0 ||
|
2013-08-29 20:53:20 +00:00
|
|
|
strcmp(in->format_name(), "jpeg2000") == 0)));
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2013-08-29 20:53:20 +00:00
|
|
|
else {
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = false;
|
2013-08-29 20:53:20 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
in->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
|
2016-06-19 15:31:16 +00:00
|
|
|
if(is_half) {
|
2016-06-19 15:38:39 +00:00
|
|
|
return (channels > 1) ? IMAGE_DATA_TYPE_HALF4 : IMAGE_DATA_TYPE_HALF;
|
2016-06-19 15:31:16 +00:00
|
|
|
}
|
|
|
|
else if(is_float) {
|
2016-05-22 20:47:37 +00:00
|
|
|
return (channels > 1) ? IMAGE_DATA_TYPE_FLOAT4 : IMAGE_DATA_TYPE_FLOAT;
|
2016-05-09 10:51:42 +00:00
|
|
|
}
|
2016-05-12 12:51:42 +00:00
|
|
|
else {
|
2016-05-22 20:47:37 +00:00
|
|
|
return (channels > 1) ? IMAGE_DATA_TYPE_BYTE4 : IMAGE_DATA_TYPE_BYTE;
|
2016-05-12 12:51:42 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 13:15:15 +00:00
|
|
|
int ImageManager::max_flattened_slot(ImageDataType type)
|
|
|
|
{
|
|
|
|
if(tex_num_images[type] == 0) {
|
|
|
|
/* No textures for the type, no slots needs allocation. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return type_index_to_flattened_slot(tex_num_images[type], type);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* The lower three bits of a device texture slot number indicate its type.
|
2016-05-11 20:25:48 +00:00
|
|
|
* These functions convert the slot ids from ImageManager "images" ones
|
2017-04-28 13:15:15 +00:00
|
|
|
* to device ones and vice verse.
|
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
|
|
|
*/
|
2016-05-06 09:57:30 +00:00
|
|
|
int ImageManager::type_index_to_flattened_slot(int slot, ImageDataType type)
|
|
|
|
{
|
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
|
|
|
return (slot << IMAGE_DATA_TYPE_SHIFT) | (type);
|
2016-05-06 09:57:30 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 19:41:25 +00:00
|
|
|
int ImageManager::flattened_slot_to_type_index(int flat_slot, ImageDataType *type)
|
2016-05-06 09:57:30 +00:00
|
|
|
{
|
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
|
|
|
*type = (ImageDataType)(flat_slot & IMAGE_DATA_TYPE_MASK);
|
|
|
|
return flat_slot >> IMAGE_DATA_TYPE_SHIFT;
|
2016-05-06 09:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string ImageManager::name_from_type(int type)
|
|
|
|
{
|
2016-05-06 11:42:50 +00:00
|
|
|
if(type == IMAGE_DATA_TYPE_FLOAT4)
|
2016-05-09 10:51:42 +00:00
|
|
|
return "float4";
|
|
|
|
else if(type == IMAGE_DATA_TYPE_FLOAT)
|
2016-05-06 09:57:30 +00:00
|
|
|
return "float";
|
2016-05-12 12:51:42 +00:00
|
|
|
else if(type == IMAGE_DATA_TYPE_BYTE)
|
|
|
|
return "byte";
|
2016-06-19 15:31:16 +00:00
|
|
|
else if(type == IMAGE_DATA_TYPE_HALF4)
|
|
|
|
return "half4";
|
|
|
|
else if(type == IMAGE_DATA_TYPE_HALF)
|
|
|
|
return "half";
|
2016-05-06 09:57:30 +00:00
|
|
|
else
|
2016-05-09 10:51:42 +00:00
|
|
|
return "byte4";
|
2016-05-06 09:57:30 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 19:58:19 +00:00
|
|
|
static bool image_equals(ImageManager::Image *image,
|
|
|
|
const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
InterpolationType interpolation,
|
2017-01-25 13:02:59 +00:00
|
|
|
ExtensionType extension,
|
|
|
|
bool use_alpha)
|
2014-03-29 12:03:48 +00:00
|
|
|
{
|
|
|
|
return image->filename == filename &&
|
|
|
|
image->builtin_data == builtin_data &&
|
2015-07-21 19:58:19 +00:00
|
|
|
image->interpolation == interpolation &&
|
2017-01-25 13:02:59 +00:00
|
|
|
image->extension == extension &&
|
|
|
|
image->use_alpha == use_alpha;
|
2014-03-29 12:03:48 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 19:58:19 +00:00
|
|
|
int ImageManager::add_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
bool animated,
|
|
|
|
float frame,
|
|
|
|
bool& is_float,
|
|
|
|
bool& is_linear,
|
|
|
|
InterpolationType interpolation,
|
|
|
|
ExtensionType extension,
|
|
|
|
bool use_alpha)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Image *img;
|
|
|
|
size_t slot;
|
2017-07-20 20:31:46 +00:00
|
|
|
bool builtin_free_cache;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-07-20 20:31:46 +00:00
|
|
|
ImageDataType type = get_image_metadata(filename, builtin_data, is_linear, builtin_free_cache);
|
2016-05-09 10:51:42 +00:00
|
|
|
|
2016-09-09 10:27:51 +00:00
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
|
2017-03-03 09:09:42 +00:00
|
|
|
/* Check whether it's a float texture. */
|
|
|
|
is_float = (type == IMAGE_DATA_TYPE_FLOAT || type == IMAGE_DATA_TYPE_FLOAT4);
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2016-08-14 18:21:08 +00:00
|
|
|
/* No single channel and half textures on CUDA (Fermi) and no half on OpenCL, use available slots */
|
2017-04-27 09:11:08 +00:00
|
|
|
if(!has_half_images) {
|
|
|
|
if(type == IMAGE_DATA_TYPE_HALF4) {
|
|
|
|
type = IMAGE_DATA_TYPE_FLOAT4;
|
|
|
|
}
|
|
|
|
else if(type == IMAGE_DATA_TYPE_HALF) {
|
|
|
|
type = IMAGE_DATA_TYPE_FLOAT;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-04-27 09:11:08 +00:00
|
|
|
if(cuda_fermi_limits) {
|
|
|
|
if(type == IMAGE_DATA_TYPE_FLOAT) {
|
|
|
|
type = IMAGE_DATA_TYPE_FLOAT4;
|
|
|
|
}
|
|
|
|
else if(type == IMAGE_DATA_TYPE_BYTE) {
|
|
|
|
type = IMAGE_DATA_TYPE_BYTE4;
|
|
|
|
}
|
2016-06-19 15:31:16 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
/* Fnd existing image. */
|
|
|
|
for(slot = 0; slot < images[type].size(); slot++) {
|
|
|
|
img = images[type][slot];
|
|
|
|
if(img && image_equals(img,
|
2016-05-16 08:55:50 +00:00
|
|
|
filename,
|
|
|
|
builtin_data,
|
|
|
|
interpolation,
|
2017-01-25 13:02:59 +00:00
|
|
|
extension,
|
|
|
|
use_alpha))
|
2016-05-06 09:57:30 +00:00
|
|
|
{
|
|
|
|
if(img->frame != frame) {
|
|
|
|
img->frame = frame;
|
|
|
|
img->need_load = true;
|
2012-07-04 11:48:42 +00:00
|
|
|
}
|
2016-05-06 09:57:30 +00:00
|
|
|
if(img->use_alpha != use_alpha) {
|
|
|
|
img->use_alpha = use_alpha;
|
|
|
|
img->need_load = true;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2016-05-06 09:57:30 +00:00
|
|
|
img->users++;
|
|
|
|
return type_index_to_flattened_slot(slot, type);
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2016-05-06 09:57:30 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
/* Find free slot. */
|
|
|
|
for(slot = 0; slot < images[type].size(); slot++) {
|
|
|
|
if(!images[type][slot])
|
|
|
|
break;
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
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
|
|
|
/* Count if we're over the limit */
|
|
|
|
if(cuda_fermi_limits) {
|
|
|
|
if(tex_num_images[IMAGE_DATA_TYPE_BYTE4] == TEX_NUM_BYTE4_CUDA
|
|
|
|
|| tex_num_images[IMAGE_DATA_TYPE_FLOAT4] == TEX_NUM_FLOAT4_CUDA)
|
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
printf("ImageManager::add_image: Reached %s image limit (%d), skipping '%s'\n",
|
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
|
|
|
name_from_type(type).c_str(), tex_num_images[type], filename.c_str());
|
2016-05-06 09:57:30 +00:00
|
|
|
return -1;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Very unlikely, since max_num_images is insanely big. But better safe than sorry. */
|
|
|
|
int tex_count = 0;
|
2017-08-07 12:47:51 +00:00
|
|
|
for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
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
|
|
|
tex_count += tex_num_images[type];
|
|
|
|
}
|
|
|
|
if(tex_count > max_num_images) {
|
|
|
|
printf("ImageManager::add_image: Reached image limit (%d), skipping '%s'\n",
|
|
|
|
max_num_images, filename.c_str());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 11:21:17 +00:00
|
|
|
|
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
|
|
|
if(slot == images[type].size()) {
|
2016-05-06 09:57:30 +00:00
|
|
|
images[type].resize(images[type].size() + 1);
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
/* Add new image. */
|
|
|
|
img = new Image();
|
|
|
|
img->filename = filename;
|
|
|
|
img->builtin_data = builtin_data;
|
2017-07-20 20:31:46 +00:00
|
|
|
img->builtin_free_cache = builtin_free_cache;
|
2016-05-06 09:57:30 +00:00
|
|
|
img->need_load = true;
|
|
|
|
img->animated = animated;
|
|
|
|
img->frame = frame;
|
|
|
|
img->interpolation = interpolation;
|
|
|
|
img->extension = extension;
|
|
|
|
img->users = 1;
|
|
|
|
img->use_alpha = use_alpha;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
images[type][slot] = img;
|
2017-04-28 11:21:17 +00:00
|
|
|
|
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
|
|
|
++tex_num_images[type];
|
2014-06-21 20:18:48 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
need_update = true;
|
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
return type_index_to_flattened_slot(slot, type);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 19:41:25 +00:00
|
|
|
void ImageManager::remove_image(int flat_slot)
|
2014-03-29 12:03:48 +00:00
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
ImageDataType type;
|
2016-05-08 19:41:25 +00:00
|
|
|
int slot = flattened_slot_to_type_index(flat_slot, &type);
|
2014-03-29 12:03:48 +00:00
|
|
|
|
2016-05-08 18:18:52 +00:00
|
|
|
Image *image = images[type][slot];
|
|
|
|
assert(image && image->users >= 1);
|
2014-03-29 12:03:48 +00:00
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
/* decrement user count */
|
2016-05-08 18:18:52 +00:00
|
|
|
image->users--;
|
2014-03-29 12:03:48 +00:00
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
/* don't remove immediately, rather do it all together later on. one of
|
|
|
|
* the reasons for this is that on shader changes we add and remove nodes
|
|
|
|
* that use them, but we do not want to reload the image all the time. */
|
2016-05-08 18:18:52 +00:00
|
|
|
if(image->users == 0)
|
2016-05-06 09:57:30 +00:00
|
|
|
need_update = true;
|
2014-03-29 12:03:48 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 19:58:19 +00:00
|
|
|
void ImageManager::remove_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
InterpolationType interpolation,
|
2017-01-25 13:02:59 +00:00
|
|
|
ExtensionType extension,
|
|
|
|
bool use_alpha)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-05-31 16:21:30 +00:00
|
|
|
size_t slot;
|
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
|
|
|
for(slot = 0; slot < images[type].size(); slot++) {
|
|
|
|
if(images[type][slot] && image_equals(images[type][slot],
|
2016-05-16 08:55:50 +00:00
|
|
|
filename,
|
|
|
|
builtin_data,
|
|
|
|
interpolation,
|
2017-01-25 13:02:59 +00:00
|
|
|
extension,
|
|
|
|
use_alpha))
|
2016-02-03 14:00:55 +00:00
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
remove_image(type_index_to_flattened_slot(slot, (ImageDataType)type));
|
|
|
|
return;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 13:28:33 +00:00
|
|
|
/* TODO(sergey): Deduplicate with the iteration above, but make it pretty,
|
|
|
|
* without bunch of arguments passing around making code readability even
|
|
|
|
* more cluttered.
|
|
|
|
*/
|
2015-07-21 19:58:19 +00:00
|
|
|
void ImageManager::tag_reload_image(const string& filename,
|
|
|
|
void *builtin_data,
|
|
|
|
InterpolationType interpolation,
|
2017-01-25 13:02:59 +00:00
|
|
|
ExtensionType extension,
|
|
|
|
bool use_alpha)
|
2014-07-18 13:28:33 +00:00
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
for(size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
|
|
|
for(size_t slot = 0; slot < images[type].size(); slot++) {
|
|
|
|
if(images[type][slot] && image_equals(images[type][slot],
|
2016-05-16 08:55:50 +00:00
|
|
|
filename,
|
|
|
|
builtin_data,
|
|
|
|
interpolation,
|
2017-01-25 13:02:59 +00:00
|
|
|
extension,
|
|
|
|
use_alpha))
|
2016-02-03 14:00:55 +00:00
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
images[type][slot]->need_load = true;
|
2014-07-18 13:28:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 20:31:46 +00:00
|
|
|
bool ImageManager::file_load_image_generic(Image *img,
|
|
|
|
ImageInput **in,
|
|
|
|
int &width,
|
|
|
|
int &height,
|
|
|
|
int &depth,
|
|
|
|
int &components)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
if(img->filename == "")
|
|
|
|
return false;
|
|
|
|
|
2013-01-30 13:42:12 +00:00
|
|
|
if(!img->builtin_data) {
|
2017-03-17 13:47:12 +00:00
|
|
|
/* NOTE: Error logging is done in meta data acquisition. */
|
|
|
|
if(!path_exists(img->filename) || path_is_directory(img->filename)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
/* load image from file through OIIO */
|
2016-05-09 10:51:42 +00:00
|
|
|
*in = ImageInput::create(img->filename);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
if(!*in)
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
return false;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
ImageSpec spec = ImageSpec();
|
|
|
|
ImageSpec config = ImageSpec();
|
|
|
|
|
|
|
|
if(img->use_alpha == false)
|
|
|
|
config.attribute("oiio:UnassociatedAlpha", 1);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
if(!(*in)->open(img->filename, spec, config)) {
|
|
|
|
delete *in;
|
|
|
|
*in = NULL;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = spec.width;
|
|
|
|
height = spec.height;
|
2014-03-29 12:03:48 +00:00
|
|
|
depth = spec.depth;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
components = spec.nchannels;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* load image using builtin images callbacks */
|
|
|
|
if(!builtin_image_info_cb || !builtin_image_pixels_cb)
|
|
|
|
return false;
|
|
|
|
|
2017-07-20 20:31:46 +00:00
|
|
|
bool is_float, free_cache;
|
|
|
|
builtin_image_info_cb(img->filename, img->builtin_data, is_float, width, height, depth, components, free_cache);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we only handle certain number of components */
|
2013-08-30 17:01:44 +00:00
|
|
|
if(!(components >= 1 && components <= 4)) {
|
2016-05-09 10:51:42 +00:00
|
|
|
if(*in) {
|
|
|
|
(*in)->close();
|
|
|
|
delete *in;
|
|
|
|
*in = NULL;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-14 13:03:17 +00:00
|
|
|
template<TypeDesc::BASETYPE FileFormat,
|
|
|
|
typename StorageType,
|
|
|
|
typename DeviceType>
|
|
|
|
bool ImageManager::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-05-09 10:51:42 +00:00
|
|
|
{
|
2016-11-14 13:03:17 +00:00
|
|
|
const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1;
|
2016-05-09 10:51:42 +00:00
|
|
|
ImageInput *in = NULL;
|
|
|
|
int width, height, depth, components;
|
2016-11-14 13:03:17 +00:00
|
|
|
if(!file_load_image_generic(img, &in, width, height, depth, components)) {
|
2015-09-04 07:38:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-11-14 13:03:17 +00:00
|
|
|
/* Read RGBA pixels. */
|
2016-11-17 11:13:22 +00:00
|
|
|
vector<StorageType> pixels_storage;
|
|
|
|
StorageType *pixels;
|
|
|
|
const size_t max_size = max(max(width, height), depth);
|
2017-09-04 11:14:54 +00:00
|
|
|
if(max_size == 0) {
|
|
|
|
/* Don't bother with invalid images. */
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-17 11:13:22 +00:00
|
|
|
if(texture_limit > 0 && max_size > texture_limit) {
|
|
|
|
pixels_storage.resize(((size_t)width)*height*depth*4);
|
|
|
|
pixels = &pixels_storage[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pixels = (StorageType*)tex_img.resize(width, height, depth);
|
2015-09-04 07:38:10 +00:00
|
|
|
}
|
2017-09-04 11:14:54 +00:00
|
|
|
if(pixels == NULL) {
|
|
|
|
/* Could be that we've run out of memory. */
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-21 18:42:03 +00:00
|
|
|
bool cmyk = false;
|
2016-11-29 10:03:11 +00:00
|
|
|
const size_t num_pixels = ((size_t)width) * height * depth;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(in) {
|
2016-11-14 13:03:17 +00:00
|
|
|
StorageType *readpixels = pixels;
|
|
|
|
vector<StorageType> tmppixels;
|
2014-05-19 14:23:37 +00:00
|
|
|
if(components > 4) {
|
2015-05-12 13:33:31 +00:00
|
|
|
tmppixels.resize(((size_t)width)*height*components);
|
2014-05-19 14:23:37 +00:00
|
|
|
readpixels = &tmppixels[0];
|
|
|
|
}
|
2014-03-29 12:03:48 +00:00
|
|
|
if(depth <= 1) {
|
2016-11-14 13:03:17 +00:00
|
|
|
size_t scanlinesize = ((size_t)width)*components*sizeof(StorageType);
|
|
|
|
in->read_image(FileFormat,
|
2016-05-16 08:55:50 +00:00
|
|
|
(uchar*)readpixels + (height-1)*scanlinesize,
|
|
|
|
AutoStride,
|
|
|
|
-scanlinesize,
|
|
|
|
AutoStride);
|
2014-03-29 12:03:48 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-11-14 13:03:17 +00:00
|
|
|
in->read_image(FileFormat, (uchar*)readpixels);
|
2014-05-19 14:23:37 +00:00
|
|
|
}
|
|
|
|
if(components > 4) {
|
2015-05-12 13:33:31 +00:00
|
|
|
size_t dimensions = ((size_t)width)*height;
|
|
|
|
for(size_t i = dimensions-1, pixel = 0; pixel < dimensions; pixel++, i--) {
|
2014-05-19 14:23:37 +00:00
|
|
|
pixels[i*4+3] = tmppixels[i*components+3];
|
|
|
|
pixels[i*4+2] = tmppixels[i*components+2];
|
|
|
|
pixels[i*4+1] = tmppixels[i*components+1];
|
|
|
|
pixels[i*4+0] = tmppixels[i*components+0];
|
|
|
|
}
|
|
|
|
tmppixels.clear();
|
2014-03-29 12:03:48 +00:00
|
|
|
}
|
2014-06-21 18:42:03 +00:00
|
|
|
cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
in->close();
|
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
else {
|
2016-11-14 13:03:17 +00:00
|
|
|
if(FileFormat == TypeDesc::FLOAT) {
|
|
|
|
builtin_image_float_pixels_cb(img->filename,
|
|
|
|
img->builtin_data,
|
2016-11-29 10:03:11 +00:00
|
|
|
(float*)&pixels[0],
|
2017-07-20 20:31:46 +00:00
|
|
|
num_pixels * components,
|
|
|
|
img->builtin_free_cache);
|
2016-11-14 13:03:17 +00:00
|
|
|
}
|
|
|
|
else if(FileFormat == TypeDesc::UINT8) {
|
|
|
|
builtin_image_pixels_cb(img->filename,
|
|
|
|
img->builtin_data,
|
2016-11-29 10:03:11 +00:00
|
|
|
(uchar*)&pixels[0],
|
2017-07-20 20:31:46 +00:00
|
|
|
num_pixels * components,
|
|
|
|
img->builtin_free_cache);
|
2016-11-14 13:03:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* TODO(dingto): Support half for ImBuf. */
|
|
|
|
}
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
2016-11-14 13:03:17 +00:00
|
|
|
/* Check if we actually have a float4 slot, in case components == 1,
|
|
|
|
* but device doesn't support single channel textures.
|
|
|
|
*/
|
2016-11-17 11:13:22 +00:00
|
|
|
bool is_rgba = (type == IMAGE_DATA_TYPE_FLOAT4 ||
|
|
|
|
type == IMAGE_DATA_TYPE_HALF4 ||
|
|
|
|
type == IMAGE_DATA_TYPE_BYTE4);
|
|
|
|
if(is_rgba) {
|
2016-05-22 21:24:26 +00:00
|
|
|
if(cmyk) {
|
|
|
|
/* CMYK */
|
|
|
|
for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
|
|
|
|
pixels[i*4+2] = (pixels[i*4+2]*pixels[i*4+3])/255;
|
|
|
|
pixels[i*4+1] = (pixels[i*4+1]*pixels[i*4+3])/255;
|
|
|
|
pixels[i*4+0] = (pixels[i*4+0]*pixels[i*4+3])/255;
|
2016-11-14 13:03:17 +00:00
|
|
|
pixels[i*4+3] = alpha_one;
|
2016-05-22 21:24:26 +00:00
|
|
|
}
|
2013-08-30 17:01:44 +00:00
|
|
|
}
|
2016-05-22 21:24:26 +00:00
|
|
|
else if(components == 2) {
|
|
|
|
/* grayscale + alpha */
|
|
|
|
for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
|
|
|
|
pixels[i*4+3] = pixels[i*2+1];
|
|
|
|
pixels[i*4+2] = pixels[i*2+0];
|
|
|
|
pixels[i*4+1] = pixels[i*2+0];
|
|
|
|
pixels[i*4+0] = pixels[i*2+0];
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2016-05-22 21:24:26 +00:00
|
|
|
else if(components == 3) {
|
|
|
|
/* RGB */
|
|
|
|
for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
|
2016-11-14 13:03:17 +00:00
|
|
|
pixels[i*4+3] = alpha_one;
|
2016-05-22 21:24:26 +00:00
|
|
|
pixels[i*4+2] = pixels[i*3+2];
|
|
|
|
pixels[i*4+1] = pixels[i*3+1];
|
|
|
|
pixels[i*4+0] = pixels[i*3+0];
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2016-05-22 21:24:26 +00:00
|
|
|
else if(components == 1) {
|
|
|
|
/* grayscale */
|
|
|
|
for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
|
2016-11-14 13:03:17 +00:00
|
|
|
pixels[i*4+3] = alpha_one;
|
2016-05-22 21:24:26 +00:00
|
|
|
pixels[i*4+2] = pixels[i];
|
|
|
|
pixels[i*4+1] = pixels[i];
|
|
|
|
pixels[i*4+0] = pixels[i];
|
|
|
|
}
|
2014-05-07 14:36:44 +00:00
|
|
|
}
|
2016-05-22 21:24:26 +00:00
|
|
|
if(img->use_alpha == false) {
|
|
|
|
for(size_t i = num_pixels-1, pixel = 0; pixel < num_pixels; pixel++, i--) {
|
2016-11-14 13:03:17 +00:00
|
|
|
pixels[i*4+3] = alpha_one;
|
2016-05-22 21:24:26 +00:00
|
|
|
}
|
2016-05-09 10:51:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-17 13:29:47 +00:00
|
|
|
/* Make sure we don't have buggy values. */
|
|
|
|
if(FileFormat == TypeDesc::FLOAT) {
|
|
|
|
/* For RGBA buffers we put all channels to 0 if either of them is not
|
|
|
|
* finite. This way we avoid possible artifacts caused by fully changed
|
|
|
|
* hue.
|
|
|
|
*/
|
|
|
|
if(is_rgba) {
|
|
|
|
for(size_t i = 0; i < num_pixels; i += 4) {
|
|
|
|
StorageType *pixel = &pixels[i*4];
|
|
|
|
if(!isfinite(pixel[0]) ||
|
|
|
|
!isfinite(pixel[1]) ||
|
|
|
|
!isfinite(pixel[2]) ||
|
|
|
|
!isfinite(pixel[3]))
|
|
|
|
{
|
|
|
|
pixel[0] = 0;
|
|
|
|
pixel[1] = 0;
|
|
|
|
pixel[2] = 0;
|
|
|
|
pixel[3] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(size_t i = 0; i < num_pixels; ++i) {
|
2017-05-18 13:49:03 +00:00
|
|
|
StorageType *pixel = &pixels[i];
|
2017-05-17 13:29:47 +00:00
|
|
|
if(!isfinite(pixel[0])) {
|
|
|
|
pixel[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Scale image down if needed. */
|
2016-11-17 11:13:22 +00:00
|
|
|
if(pixels_storage.size() > 0) {
|
|
|
|
float scale_factor = 1.0f;
|
|
|
|
while(max_size * scale_factor > texture_limit) {
|
|
|
|
scale_factor *= 0.5f;
|
|
|
|
}
|
|
|
|
VLOG(1) << "Scaling image " << img->filename
|
|
|
|
<< " by a factor of " << scale_factor << ".";
|
|
|
|
vector<StorageType> scaled_pixels;
|
|
|
|
size_t scaled_width, scaled_height, scaled_depth;
|
|
|
|
util_image_resize_pixels(pixels_storage,
|
|
|
|
width, height, depth,
|
|
|
|
is_rgba ? 4 : 1,
|
|
|
|
scale_factor,
|
|
|
|
&scaled_pixels,
|
|
|
|
&scaled_width, &scaled_height, &scaled_depth);
|
|
|
|
StorageType *texture_pixels = (StorageType*)tex_img.resize(scaled_width,
|
|
|
|
scaled_height,
|
|
|
|
scaled_depth);
|
|
|
|
memcpy(texture_pixels,
|
|
|
|
&scaled_pixels[0],
|
|
|
|
scaled_pixels.size() * sizeof(StorageType));
|
|
|
|
}
|
2016-06-19 15:31:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
void ImageManager::device_load_image(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
ImageDataType type,
|
|
|
|
int slot,
|
|
|
|
Progress *progress)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-05-05 19:44:33 +00:00
|
|
|
if(progress->get_cancel())
|
|
|
|
return;
|
2016-11-17 11:13:22 +00:00
|
|
|
|
2016-05-08 18:18:52 +00:00
|
|
|
Image *img = images[type][slot];
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
if(osl_texture_system && !img->builtin_data)
|
|
|
|
return;
|
|
|
|
|
2016-05-08 18:18:52 +00:00
|
|
|
string filename = path_filename(images[type][slot]->filename);
|
2016-05-06 09:57:30 +00:00
|
|
|
progress->set_status("Updating Images", "Loading " + filename);
|
2012-05-05 19:44:33 +00:00
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
const int texture_limit = scene->params.texture_limit;
|
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
/* Slot assignment */
|
|
|
|
int flat_slot = type_index_to_flattened_slot(slot, type);
|
|
|
|
|
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
|
|
|
string name = string_printf("__tex_image_%s_%03d", name_from_type(type).c_str(), flat_slot);
|
2016-05-09 10:51:42 +00:00
|
|
|
|
2016-05-06 11:42:50 +00:00
|
|
|
if(type == IMAGE_DATA_TYPE_FLOAT4) {
|
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
|
|
|
if(dscene->tex_float4_image[slot] == NULL)
|
|
|
|
dscene->tex_float4_image[slot] = new device_vector<float4>();
|
|
|
|
device_vector<float4>& tex_img = *dscene->tex_float4_image[slot];
|
2017-08-09 08:24:03 +00:00
|
|
|
|
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(tex_img);
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
if(!file_load_image<TypeDesc::FLOAT, float>(img,
|
|
|
|
type,
|
|
|
|
texture_limit,
|
|
|
|
tex_img))
|
|
|
|
{
|
2012-07-04 11:48:42 +00:00
|
|
|
/* on failure to load, we set a 1x1 pixels pink image */
|
2012-03-07 12:27:18 +00:00
|
|
|
float *pixels = (float*)tex_img.resize(1, 1);
|
|
|
|
|
2012-07-04 11:48:42 +00:00
|
|
|
pixels[0] = TEX_IMAGE_MISSING_R;
|
|
|
|
pixels[1] = TEX_IMAGE_MISSING_G;
|
|
|
|
pixels[2] = TEX_IMAGE_MISSING_B;
|
|
|
|
pixels[3] = TEX_IMAGE_MISSING_A;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-08-08 11:12:04 +00:00
|
|
|
{
|
2016-05-09 10:51:42 +00:00
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_alloc(name.c_str(),
|
|
|
|
tex_img,
|
|
|
|
img->interpolation,
|
|
|
|
img->extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(type == IMAGE_DATA_TYPE_FLOAT) {
|
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
|
|
|
if(dscene->tex_float_image[slot] == NULL)
|
|
|
|
dscene->tex_float_image[slot] = new device_vector<float>();
|
|
|
|
device_vector<float>& tex_img = *dscene->tex_float_image[slot];
|
2017-08-09 08:24:03 +00:00
|
|
|
|
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(tex_img);
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
if(!file_load_image<TypeDesc::FLOAT, float>(img,
|
|
|
|
type,
|
|
|
|
texture_limit,
|
|
|
|
tex_img))
|
|
|
|
{
|
2016-05-09 10:51:42 +00:00
|
|
|
/* on failure to load, we set a 1x1 pixels pink image */
|
|
|
|
float *pixels = (float*)tex_img.resize(1, 1);
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2016-05-09 10:51:42 +00:00
|
|
|
pixels[0] = TEX_IMAGE_MISSING_R;
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2017-08-08 11:12:04 +00:00
|
|
|
{
|
2012-09-27 17:42:09 +00:00
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
2015-07-21 19:58:19 +00:00
|
|
|
device->tex_alloc(name.c_str(),
|
|
|
|
tex_img,
|
|
|
|
img->interpolation,
|
2015-07-28 11:51:10 +00:00
|
|
|
img->extension);
|
2012-09-27 17:42:09 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2016-05-16 08:55:50 +00:00
|
|
|
else if(type == IMAGE_DATA_TYPE_BYTE4) {
|
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
|
|
|
if(dscene->tex_byte4_image[slot] == NULL)
|
|
|
|
dscene->tex_byte4_image[slot] = new device_vector<uchar4>();
|
|
|
|
device_vector<uchar4>& tex_img = *dscene->tex_byte4_image[slot];
|
2017-08-09 08:24:03 +00:00
|
|
|
|
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(tex_img);
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
if(!file_load_image<TypeDesc::UINT8, uchar>(img,
|
|
|
|
type,
|
|
|
|
texture_limit,
|
|
|
|
tex_img))
|
|
|
|
{
|
2012-07-04 11:48:42 +00:00
|
|
|
/* on failure to load, we set a 1x1 pixels pink image */
|
2012-03-07 12:27:18 +00:00
|
|
|
uchar *pixels = (uchar*)tex_img.resize(1, 1);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-07-04 11:48:42 +00:00
|
|
|
pixels[0] = (TEX_IMAGE_MISSING_R * 255);
|
|
|
|
pixels[1] = (TEX_IMAGE_MISSING_G * 255);
|
|
|
|
pixels[2] = (TEX_IMAGE_MISSING_B * 255);
|
|
|
|
pixels[3] = (TEX_IMAGE_MISSING_A * 255);
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 11:12:04 +00:00
|
|
|
{
|
2012-09-27 17:42:09 +00:00
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
2015-07-21 19:58:19 +00:00
|
|
|
device->tex_alloc(name.c_str(),
|
|
|
|
tex_img,
|
|
|
|
img->interpolation,
|
2015-07-28 11:51:10 +00:00
|
|
|
img->extension);
|
2012-09-27 17:42:09 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2016-06-19 15:31:16 +00:00
|
|
|
else if(type == IMAGE_DATA_TYPE_BYTE){
|
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
|
|
|
if(dscene->tex_byte_image[slot] == NULL)
|
|
|
|
dscene->tex_byte_image[slot] = new device_vector<uchar>();
|
|
|
|
device_vector<uchar>& tex_img = *dscene->tex_byte_image[slot];
|
2017-08-09 08:24:03 +00:00
|
|
|
|
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(tex_img);
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
if(!file_load_image<TypeDesc::UINT8, uchar>(img,
|
|
|
|
type,
|
|
|
|
texture_limit,
|
|
|
|
tex_img)) {
|
2016-05-12 12:51:42 +00:00
|
|
|
/* on failure to load, we set a 1x1 pixels pink image */
|
|
|
|
uchar *pixels = (uchar*)tex_img.resize(1, 1);
|
|
|
|
|
|
|
|
pixels[0] = (TEX_IMAGE_MISSING_R * 255);
|
|
|
|
}
|
|
|
|
|
2017-08-08 11:12:04 +00:00
|
|
|
{
|
2016-05-12 12:51:42 +00:00
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_alloc(name.c_str(),
|
|
|
|
tex_img,
|
|
|
|
img->interpolation,
|
|
|
|
img->extension);
|
|
|
|
}
|
|
|
|
}
|
2016-06-19 15:31:16 +00:00
|
|
|
else if(type == IMAGE_DATA_TYPE_HALF4){
|
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
|
|
|
if(dscene->tex_half4_image[slot] == NULL)
|
|
|
|
dscene->tex_half4_image[slot] = new device_vector<half4>();
|
|
|
|
device_vector<half4>& tex_img = *dscene->tex_half4_image[slot];
|
2017-08-09 08:24:03 +00:00
|
|
|
|
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(tex_img);
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
if(!file_load_image<TypeDesc::HALF, half>(img,
|
|
|
|
type,
|
|
|
|
texture_limit,
|
|
|
|
tex_img)) {
|
2016-06-19 15:31:16 +00:00
|
|
|
/* on failure to load, we set a 1x1 pixels pink image */
|
|
|
|
half *pixels = (half*)tex_img.resize(1, 1);
|
|
|
|
|
|
|
|
pixels[0] = TEX_IMAGE_MISSING_R;
|
|
|
|
pixels[1] = TEX_IMAGE_MISSING_G;
|
|
|
|
pixels[2] = TEX_IMAGE_MISSING_B;
|
|
|
|
pixels[3] = TEX_IMAGE_MISSING_A;
|
|
|
|
}
|
|
|
|
|
2017-08-08 11:12:04 +00:00
|
|
|
{
|
2016-06-19 15:31:16 +00:00
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_alloc(name.c_str(),
|
|
|
|
tex_img,
|
|
|
|
img->interpolation,
|
|
|
|
img->extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(type == IMAGE_DATA_TYPE_HALF){
|
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
|
|
|
if(dscene->tex_half_image[slot] == NULL)
|
|
|
|
dscene->tex_half_image[slot] = new device_vector<half>();
|
|
|
|
device_vector<half>& tex_img = *dscene->tex_half_image[slot];
|
2017-08-09 08:24:03 +00:00
|
|
|
|
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(tex_img);
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:13:22 +00:00
|
|
|
if(!file_load_image<TypeDesc::HALF, half>(img,
|
|
|
|
type,
|
|
|
|
texture_limit,
|
|
|
|
tex_img)) {
|
2016-06-19 15:31:16 +00:00
|
|
|
/* on failure to load, we set a 1x1 pixels pink image */
|
|
|
|
half *pixels = (half*)tex_img.resize(1, 1);
|
|
|
|
|
|
|
|
pixels[0] = TEX_IMAGE_MISSING_R;
|
|
|
|
}
|
|
|
|
|
2017-08-08 11:12:04 +00:00
|
|
|
{
|
2016-06-19 15:31:16 +00:00
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_alloc(name.c_str(),
|
|
|
|
tex_img,
|
|
|
|
img->interpolation,
|
|
|
|
img->extension);
|
|
|
|
}
|
|
|
|
}
|
2012-05-05 19:44:33 +00:00
|
|
|
|
|
|
|
img->need_load = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 18:18:52 +00:00
|
|
|
void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageDataType type, int slot)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-08 18:18:52 +00:00
|
|
|
Image *img = images[type][slot];
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
if(img) {
|
2014-03-29 12:03:48 +00:00
|
|
|
if(osl_texture_system && !img->builtin_data) {
|
2011-05-31 16:21:30 +00:00
|
|
|
#ifdef WITH_OSL
|
2016-05-06 09:57:30 +00:00
|
|
|
ustring filename(images[type][slot]->filename);
|
2011-05-31 16:21:30 +00:00
|
|
|
((OSL::TextureSystem*)osl_texture_system)->invalidate(filename);
|
|
|
|
#endif
|
|
|
|
}
|
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
|
|
|
else {
|
|
|
|
device_memory *tex_img = NULL;
|
|
|
|
switch(type) {
|
|
|
|
case IMAGE_DATA_TYPE_FLOAT4:
|
2017-04-28 22:47:47 +00:00
|
|
|
if(slot >= dscene->tex_float4_image.size()) {
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
tex_img = dscene->tex_float4_image[slot];
|
|
|
|
dscene->tex_float4_image[slot] = NULL;
|
|
|
|
break;
|
2017-04-27 09:11:08 +00:00
|
|
|
case IMAGE_DATA_TYPE_BYTE4:
|
2017-04-28 22:47:47 +00:00
|
|
|
if(slot >= dscene->tex_byte4_image.size()) {
|
|
|
|
break;
|
|
|
|
}
|
2017-04-27 09:11:08 +00:00
|
|
|
tex_img = dscene->tex_byte4_image[slot];
|
|
|
|
dscene->tex_byte4_image[slot]= NULL;
|
|
|
|
break;
|
|
|
|
case IMAGE_DATA_TYPE_HALF4:
|
2017-04-28 22:47:47 +00:00
|
|
|
if(slot >= dscene->tex_half4_image.size()) {
|
|
|
|
break;
|
|
|
|
}
|
2017-04-27 09:11:08 +00:00
|
|
|
tex_img = dscene->tex_half4_image[slot];
|
|
|
|
dscene->tex_half4_image[slot]= NULL;
|
|
|
|
break;
|
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
|
|
|
case IMAGE_DATA_TYPE_FLOAT:
|
2017-04-28 22:47:47 +00:00
|
|
|
if(slot >= dscene->tex_float_image.size()) {
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
tex_img = dscene->tex_float_image[slot];
|
|
|
|
dscene->tex_float_image[slot] = NULL;
|
|
|
|
break;
|
|
|
|
case IMAGE_DATA_TYPE_BYTE:
|
2017-04-28 22:47:47 +00:00
|
|
|
if(slot >= dscene->tex_byte_image.size()) {
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
tex_img = dscene->tex_byte_image[slot];
|
|
|
|
dscene->tex_byte_image[slot]= NULL;
|
|
|
|
break;
|
|
|
|
case IMAGE_DATA_TYPE_HALF:
|
2017-04-28 22:47:47 +00:00
|
|
|
if(slot >= dscene->tex_half_image.size()) {
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
tex_img = dscene->tex_half_image[slot];
|
|
|
|
dscene->tex_half_image[slot]= NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
tex_img = NULL;
|
2016-06-19 15:31:16 +00:00
|
|
|
}
|
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
|
|
|
if(tex_img) {
|
2017-08-09 08:24:03 +00:00
|
|
|
if(tex_img->device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(*tex_img);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
delete tex_img;
|
2016-06-19 15:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-12 12:51:42 +00:00
|
|
|
|
|
|
|
delete images[type][slot];
|
|
|
|
images[type][slot] = NULL;
|
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
|
|
|
--tex_num_images[type];
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 14:27:31 +00:00
|
|
|
void ImageManager::device_prepare_update(DeviceScene *dscene)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
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
|
|
|
switch(type) {
|
2017-04-27 09:11:08 +00:00
|
|
|
case IMAGE_DATA_TYPE_FLOAT4:
|
|
|
|
if(dscene->tex_float4_image.size() <= tex_num_images[IMAGE_DATA_TYPE_FLOAT4])
|
|
|
|
dscene->tex_float4_image.resize(tex_num_images[IMAGE_DATA_TYPE_FLOAT4]);
|
|
|
|
break;
|
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
|
|
|
case IMAGE_DATA_TYPE_BYTE4:
|
|
|
|
if(dscene->tex_byte4_image.size() <= tex_num_images[IMAGE_DATA_TYPE_BYTE4])
|
|
|
|
dscene->tex_byte4_image.resize(tex_num_images[IMAGE_DATA_TYPE_BYTE4]);
|
|
|
|
break;
|
2017-04-27 09:11:08 +00:00
|
|
|
case IMAGE_DATA_TYPE_HALF4:
|
|
|
|
if(dscene->tex_half4_image.size() <= tex_num_images[IMAGE_DATA_TYPE_HALF4])
|
|
|
|
dscene->tex_half4_image.resize(tex_num_images[IMAGE_DATA_TYPE_HALF4]);
|
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
|
|
|
break;
|
|
|
|
case IMAGE_DATA_TYPE_BYTE:
|
|
|
|
if(dscene->tex_byte_image.size() <= tex_num_images[IMAGE_DATA_TYPE_BYTE])
|
|
|
|
dscene->tex_byte_image.resize(tex_num_images[IMAGE_DATA_TYPE_BYTE]);
|
|
|
|
break;
|
|
|
|
case IMAGE_DATA_TYPE_FLOAT:
|
|
|
|
if(dscene->tex_float_image.size() <= tex_num_images[IMAGE_DATA_TYPE_FLOAT])
|
|
|
|
dscene->tex_float_image.resize(tex_num_images[IMAGE_DATA_TYPE_FLOAT]);
|
|
|
|
break;
|
|
|
|
case IMAGE_DATA_TYPE_HALF:
|
|
|
|
if(dscene->tex_half_image.size() <= tex_num_images[IMAGE_DATA_TYPE_HALF])
|
|
|
|
dscene->tex_half_image.resize(tex_num_images[IMAGE_DATA_TYPE_HALF]);
|
|
|
|
break;
|
|
|
|
}
|
2017-05-04 14:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageManager::device_update(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
Progress& progress)
|
|
|
|
{
|
|
|
|
if(!need_update) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure arrays are proper size. */
|
|
|
|
device_prepare_update(dscene);
|
|
|
|
|
|
|
|
TaskPool pool;
|
|
|
|
for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
2016-05-06 09:57:30 +00:00
|
|
|
for(size_t slot = 0; slot < images[type].size(); slot++) {
|
|
|
|
if(!images[type][slot])
|
|
|
|
continue;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2016-05-06 09:57:30 +00:00
|
|
|
if(images[type][slot]->users == 0) {
|
2016-05-08 18:18:52 +00:00
|
|
|
device_free_image(device, dscene, (ImageDataType)type, slot);
|
2016-05-06 09:57:30 +00:00
|
|
|
}
|
|
|
|
else if(images[type][slot]->need_load) {
|
|
|
|
if(!osl_texture_system || images[type][slot]->builtin_data)
|
2016-11-17 11:13:22 +00:00
|
|
|
pool.push(function_bind(&ImageManager::device_load_image,
|
|
|
|
this,
|
|
|
|
device,
|
|
|
|
dscene,
|
|
|
|
scene,
|
|
|
|
(ImageDataType)type,
|
|
|
|
slot,
|
|
|
|
&progress));
|
2016-05-06 09:57:30 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
pool.wait_work();
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
need_update = false;
|
|
|
|
}
|
|
|
|
|
2015-04-02 15:37:57 +00:00
|
|
|
void ImageManager::device_update_slot(Device *device,
|
|
|
|
DeviceScene *dscene,
|
2016-11-17 11:13:22 +00:00
|
|
|
Scene *scene,
|
2016-05-08 19:41:25 +00:00
|
|
|
int flat_slot,
|
2015-04-02 15:37:57 +00:00
|
|
|
Progress *progress)
|
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
ImageDataType type;
|
2016-05-08 19:41:25 +00:00
|
|
|
int slot = flattened_slot_to_type_index(flat_slot, &type);
|
2016-05-06 09:57:30 +00:00
|
|
|
|
2016-05-08 18:18:52 +00:00
|
|
|
Image *image = images[type][slot];
|
|
|
|
assert(image != NULL);
|
2016-05-06 09:57:30 +00:00
|
|
|
|
2015-04-02 15:37:57 +00:00
|
|
|
if(image->users == 0) {
|
2016-05-08 18:18:52 +00:00
|
|
|
device_free_image(device, dscene, type, slot);
|
2015-04-02 15:37:57 +00:00
|
|
|
}
|
|
|
|
else if(image->need_load) {
|
2016-05-06 09:57:30 +00:00
|
|
|
if(!osl_texture_system || image->builtin_data)
|
2015-04-02 15:37:57 +00:00
|
|
|
device_load_image(device,
|
|
|
|
dscene,
|
2016-11-17 11:13:22 +00:00
|
|
|
scene,
|
2016-05-08 18:18:52 +00:00
|
|
|
type,
|
2015-04-02 15:37:57 +00:00
|
|
|
slot,
|
|
|
|
progress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-19 12:45:52 +00:00
|
|
|
void ImageManager::device_free_builtin(Device *device, DeviceScene *dscene)
|
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
|
|
|
for(size_t slot = 0; slot < images[type].size(); slot++) {
|
|
|
|
if(images[type][slot] && images[type][slot]->builtin_data)
|
2016-05-08 18:18:52 +00:00
|
|
|
device_free_image(device, dscene, (ImageDataType)type, slot);
|
2016-05-06 09:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 12:45:52 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void ImageManager::device_free(Device *device, DeviceScene *dscene)
|
|
|
|
{
|
2016-05-06 09:57:30 +00:00
|
|
|
for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
|
|
|
|
for(size_t slot = 0; slot < images[type].size(); slot++) {
|
2016-05-08 18:18:52 +00:00
|
|
|
device_free_image(device, dscene, (ImageDataType)type, slot);
|
2016-05-06 09:57:30 +00:00
|
|
|
}
|
|
|
|
images[type].clear();
|
|
|
|
}
|
2017-04-27 09:11:08 +00:00
|
|
|
|
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
|
|
|
dscene->tex_float4_image.clear();
|
2017-04-27 09:11:08 +00:00
|
|
|
dscene->tex_byte4_image.clear();
|
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
|
|
|
dscene->tex_half4_image.clear();
|
2017-04-27 09:11:08 +00:00
|
|
|
dscene->tex_float_image.clear();
|
|
|
|
dscene->tex_byte_image.clear();
|
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
|
|
|
dscene->tex_half_image.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|