| 34 | { |
| 35 | |
| 36 | RtStateObject::RtStateObject(ref<Device> pDevice, const RtStateObjectDesc& desc) : mpDevice(pDevice), mDesc(desc) |
| 37 | { |
| 38 | auto pKernels = getKernels(); |
| 39 | gfx::RayTracingPipelineStateDesc rtpDesc = {}; |
| 40 | std::vector<gfx::HitGroupDesc> hitGroups; |
| 41 | // Loop over the hitgroups |
| 42 | for (const auto& pEntryPointGroup : pKernels->getUniqueEntryPointGroups()) |
| 43 | { |
| 44 | if (pEntryPointGroup->getType() == EntryPointGroupKernels::Type::RtHitGroup) |
| 45 | { |
| 46 | const EntryPointKernel* pIntersection = pEntryPointGroup->getKernel(ShaderType::Intersection); |
| 47 | const EntryPointKernel* pAhs = pEntryPointGroup->getKernel(ShaderType::AnyHit); |
| 48 | const EntryPointKernel* pChs = pEntryPointGroup->getKernel(ShaderType::ClosestHit); |
| 49 | |
| 50 | gfx::HitGroupDesc hitgroupDesc = {}; |
| 51 | hitgroupDesc.anyHitEntryPoint = pAhs ? pAhs->getEntryPointName().c_str() : nullptr; |
| 52 | hitgroupDesc.closestHitEntryPoint = pChs ? pChs->getEntryPointName().c_str() : nullptr; |
| 53 | hitgroupDesc.intersectionEntryPoint = pIntersection ? pIntersection->getEntryPointName().c_str() : nullptr; |
| 54 | hitgroupDesc.hitGroupName = pEntryPointGroup->getExportName().c_str(); |
| 55 | hitGroups.push_back(hitgroupDesc); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | rtpDesc.hitGroupCount = (uint32_t)hitGroups.size(); |
| 60 | rtpDesc.hitGroups = hitGroups.data(); |
| 61 | rtpDesc.maxRecursion = mDesc.maxTraceRecursionDepth; |
| 62 | |
| 63 | static_assert((uint32_t)gfx::RayTracingPipelineFlags::SkipProcedurals == (uint32_t)RtPipelineFlags::SkipProceduralPrimitives); |
| 64 | static_assert((uint32_t)gfx::RayTracingPipelineFlags::SkipTriangles == (uint32_t)RtPipelineFlags::SkipTriangles); |
| 65 | |
| 66 | rtpDesc.flags = (gfx::RayTracingPipelineFlags::Enum)mDesc.pipelineFlags; |
| 67 | auto rtProgram = dynamic_cast<Program*>(mDesc.pProgramKernels->getProgramVersion()->getProgram()); |
| 68 | FALCOR_ASSERT(rtProgram); |
| 69 | rtpDesc.maxRayPayloadSize = rtProgram->getDesc().maxPayloadSize; |
| 70 | rtpDesc.maxAttributeSizeInBytes = rtProgram->getDesc().maxAttributeSize; |
| 71 | rtpDesc.program = mDesc.pProgramKernels->getGfxProgram(); |
| 72 | |
| 73 | FALCOR_GFX_CALL(mpDevice->getGfxDevice()->createRayTracingPipelineState(rtpDesc, mGfxPipelineState.writeRef())); |
| 74 | |
| 75 | // Get shader identifiers. |
| 76 | // In GFX, a shader identifier is just the entry point group name. |
| 77 | for (const auto& pEntryPointGroup : pKernels->getUniqueEntryPointGroups()) |
| 78 | { |
| 79 | mEntryPointGroupExportNames.push_back(pEntryPointGroup->getExportName()); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | RtStateObject::~RtStateObject() |
| 84 | { |