Cleanup: stop encoding image data type in slot index

This is legacy code from when we had a fixed number of textures.
This commit is contained in:
Brecht Van Lommel 2020-02-26 17:31:33 +01:00
parent 9910803574
commit f01bc597a8
11 changed files with 131 additions and 189 deletions

@ -1169,10 +1169,10 @@ void CUDADevice::tex_alloc(device_memory &mem)
}
/* Kepler+, bindless textures. */
int flat_slot = 0;
int slot = 0;
if (string_startswith(mem.name, "__tex_image")) {
int pos = string(mem.name).rfind("_");
flat_slot = atoi(mem.name + pos + 1);
slot = atoi(mem.name + pos + 1);
}
else {
assert(0);
@ -1214,15 +1214,16 @@ void CUDADevice::tex_alloc(device_memory &mem)
cuda_assert(cuTexObjectCreate(&cmem->texobject, &resDesc, &texDesc, NULL));
/* Resize once */
if (flat_slot >= texture_info.size()) {
if (slot >= texture_info.size()) {
/* Allocate some slots in advance, to reduce amount
* of re-allocations. */
texture_info.resize(flat_slot + 128);
texture_info.resize(slot + 128);
}
/* Set Mapping and tag that we need to (re-)upload to device */
TextureInfo &info = texture_info[flat_slot];
TextureInfo &info = texture_info[slot];
info.data = (uint64_t)cmem->texobject;
info.data_type = mem.image_data_type;
info.cl_buffer = 0;
info.interpolation = mem.interpolation;
info.extension = mem.extension;

@ -465,23 +465,24 @@ class CPUDevice : public Device {
}
else {
/* Image Texture. */
int flat_slot = 0;
int slot = 0;
if (string_startswith(mem.name, "__tex_image")) {
int pos = string(mem.name).rfind("_");
flat_slot = atoi(mem.name + pos + 1);
slot = atoi(mem.name + pos + 1);
}
else {
assert(0);
}
if (flat_slot >= texture_info.size()) {
if (slot >= texture_info.size()) {
/* Allocate some slots in advance, to reduce amount
* of re-allocations. */
texture_info.resize(flat_slot + 128);
texture_info.resize(slot + 128);
}
TextureInfo &info = texture_info[flat_slot];
TextureInfo &info = texture_info[slot];
info.data = (uint64_t)mem.host_pointer;
info.data_type = mem.image_data_type;
info.cl_buffer = 0;
info.interpolation = mem.interpolation;
info.extension = mem.extension;

@ -31,6 +31,7 @@ device_memory::device_memory(Device *device, const char *name, MemoryType type)
data_depth(0),
type(type),
name(name),
image_data_type(IMAGE_DATA_NUM_TYPES),
interpolation(INTERPOLATION_NONE),
extension(EXTENSION_REPEAT),
device(device),

@ -208,6 +208,7 @@ class device_memory {
size_t data_depth;
MemoryType type;
const char *name;
ImageDataType image_data_type;
InterpolationType interpolation;
ExtensionType extension;

@ -1298,6 +1298,8 @@ void OpenCLDevice::flush_texture_buffers()
if (string_startswith(slot.name, "__tex_image")) {
device_memory *mem = textures[slot.name];
info.data_type = mem->image_data_type;
info.width = mem->data_width;
info.height = mem->data_height;
info.depth = mem->data_depth;

@ -474,7 +474,7 @@ ccl_device float4 kernel_tex_image_interp(KernelGlobals *kg, int id, float x, fl
{
const TextureInfo &info = kernel_tex_fetch(__texture_info, id);
switch (kernel_tex_type(id)) {
switch (info.data_type) {
case IMAGE_DATA_TYPE_HALF:
return TextureInterpolator<half>::interp(info, x, y);
case IMAGE_DATA_TYPE_BYTE:
@ -503,7 +503,7 @@ ccl_device float4 kernel_tex_image_interp_3d(
{
const TextureInfo &info = kernel_tex_fetch(__texture_info, id);
switch (kernel_tex_type(id)) {
switch (info.data_type) {
case IMAGE_DATA_TYPE_HALF:
return TextureInterpolator<half>::interp_3d(info, x, y, z, interp);
case IMAGE_DATA_TYPE_BYTE:

@ -124,7 +124,7 @@ ccl_device float4 kernel_tex_image_interp(KernelGlobals *kg, int id, float x, fl
CUtexObject tex = (CUtexObject)info.data;
/* float4, byte4, ushort4 and half4 */
const int texture_type = kernel_tex_type(id);
const int texture_type = info.data_type;
if (texture_type == IMAGE_DATA_TYPE_FLOAT4 || texture_type == IMAGE_DATA_TYPE_BYTE4 ||
texture_type == IMAGE_DATA_TYPE_HALF4 || texture_type == IMAGE_DATA_TYPE_USHORT4) {
if (info.interpolation == INTERPOLATION_CUBIC) {
@ -156,7 +156,7 @@ ccl_device float4 kernel_tex_image_interp_3d(
CUtexObject tex = (CUtexObject)info.data;
uint interpolation = (interp == INTERPOLATION_NONE) ? info.interpolation : interp;
const int texture_type = kernel_tex_type(id);
const int texture_type = info.data_type;
if (texture_type == IMAGE_DATA_TYPE_FLOAT4 || texture_type == IMAGE_DATA_TYPE_BYTE4 ||
texture_type == IMAGE_DATA_TYPE_HALF4 || texture_type == IMAGE_DATA_TYPE_USHORT4) {
if (interpolation == INTERPOLATION_CUBIC) {

@ -47,7 +47,7 @@ ccl_device_inline float4 svm_image_texture_read(KernelGlobals *kg,
int id,
int offset)
{
const int texture_type = kernel_tex_type(id);
const int texture_type = info->data_type;
/* Float4 */
if (texture_type == IMAGE_DATA_TYPE_FLOAT4) {

@ -50,21 +50,6 @@ bool isfinite(uint16_t /*value*/)
return true;
}
/* The lower three bits of a device texture slot number indicate its type.
* These functions convert the slot ids from ImageManager "images" ones
* to device ones and vice verse.
*/
int type_index_to_flattened_slot(int slot, ImageDataType type)
{
return (slot << IMAGE_DATA_TYPE_SHIFT) | (type);
}
int flattened_slot_to_type_index(int flat_slot, ImageDataType *type)
{
*type = (ImageDataType)(flat_slot & IMAGE_DATA_TYPE_MASK);
return flat_slot >> IMAGE_DATA_TYPE_SHIFT;
}
const char *name_from_type(ImageDataType type)
{
switch (type) {
@ -104,17 +89,13 @@ ImageManager::ImageManager(const DeviceInfo &info)
max_num_images = TEX_NUM_MAX;
has_half_images = info.has_half_images;
for (size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
tex_num_images[type] = 0;
}
tex_num_images = 0;
}
ImageManager::~ImageManager()
{
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]);
}
for (size_t slot = 0; slot < images.size(); slot++)
assert(!images[slot]);
}
void ImageManager::set_osl_texture_system(void *texture_system)
@ -127,37 +108,32 @@ bool ImageManager::set_animation_frame_update(int frame)
if (frame != animation_frame) {
animation_frame = frame;
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]->key.animated)
return true;
}
for (size_t slot = 0; slot < images.size(); slot++) {
if (images[slot] && images[slot]->key.animated)
return true;
}
}
return false;
}
device_memory *ImageManager::image_memory(int flat_slot)
device_memory *ImageManager::image_memory(int slot)
{
ImageDataType type;
int slot = flattened_slot_to_type_index(flat_slot, &type);
if (slot == -1) {
return NULL;
}
Image *img = images[type][slot];
return img->mem;
Image *img = images[slot];
return img ? img->mem : NULL;
}
bool ImageManager::get_image_metadata(int flat_slot, ImageMetaData &metadata)
bool ImageManager::get_image_metadata(int slot, ImageMetaData &metadata)
{
if (flat_slot == -1) {
if (slot == -1) {
return false;
}
ImageDataType type;
int slot = flattened_slot_to_type_index(flat_slot, &type);
Image *img = images[type][slot];
Image *img = images[slot];
if (img) {
metadata = img->metadata;
return true;
@ -297,23 +273,22 @@ int ImageManager::add_image(const ImageKey &key, float frame, ImageMetaData &met
size_t slot;
get_image_metadata(key, metadata);
ImageDataType type = metadata.type;
thread_scoped_lock device_lock(device_mutex);
/* No half textures on OpenCL, use full float instead. */
if (!has_half_images) {
if (type == IMAGE_DATA_TYPE_HALF4) {
type = IMAGE_DATA_TYPE_FLOAT4;
if (metadata.type == IMAGE_DATA_TYPE_HALF4) {
metadata.type = IMAGE_DATA_TYPE_FLOAT4;
}
else if (type == IMAGE_DATA_TYPE_HALF) {
type = IMAGE_DATA_TYPE_FLOAT;
else if (metadata.type == IMAGE_DATA_TYPE_HALF) {
metadata.type = IMAGE_DATA_TYPE_FLOAT;
}
}
/* Fnd existing image. */
for (slot = 0; slot < images[type].size(); slot++) {
img = images[type][slot];
for (slot = 0; slot < images.size(); slot++) {
img = images[slot];
if (img && img->key == key) {
if (img->frame != frame) {
img->frame = frame;
@ -324,13 +299,13 @@ int ImageManager::add_image(const ImageKey &key, float frame, ImageMetaData &met
img->need_load = true;
}
img->users++;
return type_index_to_flattened_slot(slot, type);
return slot;
}
}
/* Find free slot. */
for (slot = 0; slot < images[type].size(); slot++) {
if (!images[type][slot])
for (slot = 0; slot < images.size(); slot++) {
if (!images[slot])
break;
}
@ -338,11 +313,7 @@ int ImageManager::add_image(const ImageKey &key, float frame, ImageMetaData &met
* Very unlikely, since max_num_images is insanely big. But better safe
* than sorry.
*/
int tex_count = 0;
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
tex_count += tex_num_images[type];
}
if (tex_count > max_num_images) {
if (tex_num_images > max_num_images) {
printf(
"ImageManager::add_image: Reached image limit (%d), "
"skipping '%s'\n",
@ -351,8 +322,8 @@ int ImageManager::add_image(const ImageKey &key, float frame, ImageMetaData &met
return -1;
}
if (slot == images[type].size()) {
images[type].resize(images[type].size() + 1);
if (slot == images.size()) {
images.resize(images.size() + 1);
}
/* Add new image. */
@ -364,32 +335,26 @@ int ImageManager::add_image(const ImageKey &key, float frame, ImageMetaData &met
img->users = 1;
img->mem = NULL;
images[type][slot] = img;
images[slot] = img;
++tex_num_images[type];
++tex_num_images;
need_update = true;
return type_index_to_flattened_slot(slot, type);
return slot;
}
void ImageManager::add_image_user(int flat_slot)
void ImageManager::add_image_user(int slot)
{
ImageDataType type;
int slot = flattened_slot_to_type_index(flat_slot, &type);
Image *image = images[type][slot];
Image *image = images[slot];
assert(image && image->users >= 1);
image->users++;
}
void ImageManager::remove_image(int flat_slot)
void ImageManager::remove_image(int slot)
{
ImageDataType type;
int slot = flattened_slot_to_type_index(flat_slot, &type);
Image *image = images[type][slot];
Image *image = images[slot];
assert(image && image->users >= 1);
/* decrement user count */
@ -406,12 +371,10 @@ void ImageManager::remove_image(const ImageKey &key)
{
size_t slot;
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
for (slot = 0; slot < images[type].size(); slot++) {
if (images[type][slot] && images[type][slot]->key == key) {
remove_image(type_index_to_flattened_slot(slot, (ImageDataType)type));
return;
}
for (slot = 0; slot < images.size(); slot++) {
if (images[slot] && images[slot]->key == key) {
remove_image(slot);
return;
}
}
}
@ -422,12 +385,10 @@ void ImageManager::remove_image(const ImageKey &key)
*/
void ImageManager::tag_reload_image(const ImageKey &key)
{
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]->key == key) {
images[type][slot]->need_load = true;
break;
}
for (size_t slot = 0; slot < images.size(); slot++) {
if (images[slot] && images[slot]->key == key) {
images[slot]->need_load = true;
break;
}
}
}
@ -488,7 +449,6 @@ bool ImageManager::file_load_image_generic(Image *img, unique_ptr<ImageInput> *i
template<TypeDesc::BASETYPE FileFormat, typename StorageType, typename DeviceType>
bool ImageManager::file_load_image(Image *img,
ImageDataType type,
int texture_limit,
device_vector<DeviceType> &tex_img)
{
@ -591,8 +551,10 @@ bool ImageManager::file_load_image(Image *img,
/* The kernel can handle 1 and 4 channel images. Anything that is not a single
* channel image is converted to RGBA format. */
bool is_rgba = (type == IMAGE_DATA_TYPE_FLOAT4 || type == IMAGE_DATA_TYPE_HALF4 ||
type == IMAGE_DATA_TYPE_BYTE4 || type == IMAGE_DATA_TYPE_USHORT4);
bool is_rgba = (img->metadata.type == IMAGE_DATA_TYPE_FLOAT4 ||
img->metadata.type == IMAGE_DATA_TYPE_HALF4 ||
img->metadata.type == IMAGE_DATA_TYPE_BYTE4 ||
img->metadata.type == IMAGE_DATA_TYPE_USHORT4);
if (is_rgba) {
const StorageType one = util_image_cast_from_float<StorageType>(1.0f);
@ -716,29 +678,30 @@ bool ImageManager::file_load_image(Image *img,
static void image_set_device_memory(ImageManager::Image *img, device_memory *mem)
{
img->mem = mem;
mem->image_data_type = img->metadata.type;
mem->interpolation = img->key.interpolation;
mem->extension = img->key.extension;
}
void ImageManager::device_load_image(
Device *device, Scene *scene, ImageDataType type, int slot, Progress *progress)
void ImageManager::device_load_image(Device *device, Scene *scene, int slot, Progress *progress)
{
if (progress->get_cancel())
return;
Image *img = images[type][slot];
Image *img = images[slot];
if (osl_texture_system && !img->key.builtin_data)
return;
string filename = path_filename(images[type][slot]->key.filename);
string filename = path_filename(images[slot]->key.filename);
progress->set_status("Updating Images", "Loading " + filename);
const int texture_limit = scene->params.texture_limit;
ImageDataType type = img->metadata.type;
/* Slot assignment */
int flat_slot = type_index_to_flattened_slot(slot, type);
img->mem_name = string_printf("__tex_image_%s_%03d", name_from_type(type), flat_slot);
img->mem_name = string_printf("__tex_image_%s_%03d", name_from_type(type), slot);
/* Free previous texture in slot. */
if (img->mem) {
@ -752,7 +715,7 @@ void ImageManager::device_load_image(
device_vector<float4> *tex_img = new device_vector<float4>(
device, img->mem_name.c_str(), MEM_TEXTURE);
if (!file_load_image<TypeDesc::FLOAT, float>(img, type, texture_limit, *tex_img)) {
if (!file_load_image<TypeDesc::FLOAT, float>(img, texture_limit, *tex_img)) {
/* on failure to load, we set a 1x1 pixels pink image */
thread_scoped_lock device_lock(device_mutex);
float *pixels = (float *)tex_img->alloc(1, 1);
@ -772,7 +735,7 @@ void ImageManager::device_load_image(
device_vector<float> *tex_img = new device_vector<float>(
device, img->mem_name.c_str(), MEM_TEXTURE);
if (!file_load_image<TypeDesc::FLOAT, float>(img, type, texture_limit, *tex_img)) {
if (!file_load_image<TypeDesc::FLOAT, float>(img, texture_limit, *tex_img)) {
/* on failure to load, we set a 1x1 pixels pink image */
thread_scoped_lock device_lock(device_mutex);
float *pixels = (float *)tex_img->alloc(1, 1);
@ -789,7 +752,7 @@ void ImageManager::device_load_image(
device_vector<uchar4> *tex_img = new device_vector<uchar4>(
device, img->mem_name.c_str(), MEM_TEXTURE);
if (!file_load_image<TypeDesc::UINT8, uchar>(img, type, texture_limit, *tex_img)) {
if (!file_load_image<TypeDesc::UINT8, uchar>(img, texture_limit, *tex_img)) {
/* on failure to load, we set a 1x1 pixels pink image */
thread_scoped_lock device_lock(device_mutex);
uchar *pixels = (uchar *)tex_img->alloc(1, 1);
@ -809,7 +772,7 @@ void ImageManager::device_load_image(
device_vector<uchar> *tex_img = new device_vector<uchar>(
device, img->mem_name.c_str(), MEM_TEXTURE);
if (!file_load_image<TypeDesc::UINT8, uchar>(img, type, texture_limit, *tex_img)) {
if (!file_load_image<TypeDesc::UINT8, uchar>(img, texture_limit, *tex_img)) {
/* on failure to load, we set a 1x1 pixels pink image */
thread_scoped_lock device_lock(device_mutex);
uchar *pixels = (uchar *)tex_img->alloc(1, 1);
@ -826,7 +789,7 @@ void ImageManager::device_load_image(
device_vector<half4> *tex_img = new device_vector<half4>(
device, img->mem_name.c_str(), MEM_TEXTURE);
if (!file_load_image<TypeDesc::HALF, half>(img, type, texture_limit, *tex_img)) {
if (!file_load_image<TypeDesc::HALF, half>(img, texture_limit, *tex_img)) {
/* on failure to load, we set a 1x1 pixels pink image */
thread_scoped_lock device_lock(device_mutex);
half *pixels = (half *)tex_img->alloc(1, 1);
@ -846,7 +809,7 @@ void ImageManager::device_load_image(
device_vector<uint16_t> *tex_img = new device_vector<uint16_t>(
device, img->mem_name.c_str(), MEM_TEXTURE);
if (!file_load_image<TypeDesc::USHORT, uint16_t>(img, type, texture_limit, *tex_img)) {
if (!file_load_image<TypeDesc::USHORT, uint16_t>(img, texture_limit, *tex_img)) {
/* on failure to load, we set a 1x1 pixels pink image */
thread_scoped_lock device_lock(device_mutex);
uint16_t *pixels = (uint16_t *)tex_img->alloc(1, 1);
@ -863,7 +826,7 @@ void ImageManager::device_load_image(
device_vector<ushort4> *tex_img = new device_vector<ushort4>(
device, img->mem_name.c_str(), MEM_TEXTURE);
if (!file_load_image<TypeDesc::USHORT, uint16_t>(img, type, texture_limit, *tex_img)) {
if (!file_load_image<TypeDesc::USHORT, uint16_t>(img, texture_limit, *tex_img)) {
/* on failure to load, we set a 1x1 pixels pink image */
thread_scoped_lock device_lock(device_mutex);
uint16_t *pixels = (uint16_t *)tex_img->alloc(1, 1);
@ -883,7 +846,7 @@ void ImageManager::device_load_image(
device_vector<half> *tex_img = new device_vector<half>(
device, img->mem_name.c_str(), MEM_TEXTURE);
if (!file_load_image<TypeDesc::HALF, half>(img, type, texture_limit, *tex_img)) {
if (!file_load_image<TypeDesc::HALF, half>(img, texture_limit, *tex_img)) {
/* on failure to load, we set a 1x1 pixels pink image */
thread_scoped_lock device_lock(device_mutex);
half *pixels = (half *)tex_img->alloc(1, 1);
@ -899,14 +862,14 @@ void ImageManager::device_load_image(
img->need_load = false;
}
void ImageManager::device_free_image(Device *, ImageDataType type, int slot)
void ImageManager::device_free_image(Device *, int slot)
{
Image *img = images[type][slot];
Image *img = images[slot];
if (img) {
if (osl_texture_system && !img->key.builtin_data) {
#ifdef WITH_OSL
ustring filename(images[type][slot]->key.filename);
ustring filename(images[slot]->key.filename);
((OSL::TextureSystem *)osl_texture_system)->invalidate(filename);
#endif
}
@ -917,8 +880,8 @@ void ImageManager::device_free_image(Device *, ImageDataType type, int slot)
}
delete img;
images[type][slot] = NULL;
--tex_num_images[type];
images[slot] = NULL;
--tex_num_images;
}
}
@ -929,24 +892,17 @@ void ImageManager::device_update(Device *device, Scene *scene, Progress &progres
}
TaskPool pool;
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
for (size_t slot = 0; slot < images[type].size(); slot++) {
if (!images[type][slot])
continue;
for (size_t slot = 0; slot < images.size(); slot++) {
if (!images[slot])
continue;
if (images[type][slot]->users == 0) {
device_free_image(device, (ImageDataType)type, slot);
}
else if (images[type][slot]->need_load) {
if (!osl_texture_system || images[type][slot]->key.builtin_data)
pool.push(function_bind(&ImageManager::device_load_image,
this,
device,
scene,
(ImageDataType)type,
slot,
&progress));
}
if (images[slot]->users == 0) {
device_free_image(device, slot);
}
else if (images[slot]->need_load) {
if (!osl_texture_system || images[slot]->key.builtin_data)
pool.push(
function_bind(&ImageManager::device_load_image, this, device, scene, slot, &progress));
}
}
@ -955,23 +911,17 @@ void ImageManager::device_update(Device *device, Scene *scene, Progress &progres
need_update = false;
}
void ImageManager::device_update_slot(Device *device,
Scene *scene,
int flat_slot,
Progress *progress)
void ImageManager::device_update_slot(Device *device, Scene *scene, int slot, Progress *progress)
{
ImageDataType type;
int slot = flattened_slot_to_type_index(flat_slot, &type);
Image *image = images[type][slot];
Image *image = images[slot];
assert(image != NULL);
if (image->users == 0) {
device_free_image(device, type, slot);
device_free_image(device, slot);
}
else if (image->need_load) {
if (!osl_texture_system || image->key.builtin_data)
device_load_image(device, scene, type, slot, progress);
device_load_image(device, scene, slot, progress);
}
}
@ -984,21 +934,14 @@ void ImageManager::device_load_builtin(Device *device, Scene *scene, Progress &p
}
TaskPool pool;
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
for (size_t slot = 0; slot < images[type].size(); slot++) {
if (!images[type][slot])
continue;
for (size_t slot = 0; slot < images.size(); slot++) {
if (!images[slot])
continue;
if (images[type][slot]->need_load) {
if (images[type][slot]->key.builtin_data) {
pool.push(function_bind(&ImageManager::device_load_image,
this,
device,
scene,
(ImageDataType)type,
slot,
&progress));
}
if (images[slot]->need_load) {
if (images[slot]->key.builtin_data) {
pool.push(
function_bind(&ImageManager::device_load_image, this, device, scene, slot, &progress));
}
}
}
@ -1008,31 +951,25 @@ void ImageManager::device_load_builtin(Device *device, Scene *scene, Progress &p
void ImageManager::device_free_builtin(Device *device)
{
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]->key.builtin_data)
device_free_image(device, (ImageDataType)type, slot);
}
for (size_t slot = 0; slot < images.size(); slot++) {
if (images[slot] && images[slot]->key.builtin_data)
device_free_image(device, slot);
}
}
void ImageManager::device_free(Device *device)
{
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
for (size_t slot = 0; slot < images[type].size(); slot++) {
device_free_image(device, (ImageDataType)type, slot);
}
images[type].clear();
for (size_t slot = 0; slot < images.size(); slot++) {
device_free_image(device, slot);
}
images.clear();
}
void ImageManager::collect_statistics(RenderStats *stats)
{
for (int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) {
foreach (const Image *image, images[type]) {
stats->image.textures.add_entry(
NamedSizeEntry(path_filename(image->key.filename), image->mem->memory_size()));
}
foreach (const Image *image, images) {
stats->image.textures.add_entry(
NamedSizeEntry(path_filename(image->key.filename), image->mem->memory_size()));
}
}

@ -57,7 +57,7 @@ class ImageMetaData {
height(0),
depth(0),
builtin_free_cache(false),
type((ImageDataType)0),
type(IMAGE_DATA_NUM_TYPES),
colorspace(u_colorspace_raw),
compress_as_srgb(false)
{
@ -107,15 +107,15 @@ class ImageManager {
~ImageManager();
int add_image(const ImageKey &key, float frame, ImageMetaData &metadata);
void add_image_user(int flat_slot);
void remove_image(int flat_slot);
void add_image_user(int slot);
void remove_image(int slot);
void remove_image(const ImageKey &key);
void tag_reload_image(const ImageKey &key);
bool get_image_metadata(const ImageKey &key, ImageMetaData &metadata);
bool get_image_metadata(int flat_slot, ImageMetaData &metadata);
bool get_image_metadata(int slot, ImageMetaData &metadata);
void device_update(Device *device, Scene *scene, Progress &progress);
void device_update_slot(Device *device, Scene *scene, int flat_slot, Progress *progress);
void device_update_slot(Device *device, Scene *scene, int slot, Progress *progress);
void device_free(Device *device);
void device_load_builtin(Device *device, Scene *scene, Progress &progress);
@ -124,7 +124,7 @@ class ImageManager {
void set_osl_texture_system(void *texture_system);
bool set_animation_frame_update(int frame);
device_memory *image_memory(int flat_slot);
device_memory *image_memory(int slot);
void collect_statistics(RenderStats *stats);
@ -167,29 +167,25 @@ class ImageManager {
};
private:
int tex_num_images[IMAGE_DATA_NUM_TYPES];
int tex_num_images;
int max_num_images;
bool has_half_images;
thread_mutex device_mutex;
int animation_frame;
vector<Image *> images[IMAGE_DATA_NUM_TYPES];
vector<Image *> images;
void *osl_texture_system;
bool file_load_image_generic(Image *img, unique_ptr<ImageInput> *in);
template<TypeDesc::BASETYPE FileFormat, typename StorageType, typename DeviceType>
bool file_load_image(Image *img,
ImageDataType type,
int texture_limit,
device_vector<DeviceType> &tex_img);
bool file_load_image(Image *img, int texture_limit, device_vector<DeviceType> &tex_img);
void metadata_detect_colorspace(ImageMetaData &metadata, const char *file_format);
void device_load_image(
Device *device, Scene *scene, ImageDataType type, int slot, Progress *progress);
void device_free_image(Device *device, ImageDataType type, int slot);
void device_load_image(Device *device, Scene *scene, int slot, Progress *progress);
void device_free_image(Device *device, int slot);
};
CCL_NAMESPACE_END

@ -91,12 +91,15 @@ typedef enum ExtensionType {
typedef struct TextureInfo {
/* Pointer, offset or texture depending on device. */
uint64_t data;
/* Data Type */
uint data_type;
/* Buffer number for OpenCL. */
uint cl_buffer;
/* Interpolation and extension type. */
uint interpolation, extension;
/* Dimensions. */
uint width, height, depth;
uint pad[3];
} TextureInfo;
CCL_NAMESPACE_END