Path: blob/master/thirdparty/embree/kernels/subdiv/subdivpatch1base.h
9913 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "../geometry/primitive.h"6#include "bspline_patch.h"7#include "bezier_patch.h"8#include "gregory_patch.h"9#include "gregory_patch_dense.h"10#include "tessellation.h"11#include "tessellation_cache.h"12#include "gridrange.h"13#include "patch_eval_grid.h"14#include "feature_adaptive_eval_grid.h"15#include "../common/scene_subdiv_mesh.h"1617namespace embree18{19struct __aligned(64) SubdivPatch1Base20{21public:2223enum Type {24INVALID_PATCH = 0,25BSPLINE_PATCH = 1,26BEZIER_PATCH = 2,27GREGORY_PATCH = 3,28EVAL_PATCH = 5,29BILINEAR_PATCH = 6,30};3132enum Flags {33TRANSITION_PATCH = 16,34};3536/*! Default constructor. */37__forceinline SubdivPatch1Base () {}3839SubdivPatch1Base (const unsigned int gID,40const unsigned int pID,41const unsigned int subPatch,42const SubdivMesh *const mesh,43const size_t time,44const Vec2f uv[4],45const float edge_level[4],46const int subdiv[4],47const int simd_width);4849__forceinline bool needsStitching() const {50return flags & TRANSITION_PATCH;51}5253__forceinline Vec2f getUV(const size_t i) const {54return Vec2f((float)u[i],(float)v[i]) * (8.0f/0x10000);55}5657static void computeEdgeLevels(const float edge_level[4], const int subdiv[4], float level[4]);58static Vec2i computeGridSize(const float level[4]);59bool updateEdgeLevels(const float edge_level[4], const int subdiv[4], const SubdivMesh *const mesh, const int simd_width);6061public:6263__forceinline size_t getGridBytes() const {64const size_t grid_size_xyzuv = (grid_size_simd_blocks * VSIZEX) * 4;65return 64*((grid_size_xyzuv+15) / 16);66}6768__forceinline void write_lock() { mtx.lock(); }69__forceinline void write_unlock() { mtx.unlock(); }70__forceinline bool try_write_lock() { return mtx.try_lock(); }71//__forceinline bool try_read_lock() { return mtx.try_read_lock(); }7273__forceinline void resetRootRef() {74//assert( mtx.hasInitialState() );75root_ref = SharedLazyTessellationCache::Tag();76}7778__forceinline SharedLazyTessellationCache::CacheEntry& entry() {79return (SharedLazyTessellationCache::CacheEntry&) root_ref;80}8182public:83__forceinline unsigned int geomID() const {84return geom;85}8687__forceinline unsigned int primID() const {88return prim;89}9091public:92SharedLazyTessellationCache::Tag root_ref;93SpinLock mtx;9495unsigned short u[4]; //!< 16bit discretized u,v coordinates96unsigned short v[4];97float level[4];9899unsigned char flags;100unsigned char type;101unsigned short grid_u_res;102unsigned int geom; //!< geometry ID of the subdivision mesh this patch belongs to103unsigned int prim; //!< primitive ID of this subdivision patch104unsigned short grid_v_res;105106unsigned short grid_size_simd_blocks;107unsigned int time_;108109struct PatchHalfEdge {110const HalfEdge* edge;111unsigned subPatch;112};113114Vec3fa patch_v[4][4];115116const HalfEdge *edge() const { return ((PatchHalfEdge*)patch_v)->edge; }117unsigned time() const { return time_; }118unsigned subPatch() const { return ((PatchHalfEdge*)patch_v)->subPatch; }119120void set_edge(const HalfEdge *h) const { ((PatchHalfEdge*)patch_v)->edge = h; }121void set_subPatch(const unsigned s) const { ((PatchHalfEdge*)patch_v)->subPatch = s; }122};123124namespace isa125{126Vec3fa patchEval(const SubdivPatch1Base& patch, const float uu, const float vv);127Vec3fa patchNormal(const SubdivPatch1Base& patch, const float uu, const float vv);128129template<typename simdf>130Vec3<simdf> patchEval(const SubdivPatch1Base& patch, const simdf& uu, const simdf& vv);131132template<typename simdf>133Vec3<simdf> patchNormal(const SubdivPatch1Base& patch, const simdf& uu, const simdf& vv);134135136/* eval grid over patch and stich edges when required */137void evalGrid(const SubdivPatch1Base& patch,138const unsigned x0, const unsigned x1,139const unsigned y0, const unsigned y1,140const unsigned swidth, const unsigned sheight,141float *__restrict__ const grid_x,142float *__restrict__ const grid_y,143float *__restrict__ const grid_z,144float *__restrict__ const grid_u,145float *__restrict__ const grid_v,146const SubdivMesh* const geom);147148/* eval grid over patch and stich edges when required */149BBox3fa evalGridBounds(const SubdivPatch1Base& patch,150const unsigned x0, const unsigned x1,151const unsigned y0, const unsigned y1,152const unsigned swidth, const unsigned sheight,153const SubdivMesh* const geom);154}155}156157158