diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-cuda.cpp | 4 | ||||
| -rw-r--r-- | source/slang/slang-ir-optix-entry-point-uniforms.cpp | 16 |
2 files changed, 11 insertions, 9 deletions
diff --git a/source/slang/slang-emit-cuda.cpp b/source/slang/slang-emit-cuda.cpp index 61d51cbda..27eb75d34 100644 --- a/source/slang/slang-emit-cuda.cpp +++ b/source/slang/slang-emit-cuda.cpp @@ -813,9 +813,9 @@ bool CUDASourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu } case kIROp_GetOptiXSbtDataPtr: { - m_writer->emit("(*(("); + m_writer->emit("(("); emitType(inst->getDataType()); - m_writer->emit(")optixGetSbtDataPointer()))"); + m_writer->emit(")optixGetSbtDataPointer())"); return true; } default: break; diff --git a/source/slang/slang-ir-optix-entry-point-uniforms.cpp b/source/slang/slang-ir-optix-entry-point-uniforms.cpp index b26af3e16..0ec8e3adb 100644 --- a/source/slang/slang-ir-optix-entry-point-uniforms.cpp +++ b/source/slang/slang-ir-optix-entry-point-uniforms.cpp @@ -234,15 +234,16 @@ struct CollectOptixEntryPointUniformParams : PerEntryPointPass { // IRInst* fieldVal = nullptr; - // Note: for an optix SBT pointer, we can't dereference - // optixGetSbtDataPointer() like builder->emitFieldAddress requires. - // (thus, this code differs from slang-ir-entry-point-uniforms.cpp) - // Instead, we always use emitFieldExtract, and then the SBT instruction - // emits a C-style cast to the appropriate struct type. - fieldVal = builder->emitFieldExtract( - paramType, + // A constant buffer behaves like a pointer + // at the IR level, so we first do a pointer + // offset operation to compute what amounts + // to `&cb->field`, and then load from that address. + // + auto fieldAddress = builder->emitFieldAddress( + builder->getPtrType(paramType), collectedParam, paramFieldKey); + fieldVal = builder->emitLoad(fieldAddress); // We replace the value used at this use site, which // will have a side effect of making `use` no longer @@ -270,6 +271,7 @@ struct CollectOptixEntryPointUniformParams : PerEntryPointPass { // Now, replace the collected parameter with OptiX SBT accesses. auto paramType = collectedParam->getFullType(); + builder->setInsertBefore(entryPointFunc->getFirstBlock()->getFirstOrdinaryInst()); IRInst* getAttr = builder->emitIntrinsicInst(paramType, kIROp_GetOptiXSbtDataPtr, 0, nullptr); collectedParam->replaceUsesWith(getAttr); collectedParam->removeAndDeallocate(); |
