diff options
| author | Yong He <yonghe@outlook.com> | 2020-07-23 15:33:04 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-23 15:33:04 -0700 |
| commit | 61be38f39cc96ad9644f17f6ab8d262875e99e9e (patch) | |
| tree | 84d208568e9c412d938cfde42015f096c82fb99a /source/slang/slang-ir-specialize-arrays.cpp | |
| parent | fed4292a581364b611a82a0f6c1c1c95f82dfeb2 (diff) | |
Run array specialization in a sperate pass. (#1449)
* Run array specialization in a sperate pass.
* rename specializeFunctionCall->specializeFunctionCalls
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-ir-specialize-arrays.cpp')
| -rw-r--r-- | source/slang/slang-ir-specialize-arrays.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/source/slang/slang-ir-specialize-arrays.cpp b/source/slang/slang-ir-specialize-arrays.cpp new file mode 100644 index 000000000..53e317b81 --- /dev/null +++ b/source/slang/slang-ir-specialize-arrays.cpp @@ -0,0 +1,53 @@ +// slang-ir-specialize-arrays.cpp +#include "slang-ir-specialize-arrays.h" + +#include "slang-ir-specialize-function-call.h" +#include "slang-ir.h" +#include "slang-ir-insts.h" + +namespace Slang +{ + +struct ArrayParameterSpecializationCondition : FunctionCallSpecializeCondition +{ + // This pass is intended to specialize functions + // with struct parameters that has array fields + // to avoid performance problems for GLSL targets. + + // Returns true if `type` is an `IRStructType` with array-typed fields. + bool isStructTypeWithArray(IRType* type) + { + if (auto structType = as<IRStructType>(type)) + { + for (auto field : structType->getFields()) + { + if (auto arrayType = as<IRArrayType>(field->getFieldType())) + { + return true; + } + if (auto subStructType = as<IRStructType>(field->getFieldType())) + { + if (isStructTypeWithArray(subStructType)) + return true; + } + } + } + return false; + } + + bool doesParamNeedSpecialization(IRParam* param) + { + return isStructTypeWithArray(param->getDataType()); + } +}; + +void specializeArrayParameters( + BackEndCompileRequest* compileRequest, + TargetRequest* targetRequest, + IRModule* module) +{ + ArrayParameterSpecializationCondition condition; + specializeFunctionCalls(compileRequest, targetRequest, module, &condition); +} + +} // namesapce Slang |
