| 73 | } |
| 74 | |
| 75 | void RtProgramVars::init(const ref<RtBindingTable>& pBindingTable) |
| 76 | { |
| 77 | mRayTypeCount = pBindingTable->getRayTypeCount(); |
| 78 | mGeometryCount = pBindingTable->getGeometryCount(); |
| 79 | |
| 80 | // We must create sub-shader-objects for all the entry point |
| 81 | // groups that are used by the supplied binding table. |
| 82 | // |
| 83 | FALCOR_ASSERT(mpProgramVersion); |
| 84 | auto pProgram = dynamic_cast<Program*>(mpProgramVersion->getProgram()); |
| 85 | FALCOR_ASSERT(pProgram); |
| 86 | auto pReflector = mpProgramVersion->getReflector(); |
| 87 | |
| 88 | std::set<int32_t> entryPointGroupIndices; |
| 89 | |
| 90 | // Ray generation and miss programs are easy: we just allocate space |
| 91 | // for one parameter block per entry-point of the given type in the binding table. |
| 92 | // |
| 93 | const auto& rayGenInfo = pBindingTable->getRayGen(); |
| 94 | FALCOR_ASSERT(rayGenInfo.isValid()); |
| 95 | mRayGenVars.resize(1); |
| 96 | mRayGenVars[0].entryPointGroupIndex = rayGenInfo.groupIndex; |
| 97 | entryPointGroupIndices.insert(rayGenInfo.groupIndex); |
| 98 | |
| 99 | uint32_t missCount = pBindingTable->getMissCount(); |
| 100 | mMissVars.resize(missCount); |
| 101 | |
| 102 | for (uint32_t i = 0; i < missCount; ++i) |
| 103 | { |
| 104 | const auto& missInfo = pBindingTable->getMiss(i); |
| 105 | if (!missInfo.isValid()) |
| 106 | { |
| 107 | logWarning("Raytracing binding table has no shader at miss index {}. Is that intentional?", i); |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | mMissVars[i].entryPointGroupIndex = missInfo.groupIndex; |
| 112 | |
| 113 | entryPointGroupIndices.insert(missInfo.groupIndex); |
| 114 | } |
| 115 | |
| 116 | // Hit groups are more complicated than ray generation and miss shaders. |
| 117 | // We typically want a distinct parameter block per declared hit group |
| 118 | // and per geometry in the scene. |
| 119 | // |
| 120 | // We need to take this extra complexity into account when allocating |
| 121 | // space for the hit group parameter blocks. |
| 122 | // |
| 123 | uint32_t hitCount = mRayTypeCount * mGeometryCount; |
| 124 | mHitVars.resize(hitCount); |
| 125 | |
| 126 | for (uint32_t rayType = 0; rayType < mRayTypeCount; rayType++) |
| 127 | { |
| 128 | for (uint32_t geometryID = 0; geometryID < mGeometryCount; geometryID++) |
| 129 | { |
| 130 | const auto& hitGroupInfo = pBindingTable->getHitGroup(rayType, geometryID); |
| 131 | if (!hitGroupInfo.isValid()) |
| 132 | continue; |
no test coverage detected