diff options
| author | Yong He <yonghe@outlook.com> | 2023-06-28 16:09:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-28 16:09:06 -0700 |
| commit | b45e5aa07cf5e2e0bd23cf4c14bb40104b0b641c (patch) | |
| tree | 52477da6fb0c75fd4e424a68850fdb703006f153 /source/slang/slang-ir-glsl-legalize.cpp | |
| parent | 97963c5c119a3445fa6353809669d4553952e66c (diff) | |
Fix parameter block loads in GLSL emit. (#2946)
* Fix parameter block loads in GLSL emit.
* Revert `[NoSideEffect]` declarations in DXR1.1 API.
* fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-glsl-legalize.cpp')
| -rw-r--r-- | source/slang/slang-ir-glsl-legalize.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index f02360416..216471d65 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -2778,4 +2778,48 @@ void legalizeEntryPointsForGLSL( } } +void legalizeConstantBufferLoadForGLSL(IRModule* module) +{ + // Constant buffers and parameter blocks are represented as `uniform` blocks + // in GLSL. These uniform blocks can't be used directly as a value of the underlying + // struct type. If we see a direct load of the constant buffer pointer, + // we need to replace it with a `MakeStruct` inst where each field is separately + // loaded. + IRBuilder builder(module); + for (auto globalInst : module->getGlobalInsts()) + { + if (auto func = as<IRGlobalValueWithCode>(globalInst)) + { + for (auto block : func->getBlocks()) + { + for (auto inst = block->getFirstInst(); inst;) + { + auto load = as<IRLoad>(inst); + inst = inst->next; + if (!load) continue; + auto bufferType = load->getPtr()->getDataType(); + if (as<IRConstantBufferType>(bufferType) || as<IRParameterBlockType>(bufferType)) + { + auto parameterGroupType = as<IRUniformParameterGroupType>(bufferType); + auto elementType = as<IRStructType>(parameterGroupType->getElementType()); + if (!elementType) continue; + List<IRInst*> elements; + builder.setInsertBefore(load); + for (auto field : elementType->getFields()) + { + auto fieldAddr = builder.emitFieldAddress(field->getFieldType(), load->getPtr(), field->getKey()); + auto fieldValue = builder.emitLoad(field->getFieldType(), fieldAddr); + elements.add(fieldValue); + } + auto makeStruct = builder.emitMakeStruct(elementType, elements.getCount(), elements.getBuffer()); + load->replaceUsesWith(makeStruct); + load->removeAndDeallocate(); + } + } + } + } + } +} + + } // namespace Slang |
