diff options
| author | Dietrich Geisler <dag368@cornell.edu> | 2020-08-17 12:50:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-17 09:50:44 -0700 |
| commit | ff2d490dc120708a2fcb6eea5880a6b7c6586a4b (patch) | |
| tree | 4bab7a7353ed5e9149510a48227da029d40d9d97 /source/slang/slang-lower-to-ir.cpp | |
| parent | 0640a10ab85f8be3c3c925cb70711560265e6548 (diff) | |
GPU Foreach Loop (#1498)
* GPU Foreach Loop
This PR introduces the completed GPU foreach loop and updates the
heterogeneous-hello-world example to use it. This PR builds on the
previous introduction of the GPU Foreach loop parsing and semantic
checking PR (#1482) by introducing IR lowering and emmitting. THe new
feature can be used by having a GPU_Foreach loop interacting with a
named non-CPP entry point, and using the -heterogeneous flag.
* Fix to path
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 9c4808f31..864491f7e 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -4116,7 +4116,39 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> void visitGpuForeachStmt(GpuForeachStmt* stmt) { + auto builder = getBuilder(); startBlockIfNeeded(stmt); + + auto renderer = getSimpleVal(context, lowerRValueExpr(context, stmt->renderer)); + auto gridDims = getSimpleVal(context, lowerRValueExpr(context, stmt->gridDims)); + + List<IRInst*> irArgs; + if (auto callExpr = as<InvokeExpr>(stmt->kernelCall)) + { + irArgs.add(renderer); + irArgs.add(gridDims); + auto fref = getSimpleVal(context, lowerRValueExpr(context, callExpr->functionExpr)); + irArgs.add(fref); + for (auto arg : callExpr->arguments) + { + // if a reference to dispatchThreadID, don't emit + if (auto declRefExpr = as<DeclRefExpr>(arg)) + { + if (declRefExpr->declRef.getDecl() == stmt->dispatchThreadID) + { + continue; + } + } + auto irArg = getSimpleVal(context, lowerRValueExpr(context, arg)); + irArgs.add(irArg); + } + } + else + { + SLANG_UNEXPECTED("GPUForeach parsing produced an invalid result"); + } + + builder->emitGpuForeach(irArgs); return; } |
