@@ -552,80 +552,57 @@ void CFrontendIR::CCookTorrance::printDot(std::ostringstream& sstr, const core::
552552 ndParams.printDot (sstr,selfID);
553553}
554554
555- // ! AST-> IR methods
556- auto CFrontendIR::CEmitter::createIRNode (const bool forBTDF, const CFrontendIR* ast, CTrueIR* ir) const -> ir_contributor_handle_t
557- {
558- assert (!forBTDF);
559- auto & irPool = ir->getObjectPool ();
560- const auto retval = irPool.emplace <CTrueIR::CEmitter>();
561- if (auto * const contributor=irPool.deref (retval))
562- {
563- contributor->profile = profile;
564- contributor->profileTransform = profileTransform;
565- }
566- return retval;
567- }
568555
569- auto CFrontendIR::CDeltaTransmission::createIRNode (const bool forBTDF, const CFrontendIR* ast, CTrueIR* ir) const -> ir_contributor_handle_t
556+ // ! IR making
557+ CTrueIR::SMaterialHandle CFrontendIR::SAdd2IRSession::makeFinalIR (const typed_pointer_type<const CLayer> rootH, const CFrontendIR* ast)
570558{
571- assert (forBTDF);
572- return ir-> getObjectPool (). emplace <CTrueIR::CDeltaTransmission>() ;
573- }
559+ // TODO
560+ // core::unordered_map<const CFrontendIR::IExprNode*,bool> brdfs ;
561+ // core::unordered_map<const CFrontendIR::IExprNode*,bool> btdfs;
574562
575- auto CFrontendIR::COrenNayar::createIRNode (const bool forBTDF, const CFrontendIR* ast, CTrueIR* ir) const -> ir_contributor_handle_t
576- {
577- if (ndParams.getDistribution ()!=CTrueIR::SBasicNDFParams::EDistribution::Invalid)
578- return {};
579- auto & irPool = ir->getObjectPool ();
580- const auto retval = irPool.emplace <CTrueIR::COrenNayar>();
581- if (auto * const contributor = irPool.deref (retval))
582- contributor->ndfParams = ndParams; // the padding abuse is the same between the classes
583- return retval;
584- }
563+ const auto & astPool = ast->getObjectPool ();
564+ const auto * astRoot = astPool.deref <const CFrontendIR::CLayer>(rootH);
565+ // no material
566+ if (!astRoot)
567+ return CTrueIR::BlackholeMaterialHandle;
568+ tmpIR->reset ();
569+ // reverse AST into another tree
570+ tmpAST->reset ();
571+ const auto backRootH = tmpAST->reverse (rootH,ast);
572+ CTrueIR::SMaterial material = {
573+ .front = makeOrientedMaterial (rootH,ast),
574+ .back = makeOrientedMaterial (backRootH,tmpAST.get ())
575+ };
585576
586- auto CFrontendIR::CCookTorrance::createIRNode (const bool forBTDF, const CFrontendIR* ast, CTrueIR* ir) const -> ir_contributor_handle_t
587- {
588- if (ndParams.getDistribution ()>CTrueIR::SBasicNDFParams::EDistribution::Beckmann)
577+ const auto errorLayer = args.ir ->getBasicNodes ().errorLayer ;
578+ auto printLayer = [&](const typed_pointer_type<const CLayer> _rootH, const CFrontendIR* _ast)->void
579+ {
580+ astPrinter.reset (_ast);
581+ astPrinter.layerStack .push_back (_rootH);
582+ args.logger .log (" Subtree Dot3 : \n %s\n " ,ELL_DEBUG,astPrinter ().c_str ());
583+ assert (astPrinter.layerStack .empty ());
584+ };
585+ if (material.front .root ==errorLayer)
586+ {
587+ args.logger .log (" Failed to create Frontface Material" ,ELL_ERROR);
588+ printLayer (rootH,ast);
589589 return {};
590- auto & irPool = ir->getObjectPool ();
591- CTrueIR::typed_pointer_type<const CTrueIR::ISpectralVariable> etaH = {};
592- if (forBTDF)
590+ }
591+ if (material.back .root ==errorLayer)
593592 {
594- if (!orientedRealEta)
595- return {};
596- const auto * const srcEta = ast->getObjectPool ().deref (orientedRealEta);
597- switch (srcEta->getSemantics ())
598- {
599- case CSpectralVariable::semantics_e::NoneUndefined:
600- {
601- assert (srcEta->getKnotCount ()==1 );
602- const auto handle = irPool.emplace <CTrueIR::CSpectralVariable<1 >>();
603- auto * const dstEta = irPool.deref (handle);
604- if (!dstEta)
605- return {};
606- dstEta->paramSet .uvTransform = srcEta->uvTransform ();
607- dstEta->paramSet .params [0 ] = *srcEta->getParam (0 );
608- break ;
609- }
610- default :
611- {
612- assert (srcEta->getKnotCount ()==3 );
613- const auto handle = irPool.emplace <CTrueIR::CSpectralVariable<3 >>();
614- auto * const dstEta = irPool.deref (handle);
615- if (!dstEta)
616- return {};
617- dstEta->paramSet .uvTransform = srcEta->uvTransform ();
618- for (auto i=0 ; i<3 ; i++)
619- dstEta->paramSet .params [i] = *srcEta->getParam (i);
620- break ;
621- }
622- }
593+ args.logger .log (" Failed to create Backface Material for reversed AST" ,ELL_ERROR);
594+ printLayer (backRootH,tmpAST.get ());
595+ return {};
623596 }
624- const auto retval = irPool.emplace <CTrueIR::CCookTorrance>();
625- if (auto * const ct=irPool.deref (retval); ct)
597+
598+ auto retval = args.ir ->addMaterial (material);
599+ if (retval)
626600 {
627- ct->ndfParams = ndParams; // the padding abuse is the same between the classes
628- ct->orientedRealEta = etaH;
601+ // TODO: better debug info (e.g. concat all the layer info during `makeOrientedMaterial` via the `session` object
602+ if (const auto * debug=astPool.deref <const CDebugInfo>(astRoot->debugInfo ); debug && !debug->data ().empty ())
603+ {
604+ material.debugInfo = args.ir ->getObjectPool ().emplace <CNodePool::CDebugInfo>(debug->data ().data (),debug->data ().size ());
605+ }
629606 }
630607 return retval;
631608}
@@ -664,7 +641,9 @@ auto CFrontendIR::SAdd2IRSession::makeOrientedMaterial(const CFrontendIR::typed_
664641 break ;
665642 }
666643 }
644+
667645 const auto errorBxDF = tmpIR->getBasicNodes ().errorBxDF ;
646+ const auto errorLayer = tmpIR->getBasicNodes ().errorLayer ;
668647 // Some metadata needed for us
669648 bool layersBelowCanScatterBack = false ;
670649 CTrueIR::typed_pointer_type<CTrueIR::COrientedLayer> prevLayerH = {};
@@ -679,7 +658,7 @@ auto CFrontendIR::SAdd2IRSession::makeOrientedMaterial(const CFrontendIR::typed_
679658 // process the top BRDF
680659 outLayer->brdfTop = makeContributors (inLayer->brdfTop );
681660 if (outLayer->brdfTop ==errorBxDF)
682- return {};
661+ return {. root =errorLayer };
683662 // process the BTDF
684663 btdfSubtree = true ;
685664 const auto btdfH = makeContributors (inLayer->btdf );
@@ -688,7 +667,7 @@ auto CFrontendIR::SAdd2IRSession::makeOrientedMaterial(const CFrontendIR::typed_
688667 if (btdfH)
689668 {
690669 if (btdfH==errorBxDF)
691- return {};
670+ return {. root =errorLayer };
692671 const auto transmissionH = irPool.emplace <CTrueIR::CCorellatedTransmission>();
693672 {
694673 auto * const transmission = irPool.deref (transmissionH);
@@ -698,7 +677,7 @@ auto CFrontendIR::SAdd2IRSession::makeOrientedMaterial(const CFrontendIR::typed_
698677 {
699678 transmission->brdfBottom = makeContributors (inLayer->brdfBottom );
700679 if (transmission->brdfBottom ==errorBxDF)
701- return {};
680+ return {. root =errorLayer };
702681 }
703682 // we check if previous layer didn't get oprimized away, but we don't add its optimized version because don't want pointers across two pools (crash)
704683 if (retval.root )
@@ -932,57 +911,81 @@ auto CFrontendIR::SAdd2IRSession::popContributor() -> CTrueIR::typed_pointer_typ
932911 return retval;
933912}
934913
935- //
936- CTrueIR::SMaterialHandle CFrontendIR::SAdd2IRSession::makeFinalIR (const typed_pointer_type< const CLayer> rootH , const CFrontendIR* ast)
914+ // AST Node -> IR methods
915+ auto CFrontendIR::CEmitter::createIRNode (const bool forBTDF , const CFrontendIR* ast, CTrueIR* ir) const -> ir_contributor_handle_t
937916{
938- // TODO
939- // core::unordered_map<const CFrontendIR::IExprNode*,bool> brdfs;
940- // core::unordered_map<const CFrontendIR::IExprNode*,bool> btdfs;
941-
942- const auto & astPool = ast->getObjectPool ();
943- const auto * astRoot = astPool.deref <const CFrontendIR::CLayer>(rootH);
944- // no material
945- if (!astRoot)
946- return CTrueIR::BlackholeMaterialHandle;
947- tmpIR->reset ();
948- // reverse AST into another tree
949- tmpAST->reset ();
950- const auto backRootH = tmpAST->reverse (rootH,ast);
951- CTrueIR::SMaterial material = {
952- .front = makeOrientedMaterial (rootH,ast),
953- .back = makeOrientedMaterial (backRootH,tmpAST.get ())
954- };
955-
956- const auto errorLayer = args.ir ->getBasicNodes ().errorLayer ;
957- auto printLayer = [&](const typed_pointer_type<const CLayer> _rootH, const CFrontendIR* _ast)->void
958- {
959- astPrinter.reset (_ast);
960- astPrinter.layerStack .push_back (_rootH);
961- args.logger .log (" Subtree Dot3 : \n %s\n " ,ELL_DEBUG,astPrinter ().c_str ());
962- assert (astPrinter.layerStack .empty ());
963- };
964- if (material.front .root ==errorLayer)
917+ assert (!forBTDF);
918+ auto & irPool = ir->getObjectPool ();
919+ const auto retval = irPool.emplace <CTrueIR::CEmitter>();
920+ if (auto * const contributor=irPool.deref (retval))
965921 {
966- args.logger .log (" Failed to create Frontface Material" ,ELL_ERROR);
967- printLayer (rootH,ast);
968- return {};
922+ contributor->profile = profile;
923+ contributor->profileTransform = profileTransform;
969924 }
970- if (material.back .root ==errorLayer)
971- {
972- args.logger .log (" Failed to create Backface Material for reversed AST" ,ELL_ERROR);
973- printLayer (backRootH,tmpAST.get ());
925+ return retval;
926+ }
927+
928+ auto CFrontendIR::CDeltaTransmission::createIRNode (const bool forBTDF, const CFrontendIR* ast, CTrueIR* ir) const -> ir_contributor_handle_t
929+ {
930+ assert (forBTDF);
931+ return ir->getObjectPool ().emplace <CTrueIR::CDeltaTransmission>();
932+ }
933+
934+ auto CFrontendIR::COrenNayar::createIRNode (const bool forBTDF, const CFrontendIR* ast, CTrueIR* ir) const -> ir_contributor_handle_t
935+ {
936+ if (ndParams.getDistribution ()!=CTrueIR::SBasicNDFParams::EDistribution::Invalid)
974937 return {};
975- }
938+ auto & irPool = ir->getObjectPool ();
939+ const auto retval = irPool.emplace <CTrueIR::COrenNayar>();
940+ if (auto * const contributor = irPool.deref (retval))
941+ contributor->ndfParams = ndParams; // the padding abuse is the same between the classes
942+ return retval;
943+ }
976944
977- auto retval = args.ir ->addMaterial (material);
978- if (retval)
945+ auto CFrontendIR::CCookTorrance::createIRNode (const bool forBTDF, const CFrontendIR* ast, CTrueIR* ir) const -> ir_contributor_handle_t
946+ {
947+ if (ndParams.getDistribution ()>CTrueIR::SBasicNDFParams::EDistribution::Beckmann)
948+ return {};
949+ auto & irPool = ir->getObjectPool ();
950+ CTrueIR::typed_pointer_type<const CTrueIR::ISpectralVariable> etaH = {};
951+ if (forBTDF)
979952 {
980- // TODO: better debug info (e.g. concat all the layer info during `makeOrientedMaterial` via the `session` object
981- if (const auto * debug=astPool.deref <const CDebugInfo>(astRoot->debugInfo ); debug && !debug->data ().empty ())
953+ if (!orientedRealEta)
954+ return {};
955+ const auto * const srcEta = ast->getObjectPool ().deref (orientedRealEta);
956+ switch (srcEta->getSemantics ())
982957 {
983- material.debugInfo = args.ir ->getObjectPool ().emplace <CNodePool::CDebugInfo>(debug->data ().data (),debug->data ().size ());
958+ case CSpectralVariable::semantics_e::NoneUndefined:
959+ {
960+ assert (srcEta->getKnotCount ()==1 );
961+ const auto handle = irPool.emplace <CTrueIR::CSpectralVariable<1 >>();
962+ auto * const dstEta = irPool.deref (handle);
963+ if (!dstEta)
964+ return {};
965+ dstEta->paramSet .uvTransform = srcEta->uvTransform ();
966+ dstEta->paramSet .params [0 ] = *srcEta->getParam (0 );
967+ break ;
968+ }
969+ default :
970+ {
971+ assert (srcEta->getKnotCount ()==3 );
972+ const auto handle = irPool.emplace <CTrueIR::CSpectralVariable<3 >>();
973+ auto * const dstEta = irPool.deref (handle);
974+ if (!dstEta)
975+ return {};
976+ dstEta->paramSet .uvTransform = srcEta->uvTransform ();
977+ for (auto i=0 ; i<3 ; i++)
978+ dstEta->paramSet .params [i] = *srcEta->getParam (i);
979+ break ;
980+ }
984981 }
985982 }
983+ const auto retval = irPool.emplace <CTrueIR::CCookTorrance>();
984+ if (auto * const ct=irPool.deref (retval); ct)
985+ {
986+ ct->ndfParams = ndParams; // the padding abuse is the same between the classes
987+ ct->orientedRealEta = etaH;
988+ }
986989 return retval;
987990}
988991
0 commit comments