Skip to content

Commit

Permalink
Split m_inOutCalls into m_inputCalls and m_outputCalls
Browse files Browse the repository at this point in the history
The input calls and output calls are required to be stored seperatedly
for future refactor and GS input/output packing.
  • Loading branch information
xuechen417 authored and JaxLinAMD committed Dec 3, 2020
1 parent 764ee20 commit 2a57f8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 12 additions & 12 deletions lgc/patch/PatchResourceCollect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,10 +1297,10 @@ void PatchResourceCollect::visitCallInst(CallInst &callInst) {
if (isPackIn && !m_hasDynIndexedInput && !isDeadCall &&
(mangledName.startswith(lgcName::InputImportGeneric) ||
mangledName.startswith(lgcName::InputImportInterpolant))) {
m_inOutCalls.push_back(&callInst);
m_inputCalls.push_back(&callInst);
} else if (isPackOut && mangledName.startswith(lgcName::OutputExportGeneric)) {
// Collect outputs of VS or TES
m_inOutCalls.push_back(&callInst);
m_outputCalls.push_back(&callInst);
m_deadCalls.push_back(&callInst);
}
}
Expand Down Expand Up @@ -2535,20 +2535,18 @@ void PatchResourceCollect::packInOutLocation() {
m_pipelineState->getShaderResourceUsage(nextStage)->inOutUsage.inputLocInfoMap;
}
}
// Clear it to hold previous calls
m_inOutCalls.clear();
}

// =====================================================================================================================
// Fill inputLocInfoMap based on FS or TCS input import calls
void PatchResourceCollect::fillInOutLocInfoMap() {
if (m_inOutCalls.empty())
if (m_inputCalls.empty())
return;

assert(m_shaderStage == ShaderStageFragment || m_shaderStage == ShaderStageTessControl);

// Create locationInfoMap according to the packed calls
m_locationInfoMapManager->createMap(m_inOutCalls, m_shaderStage);
m_locationInfoMapManager->createMap(m_inputCalls, m_shaderStage);

auto &inOutUsage = m_pipelineState->getShaderResourceUsage(m_shaderStage)->inOutUsage;
auto &inputLocInfoMap = inOutUsage.inputLocInfoMap;
Expand All @@ -2559,7 +2557,7 @@ void PatchResourceCollect::fillInOutLocInfoMap() {
// @llpc.input.import.interpolant.%Type%(i32 location, i32 locOffset, i32 elemIdx,
// i32 interpMode, <2 x float> | i32 auxInterpValue)
const bool isTcs = m_shaderStage == ShaderStageTessControl;
for (auto call : m_inOutCalls) {
for (auto call : m_inputCalls) {
const bool isInterpolant = !isTcs && call->getNumArgOperands() != 4;
unsigned locOffset = 0;
unsigned compIdxArgIdx = 1;
Expand All @@ -2580,16 +2578,17 @@ void PatchResourceCollect::fillInOutLocInfoMap() {
m_locationInfoMapManager->findMap(origLocInfo, mapIter);
inputLocInfoMap.insert({origLocInfo, mapIter->second});
}
m_inputCalls.clear();
}

// =====================================================================================================================
// Re-assemble output export functions based on the locationInfoMap
void PatchResourceCollect::reassembleOutputExportCalls() {
if (m_inOutCalls.empty())
if (m_outputCalls.empty())
return;

BuilderBase builder(*m_context);
builder.SetInsertPoint(m_inOutCalls.back());
builder.SetInsertPoint(m_outputCalls.back());

// ElementsInfo represents the info of composing a vector in a location
struct ElementsInfo {
Expand All @@ -2605,9 +2604,9 @@ void PatchResourceCollect::reassembleOutputExportCalls() {

// Collect ElementsInfo in each packed location
ElementsInfo elemsInfo = {{nullptr}, {nullptr}, 0, 0};
std::vector<ElementsInfo> elementsInfoArray(m_inOutCalls.size(), elemsInfo);
for (auto call : m_inOutCalls) {
InOutLocationInfo origLocInfo(0);
std::vector<ElementsInfo> elementsInfoArray(m_outputCalls.size(), elemsInfo);
for (auto call : m_outputCalls) {
InOutLocationInfo origLocInfo;
origLocInfo.setLocation(cast<ConstantInt>(call->getOperand(0))->getZExtValue());
origLocInfo.setComponent(cast<ConstantInt>(call->getOperand(1))->getZExtValue());

Expand Down Expand Up @@ -2642,6 +2641,7 @@ void PatchResourceCollect::reassembleOutputExportCalls() {
else
++elementsInfo.elemCountOf32bit;
}
m_outputCalls.clear();

// Re-assamble XX' output export calls for each packed location
Value *args[3] = {};
Expand Down
3 changes: 2 additions & 1 deletion lgc/patch/PatchResourceCollect.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class PatchResourceCollect : public Patch, public llvm::InstVisitor<PatchResourc
std::unordered_set<unsigned> m_importedOutputLocs; // Locations of imported generic outputs
std::unordered_set<unsigned> m_importedOutputBuiltIns; // IDs of imported built-in outputs

std::vector<llvm::CallInst *> m_inOutCalls; // The import or export calls
std::vector<llvm::CallInst *> m_inputCalls; // The scalarzied input import calls
std::vector<llvm::CallInst *> m_outputCalls; // The scalarized output export calls

bool m_hasDynIndexedInput; // Whether dynamic indices are used in generic input addressing (valid
// for tessellation shader, fragment shader with input interpolation)
Expand Down

0 comments on commit 2a57f8b

Please sign in to comment.