Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/image.cpp
| Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if(info.type == DEVICE_CPU) { | ||||
| tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CPU; | tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CPU; | ||||
| tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CPU; | tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CPU; | ||||
| tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CPU; | tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CPU; | ||||
| tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CPU; | tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CPU; | ||||
| tex_image_float_start = TEX_IMAGE_FLOAT_START_CPU; | tex_image_float_start = TEX_IMAGE_FLOAT_START_CPU; | ||||
| tex_image_byte_start = TEX_IMAGE_BYTE_START_CPU; | tex_image_byte_start = TEX_IMAGE_BYTE_START_CPU; | ||||
| } | } | ||||
| /* CUDA (Fermi) */ | /* CUDA (Fermi) */ | ||||
| else if((info.type == DEVICE_CUDA || info.type == DEVICE_MULTI) && !info.extended_images) { | else if((info.type == DEVICE_CUDA || info.type == DEVICE_MULTI) && !info.bindless_textures) { | ||||
| tex_num_images[IMAGE_DATA_TYPE_BYTE4] = TEX_NUM_BYTE4_IMAGES_CUDA; | tex_num_images[IMAGE_DATA_TYPE_BYTE4] = TEX_NUM_BYTE4_IMAGES_CUDA; | ||||
| tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CUDA; | tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CUDA; | ||||
| tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CUDA; | tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CUDA; | ||||
| tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CUDA; | tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CUDA; | ||||
| tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CUDA; | tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CUDA; | ||||
| tex_image_float_start = TEX_IMAGE_FLOAT_START_CUDA; | tex_image_float_start = TEX_IMAGE_FLOAT_START_CUDA; | ||||
| tex_image_byte_start = TEX_IMAGE_BYTE_START_CUDA; | tex_image_byte_start = TEX_IMAGE_BYTE_START_CUDA; | ||||
| } | } | ||||
| /* CUDA (Kepler and above) */ | /* CUDA (Kepler and above) */ | ||||
| else if((info.type == DEVICE_CUDA || info.type == DEVICE_MULTI) && info.extended_images) { | else if((info.type == DEVICE_CUDA || info.type == DEVICE_MULTI) && info.bindless_textures) { | ||||
| tex_num_images[IMAGE_DATA_TYPE_BYTE4] = TEX_NUM_BYTE4_IMAGES_CUDA_KEPLER; | tex_num_images[IMAGE_DATA_TYPE_BYTE4] = TEX_NUM_BYTE4_IMAGES_CUDA_KEPLER; | ||||
| tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CUDA_KEPLER; | tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CUDA_KEPLER; | ||||
| tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CUDA_KEPLER; | tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CUDA_KEPLER; | ||||
| tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CUDA_KEPLER; | tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CUDA_KEPLER; | ||||
| tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CUDA_KEPLER; | tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CUDA_KEPLER; | ||||
| tex_image_float_start = TEX_IMAGE_FLOAT_START_CUDA_KEPLER; | tex_image_float_start = TEX_IMAGE_FLOAT_START_CUDA_KEPLER; | ||||
| tex_image_byte_start = TEX_IMAGE_BYTE_START_CUDA_KEPLER; | tex_image_byte_start = TEX_IMAGE_BYTE_START_CUDA_KEPLER; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | int ImageManager::add_image(const string& filename, | ||||
| size_t slot; | size_t slot; | ||||
| ImageDataType type = get_image_metadata(filename, builtin_data, is_linear); | ImageDataType type = get_image_metadata(filename, builtin_data, is_linear); | ||||
| /* Do we have a float? */ | /* Do we have a float? */ | ||||
| if(type == IMAGE_DATA_TYPE_FLOAT || type == IMAGE_DATA_TYPE_FLOAT4) | if(type == IMAGE_DATA_TYPE_FLOAT || type == IMAGE_DATA_TYPE_FLOAT4) | ||||
| is_float = true; | is_float = true; | ||||
| /* No float and byte textures on GPU yet */ | /* No single channel textures on Fermi GPUs, use available slots */ | ||||
| if(type == IMAGE_DATA_TYPE_FLOAT && tex_num_images[type] == 0) | if(type == IMAGE_DATA_TYPE_FLOAT && tex_num_images[type] == 0) | ||||
| type = IMAGE_DATA_TYPE_FLOAT4; | type = IMAGE_DATA_TYPE_FLOAT4; | ||||
| if(type == IMAGE_DATA_TYPE_BYTE && tex_num_images[type] == 0) | if(type == IMAGE_DATA_TYPE_BYTE && tex_num_images[type] == 0) | ||||
| type = IMAGE_DATA_TYPE_BYTE4; | type = IMAGE_DATA_TYPE_BYTE4; | ||||
| /* Fnd existing image. */ | /* Fnd existing image. */ | ||||
| for(slot = 0; slot < images[type].size(); slot++) { | for(slot = 0; slot < images[type].size(); slot++) { | ||||
| img = images[type][slot]; | img = images[type][slot]; | ||||
| ▲ Show 20 Lines • Show All 455 Lines • ▼ Show 20 Lines | void ImageManager::device_load_image(Device *device, DeviceScene *dscene, ImageDataType type, int slot, Progress *progress) | ||||
| string name; | string name; | ||||
| if(flat_slot >= 100) | if(flat_slot >= 100) | ||||
| name = string_printf("__tex_image_%s_%d", name_from_type(type).c_str(), flat_slot); | name = string_printf("__tex_image_%s_%d", name_from_type(type).c_str(), flat_slot); | ||||
| else if(flat_slot >= 10) | else if(flat_slot >= 10) | ||||
| name = string_printf("__tex_image_%s_0%d", name_from_type(type).c_str(), flat_slot); | name = string_printf("__tex_image_%s_0%d", name_from_type(type).c_str(), flat_slot); | ||||
| else | else | ||||
| name = string_printf("__tex_image_%s_00%d", name_from_type(type).c_str(), flat_slot); | name = string_printf("__tex_image_%s_00%d", name_from_type(type).c_str(), flat_slot); | ||||
| /* Bindless slot for CUDA */ | |||||
| uint bindless_slot = 0; | |||||
| if(type == IMAGE_DATA_TYPE_FLOAT4) { | if(type == IMAGE_DATA_TYPE_FLOAT4) { | ||||
| device_vector<float4>& tex_img = dscene->tex_float4_image[slot]; | device_vector<float4>& tex_img = dscene->tex_float4_image[slot]; | ||||
| if(tex_img.device_pointer) { | if(tex_img.device_pointer) { | ||||
| thread_scoped_lock device_lock(device_mutex); | thread_scoped_lock device_lock(device_mutex); | ||||
| device->tex_free(tex_img); | device->tex_free(tex_img); | ||||
| } | } | ||||
| if(!file_load_float4_image(img, tex_img)) { | if(!file_load_float4_image(img, tex_img)) { | ||||
| /* on failure to load, we set a 1x1 pixels pink image */ | /* on failure to load, we set a 1x1 pixels pink image */ | ||||
| float *pixels = (float*)tex_img.resize(1, 1); | float *pixels = (float*)tex_img.resize(1, 1); | ||||
| pixels[0] = TEX_IMAGE_MISSING_R; | pixels[0] = TEX_IMAGE_MISSING_R; | ||||
| pixels[1] = TEX_IMAGE_MISSING_G; | pixels[1] = TEX_IMAGE_MISSING_G; | ||||
| pixels[2] = TEX_IMAGE_MISSING_B; | pixels[2] = TEX_IMAGE_MISSING_B; | ||||
| pixels[3] = TEX_IMAGE_MISSING_A; | pixels[3] = TEX_IMAGE_MISSING_A; | ||||
| } | } | ||||
| if(!pack_images) { | if(!pack_images) { | ||||
| thread_scoped_lock device_lock(device_mutex); | thread_scoped_lock device_lock(device_mutex); | ||||
| device->tex_alloc(name.c_str(), | device->tex_alloc(name.c_str(), | ||||
| tex_img, | tex_img, | ||||
| img->interpolation, | img->interpolation, | ||||
| img->extension); | img->extension, | ||||
| &bindless_slot); | |||||
| } | } | ||||
| } | } | ||||
| else if(type == IMAGE_DATA_TYPE_FLOAT) { | else if(type == IMAGE_DATA_TYPE_FLOAT) { | ||||
| device_vector<float>& tex_img = dscene->tex_float_image[slot]; | device_vector<float>& tex_img = dscene->tex_float_image[slot]; | ||||
| if(tex_img.device_pointer) { | if(tex_img.device_pointer) { | ||||
| thread_scoped_lock device_lock(device_mutex); | thread_scoped_lock device_lock(device_mutex); | ||||
| device->tex_free(tex_img); | device->tex_free(tex_img); | ||||
| } | } | ||||
| if(!file_load_float_image(img, tex_img)) { | if(!file_load_float_image(img, tex_img)) { | ||||
| /* on failure to load, we set a 1x1 pixels pink image */ | /* on failure to load, we set a 1x1 pixels pink image */ | ||||
| float *pixels = (float*)tex_img.resize(1, 1); | float *pixels = (float*)tex_img.resize(1, 1); | ||||
| pixels[0] = TEX_IMAGE_MISSING_R; | pixels[0] = TEX_IMAGE_MISSING_R; | ||||
| } | } | ||||
| if(!pack_images) { | if(!pack_images) { | ||||
| thread_scoped_lock device_lock(device_mutex); | thread_scoped_lock device_lock(device_mutex); | ||||
| device->tex_alloc(name.c_str(), | device->tex_alloc(name.c_str(), | ||||
| tex_img, | tex_img, | ||||
| img->interpolation, | img->interpolation, | ||||
| img->extension); | img->extension, | ||||
| &bindless_slot); | |||||
| } | } | ||||
| } | } | ||||
| else if(type == IMAGE_DATA_TYPE_BYTE4) { | else if(type == IMAGE_DATA_TYPE_BYTE4) { | ||||
| device_vector<uchar4>& tex_img = dscene->tex_byte4_image[slot]; | device_vector<uchar4>& tex_img = dscene->tex_byte4_image[slot]; | ||||
| if(tex_img.device_pointer) { | if(tex_img.device_pointer) { | ||||
| thread_scoped_lock device_lock(device_mutex); | thread_scoped_lock device_lock(device_mutex); | ||||
| device->tex_free(tex_img); | device->tex_free(tex_img); | ||||
| Show All 9 Lines | if(!file_load_byte4_image(img, tex_img)) { | ||||
| pixels[3] = (TEX_IMAGE_MISSING_A * 255); | pixels[3] = (TEX_IMAGE_MISSING_A * 255); | ||||
| } | } | ||||
| if(!pack_images) { | if(!pack_images) { | ||||
| thread_scoped_lock device_lock(device_mutex); | thread_scoped_lock device_lock(device_mutex); | ||||
| device->tex_alloc(name.c_str(), | device->tex_alloc(name.c_str(), | ||||
| tex_img, | tex_img, | ||||
| img->interpolation, | img->interpolation, | ||||
| img->extension); | img->extension, | ||||
| &bindless_slot); | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| device_vector<uchar>& tex_img = dscene->tex_byte_image[slot]; | device_vector<uchar>& tex_img = dscene->tex_byte_image[slot]; | ||||
| if(tex_img.device_pointer) { | if(tex_img.device_pointer) { | ||||
| thread_scoped_lock device_lock(device_mutex); | thread_scoped_lock device_lock(device_mutex); | ||||
| device->tex_free(tex_img); | device->tex_free(tex_img); | ||||
| } | } | ||||
| if(!file_load_byte_image(img, tex_img)) { | if(!file_load_byte_image(img, tex_img)) { | ||||
| /* on failure to load, we set a 1x1 pixels pink image */ | /* on failure to load, we set a 1x1 pixels pink image */ | ||||
| uchar *pixels = (uchar*)tex_img.resize(1, 1); | uchar *pixels = (uchar*)tex_img.resize(1, 1); | ||||
| pixels[0] = (TEX_IMAGE_MISSING_R * 255); | pixels[0] = (TEX_IMAGE_MISSING_R * 255); | ||||
| } | } | ||||
| if(!pack_images) { | if(!pack_images) { | ||||
| thread_scoped_lock device_lock(device_mutex); | thread_scoped_lock device_lock(device_mutex); | ||||
| device->tex_alloc(name.c_str(), | device->tex_alloc(name.c_str(), | ||||
| tex_img, | tex_img, | ||||
| img->interpolation, | img->interpolation, | ||||
| img->extension); | img->extension, | ||||
| &bindless_slot); | |||||
| } | |||||
| } | } | ||||
| /* Save mapping for Bindless Texture IDs */ | |||||
| if(device->info.bindless_textures) { | |||||
| dscene->data.bindless_mapping[flat_slot] = bindless_slot; | |||||
| } | } | ||||
| img->need_load = false; | img->need_load = false; | ||||
| } | } | ||||
| void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageDataType type, int slot) | void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageDataType type, int slot) | ||||
| { | { | ||||
| Image *img = images[type][slot]; | Image *img = images[type][slot]; | ||||
| ▲ Show 20 Lines • Show All 234 Lines • Show Last 20 Lines | |||||