Skip to content

Commit 39f5639

Browse files
author
devsh
committed
commit the iR method refactor
1 parent 4d1e32b commit 39f5639

File tree

1 file changed

+100
-21
lines changed

1 file changed

+100
-21
lines changed

13_MaterialCompilerTest/CFrontendIR.cpp

Lines changed: 100 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,84 @@
11
// Copyright (C) 2022-2025 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
#ifndef _NBL_ASSET_MATERIAL_COMPILER_V3_C_FRONTEND_IR_H_INCLUDED_
5-
#define _NBL_ASSET_MATERIAL_COMPILER_V3_C_FRONTEND_IR_H_INCLUDED_
6-
7-
84
#include "nbl/asset/material_compiler3/CFrontendIR.h"
95

106

117
namespace nbl::asset::material_compiler3
128
{
139

14-
bool CFrontendIR::CLayer::invalid(const CFrontendIR* pool) const
10+
constexpr auto ELL_ERROR = nbl::system::ILogger::E_LOG_LEVEL::ELL_ERROR;
11+
using namespace nbl::system;
12+
13+
bool CFrontendIR::CEmitter::invalid(const SInvalidCheckArgs& args) const
14+
{
15+
if (const auto* radianceNode=args.pool->deref(radiance); !radianceNode)
16+
{
17+
args.logger.log("Radiance node of correct type must be attached, but is %u of type %s",ELL_ERROR,radiance,args.pool->getTypeName(radiance).data());
18+
return false;
19+
}
20+
// not checking validty of profile because invalid means no emission profile
21+
// check for NaN and non invertible matrix
22+
if (profile && !(hlsl::determinant(profileTransform)>hlsl::numeric_limits<hlsl::float32_t>::min))
23+
{
24+
args.logger.log("Emission Profile's Transform is not an invertible matrix!");
25+
return true;
26+
}
27+
return false;
28+
}
29+
30+
bool CFrontendIR::CBeer::invalid(const SInvalidCheckArgs& args) const
31+
{
32+
if (!args.pool->deref(perpTransparency))
33+
{
34+
args.logger.log("Perpendicular Transparency node of correct type must be attached, but is %u of type %s",ELL_ERROR,perpTransparency,args.pool->getTypeName(perpTransparency).data());
35+
return true;
36+
}
37+
return false;
38+
}
39+
40+
bool CFrontendIR::CFresnel::invalid(const SInvalidCheckArgs& args) const
41+
{
42+
if (!args.pool->deref(orientedRealEta))
43+
{
44+
args.logger.log("Oriented Real Eta node of correct type must be attached, but is %u of type %s",ELL_ERROR,orientedRealEta,args.pool->getTypeName(orientedRealEta).data());
45+
return true;
46+
}
47+
if (!args.pool->deref(orientedImagEta))
48+
{
49+
args.logger.log("Oriented Imaginary Eta node of correct type must be attached, but is %u of type %s",ELL_ERROR,orientedImagEta,args.pool->getTypeName(orientedImagEta).data());
50+
return true;
51+
}
52+
return false;
53+
}
54+
55+
bool CFrontendIR::COrenNayar::invalid(const SInvalidCheckArgs& args) const
56+
{
57+
if (!ndParams)
58+
{
59+
args.logger.log("Normal Distribution Parameters are invalid",ELL_ERROR);
60+
return true;
61+
}
62+
return false;
63+
}
64+
65+
bool CFrontendIR::CCookTorrance::invalid(const SInvalidCheckArgs& args) const
1566
{
67+
if (!ndParams)
68+
{
69+
args.logger.log("Normal Distribution Parameters are invalid",ELL_ERROR);
70+
return true;
71+
}
72+
if (args.isBTDF && !args.pool->deref(orientedRealEta))
73+
{
74+
args.logger.log("Cook Torrance BTDF requires the Index of Refraction to compute the refraction direction, but is %u of type %s",ELL_ERROR,orientedRealEta,args.pool->getTypeName(orientedRealEta).data());
75+
return true;
76+
}
77+
return false;
1678
}
1779

1880

19-
TypedHandle<INode> CFrontendIR::reciprocate(const TypedHandle<const CLayer> rootNode)
81+
auto CFrontendIR::reciprocate(const TypedHandle<const IExprNode> other) -> TypedHandle<IExprNode>
2082
{
2183
assert(false); // unimplemented
2284
return {};
@@ -30,26 +92,43 @@ void CFrontendIR::printDotGraph(std::ostringstream& str) const
3092
return core::string("_")+std::to_string(handle);
3193
};
3294

33-
core::stack<TypeHandle<const INode>> stck = m_rootNodes;
95+
core::vector<TypedHandle<const CLayer>> layerStack = m_rootNodes;
96+
core::stack<TypedHandle<const IExprNode>> exprStack;
3497
// TODO : print identifiers for root nodes/materials
35-
while (!stck.empty())
36-
{
37-
const auto entry = stck.peek();
38-
stck.pop();
39-
const auto* node = deref(entry);
40-
str << "\t" << getNodeID(entry) << " [label=" << node->getTypeName() << "]";
41-
str << "\t" << getNodeID(entry) << " -> {";
42-
const auto childCount = node->getChildCount();
43-
for (auto childIx=0; chilxId<childCount childIx++)
98+
while (!layerStack.empty())
99+
{
100+
const auto* layerNode = deref(layerStack.back());
101+
layerStack.pop_back();
102+
if (layerNode->coated)
103+
{
104+
// TODO: print coating
105+
layerStack.push_back(layerNode->coated);
106+
}
107+
// TODO: print labelled edges
108+
exprStack.push(layerNode->brdfTop);
109+
exprStack.push(layerNode->btdf);
110+
exprStack.push(layerNode->brdfBottom);
111+
while (!exprStack.empty())
44112
{
45-
const auto childHandle = node->getChildHandle(childIx);
46-
if (const auto child=deref(childHandle); child)
113+
const auto entry = exprStack.top();
114+
exprStack.pop();
115+
const auto* node = deref(entry);
116+
str << "\t" << getNodeID(entry) << " [label=" << node->getTypeName() << "\\n";
117+
if (const auto* debug = deref(node->debugInfo); debug && !debug->data().empty())
118+
str << std::string_view(reinterpret_cast<const char*>(debug->data().data()),debug->data().size());
119+
str << "]\n\t" << getNodeID(entry) << " -> {";
120+
const auto childCount = node->getChildCount();
121+
for (auto childIx=0; childIx<childCount; childIx++)
47122
{
48-
str << getNodeID(childHandle) << " ";
49-
stck.push(childHandle);
123+
const auto childHandle = node->getChildHandle(childIx);
124+
if (const auto child=deref(childHandle); child)
125+
{
126+
str << getNodeID(childHandle) << " ";
127+
exprStack.push(childHandle);
128+
}
50129
}
130+
str << "}\n";
51131
}
52-
str << "}\n";
53132
}
54133

55134
str << "}\n";

0 commit comments

Comments
 (0)