https://github.com/shader-slang/slang
Tip revision: 5902acdabc4445a65741a7a6a3a95f223e301059 authored by Yong He on 23 January 2024, 07:19:40 UTC
[LSP] Fetch configs directly from didConfigurationChanged message. (#3478)
[LSP] Fetch configs directly from didConfigurationChanged message. (#3478)
Tip revision: 5902acd
slang-ir-legalize-uniform-buffer-load.cpp
#include "slang-ir-legalize-uniform-buffer-load.h"
namespace Slang
{
void legalizeUniformBufferLoad(IRModule* module)
{
List<IRLoad*> workList;
for (auto globalInst : module->getGlobalInsts())
{
if (auto func = as<IRGlobalValueWithCode>(globalInst))
{
for (auto block : func->getBlocks())
{
for (auto inst : block->getChildren())
{
if (auto load = as<IRLoad>(inst))
{
auto uniformBufferType = as<IRConstantBufferType>(load->getPtr()->getDataType());
if (!uniformBufferType)
continue;
workList.add(load);
}
}
}
}
}
IRBuilder builder(module);
for (auto load : workList)
{
auto uniformBufferType = as<IRConstantBufferType>(load->getPtr()->getDataType());
SLANG_ASSERT(uniformBufferType);
auto structType = as<IRStructType>(uniformBufferType->getElementType());
if (!structType)
continue;
builder.setInsertBefore(load);
List<IRInst*> fieldLoads;
for (auto field : structType->getFields())
{
auto fieldAddr = builder.emitFieldAddress(
builder.getPtrType(field->getFieldType()), load->getPtr(), field->getKey());
auto fieldLoad = builder.emitLoad(fieldAddr);
fieldLoads.add(fieldLoad);
}
auto makeStruct = builder.emitMakeStruct(structType, fieldLoads);
load->replaceUsesWith(makeStruct);
}
}
}