Skip to content

Commit

Permalink
Update llpc from commit 9570efcc (#2776)
Browse files Browse the repository at this point in the history
* [Continuations] Fix tablegen in cmake
* Fix unstable barycentric
* Fix the OpDPdy
* Add the missing symbol usage information in ShaderModule
* [Continuations] Rewrite continuation stack lowering in CleanupContinuations
* Remove unnecessary buffer coherency settings
* [Continuations] Use lgc.rt.shaderstage metadata instead of analyzeShaderKinds
* Fix a type mismatch in reserved field
* Fix the dir create name error.
* Fix integer alpha
* Fix dbShaderControl for color export shader
* Disable uber-fetch lit test
* llpcfe dxil: Fix some arithmetic instruction failure in HLK
* [Continuations] Clear payload with poison
* [Continuations] Replace lgc.rt.shader.index calls.
* [Continuations] Insert lgc.cps.jump and lgc.cps.await operations in LowerRaytracingPipelinePass.
* [Continuations] Enable Continuations transform in LLPC
* [Continuations] lgc/cps: use a backend-friendlier lowering of as.continuation.reference
* lgc: add a buffer flag to convert dx buffer descritpor for oob
* Add support for SPV_KHR_float_controls2
* [Continuations] Lower GetCurrentFuncAddr and GetShaderKind in lgc
* [Continuations] Merge the lgc.* dialects into the Continuations CMake project.
* Disable CPS failing lit test
* Re-enable raytracing tests
* Bump CMake minimum version to 3.21
* [ContinuationsUtil]- Remove Operations.h header
  • Loading branch information
chuang13 authored Oct 24, 2023
1 parent a0ffb64 commit 4d8954d
Show file tree
Hide file tree
Showing 128 changed files with 2,378 additions and 1,147 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
#######################################################################################################################

cmake_minimum_required(VERSION 3.13.4)
cmake_minimum_required(VERSION 3.21)

project(VKGC LANGUAGES C CXX)

Expand Down Expand Up @@ -206,7 +206,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
endif()
set_property(TARGET check-amdllpc PROPERTY FOLDER "LLPC Tests")
set_property(TARGET check-amdllpc-units PROPERTY FOLDER "LLPC Tests")
set_property(TARGET check-lgccps-units PROPERTY FOLDER "LgcCps Tests")
set_property(TARGET check-continuations PROPERTY FOLDER "Continuations Tests")
set_property(TARGET check-continuations-units PROPERTY FOLDER "Continuations Tests")
set_property(TARGET check-lgc-units PROPERTY FOLDER "LGC Tests")
endif()
endif()
Expand Down
19 changes: 8 additions & 11 deletions cmake/continuations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@

set(LLPC_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")

# Function to add continuations and its dependencies as LLVM external projects.
# Macro to add continuations and its dependencies as LLVM external projects.
# This appends the project names to LLVM_EXTERNAL_PROJECTS and sets each LLVM_EXTERNAL_*_SOURCE_DIR,
# all in the caller's scope.
function(add_continuations_projects)
if (NOT "${LLVM_EXTERNAL_CONTINUATIONS_SOURCE_DIR}")
if (NOT "${LLVM_EXTERNAL_LLVM_DIALECTS_SOURCE_DIR}")
macro(add_continuations_projects)
if (NOT continuations IN_LIST LLVM_EXTERNAL_PROJECTS)
if (NOT llvm_dialects IN_LIST LLVM_EXTERNAL_PROJECTS)
list(APPEND LLVM_EXTERNAL_PROJECTS llvm_dialects)
set(LLVM_EXTERNAL_LLVM_DIALECTS_SOURCE_DIR "${LLPC_SOURCE_DIR}/imported/llvm-dialects" PARENT_SCOPE)
set(LLVM_EXTERNAL_LLVM_DIALECTS_SOURCE_DIR "${LLPC_SOURCE_DIR}/imported/llvm-dialects")
endif()
list(APPEND LLVM_EXTERNAL_PROJECTS lgccps lgcrt continuations)
set(LLVM_EXTERNAL_CONTINUATIONS_SOURCE_DIR "${LLPC_SOURCE_DIR}/shared/continuations" PARENT_SCOPE)
set(LLVM_EXTERNAL_LGCRT_SOURCE_DIR "${LLPC_SOURCE_DIR}/shared/lgcrt" PARENT_SCOPE)
set(LLVM_EXTERNAL_LGCCPS_SOURCE_DIR "${LLPC_SOURCE_DIR}/shared/lgccps" PARENT_SCOPE)
set(LLVM_EXTERNAL_PROJECTS "${LLVM_EXTERNAL_PROJECTS}" PARENT_SCOPE)
list(APPEND LLVM_EXTERNAL_PROJECTS Continuations)
set(LLVM_EXTERNAL_CONTINUATIONS_SOURCE_DIR "${LLPC_SOURCE_DIR}/shared/continuations")
endif()
endfunction()
endmacro()
23 changes: 11 additions & 12 deletions cmake/lgc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@

set(LLPC_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")

# Function to add LGC and its dependencies as LLVM external projects.
include("${LLPC_SOURCE_DIR}/cmake/continuations.cmake")

# Macro to add LGC and its dependencies as LLVM external projects.
# This appends the project names to LLVM_EXTERNAL_PROJECTS and sets each LLVM_EXTERNAL_*_SOURCE_DIR,
# all in the caller's scope.
function(add_lgc_projects)
if (NOT "${LLVM_EXTERNAL_LGC_SOURCE_DIR}")
if (NOT "${LLVM_EXTERNAL_LLVM_DIALECTS_SOURCE_DIR}")
macro(add_lgc_projects)
add_continuations_projects()
if (NOT lgc IN_LIST LLVM_EXTERNAL_PROJECTS)
if (NOT llvm_dialects IN_LIST LLVM_EXTERNAL_PROJECTS)
list(APPEND LLVM_EXTERNAL_PROJECTS llvm_dialects)
set(LLVM_EXTERNAL_LLVM_DIALECTS_SOURCE_DIR "${LLPC_SOURCE_DIR}/imported/llvm-dialects" PARENT_SCOPE)
set(LLVM_EXTERNAL_LLVM_DIALECTS_SOURCE_DIR "${LLPC_SOURCE_DIR}/imported/llvm-dialects")
endif()
list(APPEND LLVM_EXTERNAL_PROJECTS LgcCps LgcRt Continuations lgc)
set(LLVM_EXTERNAL_PROJECTS "${LLVM_EXTERNAL_PROJECTS}" PARENT_SCOPE)
set(LLVM_EXTERNAL_LGCCPS_SOURCE_DIR "${LLPC_SOURCE_DIR}/shared/lgccps" PARENT_SCOPE)
set(LLVM_EXTERNAL_LGCRT_SOURCE_DIR "${LLPC_SOURCE_DIR}/shared/lgcrt" PARENT_SCOPE)
set(LLVM_EXTERNAL_CONTINUATIONS_SOURCE_DIR "${LLPC_SOURCE_DIR}/shared/continuations" PARENT_SCOPE)
set(LLVM_EXTERNAL_LGC_SOURCE_DIR "${LLPC_SOURCE_DIR}/lgc" PARENT_SCOPE)
list(APPEND LLVM_EXTERNAL_PROJECTS lgc)
set(LLVM_EXTERNAL_LGC_SOURCE_DIR "${LLPC_SOURCE_DIR}/lgc")
endif()
endfunction()
endmacro()
23 changes: 17 additions & 6 deletions include/vkgcDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#define LLPC_INTERFACE_MAJOR_VERSION 69

/// LLPC minor interface version.
#define LLPC_INTERFACE_MINOR_VERSION 0
#define LLPC_INTERFACE_MINOR_VERSION 2

#ifndef LLPC_CLIENT_INTERFACE_MAJOR_VERSION
#error LLPC client version is not defined
Expand Down Expand Up @@ -80,7 +80,9 @@
// %Version History
// | %Version | Change Description |
// | -------- | ----------------------------------------------------------------------------------------------------- |
// | 69.0 | Add enablePrimGeneratedQuery to PipelineOptions |
// | 69.2 | Add enablePrimGeneratedQuery to PipelineOptions |
// | 69.1 | Add useBarycentric to ShaderModuleUsage |
// | 69.0 | Enable continuations transform in LLPC |
// | 68.0 | Remove ICache *cache in all PipelineBuildInfo |
// | 67.0 | Modify the uber fetch shader. Adds locationMask(64bit) at the beginning of uber fetch shader internal |
// | | buffer which flags whether the related attribute data is valid. |
Expand Down Expand Up @@ -686,6 +688,11 @@ struct ShaderModuleUsage {
bool pixelCenterInteger; ///< Whether pixel coord is Integer
bool useGenericBuiltIn; ///< Whether to use builtIn inputs that include gl_PointCoord, gl_PrimitiveId,
/// gl_Layer, gl_ClipDistance or gl_CullDistance.
bool enableXfb; ///< Whether transform feedback is enabled
unsigned localSizeX; ///< Compute shader work-group size in the X dimension
unsigned localSizeY; ///< Compute shader work-group size in the Y dimension
unsigned localSizeZ; ///< Compute shader work-group size in the Z dimension
bool useBarycentric; ///< Whether to use gl_BarycentricXX or pervertexEXT decoration
};

/// Represents common part of shader module data
Expand Down Expand Up @@ -862,7 +869,7 @@ struct PipelineShaderOptions {
/// Threshold to use for loops with "DontUnroll" hint (0 = use llvm.loop.unroll.disable).
unsigned dontUnrollHintThreshold;

/// Whether fastmath contract could be disabled on Dot operations.
/// Whether fast math contract could be disabled on Dot operations.
bool noContractOpDot;

/// The enabled fast math flags (0 = depends on input language).
Expand Down Expand Up @@ -1170,9 +1177,13 @@ enum DispatchDimSwizzleMode : unsigned {
};

enum class LlpcRaytracingMode : unsigned {
None = 0, // Not goto any raytracing compiling path
Legacy, // LLpc Legacy compiling path
Gpurt2, // Raytracing lowering at the end of spirvLower.
None = 0, // Not goto any raytracing compiling path
Legacy, // LLpc Legacy compiling path
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION < 69
Gpurt2, // Raytracing lowering at the end of spirvLower.
#else
Continufy, // Enable continuation with the continufy path.
#endif
Continuations, // Enable continuation in the new raytracing path
};

Expand Down
13 changes: 2 additions & 11 deletions lgc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ add_llvm_library(LLVMlgc LINK_COMPONENTS
Vectorize
)

target_link_libraries(LLVMlgc PUBLIC llvm_dialects)
target_link_libraries(LLVMlgc PUBLIC LLVMContinuations)

### Cached Project Options #############################################################################################
option(LLPC_BUILD_NAVI12 "LLPC support for NAVI12?" ON)
Expand Down Expand Up @@ -91,14 +91,6 @@ tablegen(LGC state/LgcDialect.cpp.inc -gen-dialect-defs --dialect lgc
EXTRA_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../imported/llvm-dialects/include
)

set(LLVM_TARGET_DEFINITIONS interface/lgc/GpurtDialect.td)
tablegen(LGC interface/lgc/GpurtDialect.h.inc -gen-dialect-decls --dialect lgc.gpurt
EXTRA_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../imported/llvm-dialects/include
)
tablegen(LGC state/GpurtDialect.cpp.inc -gen-dialect-defs --dialect lgc.gpurt
EXTRA_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../imported/llvm-dialects/include
)

add_public_tablegen_target(LgcDialectTableGen)

add_dependencies(LLVMlgc LgcDialectTableGen)
Expand Down Expand Up @@ -254,7 +246,6 @@ target_sources(LLVMlgc PRIVATE
state/Compiler.cpp
state/LgcContext.cpp
state/LgcDialect.cpp
state/GpurtDialect.cpp
state/PalMetadata.cpp
state/PassManagerCache.cpp
state/PipelineShaders.cpp
Expand Down Expand Up @@ -288,4 +279,4 @@ if (LLPC_BUILD_TESTS)
add_subdirectory(unittests)
endif()

target_link_libraries(LLVMlgc PRIVATE LLVMLgcCps LLVMLgcRt)
target_link_libraries(LLVMlgc PRIVATE LLVMContinuations)
7 changes: 4 additions & 3 deletions lgc/builder/ArithBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ Value *BuilderImpl::CreateATan(Value *yOverX, const Twine &instName) {
Value *outsideBound = CreateSelect(CreateFCmpOGT(absX, one), one, zero);
result = CreateFMul(outsideBound, result);
result = CreateFAdd(partialResult, result);
return CreateFMul(result, CreateFSign(yOverX));
result = CreateFMul(result, CreateFSign(yOverX));
return CreateSelect(CreateIsNaN(yOverX), ConstantFP::getNaN(yOverX->getType()), result);
}

// =====================================================================================================================
Expand Down Expand Up @@ -452,9 +453,9 @@ Value *BuilderImpl::CreateATan2(Value *y, Value *x, const Twine &instName) {
Value *result = CreateATan(yOverX);
Value *addP1 = CreateFAdd(result, p1);
result = CreateSelect(CreateFCmpOLT(x, zero), addP1, result);
result = CreateSelect(CreateFCmpONE(x, zero), result, p0);
result = CreateSelect(CreateFCmpUNE(x, zero), result, p0);
Value *zeroOrPi = CreateSelect(CreateFCmpOGT(x, zero), zero, getPi(x->getType()));
result = CreateSelect(CreateFCmpONE(y, zero), result, zeroOrPi, instName);
result = CreateSelect(CreateFCmpUNE(y, zero), result, zeroOrPi, instName);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion lgc/builder/BuilderRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@ Value *Builder::CreateSubgroupShuffleDown(Value *const value, Value *const offse
// @param value : The value to read from the chosen rotated lane to all active lanes.
// @param delta : The delta/offset added to lane id.
// @param clusterSize : The cluster size if exists.
// @param instName : Name to give instruction.
// @param instName : Name to give final instruction.
Value *Builder::CreateSubgroupRotate(Value *const value, Value *const delta, Value *const clusterSize,
const Twine &instName) {
return record(BuilderOpcode::SubgroupRotate, value->getType(), {value, delta, clusterSize}, instName);
Expand Down
19 changes: 18 additions & 1 deletion lgc/builder/DescBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ Value *BuilderImpl::CreateBufferDesc(uint64_t descSet, unsigned binding, Value *
descPtr = CreateBitCast(descPtr, getDescPtrTy(resType));
// Load the descriptor.
desc = CreateLoad(getDescTy(resType), descPtr);

// Force convert the buffer view to raw view.
if (flags & BufferFlagForceRawView) {
Value *desc1 = CreateExtractElement(desc, 1);
Value *desc2 = CreateExtractElement(desc, 2);
Value *desc3 = CreateExtractElement(desc, 3);
// stride is 14 bits in dword1[29:16]
Value *stride = CreateAnd(CreateLShr(desc1, getInt32(16)), getInt32(0x3fff));
stride = CreateBinaryIntrinsic(Intrinsic::smax, stride, getInt32(1));
// set srd with new stride = 0 and new num_record = stride * num_record, num_record is dword2[31:0]
desc = CreateInsertElement(desc, CreateAnd(desc1, getInt32(0xc000ffff)), 1);
desc = CreateInsertElement(desc, CreateMul(stride, desc2), 2);
// gfx10 and gfx11 have oob fields with 2 bits in dword3[29:28] here force to set to 3 as OOB_COMPLETE mode.
if (getPipelineState()->getTargetInfo().getGfxIpVersion().major >= 10)
desc = CreateInsertElement(desc, CreateOr(desc3, getInt32(0x30000000)), 3);
}
}

if (node && (node->concreteType == ResourceNodeType::DescriptorBufferCompact ||
Expand Down Expand Up @@ -257,7 +273,8 @@ Value *BuilderImpl::CreateGetDescPtr(ResourceNodeType concreteType, ResourceNode
// to that. For a simple non-variably-indexed immutable sampler not passed through a function call
// or phi node, we rely on subsequent LLVM optimizations promoting the value back to a constant.
StringRef startGlobalName = lgcName::ImmutableSamplerGlobal;
std::string globalName = (startGlobalName + Twine(node->set) + "_" + Twine(node->binding)).str();
std::string globalName =
(startGlobalName + Twine(node->set) + "_" + Twine(node->binding) + "_" + Twine(node->visibility)).str();
Module *module = GetInsertPoint()->getModule();
descPtr = module->getGlobalVariable(globalName, /*AllowInternal=*/true);
if (!descPtr) {
Expand Down
Loading

0 comments on commit 4d8954d

Please sign in to comment.