Skip to content

Commit

Permalink
Decouple primitive generated query from xfb
Browse files Browse the repository at this point in the history
The query for primitive generated (pgq) is independent of transform
feedback workflow. This PR aims to decouple pgq from xfb by taking pgq
as a pipeline option.
- Add a new interface `PipelineOptions::enablePrimGeneratedQuery`.
- Guard the old interface `ApiXfbOutData::forceEnablePrimStats` with
  llpc version.
  • Loading branch information
xuechen417 committed Sep 19, 2023
1 parent 7aa4658 commit 7ebe376
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
8 changes: 6 additions & 2 deletions include/vkgcDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#endif

/// LLPC major interface version.
#define LLPC_INTERFACE_MAJOR_VERSION 66
#define LLPC_INTERFACE_MAJOR_VERSION 69

/// LLPC minor interface version.
#define LLPC_INTERFACE_MINOR_VERSION 1
Expand Down Expand Up @@ -80,6 +80,7 @@
// %Version History
// | %Version | Change Description |
// | -------- | ----------------------------------------------------------------------------------------------------- |
// | 69.0 | Add enablePrimGeneratedQuery to PipelineOptions |
// | 66.1 | Add forwardPropagateNoContract and backwardPropagateNoContract to PipelineShaderOptions |
// | 66.0 | Rename noContract in PipelineShaderOptions to noContractOpDot |
// | 65.1 | Add disableSampleMask to PipelineOptions |
Expand Down Expand Up @@ -594,6 +595,7 @@ struct PipelineOptions {
bool enableCombinedTexture; ///< For OGL only, use the 'set' for DescriptorCombinedTexture
///< for sampled images and samplers
bool vertex64BitsAttribSingleLoc; ///< For OGL only, dvec3/dvec4 vertex attrib only consumes 1 location.
bool enablePrimGeneratedQuery; ///< If set, primitive generated query is enabled
};

/// Prototype of allocator for output data buffer, used in shader-specific operations.
Expand Down Expand Up @@ -1210,7 +1212,9 @@ struct ApiXfbOutData {
XfbOutInfo *pXfbOutInfos; ///< An array of XfbOutInfo iterms
unsigned numXfbOutInfo; ///< Count of XfbOutInfo iterms
bool forceDisableStreamOut; ///< Force to disable stream out XFB outputs
bool forceEnablePrimStats; ///< Force to enable counting generated primitives
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION < 69
bool forceEnablePrimStats; ///< Force to enable counting generated primitives
#endif
};

/// Represents the tessellation level passed from driver API
Expand Down
3 changes: 2 additions & 1 deletion lgc/include/lgc/state/PipelineState.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ class PipelineState final : public Pipeline {
bool enableXfb() const { return m_xfbStateMetadata.enableXfb; }

// Check if we need count primitives if XFB is disabled
bool enablePrimStats() const { return m_xfbStateMetadata.enablePrimStats; }
// NOTE: The old interface m_xfbStateMetadata.enablePrimStats will be removed later
bool enablePrimStats() const { return m_options.enablePrimGeneratedQuery || m_xfbStateMetadata.enablePrimStats; }

// Get transform feedback strides
const std::array<unsigned, MaxTransformFeedbackBuffers> &getXfbBufferStrides() const {
Expand Down
1 change: 1 addition & 0 deletions lgc/interface/lgc/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ union Options {
bool disableSampleMask; // Disable export of sample mask from PS
bool reserved20;
RayTracingIndirectMode rtIndirectMode; // Ray tracing indirect mode
bool enablePrimGeneratedQuery; // Whether to enable primitive generated counter
};
};
static_assert(sizeof(Options) == sizeof(Options::u32All));
Expand Down
1 change: 1 addition & 0 deletions llpc/context/llpcPipelineContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ Options PipelineContext::computePipelineOptions() const {
options.internalRtShaders = getPipelineOptions()->internalRtShaders;
options.disableSampleMask = getPipelineOptions()->disableSampleMask;
options.disableTruncCoordForGather = getPipelineOptions()->disableTruncCoordForGather;
options.enablePrimGeneratedQuery = getPipelineOptions()->enablePrimGeneratedQuery;

return options;
}
Expand Down
7 changes: 5 additions & 2 deletions llpc/translator/lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9651,8 +9651,11 @@ void SPIRVToLLVM::insertScratchBoundsChecks(SPIRVValue *memOp, const ScratchBoun
void SPIRVToLLVM::createXfbMetadata(bool hasXfbOuts) {
auto llpcContext = static_cast<Llpc::Context *>(m_context);
auto pipelineBuildInfo = static_cast<const Vkgc::GraphicsPipelineBuildInfo *>(llpcContext->getPipelineBuildInfo());
const bool needXfbMetadata = (hasXfbOuts && !pipelineBuildInfo->apiXfbOutData.forceDisableStreamOut) ||
pipelineBuildInfo->apiXfbOutData.forceEnablePrimStats;
bool needXfbMetadata = hasXfbOuts && !pipelineBuildInfo->apiXfbOutData.forceDisableStreamOut;
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION < 69
needXfbMetadata |= pipelineBuildInfo->apiXfbOutData.forceEnablePrimStats;
#endif

if (!needXfbMetadata)
return;

Expand Down
6 changes: 6 additions & 0 deletions tool/dumper/vkgcPipelineDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ void PipelineDumper::dumpPipelineOptions(const PipelineOptions *options, std::os
dumpFile << "options.buildResourcesDataForShaderModule = " << options->buildResourcesDataForShaderModule << "\n";
dumpFile << "options.disableTruncCoordForGather = " << options->disableTruncCoordForGather << "\n";
dumpFile << "options.vertex64BitsAttribSingleLoc = " << options->vertex64BitsAttribSingleLoc << "\n";
dumpFile << "options.enablePrimGeneratedQuery = " << options->enablePrimGeneratedQuery << "\n";
}

// =====================================================================================================================
Expand Down Expand Up @@ -1017,7 +1018,9 @@ void PipelineDumper::dumpGraphicsStateInfo(const GraphicsPipelineBuildInfo *pipe

dumpFile << "\n[ApiXfbOutInfo]\n";
dumpFile << "forceDisableStreamOut = " << pipelineInfo->apiXfbOutData.forceDisableStreamOut << "\n";
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION < 69
dumpFile << "forceEnablePrimStats = " << pipelineInfo->apiXfbOutData.forceEnablePrimStats << "\n";
#endif
const auto pXfbOutInfos = pipelineInfo->apiXfbOutData.pXfbOutInfos;
for (unsigned idx = 0; idx < pipelineInfo->apiXfbOutData.numXfbOutInfo; ++idx) {
dumpFile << "xfbOutInfo[" << idx << "].isBuiltIn = " << pXfbOutInfos[idx].isBuiltIn << "\n";
Expand Down Expand Up @@ -1567,7 +1570,9 @@ void PipelineDumper::updateHashForNonFragmentState(const GraphicsPipelineBuildIn
}

hasher->Update(pipeline->apiXfbOutData.forceDisableStreamOut);
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION < 69
hasher->Update(pipeline->apiXfbOutData.forceEnablePrimStats);
#endif
}

// =====================================================================================================================
Expand Down Expand Up @@ -1654,6 +1659,7 @@ void PipelineDumper::updateHashForPipelineOptions(const PipelineOptions *options
hasher->Update(options->forceNonUniformResourceIndexStageMask);
hasher->Update(options->replaceSetWithResourceType);
hasher->Update(options->disableTruncCoordForGather);
hasher->Update(options->enablePrimGeneratedQuery);
}

// =====================================================================================================================
Expand Down
3 changes: 3 additions & 0 deletions tool/vfx/vfxVkSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ class SectionPipelineOption : public Section {
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionPipelineOption, buildResourcesDataForShaderModule, MemberTypeBool, false);
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionPipelineOption, disableTruncCoordForGather, MemberTypeBool, false);
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionPipelineOption, vertex64BitsAttribSingleLoc, MemberTypeBool, false);
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionPipelineOption, enablePrimGeneratedQuery, MemberTypeBool, false);
return addrTableInitializer;
}();
return {addrTable.data(), addrTable.size()};
Expand Down Expand Up @@ -1033,7 +1034,9 @@ class SectionApiXfbOutput : public Section {
static std::vector<StrToMemberAddr> addrTable = []() {
std::vector<StrToMemberAddr> addrTableInitializer;
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionApiXfbOutput, forceDisableStreamOut, MemberTypeBool, false);
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION < 69
INIT_STATE_MEMBER_NAME_TO_ADDR(SectionApiXfbOutput, forceEnablePrimStats, MemberTypeBool, false);
#endif
INIT_MEMBER_DYNARRAY_NAME_TO_ADDR(SectionApiXfbOutput, m_xfbOutInfo, MemberTypeXfbOutInfo, true);
return addrTableInitializer;
}();
Expand Down

0 comments on commit 7ebe376

Please sign in to comment.