Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the use of descriptor set indices in the PAL metadata #497

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/vkgcDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ struct PipelineShaderOptions
/// Use the LLVM backend's SI scheduler instead of the default scheduler.
bool useSiScheduler;

// Whether update descriptor root offset in ELF
bool updateDescInElf;
/// Emit descriptor set indices instead of userdata table indices in the PAL userdata mapping metadata. For use with
/// pre-compilation: the userdata mapping must be adjusted later.
bool emitDescriptorSetIndexInMetadata;

#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION >= 35
/// Disable the the LLVM backend's LICM pass.
Expand Down
1 change: 1 addition & 0 deletions llpc/builder/llpcBuilderImplInOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "llpcBuilderImpl.h"
#include "llpcInternal.h"
#include "llpcPipelineState.h"
#include "llpcUtil.h"

#define DEBUG_TYPE "llpc-builder-impl-inout"

Expand Down
5 changes: 3 additions & 2 deletions llpc/builder/llpcPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ struct ShaderOptions
// Use the LLVM backend's SI scheduler instead of the default scheduler.
bool useSiScheduler;

// Whether update descriptor root offset in ELF
bool updateDescInElf;
/// Emit descriptor set indices instead of userdata table indices in the PAL userdata mapping metadata. For use with
/// pre-compilation: the userdata mapping must be adjusted later.
bool emitDescriptorSetIndexInMetadata;

/// Default unroll threshold for LLVM.
uint32_t unrollThreshold;
Expand Down
1 change: 1 addition & 0 deletions llpc/builder/llpcPipelineState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llpcPatch.h"
#include "llpcPipelineState.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Module.h"
Expand Down
4 changes: 2 additions & 2 deletions llpc/builder/llpcResourceUsage.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct FsInterpInfo
};

// Invalid interpolation info
static const FsInterpInfo InvalidFsInterpInfo = { InvalidValue, false, false, false };
static const FsInterpInfo InvalidFsInterpInfo = { ~0u, false, false, false };

// Enumerate the workgroup layout options.
enum class WorkgroupLayout : uint32_t
Expand Down Expand Up @@ -453,7 +453,7 @@ struct InterfaceData
static const uint32_t MaxEsGsOffsetCount = 6;
static const uint32_t MaxCsUserDataCount = 10;
static const uint32_t CsStartUserData = 2;
static const uint32_t UserDataUnmapped = InvalidValue;
static const uint32_t UserDataUnmapped = ~0u;

uint32_t userDataCount; // User data count
uint32_t userDataMap[MaxUserDataCount]; // User data map (from SGPR No. to API logical ID)
Expand Down
27 changes: 3 additions & 24 deletions llpc/context/llpcCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,14 +1270,6 @@ Result Compiler::BuildPipelineInternal(
graphicsShaderCacheChecker.UpdateAndMerge(result, pPipelineElf);
}

if ((result == Result::Success) &&
pFragmentShaderInfo &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: pFragmentShaderInfo isn't used any more, so you can remove it together.

pFragmentShaderInfo->options.updateDescInElf &&
(pContext->GetShaderStageMask() & ShaderStageToMask(ShaderStageFragment)))
{
graphicsShaderCacheChecker.UpdateRootUserDateOffset(pPipelineElf);
}

pContext->setDiagnosticHandlerCallBack(nullptr);

return result;
Expand Down Expand Up @@ -1334,19 +1326,6 @@ uint32_t GraphicsShaderCacheChecker::Check(
return stageMask;
}

// =====================================================================================================================
// Update root level descriptor offset for graphics pipeline.
void GraphicsShaderCacheChecker::UpdateRootUserDateOffset(
ElfPackage* pPipelineElf) // [In, Out] ELF that could be from compile or merged
{
ElfWriter<Elf64> writer(m_pContext->GetGfxIpVersion());
// Load ELF binary
auto result = writer.ReadFromBuffer(pPipelineElf->data(), pPipelineElf->size());
assert(result == Result::Success);
(void(result)); // unused
writer.UpdateElfBinary(m_pContext, pPipelineElf);
}

// =====================================================================================================================
// Update shader caches for graphics pipeline from compile result, and merge ELF outputs if necessary.
void GraphicsShaderCacheChecker::UpdateAndMerge(
Expand All @@ -1371,7 +1350,7 @@ void GraphicsShaderCacheChecker::UpdateAndMerge(
auto result = writer.ReadFromBuffer(nonFragmentPipelineElf.pCode, nonFragmentPipelineElf.codeSize);
assert(result == Result::Success);
(void(result)); // unused
writer.MergeElfBinary(m_pContext, &m_fragmentElf, pPipelineElf);
writer.MergeFragmentShader(m_pContext, &m_fragmentElf, pPipelineElf);

pipelineElf.codeSize = pPipelineElf->size();
pipelineElf.pCode = pPipelineElf->data();
Expand Down Expand Up @@ -1400,7 +1379,7 @@ void GraphicsShaderCacheChecker::UpdateAndMerge(
assert(result == Result::Success);
(void(result)); // unused

writer.MergeElfBinary(m_pContext, &fragmentPipelineElf, pPipelineElf);
writer.MergeFragmentShader(m_pContext, &fragmentPipelineElf, pPipelineElf);

pipelineElf.codeSize = pPipelineElf->size();
pipelineElf.pCode = pPipelineElf->data();
Expand All @@ -1419,7 +1398,7 @@ void GraphicsShaderCacheChecker::UpdateAndMerge(
auto result = writer.ReadFromBuffer(m_nonFragmentElf.pCode, m_nonFragmentElf.codeSize);
assert(result == Result::Success);
(void(result)); // unused
writer.MergeElfBinary(m_pContext, &m_fragmentElf, pPipelineElf);
writer.MergeFragmentShader(m_pContext, &m_fragmentElf, pPipelineElf);
}

// Whole pipeline is compiled
Expand Down
1 change: 0 additions & 1 deletion llpc/context/llpcCompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class GraphicsShaderCacheChecker

// Update shader caches with results of compile, and merge ELF outputs if necessary.
void UpdateAndMerge(Result result, ElfPackage* pPipelineElf);
void UpdateRootUserDateOffset(ElfPackage* pPipelineElf);

private:
Compiler* m_pCompiler;
Expand Down
2 changes: 1 addition & 1 deletion llpc/context/llpcPipelineContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void PipelineContext::SetOptionsInPipeline(
#endif

shaderOptions.useSiScheduler = EnableSiScheduler || pShaderInfo->options.useSiScheduler;
shaderOptions.updateDescInElf = pShaderInfo->options.updateDescInElf;
shaderOptions.emitDescriptorSetIndexInMetadata = pShaderInfo->options.emitDescriptorSetIndexInMetadata;
shaderOptions.unrollThreshold = pShaderInfo->options.unrollThreshold;

pPipeline->SetShaderOptions(static_cast<ShaderStage>(stage), shaderOptions);
Expand Down
3 changes: 2 additions & 1 deletion llpc/patch/gfx6/chip/llpcGfx6ConfigBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "llpcGfx6ConfigBuilder.h"
#include "llpcPipelineState.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"
#include "llvm/Support/CommandLine.h"

#define DEBUG_TYPE "llpc-gfx6-config-builder"
Expand Down Expand Up @@ -1391,7 +1392,7 @@ void ConfigBuilder::BuildUserDataConfig(
if (pIntfData->userDataMap[i] != InterfaceData::UserDataUnmapped)
{
AppendConfig(startUserData + i, pIntfData->userDataMap[i]);
if ((pIntfData->userDataMap[i] & DescRelocMagicMask) != DescRelocMagic)
if (pIntfData->userDataMap[i] < VkDescriptorSetIndexLow)
{
userDataLimit = std::max(userDataLimit, pIntfData->userDataMap[i] + 1);
}
Expand Down
3 changes: 2 additions & 1 deletion llpc/patch/gfx9/chip/llpcGfx9ConfigBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "llpcGfx9ConfigBuilder.h"
#include "llpcPipelineState.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"
#include "llvm/Support/CommandLine.h"

#define DEBUG_TYPE "llpc-gfx9-config-builder"
Expand Down Expand Up @@ -2839,7 +2840,7 @@ void ConfigBuilder::BuildUserDataConfig(
if (pIntfData1->userDataMap[i] != InterfaceData::UserDataUnmapped)
{
AppendConfig(startUserData + i, pIntfData1->userDataMap[i]);
if ((pIntfData1->userDataMap[i] & DescRelocMagicMask) != DescRelocMagic)
if (pIntfData1->userDataMap[i] < VkDescriptorSetIndexLow)
{
userDataLimit = std::max(userDataLimit, pIntfData1->userDataMap[i] + 1);
}
Expand Down
1 change: 1 addition & 0 deletions llpc/patch/gfx9/llpcNggLdsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "llvm/IR/IRBuilder.h"

#include "llpcInternal.h"
#include "llpcUtil.h"

namespace Llpc
{
Expand Down
1 change: 1 addition & 0 deletions llpc/patch/llpcPatchCopyShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "llpcPipelineShaders.h"
#include "llpcPipelineState.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"

#define DEBUG_TYPE "llpc-patch-copy-shader"

Expand Down
1 change: 1 addition & 0 deletions llpc/patch/llpcPatchDescriptorLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "llpcPatchDescriptorLoad.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"

#define DEBUG_TYPE "llpc-patch-descriptor-load"

Expand Down
13 changes: 8 additions & 5 deletions llpc/patch/llpcPatchEntryPointMutate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "llpcPatchEntryPointMutate.h"
#include "llpcPipelineShaders.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"

#define DEBUG_TYPE "llpc-patch-entry-point-mutate"

Expand Down Expand Up @@ -674,15 +675,17 @@ FunctionType* PatchEntryPointMutate::GenerateEntryPointType(
assert(pNode->sizeInDwords == 1);

auto pShaderOptions = &m_pPipelineState->GetShaderOptions(m_shaderStage);
if (pShaderOptions->updateDescInElf && (m_shaderStage == ShaderStageFragment))
if (pShaderOptions->emitDescriptorSetIndexInMetadata && (m_shaderStage == ShaderStageFragment))
{
// Put set number to register first, will update offset after merge ELFs
// For partial pipeline compile, only fragment shader needs to adjust offset of root descriptor
// If there are more individual shader compile in future, we can add more stages here
pIntfData->userDataMap[userDataIdx] = DescRelocMagic | pNode->innerTable[0].set;
// Record the descriptor set index into the mapping now instead of. This is used during partial
// pipeline compile, when the final offset of descriptor set VA pointers within the PAL
// userdata table are not yet known.
assert(pNode->innerTable[0].set <= VkDescriptorSetIndexHigh - VkDescriptorSetIndexLow);
pIntfData->userDataMap[userDataIdx] = VkDescriptorSetIndexLow + pNode->innerTable[0].set;
}
else
{
// Record the offset into the PAL userdata table.
pIntfData->userDataMap[userDataIdx] = pNode->offsetInDwords;
}

Expand Down
1 change: 1 addition & 0 deletions llpc/patch/llpcPatchInOutImportExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "llpcPatchInOutImportExport.h"
#include "llpcPipelineShaders.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"
#include "llpcVertexFetch.h"

#define DEBUG_TYPE "llpc-patch-in-out-import-export"
Expand Down
1 change: 1 addition & 0 deletions llpc/patch/llpcPatchNullFragShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "llpcInternal.h"
#include "llpcPatch.h"
#include "llpcPipelineState.h"
#include "llpcUtil.h"

#define DEBUG_TYPE "llpc-patch-null-frag-shader"

Expand Down
1 change: 1 addition & 0 deletions llpc/patch/llpcPatchPushConstOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llpcPatchPushConstOp.h"
#include "llpcPipelineShaders.h"
#include "llpcPipelineState.h"
#include "llpcUtil.h"

#define DEBUG_TYPE "llpc-patch-push-const"

Expand Down
1 change: 1 addition & 0 deletions llpc/patch/llpcSystemValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "llpcPipelineState.h"
#include "llpcSystemValues.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"

#define DEBUG_TYPE "llpc-system-values"

Expand Down
1 change: 1 addition & 0 deletions llpc/patch/llpcVertexFetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "llpcPipelineState.h"
#include "llpcSystemValues.h"
#include "llpcTargetInfo.h"
#include "llpcUtil.h"
#include "llpcVertexFetch.h"

#define DEBUG_TYPE "llpc-vertex-fetch"
Expand Down
2 changes: 1 addition & 1 deletion llpc/tool/vfx/vfxSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ class SectionShaderOption : public Section

INIT_STATE_MEMBER_NAME_TO_ADDR(SectionShaderOption, forceLoopUnrollCount, MemberTypeInt, false);
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionShaderOption, useSiScheduler, MemberTypeBool, false);
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionShaderOption, updateDescInElf, MemberTypeBool, false);
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionShaderOption, emitDescriptorSetIndexInMetadata, MemberTypeBool, false);
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionShaderOption, allowVaryWaveSize, MemberTypeBool, false);
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION >= 33
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionShaderOption, enableLoadScalarizer, MemberTypeBool, false);
Expand Down
Loading