| 146 | } |
| 147 | |
| 148 | bool RtProgramVars::prepareShaderTable(RenderContext* pCtx, RtStateObject* pRtso) |
| 149 | { |
| 150 | auto& pKernels = pRtso->getKernels(); |
| 151 | |
| 152 | bool needShaderTableUpdate = false; |
| 153 | if (!mpShaderTable) |
| 154 | { |
| 155 | needShaderTableUpdate = true; |
| 156 | } |
| 157 | |
| 158 | if (!needShaderTableUpdate) |
| 159 | { |
| 160 | if (pRtso != mpCurrentRtStateObject) |
| 161 | { |
| 162 | needShaderTableUpdate = true; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if (needShaderTableUpdate) |
| 167 | { |
| 168 | auto getShaderNames = [&](VarsVector& varsVec, std::vector<const char*>& shaderNames) |
| 169 | { |
| 170 | for (uint32_t i = 0; i < (uint32_t)varsVec.size(); i++) |
| 171 | { |
| 172 | auto& varsInfo = varsVec[i]; |
| 173 | |
| 174 | auto uniqueGroupIndex = varsInfo.entryPointGroupIndex; |
| 175 | |
| 176 | auto pGroupKernels = uniqueGroupIndex >= 0 ? pKernels->getUniqueEntryPointGroup(uniqueGroupIndex) : nullptr; |
| 177 | if (!pGroupKernels) |
| 178 | { |
| 179 | shaderNames.push_back(nullptr); |
| 180 | continue; |
| 181 | } |
| 182 | |
| 183 | shaderNames.push_back(static_cast<const char*>(pRtso->getShaderIdentifier(uniqueGroupIndex))); |
| 184 | } |
| 185 | }; |
| 186 | |
| 187 | std::vector<const char*> rayGenShaders; |
| 188 | getShaderNames(mRayGenVars, rayGenShaders); |
| 189 | |
| 190 | std::vector<const char*> missShaders; |
| 191 | getShaderNames(mMissVars, missShaders); |
| 192 | |
| 193 | std::vector<const char*> hitgroupShaders; |
| 194 | getShaderNames(mHitVars, hitgroupShaders); |
| 195 | |
| 196 | gfx::IShaderTable::Desc desc = {}; |
| 197 | desc.rayGenShaderCount = (uint32_t)rayGenShaders.size(); |
| 198 | desc.rayGenShaderEntryPointNames = rayGenShaders.data(); |
| 199 | desc.missShaderCount = (uint32_t)missShaders.size(); |
| 200 | desc.missShaderEntryPointNames = missShaders.data(); |
| 201 | desc.hitGroupCount = (uint32_t)hitgroupShaders.size(); |
| 202 | desc.hitGroupNames = hitgroupShaders.data(); |
| 203 | desc.program = pRtso->getKernels()->getGfxProgram(); |
| 204 | if (SLANG_FAILED(mpDevice->getGfxDevice()->createShaderTable(desc, mpShaderTable.writeRef()))) |
| 205 | return false; |