Skip to content

Commit

Permalink
Integrate the KernelEntry Function
Browse files Browse the repository at this point in the history
Integrate the KernelEntry Function to the empty entry module
  • Loading branch information
jiaolu committed Dec 5, 2023
1 parent 359e215 commit 929e721
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions llpc/lower/llpcSpirvProcessGpuRtLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ SpirvProcessGpuRtLibrary::LibraryFunctionTable::LibraryFunctionTable() {
m_libFuncPtrs["_AmdContStackFree"] = &SpirvProcessGpuRtLibrary::createContStackFree;
m_libFuncPtrs["_AmdContStackGetPtr"] = &SpirvProcessGpuRtLibrary::createContStackGetPtr;
m_libFuncPtrs["_AmdContStackSetPtr"] = &SpirvProcessGpuRtLibrary::createContStackSetPtr;
m_libFuncPtrs["_AmdEnqueueRayGen"] = &SpirvProcessGpuRtLibrary::createEnqueueRayGen;
}

// =====================================================================================================================
Expand Down Expand Up @@ -752,4 +753,17 @@ void SpirvProcessGpuRtLibrary::createContStackStore(llvm::Function *func) {
m_builder->CreateRetVoid();
}

// =====================================================================================================================
// Fill in function to execute raygen shader with given address
//
// @param func : The function to create
void SpirvProcessGpuRtLibrary::createEnqueueRayGen(llvm::Function *func) {
auto addr = m_builder->CreateLoad(m_builder->getInt64Ty(), func->getArg(0));
auto dispatchData = func->getArg(1);
auto funcPtr = m_builder->CreateIntToPtr(addr, m_builder->getPtrTy(SPIRAS_Global));
auto funcTy = FunctionType::get(m_builder->getVoidTy(), {dispatchData->getType()}, false);
m_builder->CreateCall(funcTy, funcPtr, {dispatchData});
m_builder->CreateRetVoid();
}

} // namespace Llpc
1 change: 1 addition & 0 deletions llpc/lower/llpcSpirvProcessGpuRtLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class SpirvProcessGpuRtLibrary : public SpirvLower, public llvm::PassInfoMixin<S
void createContStackSetPtr(llvm::Function *func);
void createContStackLoad(llvm::Function *func);
void createContStackStore(llvm::Function *func);
void createEnqueueRayGen(llvm::Function *func);
llvm::Value *createGetBvhSrd(llvm::Value *expansion, llvm::Value *boxSortMode);
};
} // namespace Llpc
13 changes: 13 additions & 0 deletions shared/continuations/lib/LowerRaytracingPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,19 @@ LowerRaytracingPipelinePassImpl::LowerRaytracingPipelinePassImpl(
PAQManager{Mod, MetadataState.getMaxPayloadRegisterCount()} {}

bool LowerRaytracingPipelinePassImpl::run() {
if (Mod->empty()) {
auto FuncTy = FunctionType::get(Builder.getVoidTy(), {}, false);
// GpurtLibrary is not defined in the gpuopen, use Mod in place of
// GpurtLibrary
Function *ConKernel = Mod->getFunction("_cont_KernelEntry");
Function *EntryFunc =
Function::Create(FuncTy, GlobalValue::ExternalLinkage, "main", *Mod);
EntryFunc->setCallingConv(CallingConv::C);
moveFunctionBody(*ConKernel, *EntryFunc);
setLgcRtShaderStage(EntryFunc, RayTracingShaderStage::RayGeneration);

return true;
}
MetadataState.updateModuleMetadata();

collectDriverFunctions();
Expand Down

0 comments on commit 929e721

Please sign in to comment.