Skip to content

Commit

Permalink
Fix test failure
Browse files Browse the repository at this point in the history
The resource mapping seems to be messed up when using CreateReadBuiltInInput
out of builder replayer.
  • Loading branch information
LLJJDD committed Nov 29, 2023
1 parent d15e7f2 commit b8614d2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lgc/include/lgc/patch/LowerGpuRt.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "llvm/IR/PassManager.h"

namespace lgc {
class BuilderImpl;
class Builder;
class PipelineState;

class GpurtGetStackSizeOp;
Expand Down Expand Up @@ -76,6 +76,6 @@ class LowerGpuRt : public llvm::PassInfoMixin<LowerGpuRt> {
PipelineState *m_pipelineState = nullptr; // Pipeline state
llvm::SmallVector<llvm::Instruction *> m_callsToLower; // Call instruction to lower
llvm::SmallSet<llvm::Function *, 4> m_funcsToLower; // Functions to lower
BuilderImpl *m_builder = nullptr;
Builder *m_builder = nullptr;
};
} // namespace lgc
1 change: 1 addition & 0 deletions lgc/interface/lgc/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ union Options {
unsigned rtBoxSortHeuristicMode; // Ray tracing box sort heuristic mode
unsigned rtStaticPipelineFlags; // Ray tracing static pipeline flags
unsigned rtTriCompressMode; // Ray tracing triangle compression mode
bool useGpurt; // Whether GPURT is used
};
};
static_assert(sizeof(Options) == sizeof(Options::u32All));
Expand Down
4 changes: 1 addition & 3 deletions lgc/patch/LowerGpuRt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ PreservedAnalyses LowerGpuRt::run(Module &module, ModuleAnalysisManager &analysi
PipelineState *pipelineState = analysisManager.getResult<PipelineStateWrapper>(module).getPipelineState();
m_pipelineState = pipelineState;

BuilderImpl builderImpl(pipelineState);
Builder builderImpl(pipelineState->getContext());
m_builder = &builderImpl;
m_builder->setShaderStage(ShaderStageCompute);

createGlobalStack(module);

Expand Down Expand Up @@ -127,7 +126,6 @@ Value *LowerGpuRt::getThreadIdInGroup() const {
// Create global variable for the stack
// @param [in/out] module : LLVM module to be run on
void LowerGpuRt::createGlobalStack(Module &module) {

struct Payload {
bool needGlobalStack;
bool needExtraStack;
Expand Down
10 changes: 8 additions & 2 deletions lgc/patch/Patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ void Patch::addPasses(PipelineState *pipelineState, lgc::PassManager &passMgr, T
if (patchTimer)
LgcContext::createAndAddStartStopTimer(passMgr, patchTimer, true);

if (pipelineState->getOptions().useGpurt) {
// NOTE: Lower GPURT operations and run InstCombinePass before builder replayer, because some Op are going to be
// turned into constant value, so that we can eliminate unused `@lgc.create.load.buffer.desc` before getting into
// replayer. Otherwise, unnecessary `writes_uavs` and `uses_uav` may be set.
passMgr.addPass(LowerGpuRt());
passMgr.addPass(createModuleToFunctionPassAdaptor(InstCombinePass()));
}

// We're using BuilderRecorder; replay the Builder calls now
passMgr.addPass(BuilderReplayer());

Expand All @@ -142,8 +150,6 @@ void Patch::addPasses(PipelineState *pipelineState, lgc::PassManager &passMgr, T
"// LLPC pipeline before-patching results\n"));
}

passMgr.addPass(LowerGpuRt());

const auto indirectMode = pipelineState->getOptions().rtIndirectMode;
if (indirectMode == RayTracingIndirectMode::ContinuationsContinufy ||
indirectMode == RayTracingIndirectMode::Continuations) {
Expand Down
12 changes: 12 additions & 0 deletions llpc/context/llpcCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,7 @@ Result Compiler::buildPipelineInternal(Context *context, ArrayRef<const Pipeline

if (numStagesWithRayQuery) {
std::unique_ptr<Module> gpurtShaderLibrary = createGpurtShaderLibrary(context);
setUseGpurt(&*pipeline);
if (!gpurtShaderLibrary)
return Result::ErrorInvalidShader;

Expand Down Expand Up @@ -2677,6 +2678,16 @@ Result Compiler::generatePipeline(Context *context, unsigned moduleIndex, std::u
return Result::Success;
}

// =====================================================================================================================
// Set this pipeline use GPURT library
//
// @param pipeline : The pipeline object
void Compiler::setUseGpurt(lgc::Pipeline *pipeline) {
auto options = pipeline->getOptions();
options.useGpurt = true;
pipeline->setOptions(options);
}

// =====================================================================================================================
// Build single ray tracing pipeline ELF package.
//
Expand Down Expand Up @@ -2888,6 +2899,7 @@ Result Compiler::buildRayTracingPipelineInternal(RayTracingContext &rtContext,
std::unique_ptr<Module> gpurtShaderLibrary;
if (needGpurtShaderLibrary) {
gpurtShaderLibrary = createGpurtShaderLibrary(mainContext);
setUseGpurt(&*pipeline);
if (!gpurtShaderLibrary)
return Result::ErrorInvalidShader;
}
Expand Down
2 changes: 2 additions & 0 deletions llpc/context/llpcCompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class Compiler : public ICompiler {
Result generatePipeline(Context *context, unsigned moduleIndex, std::unique_ptr<llvm::Module> module,
ElfPackage &pipelineElf, lgc::Pipeline *pipeline, TimerProfiler &timerProfiler);

void setUseGpurt(lgc::Pipeline *pipeline);

std::vector<std::string> m_options; // Compilation options
MetroHash::Hash m_optionHash; // Hash code of compilation options
GfxIpVersion m_gfxIp; // Graphics IP version info
Expand Down

0 comments on commit b8614d2

Please sign in to comment.