Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/osl/services.cpp
| Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | |||||
| ustring OSLRenderServices::u_N("N"); | ustring OSLRenderServices::u_N("N"); | ||||
| ustring OSLRenderServices::u_Ng("Ng"); | ustring OSLRenderServices::u_Ng("Ng"); | ||||
| ustring OSLRenderServices::u_P("P"); | ustring OSLRenderServices::u_P("P"); | ||||
| ustring OSLRenderServices::u_I("I"); | ustring OSLRenderServices::u_I("I"); | ||||
| ustring OSLRenderServices::u_u("u"); | ustring OSLRenderServices::u_u("u"); | ||||
| ustring OSLRenderServices::u_v("v"); | ustring OSLRenderServices::u_v("v"); | ||||
| ustring OSLRenderServices::u_empty; | ustring OSLRenderServices::u_empty; | ||||
| OSLRenderServices::OSLRenderServices(OSL::TextureSystem *texture_system) | OSLRenderServices::OSLRenderServices(OSL::TextureSystem *texture_system, int device_type) | ||||
| : OSL::RendererServices(texture_system) | : OSL::RendererServices(texture_system), device_type_(device_type) | ||||
| { | { | ||||
| } | } | ||||
| OSLRenderServices::~OSLRenderServices() | OSLRenderServices::~OSLRenderServices() | ||||
| { | { | ||||
| if (m_texturesys) { | if (m_texturesys) { | ||||
| VLOG_INFO << "OSL texture system stats:\n" << m_texturesys->getstats(); | VLOG_INFO << "OSL texture system stats:\n" << m_texturesys->getstats(); | ||||
| } | } | ||||
| } | } | ||||
| int OSLRenderServices::supports(string_view feature) const | |||||
| { | |||||
| #ifdef WITH_OPTIX | |||||
| if (feature == "OptiX") { | |||||
| return device_type_ == DEVICE_OPTIX; | |||||
| } | |||||
| #endif | |||||
| return false; | |||||
| } | |||||
| bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, | bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, | ||||
| OSL::Matrix44 &result, | OSL::Matrix44 &result, | ||||
| OSL::TransformationPtr xform, | OSL::TransformationPtr xform, | ||||
| float time) | float time) | ||||
| { | { | ||||
| /* this is only used for shader and object space, we don't really have | /* this is only used for shader and object space, we don't really have | ||||
| * a concept of shader space, so we just use object space for both. */ | * a concept of shader space, so we just use object space for both. */ | ||||
| if (xform) { | if (xform) { | ||||
| ▲ Show 20 Lines • Show All 992 Lines • ▼ Show 20 Lines | TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(ustring filename, | ||||
| OSL::ShadingContext *) | OSL::ShadingContext *) | ||||
| #else | #else | ||||
| TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(ustring filename) | TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(ustring filename) | ||||
| #endif | #endif | ||||
| { | { | ||||
| OSLTextureHandleMap::iterator it = textures.find(filename); | OSLTextureHandleMap::iterator it = textures.find(filename); | ||||
| if (device_type_ == DEVICE_CPU) { | |||||
| /* For non-OIIO textures, just return a pointer to our own OSLTextureHandle. */ | /* For non-OIIO textures, just return a pointer to our own OSLTextureHandle. */ | ||||
| if (it != textures.end()) { | if (it != textures.end()) { | ||||
| if (it->second->type != OSLTextureHandle::OIIO) { | if (it->second->type != OSLTextureHandle::OIIO) { | ||||
| return (TextureSystem::TextureHandle *)it->second.get(); | return (TextureSystem::TextureHandle *)it->second.get(); | ||||
| } | } | ||||
| } | } | ||||
| /* Get handle from OpenImageIO. */ | /* Get handle from OpenImageIO. */ | ||||
| OSL::TextureSystem *ts = m_texturesys; | OSL::TextureSystem *ts = m_texturesys; | ||||
| TextureSystem::TextureHandle *handle = ts->get_texture_handle(filename); | TextureSystem::TextureHandle *handle = ts->get_texture_handle(filename); | ||||
| if (handle == NULL) { | if (handle == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Insert new OSLTextureHandle if needed. */ | /* Insert new OSLTextureHandle if needed. */ | ||||
| if (it == textures.end()) { | if (it == textures.end()) { | ||||
| textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::OIIO)); | textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::OIIO)); | ||||
| it = textures.find(filename); | it = textures.find(filename); | ||||
| } | } | ||||
| /* Assign OIIO texture handle and return. */ | /* Assign OIIO texture handle and return. */ | ||||
| it->second->oiio_handle = handle; | it->second->oiio_handle = handle; | ||||
| return (TextureSystem::TextureHandle *)it->second.get(); | return (TextureSystem::TextureHandle *)it->second.get(); | ||||
| } | } | ||||
| else { | |||||
| if (it != textures.end() && it->second->type == OSLTextureHandle::SVM && it->second->svm_slots[0].w == -1) { | |||||
| return reinterpret_cast<TextureSystem::TextureHandle *>( | |||||
| static_cast<uintptr_t>(it->second->svm_slots[0].y + 1)); | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| bool OSLRenderServices::good(TextureSystem::TextureHandle *texture_handle) | bool OSLRenderServices::good(TextureSystem::TextureHandle *texture_handle) | ||||
| { | { | ||||
| OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle; | OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle; | ||||
| if (handle->oiio_handle) { | if (handle->oiio_handle) { | ||||
| OSL::TextureSystem *ts = m_texturesys; | OSL::TextureSystem *ts = m_texturesys; | ||||
| return ts->good(handle->oiio_handle); | return ts->good(handle->oiio_handle); | ||||
| ▲ Show 20 Lines • Show All 549 Lines • Show Last 20 Lines | |||||