void QuadMesh::updateBuffer(RTCBufferType type, unsigned int slot) { if (type == RTC_BUFFER_TYPE_INDEX) { if (slot != 0) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "invalid buffer slot"); quads.setModified(true); } else if (type == RTC_BUFFER_TYPE_VERTEX) { if (slot >= vertices.size()) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "invalid buffer slot"); vertices[slot].setModified(true); } else if (type == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { if (slot >= vertexAttribs.size()) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "invalid buffer slot"); vertexAttribs[slot].setModified(true); } else { throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "unknown buffer type"); } Geometry::update(); }
void* QuadMesh::getBuffer(RTCBufferType type, unsigned int slot) { if (type == RTC_BUFFER_TYPE_INDEX) { if (slot != 0) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "invalid buffer slot"); return quads.getPtr(); } else if (type == RTC_BUFFER_TYPE_VERTEX) { if (slot >= vertices.size()) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "invalid buffer slot"); return vertices[slot].getPtr(); } else if (type == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) { if (slot >= vertexAttribs.size()) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "invalid buffer slot"); return vertexAttribs[slot].getPtr(); } else { throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "unknown buffer type"); return nullptr; } }
void NativeCurves::setBuffer(RTCBufferType type, void* ptr, size_t offset, size_t stride, size_t size) { if (scene->isStatic() && scene->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static geometries cannot get modified"); /* verify that all accesses are 4 bytes aligned */ if (((size_t(ptr) + offset) & 0x3) || (stride & 0x3)) throw_RTCError(RTC_INVALID_OPERATION,"data must be 4 bytes aligned"); unsigned bid = type & 0xFFFF; if (type >= RTC_VERTEX_BUFFER0 && type < RTCBufferType(RTC_VERTEX_BUFFER0 + numTimeSteps)) { size_t t = type - RTC_VERTEX_BUFFER0; vertices[t].set(ptr,offset,stride,size); vertices[t].checkPadding16(); } else if (type >= RTC_USER_VERTEX_BUFFER0 && type < RTC_USER_VERTEX_BUFFER0+RTC_MAX_USER_VERTEX_BUFFERS) { if (bid >= userbuffers.size()) userbuffers.resize(bid+1); userbuffers[bid] = APIBuffer<char>(scene->device,numVertices(),stride); userbuffers[bid].set(ptr,offset,stride,size); userbuffers[bid].checkPadding16(); } else if (type == RTC_INDEX_BUFFER) { if (isEnabled() && size != (size_t)-1) disabling(); curves.set(ptr,offset,stride,size); setNumPrimitives(size); if (isEnabled() && size != (size_t)-1) enabling(); } else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown buffer type"); }
RTCORE_API void rtcCommitThread(RTCScene hscene, unsigned int threadID, unsigned int numThreads) { Scene* scene = (Scene*) hscene; RTCORE_CATCH_BEGIN; RTCORE_TRACE(rtcCommitThread); RTCORE_VERIFY_HANDLE(hscene); if (unlikely(numThreads == 0)) throw_RTCError(RTC_INVALID_OPERATION,"invalid number of threads specified"); #if defined(__MIC__) if (unlikely(numThreads % 4 != 0 && numThreads != 1)) throw_RTCError(RTC_INVALID_OPERATION,"MIC requires numThreads % 4 == 0 in rtcCommitThread"); #endif /* for best performance set FTZ and DAZ flags in the MXCSR control and status register */ #if !defined(__MIC__) unsigned int mxcsr = _mm_getcsr(); _mm_setcsr(mxcsr | /* FTZ */ (1<<15) | /* DAZ */ (1<<6)); #endif /* perform scene build */ scene->build(threadID,numThreads); /* reset MXCSR register again */ #if !defined(__MIC__) _mm_setcsr(mxcsr); #endif RTCORE_CATCH_END(scene->device); }
void UserGeometry::setOccludedFunctionN (RTCOccludedFuncN occluded) { if (!parent->isStreamMode()) throw_RTCError(RTC_INVALID_OPERATION,"you can use rtcSetOccludedFunctionN only in stream mode"); if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); intersectors.intersectorN.occluded = occluded; }
void UserGeometry::setIntersectFunction (RTCIntersectFunc intersect1, bool ispc) { if (parent->isStreamMode()) throw_RTCError(RTC_INVALID_OPERATION,"you have to use rtcSetIntersectFunctionN (and optionally rtcSetIntersectFunction1Mp) in stream mode"); if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); intersectors.intersector1.intersect = intersect1; }
void UserGeometry::setIntersectFunction1Mp (RTCIntersectFunc1Mp intersect) { if (!parent->isStreamMode()) throw_RTCError(RTC_INVALID_OPERATION,"you can use rtcSetIntersectFunction1Mp only in stream mode"); if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); intersectors.intersector1M.intersect = intersect; }
void UserGeometry::setOccludedFunction16 (RTCOccludedFunc16 occluded16, bool ispc) { if (parent->isStreamMode()) throw_RTCError(RTC_INVALID_OPERATION,"you have to use rtcSetOccludedFunctionN (and optionally rtcSetOccludedFunction1Mp) in stream mode"); if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); intersectors.intersector16.occluded = (void*)occluded16; intersectors.intersector16.ispc = ispc; }
void GeometryInstance::setTransform(const AffineSpace3fa& xfm, size_t timeStep) { if (scene->isStatic() && scene->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); if (timeStep != 0) throw_RTCError(RTC_INVALID_OPERATION,"geometry instances only support a single timestep"); local2world = xfm; world2local = rcp(xfm); }
void BezierCurves::unmap(RTCBufferType type) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static geometries cannot get modified"); switch (type) { case RTC_INDEX_BUFFER : curves.unmap(parent->numMappedBuffers); break; case RTC_VERTEX_BUFFER0: vertices[0].unmap(parent->numMappedBuffers); break; case RTC_VERTEX_BUFFER1: vertices[1].unmap(parent->numMappedBuffers); break; default: throw_RTCError(RTC_INVALID_ARGUMENT,"unknown buffer type"); break; } }
void* TriangleMesh::map(RTCBufferType type) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); switch (type) { case RTC_INDEX_BUFFER : return triangles .map(parent->numMappedBuffers); case RTC_VERTEX_BUFFER0: return vertices[0].map(parent->numMappedBuffers); case RTC_VERTEX_BUFFER1: return vertices[1].map(parent->numMappedBuffers); default : throw_RTCError(RTC_INVALID_ARGUMENT,"unknown buffer type"); return nullptr; } }
void NativeCurves::unmap(RTCBufferType type) { if (scene->isStatic() && scene->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static geometries cannot get modified"); if (type == RTC_INDEX_BUFFER) { curves.unmap(scene->numMappedBuffers); } else if (type >= RTC_VERTEX_BUFFER0 && type < RTCBufferType(RTC_VERTEX_BUFFER0 + numTimeSteps)) { vertices[type - RTC_VERTEX_BUFFER0].unmap(scene->numMappedBuffers); } else { throw_RTCError(RTC_INVALID_ARGUMENT,"unknown buffer type"); } }
RTCORE_API void rtcIntersect4 (const void* valid, RTCScene hscene, RTCRay4& ray) { Scene* scene = (Scene*) hscene; RTCORE_CATCH_BEGIN; RTCORE_TRACE(rtcIntersect4); #if !defined(__TARGET_SIMD4__) throw_RTCError(RTC_INVALID_OPERATION,"rtcIntersect4 not supported"); #else #if defined(DEBUG) RTCORE_VERIFY_HANDLE(hscene); if (scene->isModified()) throw_RTCError(RTC_INVALID_OPERATION,"scene got not committed"); if (((size_t)valid) & 0x0F ) throw_RTCError(RTC_INVALID_ARGUMENT, "mask not aligned to 16 bytes"); if (((size_t)&ray ) & 0x0F ) throw_RTCError(RTC_INVALID_ARGUMENT, "ray not aligned to 16 bytes"); #endif STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
void TriangleMesh::unmap(RTCBufferType type) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); if (type == RTC_INDEX_BUFFER) { triangles.unmap(parent->numMappedBuffers); } else if (type >= RTC_VERTEX_BUFFER0 && type < RTCBufferType(RTC_VERTEX_BUFFER0 + numTimeSteps)) { vertices[type - RTC_VERTEX_BUFFER0].unmap(parent->numMappedBuffers); vertices0 = vertices[0]; } else { throw_RTCError(RTC_INVALID_ARGUMENT,"unknown buffer type"); } }
void UserGeometry::setIntersectFunction (RTCIntersectFunc intersect1, bool ispc) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); intersectors.intersector1.intersect = intersect1; }
void LineSegments::interpolate(unsigned primID, float u, float v, RTCBufferType buffer, float* P, float* dPdu, float* dPdv, float* ddPdudu, float* ddPdvdv, float* ddPdudv, size_t numFloats) { /* test if interpolation is enabled */ #if defined(DEBUG) if ((parent->aflags & RTC_INTERPOLATE) == 0) throw_RTCError(RTC_INVALID_OPERATION,"rtcInterpolate can only get called when RTC_INTERPOLATE is enabled for the scene"); #endif /* calculate base pointer and stride */ assert((buffer >= RTC_VERTEX_BUFFER0 && buffer < RTCBufferType(RTC_VERTEX_BUFFER0 + numTimeSteps)) || (buffer >= RTC_USER_VERTEX_BUFFER0 && buffer <= RTC_USER_VERTEX_BUFFER1)); const char* src = nullptr; size_t stride = 0; if (buffer >= RTC_USER_VERTEX_BUFFER0) { src = userbuffers[buffer&0xFFFF]->getPtr(); stride = userbuffers[buffer&0xFFFF]->getStride(); } else { src = vertices[buffer&0xFFFF].getPtr(); stride = vertices[buffer&0xFFFF].getStride(); } for (size_t i=0; i<numFloats; i+=VSIZEX) { const size_t ofs = i*sizeof(float); const size_t segment = segments[primID]; const vboolx valid = vintx((int)i)+vintx(step) < vintx(numFloats); const vfloatx p0 = vfloatx::loadu(valid,(float*)&src[(segment+0)*stride+ofs]); const vfloatx p1 = vfloatx::loadu(valid,(float*)&src[(segment+1)*stride+ofs]); if (P ) vfloatx::storeu(valid,P+i,(1.0f-u)*p0 + u*p1); if (dPdu ) vfloatx::storeu(valid,dPdu+i,p1-p0); if (ddPdudu) vfloatx::storeu(valid,dPdu+i,vfloatx(zero)); } }
void NativeCurves::setTessellationRate(float N) { if (scene->isStatic() && scene->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static geometries cannot get modified"); tessellationRate = clamp((int)N,1,16); }
void UserGeometry::setOccludedFunction (RTCOccludedFunc occluded1, bool ispc) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); intersectors.intersector1.occluded = occluded1; }
void UserGeometry::setBoundsFunction (RTCBoundsFunc bounds) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); this->boundsFunc = bounds; }
void* QuadMesh::map(RTCBufferType type) { if (scene->isStatic() && scene->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); if (type == RTC_INDEX_BUFFER) { return quads.map(scene->numMappedBuffers); } else if (type >= RTC_VERTEX_BUFFER0 && type < RTCBufferType(RTC_VERTEX_BUFFER0 + numTimeSteps)) { return vertices[type - RTC_VERTEX_BUFFER0].map(scene->numMappedBuffers); } else { throw_RTCError(RTC_INVALID_ARGUMENT,"unknown buffer type"); return nullptr; } }
void QuadMesh::preCommit () { /* verify that stride of all time steps are identical */ for (size_t t=0; t<numTimeSteps; t++) if (vertices[t].getStride() != vertices[0].getStride()) throw_RTCError(RTC_INVALID_OPERATION,"stride of vertex buffers have to be identical for each time step"); }
void BezierCurves::interpolate(unsigned primID, float u, float v, RTCBufferType buffer, float* P, float* dPdu, float* dPdv, size_t numFloats) { /* test if interpolation is enabled */ #if defined(DEBUG) if ((parent->aflags & RTC_INTERPOLATE) == 0) throw_RTCError(RTC_INVALID_OPERATION,"rtcInterpolate can only get called when RTC_INTERPOLATE is enabled for the scene"); #endif /* calculate base pointer and stride */ assert((buffer >= RTC_VERTEX_BUFFER0 && buffer <= RTC_VERTEX_BUFFER1) || (buffer >= RTC_USER_VERTEX_BUFFER0 && buffer <= RTC_USER_VERTEX_BUFFER1)); const char* src = nullptr; size_t stride = 0; if (buffer >= RTC_USER_VERTEX_BUFFER0) { src = userbuffers[buffer&0xFFFF]->getPtr(); stride = userbuffers[buffer&0xFFFF]->getStride(); } else { src = vertices[buffer&0xFFFF].getPtr(); stride = vertices[buffer&0xFFFF].getStride(); } #if !defined(__MIC__) for (size_t i=0; i<numFloats; i+=4) { size_t ofs = i*sizeof(float); const size_t curve = curves[primID]; const vfloat4 p0 = vfloat4::loadu((float*)&src[(curve+0)*stride+ofs]); const vfloat4 p1 = vfloat4::loadu((float*)&src[(curve+1)*stride+ofs]); const vfloat4 p2 = vfloat4::loadu((float*)&src[(curve+2)*stride+ofs]); const vfloat4 p3 = vfloat4::loadu((float*)&src[(curve+3)*stride+ofs]); const vbool4 valid = vint4(i)+vint4(step) < vint4(numFloats); const BezierCurveT<vfloat4> bezier(p0,p1,p2,p3,0.0f,1.0f,0); vfloat4 Q, dQdu; bezier.eval(u,Q,dQdu); if (P ) vfloat4::storeu(valid,P+i,Q); if (dPdu) vfloat4::storeu(valid,dPdu+i,dQdu); } #else for (size_t i=0; i<numFloats; i+=16) { size_t ofs = i*sizeof(float); vbool16 mask = (i+16 > numFloats) ? (vbool16)(((unsigned int)1 << (numFloats-i))-1) : vbool16( true ); const size_t curve = curves[primID]; const vfloat16 p0 = vfloat16::loadu(mask,(float*)&src[(curve+0)*stride+ofs]); const vfloat16 p1 = vfloat16::loadu(mask,(float*)&src[(curve+1)*stride+ofs]); const vfloat16 p2 = vfloat16::loadu(mask,(float*)&src[(curve+2)*stride+ofs]); const vfloat16 p3 = vfloat16::loadu(mask,(float*)&src[(curve+3)*stride+ofs]); const BezierCurveT<vfloat16> bezier(p0,p1,p2,p3,0.0f,1.0f,0); vfloat16 Q, dQdu; bezier.eval(u,Q,dQdu); if (P ) vfloat16::storeu_compact(mask,P+i,Q); if (dPdu) vfloat16::storeu_compact(mask,dPdu+i,dQdu); } #endif }
void GeometryInstance::setMask (unsigned mask) { if (scene->isStatic() && scene->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); this->mask = mask; Geometry::update(); }
void TriangleMesh::setMask (unsigned mask) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); this->mask = mask; Geometry::update(); }
void AccelN::add(Accel* accel) { assert(accel); if (accels.size() == accels.max_size()) throw_RTCError(RTC_UNKNOWN_ERROR,"internal error: AccelN too small"); accels.push_back(accel); }
void BezierCurves::setMask (unsigned mask) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static geometries cannot get modified"); this->mask = mask; Geometry::update(); }
void UserGeometry::setBoundsFunction3 (RTCBoundsFunc3 bounds, void* userPtr) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); this->boundsFunc3 = bounds; this->boundsFuncUserPtr = userPtr; }
void UserGeometry::setIntersectFunction16 (RTCIntersectFunc16 intersect16, bool ispc) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); intersectors.intersector16.intersect = (void*)intersect16; intersectors.intersector16.ispc = ispc; }
void UserGeometry::setOccludedFunction8 (RTCOccludedFunc8 occluded8, bool ispc) { if (parent->isStatic() && parent->isBuild()) throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified"); intersectors.intersector8.occluded = (void*)occluded8; intersectors.intersector8.ispc = ispc; }
Accel* BVH8Factory::BVH8Quad4v(Scene* scene) { BVH8* accel = new BVH8(Quad4v::type,scene); Accel::Intersectors intersectors = BVH8Quad4vIntersectors(accel); Builder* builder = nullptr; if (scene->device->quad_builder == "default" ) builder = BVH8Quad4vSceneBuilderSAH(accel,scene,0); else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown builder "+scene->device->quad_builder+" for BVH8<Quad4v>"); return new AccelInstance(accel,builder,intersectors); }