forked from bartvdbraak/blender
Cycles: OSL build & image manager fixes.
This commit is contained in:
parent
fc68daff58
commit
966e004bbe
@ -28,7 +28,7 @@ SET(CYCLES_BOOST "/usr" CACHE PATH "Path to Boost installation")
|
||||
SET(CYCLES_CUDA "/usr/local/cuda" CACHE PATH "Path to CUDA installation")
|
||||
SET(CYCLES_OPENCL "" CACHE PATH "Path to OpenCL installation")
|
||||
SET(CYCLES_PARTIO "" CACHE PATH "Path to Partio installation")
|
||||
SET(CYCLES_GLEW "" CACHE PATH "Path to GLUT installation")
|
||||
SET(CYCLES_GLEW "" CACHE PATH "Path to GLEW installation")
|
||||
|
||||
# Install, todo: deduplicate install path code
|
||||
|
||||
|
@ -42,6 +42,25 @@ __device float kernel_tex_interp_(__global float *data, int width, float x)
|
||||
return (1.0f - t)*data[index] + t*data[nindex];
|
||||
}
|
||||
|
||||
#ifdef make_float2
|
||||
#undef make_float2
|
||||
#endif
|
||||
#ifdef make_float3
|
||||
#undef make_float3
|
||||
#endif
|
||||
#ifdef make_float4
|
||||
#undef make_float4
|
||||
#endif
|
||||
#ifdef make_int2
|
||||
#undef make_int2
|
||||
#endif
|
||||
#ifdef make_int3
|
||||
#undef make_int3
|
||||
#endif
|
||||
#ifdef make_int4
|
||||
#undef make_int4
|
||||
#endif
|
||||
|
||||
#define make_float2(x, y) ((float2)(x, y))
|
||||
#define make_float3(x, y, z) ((float3)(x, y, z, 0.0f))
|
||||
#define make_float4(x, y, z, w) ((float4)(x, y, z, w))
|
||||
@ -49,6 +68,13 @@ __device float kernel_tex_interp_(__global float *data, int width, float x)
|
||||
#define make_int3(x, y, z) ((int3)(x, y, z, 0))
|
||||
#define make_int4(x, y, z, w) ((int4)(x, y, z, w))
|
||||
|
||||
#ifdef float3
|
||||
#undef float3
|
||||
#endif
|
||||
#ifdef int3
|
||||
#undef int3
|
||||
#endif
|
||||
|
||||
typedef float4 float3;
|
||||
typedef int4 int3;
|
||||
|
||||
|
@ -18,6 +18,14 @@
|
||||
|
||||
/* Constant Globals */
|
||||
|
||||
#ifdef __KERNEL_CPU__
|
||||
|
||||
#ifdef WITH_OSL
|
||||
#include "osl_globals.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
/* On the CPU, we pass along the struct KernelGlobals to nearly everywhere in
|
||||
@ -27,10 +35,6 @@ CCL_NAMESPACE_BEGIN
|
||||
|
||||
#ifdef __KERNEL_CPU__
|
||||
|
||||
#ifdef WITH_OSL
|
||||
//#include "osl_globals.h"
|
||||
#endif
|
||||
|
||||
typedef struct KernelGlobals {
|
||||
|
||||
#define KERNEL_TEX(type, ttype, name) ttype name;
|
||||
@ -42,7 +46,7 @@ typedef struct KernelGlobals {
|
||||
#ifdef WITH_OSL
|
||||
/* On the CPU, we also have the OSL globals here. Most data structures are shared
|
||||
with SVM, the difference is in the shaders and object/mesh attributes. */
|
||||
//OSLGlobals osl;
|
||||
OSLGlobals osl;
|
||||
#endif
|
||||
|
||||
} KernelGLobals;
|
||||
|
@ -176,6 +176,7 @@ static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd,
|
||||
(derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: NULL);
|
||||
}
|
||||
else {
|
||||
/* todo: this won't work when float3 has w component */
|
||||
float3 *fval = (float3*)val;
|
||||
fval[0] = triangle_attribute_float3(kg, sd, attr.elem, attr.offset,
|
||||
(derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: NULL);
|
||||
|
@ -25,11 +25,16 @@
|
||||
#include "util_path.h"
|
||||
#include "util_progress.h"
|
||||
|
||||
#ifdef WITH_OSL
|
||||
#include <OSL/oslexec.h>
|
||||
#endif
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
ImageManager::ImageManager()
|
||||
{
|
||||
need_update = true;
|
||||
osl_texture_system = NULL;
|
||||
}
|
||||
|
||||
ImageManager::~ImageManager()
|
||||
@ -39,6 +44,11 @@ ImageManager::~ImageManager()
|
||||
}
|
||||
}
|
||||
|
||||
void ImageManager::set_osl_texture_system(void *texture_system)
|
||||
{
|
||||
osl_texture_system = texture_system;
|
||||
}
|
||||
|
||||
int ImageManager::add_image(const string& filename)
|
||||
{
|
||||
Image *img;
|
||||
@ -77,8 +87,17 @@ int ImageManager::add_image(const string& filename)
|
||||
return slot;
|
||||
}
|
||||
|
||||
void ImageManager::remove_image(int slot)
|
||||
void ImageManager::remove_image(const string& filename)
|
||||
{
|
||||
size_t slot;
|
||||
|
||||
for(slot = 0; slot < images.size(); slot++)
|
||||
if(images[slot] && images[slot]->filename == filename)
|
||||
break;
|
||||
|
||||
if(slot == images.size())
|
||||
return;
|
||||
|
||||
assert(images[slot]);
|
||||
|
||||
/* decrement user count */
|
||||
@ -90,8 +109,6 @@ void ImageManager::remove_image(int slot)
|
||||
that use them, but we do not want to reload the image all the time. */
|
||||
if(images[slot]->users == 0)
|
||||
need_update = true;
|
||||
|
||||
/* todo: remove OSL image from cache */
|
||||
}
|
||||
|
||||
bool ImageManager::file_load_image(Image *img, device_vector<uchar4>& tex_img)
|
||||
@ -156,10 +173,12 @@ bool ImageManager::file_load_image(Image *img, device_vector<uchar4>& tex_img)
|
||||
|
||||
void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int slot)
|
||||
{
|
||||
if(osl_texture_system)
|
||||
return;
|
||||
|
||||
Image *img = images[slot];
|
||||
device_vector<uchar4>& tex_img = dscene->tex_image[slot];
|
||||
|
||||
img->need_load = false;
|
||||
if(tex_img.device_pointer)
|
||||
device->tex_free(tex_img);
|
||||
|
||||
@ -184,8 +203,16 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl
|
||||
void ImageManager::device_free_image(Device *device, DeviceScene *dscene, int slot)
|
||||
{
|
||||
if(images[slot]) {
|
||||
device->tex_free(dscene->tex_image[slot]);
|
||||
dscene->tex_image[slot].clear();
|
||||
if(osl_texture_system) {
|
||||
#ifdef WITH_OSL
|
||||
ustring filename(images[slot]->filename);
|
||||
((OSL::TextureSystem*)osl_texture_system)->invalidate(filename);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
device->tex_free(dscene->tex_image[slot]);
|
||||
dscene->tex_image[slot].clear();
|
||||
}
|
||||
|
||||
delete images[slot];
|
||||
images[slot] = NULL;
|
||||
@ -206,6 +233,7 @@ void ImageManager::device_update(Device *device, DeviceScene *dscene, Progress&
|
||||
string name = path_filename(images[slot]->filename);
|
||||
progress.set_status("Updating Images", "Loading " + name);
|
||||
device_load_image(device, dscene, slot);
|
||||
images[slot]->need_load = false;
|
||||
}
|
||||
|
||||
if(progress.get_cancel()) return;
|
||||
|
@ -38,11 +38,13 @@ public:
|
||||
~ImageManager();
|
||||
|
||||
int add_image(const string& filename);
|
||||
void remove_image(int slot);
|
||||
void remove_image(const string& filename);
|
||||
|
||||
void device_update(Device *device, DeviceScene *dscene, Progress& progress);
|
||||
void device_free(Device *device, DeviceScene *dscene);
|
||||
|
||||
void set_osl_texture_system(void *texture_system);
|
||||
|
||||
bool need_update;
|
||||
|
||||
private:
|
||||
@ -54,6 +56,7 @@ private:
|
||||
};
|
||||
|
||||
vector<Image*> images;
|
||||
void *osl_texture_system;
|
||||
|
||||
bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
|
||||
|
||||
|
@ -53,8 +53,8 @@ ImageTextureNode::ImageTextureNode()
|
||||
|
||||
ImageTextureNode::~ImageTextureNode()
|
||||
{
|
||||
if(image_manager && slot != -1)
|
||||
image_manager->remove_image(slot);
|
||||
if(image_manager)
|
||||
image_manager->remove_image(filename);
|
||||
}
|
||||
|
||||
ShaderNode *ImageTextureNode::clone() const
|
||||
@ -117,8 +117,8 @@ EnvironmentTextureNode::EnvironmentTextureNode()
|
||||
|
||||
EnvironmentTextureNode::~EnvironmentTextureNode()
|
||||
{
|
||||
if(image_manager && slot != -1)
|
||||
image_manager->remove_image(slot);
|
||||
if(image_manager)
|
||||
image_manager->remove_image(filename);
|
||||
}
|
||||
|
||||
ShaderNode *EnvironmentTextureNode::clone() const
|
||||
|
@ -44,9 +44,6 @@ CCL_NAMESPACE_BEGIN
|
||||
|
||||
OSLShaderManager::OSLShaderManager()
|
||||
{
|
||||
/* todo: verify if we are leaking shaders
|
||||
* todo: verify if we are leaking image cache memory */
|
||||
|
||||
services = new OSLRenderServices();
|
||||
|
||||
/* if we let OSL create it, it leaks */
|
||||
@ -112,6 +109,9 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene
|
||||
|
||||
foreach(Shader *shader, scene->shaders)
|
||||
shader->need_update = false;
|
||||
|
||||
/* set texture system */
|
||||
scene->image_manager->set_osl_texture_system((void*)ts);
|
||||
}
|
||||
|
||||
void OSLShaderManager::device_free(Device *device, DeviceScene *dscene)
|
||||
|
@ -172,6 +172,10 @@ struct float2 {
|
||||
struct float3 {
|
||||
float x, y, z;
|
||||
|
||||
#ifdef WITH_OPENCL
|
||||
float w;
|
||||
#endif
|
||||
|
||||
float operator[](int i) const { return *(&x + i); }
|
||||
float& operator[](int i) { return *(&x + i); }
|
||||
};
|
||||
@ -253,7 +257,11 @@ __device float2 make_float2(float x, float y)
|
||||
|
||||
__device float3 make_float3(float x, float y, float z)
|
||||
{
|
||||
#ifdef WITH_OPENCL
|
||||
float3 a = {x, y, z, 0.0f};
|
||||
#else
|
||||
float3 a = {x, y, z};
|
||||
#endif
|
||||
return a;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user