Cycles: Prepare for more image extension types support

Basically just replace boolean periodic flag with extension type enum in the
device API.
This commit is contained in:
Sergey Sharybin 2015-07-28 13:51:10 +02:00
parent 29ebb56f4d
commit 3fba620858
10 changed files with 37 additions and 27 deletions

View File

@ -173,10 +173,10 @@ public:
virtual void tex_alloc(const char * /*name*/,
device_memory& /*mem*/,
InterpolationType interpolation = INTERPOLATION_NONE,
bool periodic = false)
ExtensionType extension = EXTENSION_REPEAT)
{
(void)interpolation; /* Ignored. */
(void)periodic; /* Ignored. */
(void)extension; /* Ignored. */
};
virtual void tex_free(device_memory& /*mem*/) {};

View File

@ -126,7 +126,7 @@ public:
void tex_alloc(const char *name,
device_memory& mem,
InterpolationType interpolation,
bool periodic)
ExtensionType extension)
{
VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
kernel_tex_copy(&kernel_globals,
@ -136,7 +136,7 @@ public:
mem.data_height,
mem.data_depth,
interpolation,
periodic);
extension);
mem.device_pointer = mem.data_pointer;
mem.device_size = mem.memory_size();
stats.mem_alloc(mem.device_size);

View File

@ -416,7 +416,10 @@ public:
cuda_pop_context();
}
void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
void tex_alloc(const char *name,
device_memory& mem,
InterpolationType interpolation,
ExtensionType extension)
{
/* todo: support 3D textures, only CPU for now */
VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
@ -510,7 +513,7 @@ public:
cuda_assert(cuTexRefSetFlags(texref, CU_TRSF_READ_AS_INTEGER));
}
if(periodic) {
if(extension == EXTENSION_REPEAT) {
cuda_assert(cuTexRefSetAddressMode(texref, 0, CU_TR_ADDRESS_MODE_WRAP));
cuda_assert(cuTexRefSetAddressMode(texref, 1, CU_TR_ADDRESS_MODE_WRAP));
}

View File

@ -169,13 +169,17 @@ public:
sub.device->const_copy_to(name, host, size);
}
void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
void tex_alloc(const char *name,
device_memory& mem,
InterpolationType
interpolation,
ExtensionType extension)
{
VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
foreach(SubDevice& sub, devices) {
mem.device_pointer = 0;
sub.device->tex_alloc(name, mem, interpolation, periodic);
sub.device->tex_alloc(name, mem, interpolation, extension);
sub.ptr_map[unique_ptr] = mem.device_pointer;
}

View File

@ -163,7 +163,10 @@ public:
snd.write_buffer(host, size);
}
void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
void tex_alloc(const char *name,
device_memory& mem,
InterpolationType interpolation,
ExtensionType extension)
{
VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
@ -178,7 +181,7 @@ public:
snd.add(name_string);
snd.add(mem);
snd.add(interpolation);
snd.add(periodic);
snd.add(extension);
snd.write();
snd.write_buffer((void*)mem.data_pointer, mem.memory_size());
}
@ -571,13 +574,13 @@ protected:
network_device_memory mem;
string name;
InterpolationType interpolation;
bool periodic;
ExtensionType extension_typr;
device_ptr client_pointer;
rcv.read(name);
rcv.read(mem);
rcv.read(interpolation);
rcv.read(periodic);
rcv.read(extension);
lock.unlock();
client_pointer = mem.device_pointer;
@ -593,7 +596,7 @@ protected:
rcv.read_buffer((uint8_t*)mem.data_pointer, data_size);
device->tex_alloc(name.c_str(), mem, interpolation, periodic);
device->tex_alloc(name.c_str(), mem, interpolation, extension);
pointer_mapping_insert(client_pointer, mem.device_pointer);
}

View File

@ -1179,7 +1179,7 @@ public:
void tex_alloc(const char *name,
device_memory& mem,
InterpolationType /*interpolation*/,
bool /*periodic*/)
ExtensionType /*extension*/)
{
VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
mem_alloc(mem, MEM_READ_ONLY);

View File

@ -39,7 +39,7 @@ void kernel_tex_copy(KernelGlobals *kg,
size_t height,
size_t depth,
InterpolationType interpolation=INTERPOLATION_LINEAR,
bool periodic = true);
ExtensionType extension = EXTENSION_REPEAT);
void kernel_cpu_path_trace(KernelGlobals *kg, float *buffer, unsigned int *rng_state,
int sample, int x, int y, int offset, int stride);

View File

@ -138,7 +138,7 @@ template<typename T> struct texture_image {
if(interpolation == INTERPOLATION_CLOSEST) {
frac(x*(float)width, &ix);
frac(y*(float)height, &iy);
if(periodic) {
if(extension == EXTENSION_REPEAT) {
ix = wrap_periodic(ix, width);
iy = wrap_periodic(iy, height);
@ -153,7 +153,7 @@ template<typename T> struct texture_image {
float tx = frac(x*(float)width - 0.5f, &ix);
float ty = frac(y*(float)height - 0.5f, &iy);
if(periodic) {
if(extension == EXTENSION_REPEAT) {
ix = wrap_periodic(ix, width);
iy = wrap_periodic(iy, height);
@ -180,7 +180,7 @@ template<typename T> struct texture_image {
const float tx = frac(x*(float)width - 0.5f, &ix);
const float ty = frac(y*(float)height - 0.5f, &iy);
int pix, piy, nnix, nniy;
if(periodic) {
if(extension == EXTENSION_REPEAT) {
ix = wrap_periodic(ix, width);
iy = wrap_periodic(iy, height);
@ -251,7 +251,7 @@ template<typename T> struct texture_image {
frac(y*(float)height, &iy);
frac(z*(float)depth, &iz);
if(periodic) {
if(extension == EXTENSION_REPEAT) {
ix = wrap_periodic(ix, width);
iy = wrap_periodic(iy, height);
iz = wrap_periodic(iz, depth);
@ -269,7 +269,7 @@ template<typename T> struct texture_image {
float ty = frac(y*(float)height - 0.5f, &iy);
float tz = frac(z*(float)depth - 0.5f, &iz);
if(periodic) {
if(extension == EXTENSION_REPEAT) {
ix = wrap_periodic(ix, width);
iy = wrap_periodic(iy, height);
iz = wrap_periodic(iz, depth);
@ -309,7 +309,7 @@ template<typename T> struct texture_image {
const float tz = frac(z*(float)depth - 0.5f, &iz);
int pix, piy, piz, nnix, nniy, nniz;
if(periodic) {
if(extension == EXTENSION_REPEAT) {
ix = wrap_periodic(ix, width);
iy = wrap_periodic(iy, height);
iz = wrap_periodic(iz, depth);
@ -392,7 +392,7 @@ template<typename T> struct texture_image {
T *data;
int interpolation;
bool periodic;
ExtensionType extension;
int width, height, depth;
#undef SET_CUBIC_SPLINE_WEIGHTS
};

View File

@ -45,7 +45,7 @@ void kernel_tex_copy(KernelGlobals *kg,
size_t height,
size_t depth,
InterpolationType interpolation,
bool periodic)
ExtensionType extension)
{
if(0) {
}
@ -71,7 +71,7 @@ void kernel_tex_copy(KernelGlobals *kg,
tex->data = (float4*)mem;
tex->dimensions_set(width, height, depth);
tex->interpolation = interpolation;
tex->periodic = periodic;
tex->extension = extension;
}
}
else if(strstr(name, "__tex_image")) {
@ -87,7 +87,7 @@ void kernel_tex_copy(KernelGlobals *kg,
tex->data = (uchar4*)mem;
tex->dimensions_set(width, height, depth);
tex->interpolation = interpolation;
tex->periodic = periodic;
tex->extension = extension;
}
}
else

View File

@ -714,7 +714,7 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl
device->tex_alloc(name.c_str(),
tex_img,
img->interpolation,
img->extension == EXTENSION_REPEAT);
img->extension);
}
}
else {
@ -749,7 +749,7 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl
device->tex_alloc(name.c_str(),
tex_img,
img->interpolation,
img->extension == EXTENSION_REPEAT);
img->extension);
}
}