@@ -89,7 +89,8 @@ void CFrontendIR::printDotGraph(std::ostringstream& str) const
8989 str << " digraph {\n " ;
9090
9191 // TODO: track layering depth and indent accordingly?
92- core::vector<TypedHandle<const CLayer>> layerStack = m_rootNodes;
92+ // assign in reverse because we want materials to print in order
93+ core::vector<TypedHandle<const CLayer>> layerStack (m_rootNodes.rbegin (),m_rootNodes.rend ());
9394 core::stack<TypedHandle<const IExprNode>> exprStack;
9495 while (!layerStack.empty ())
9596 {
@@ -119,24 +120,140 @@ void CFrontendIR::printDotGraph(std::ostringstream& str) const
119120 {
120121 const auto entry = exprStack.top ();
121122 exprStack.pop ();
123+ const auto nodeID = getNodeID (entry);
122124 str << " \n\t " << getLabelledNodeID (entry);
123- str << " \n\t " << getNodeID (entry) << " -> {" ;
124125 const auto * node = deref (entry);
125126 const auto childCount = node->getChildCount ();
126- for ( auto childIx= 0 ; childIx< childCount; childIx++ )
127+ if ( childCount)
127128 {
128- const auto childHandle = node-> getChildHandle (childIx) ;
129- if ( const auto child= deref (childHandle); child )
129+ str << " \n\t " << nodeID << " -> { " ;
130+ for ( auto childIx= 0 ; childIx<childCount; childIx++ )
130131 {
131- str << getNodeID (childHandle) << " " ;
132- exprStack.push (childHandle);
132+ const auto childHandle = node->getChildHandle (childIx);
133+ if (const auto child=deref (childHandle); child)
134+ {
135+ str << getNodeID (childHandle) << " " ;
136+ exprStack.push (childHandle);
137+ }
133138 }
139+ str << " }\n " ;
134140 }
135- str << " }\n " ;
141+ // special printing
142+ node->printDot (str,nodeID);
136143 }
137144 }
138145
146+ // TODO: print image views
147+
139148 str << " \n }\n " ;
140149}
141150
151+ void CFrontendIR::SParameter::printDot (std::ostringstream& sstr, const core::string& selfID) const
152+ {
153+ sstr << " \n\t " << selfID << " [label=\" scale = " << std::to_string (scale);
154+ if (view)
155+ {
156+ sstr << " \\ nchannel = " << std::to_string (viewChannel);
157+ const auto & viewParams = view->getCreationParameters ();
158+ sstr << " \\ nWraps = {" << sampler.TextureWrapU ;
159+ if (viewParams.viewType !=ICPUImageView::ET_1D && viewParams.viewType !=ICPUImageView::ET_1D_ARRAY)
160+ sstr << " ," << sampler.TextureWrapV ;
161+ if (viewParams.viewType ==ICPUImageView::ET_3D)
162+ sstr << " ," << sampler.TextureWrapW ;
163+ sstr << " }\\ nBorder = " << sampler.BorderColor ;
164+ // don't bother printing the rest, we really don't care much about those
165+ }
166+ sstr << " \" ]" ;
167+ // TODO: do specialized printing for image views (they need to be gathered into a view set -> need a printing context struct)
168+ /*
169+ struct SDotPrintContext
170+ {
171+ std::ostringstream* sstr;
172+ core::unordered_map<ICPUImageView*,core::blake3_hash>* usedViews;
173+ uint16_t indentation = 0;
174+ };
175+ */
176+ if (view)
177+ sstr << " \n\t " << selfID << " -> _view_" << std::to_string (reinterpret_cast <const uint64_t &>(view));
178+ }
179+
180+ void CFrontendIR::CSpectralVariable::printDot (std::ostringstream& sstr, const core::string& selfID) const
181+ {
182+ auto pWonky = reinterpret_cast <const SCreationParams<2 >*>(this +1 );
183+ const auto knotCount = getKnotCount ();
184+ // single knot stuff is monochrome
185+ if (knotCount>1 )
186+ {
187+ sstr << " \n\t " << selfID << " -> " ;
188+ constexpr const char * semanticNames[] =
189+ {
190+ " Fixed3_SRGB" ,
191+ " Fixed3_DCI_P3" ,
192+ " Fixed3_BT2020" ,
193+ " Fixed3_AdobeRGB" ,
194+ " Fixed3_AcesCG"
195+ };
196+ sstr << semanticNames[static_cast <uint8_t >(pWonky->getSemantics ())] << " label[\" Semantics\" ]" ;
197+ }
198+ pWonky->knots .printDot (knotCount,sstr,selfID);
199+ }
200+
201+ void CFrontendIR::CEmitter::printDot (std::ostringstream& sstr, const core::string& selfID) const
202+ {
203+ if (profile)
204+ {
205+ const auto transformNodeID = selfID+" _pTform" ;
206+ sstr << " \n\t " << transformNodeID << " [label=\" " ;
207+ printMatrix (sstr,profileTransform);
208+ sstr << " \" ]" ;
209+ // connect up
210+ sstr << " \n\t " << selfID << " -> " << transformNodeID;
211+ }
212+ }
213+
214+ void CFrontendIR::CFresnel::printDot (std::ostringstream& sstr, const core::string& selfID) const
215+ {
216+ }
217+
218+ void CFrontendIR::IBxDF::SBasicNDFParams::printDot (std::ostringstream& sstr, const core::string& selfID) const
219+ {
220+ constexpr const char * paramSemantics[] = {
221+ " dh/du" ,
222+ " dh/dv" ,
223+ " alpha_u" ,
224+ " alpha_v"
225+ };
226+ SParameterSet<4 >::printDot (sstr,selfID,paramSemantics);
227+ if (hlsl::determinant (reference)>0 .f )
228+ {
229+ const auto referenceID = selfID+" _reference" ;
230+ sstr << " \n\t " << referenceID << " [label=\" " ;
231+ printMatrix (sstr,reference);
232+ sstr << " \" ]" ;
233+ sstr << " \n\t " << selfID << " -> " << referenceID << " [label=\" Stretch Reference\" ]" ;
234+ }
235+ }
236+
237+ void CFrontendIR::COrenNayar::printDot (std::ostringstream& sstr, const core::string& selfID) const
238+ {
239+ const auto ndParamsID = selfID + " _ndParams" ;
240+ sstr << " \n\t " << ndParamsID << " label[\" ND Params\" ]" ;
241+ ndParams.printDot (sstr,ndParamsID);
242+ }
243+
244+ void CFrontendIR::CCookTorrance::printDot (std::ostringstream& sstr, const core::string& selfID) const
245+ {
246+ sstr << " \n\t " << selfID << " -> " ;
247+ switch (ndf)
248+ {
249+ case NDF::GGX:
250+ sstr << " GGX" ;
251+ break ;
252+ case NDF::Beckmann:
253+ sstr << " Beckmann" ;
254+ break ;
255+ }
256+ ndParams.printDot (sstr,selfID);
257+ }
258+
142259}
0 commit comments