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

Fix cpp static check. #2898

Closed
wants to merge 1 commit into from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 4 additions & 15 deletions cmake/continuations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,10 @@

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

include("${LLPC_SOURCE_DIR}/cmake/llpc_version.cmake")
include("${LLPC_SOURCE_DIR}/cmake/compilerutils.cmake")
include("${LLPC_SOURCE_DIR}/cmake/llvmraytracing.cmake")

# 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.
# Deprecated transition macro for refactoring transition; use add_llvmraytracing_projects instead
macro(add_continuations_projects)
add_llpc_version_projects()
add_compilerutils_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")
endif()
list(APPEND LLVM_EXTERNAL_PROJECTS Continuations)
set(LLVM_EXTERNAL_CONTINUATIONS_SOURCE_DIR "${LLPC_SOURCE_DIR}/shared/continuations")
endif()
add_llvmraytracing_projects()
set(LLPC_RAYTRACING_ADD_TRANSITION_TARGETS ON)
endmacro()
4 changes: 2 additions & 2 deletions cmake/lgc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
set(LLPC_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")

include("${LLPC_SOURCE_DIR}/cmake/llpc_version.cmake")
include("${LLPC_SOURCE_DIR}/cmake/continuations.cmake")
include("${LLPC_SOURCE_DIR}/cmake/llvmraytracing.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.
macro(add_lgc_projects)
add_llpc_version_projects()
add_continuations_projects()
add_llvmraytracing_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)
Expand Down
45 changes: 45 additions & 0 deletions cmake/llvmraytracing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
##
#######################################################################################################################
#
# Copyright (c) 2023-2024 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
#######################################################################################################################

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

include("${LLPC_SOURCE_DIR}/cmake/llpc_version.cmake")
include("${LLPC_SOURCE_DIR}/cmake/compilerutils.cmake")

# Macro to add raytracing 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.
macro(add_llvmraytracing_projects)
add_llpc_version_projects()
add_compilerutils_projects()
if (NOT raytracing 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")
endif()
list(APPEND LLVM_EXTERNAL_PROJECTS raytracing)
set(LLVM_EXTERNAL_RAYTRACING_SOURCE_DIR "${LLPC_SOURCE_DIR}/llvmraytracing")
endif()
endmacro()
19 changes: 17 additions & 2 deletions compilerutils/lib/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Function *CompilerUtils::cloneFunctionHeader(Function &f, FunctionType *newType,
} else {
// Insert new function before f to facilitate writing tests
f.getParent()->getFunctionList().insert(f.getIterator(), newFunc);
#if !defined(LLVM_MAIN_REVISION) || LLVM_MAIN_REVISION >= 489715
// If targetModule is null then take flag from original function.
newFunc->setIsNewDbgInfoFormat(f.IsNewDbgInfoFormat);
#endif
}

newFunc->copyAttributesFrom(&f);
Expand All @@ -137,8 +141,8 @@ namespace {
std::string getCrossModuleName(GlobalValue &gv) {
if (auto *fn = dyn_cast<Function>(&gv)) {
// Intrinsics should not be renamed since the IR verifier insists on a "correct" name mangling based on any
// overloaded types.
if (fn->isIntrinsic())
// overloaded types. Lgc dialects also require exact name for similar reason.
if (fn->isIntrinsic() || fn->getName().starts_with("lgc."))
return fn->getName().str();
}
return (Twine(gv.getName()) + ".cloned." + gv.getParent()->getName()).str();
Expand Down Expand Up @@ -242,7 +246,17 @@ iterator_range<Function::iterator> CompilerUtils::CrossModuleInliner::inlineCall

// Copy code
InlineFunctionInfo ifi;
#if !defined(LLVM_MAIN_REVISION) || LLVM_MAIN_REVISION >= 489715
// calleeFunc is not from targetMod, check if we need to convert it.
bool shouldConvert = !calleeFunc->IsNewDbgInfoFormat && targetMod->IsNewDbgInfoFormat;
if (shouldConvert)
calleeFunc->convertToNewDbgValues();
#endif
auto res = InlineFunction(cb, ifi);
#if !defined(LLVM_MAIN_REVISION) || LLVM_MAIN_REVISION >= 489715
if (shouldConvert)
calleeFunc->convertFromNewDbgValues();
#endif
if (!res.isSuccess())
report_fatal_error(Twine("Failed to inline ") + calleeFunc->getName() + ": " + res.getFailureReason());

Expand Down Expand Up @@ -325,6 +339,7 @@ CompilerUtils::CrossModuleInliner::inlineCall(IRBuilder<> &b, llvm::Function *ca
result = fakeUse->getOperand(0);
fakeUse->eraseFromParent();
}

return {result, newBBs};
}

Expand Down
2 changes: 0 additions & 2 deletions include/gpurt-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

#pragma once

#define MAKE_GPURT_VERSION(MAJOR, MINOR) ((MAJOR << 16) | MINOR)

namespace GpuRt {

#pragma pack(push, 4)
Expand Down
102 changes: 58 additions & 44 deletions include/vkgcDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ struct PipelineOptions {
///< depending the values of tessellation factors.
bool enableInterpModePatch; ///< If set, per-sample interpolation for nonperspective and smooth input is enabled
bool pageMigrationEnabled; ///< If set, page migration is enabled
uint32_t optimizationLevel; ///< The higher the number the more optimizations will be performed. Valid values are
unsigned optimizationLevel; ///< The higher the number the more optimizations will be performed. Valid values are
///< between 0 and 3.
unsigned overrideThreadGroupSizeX; ///< Override value for ThreadGroupSizeX
unsigned overrideThreadGroupSizeY; ///< Override value for ThreadGroupSizeY
Expand Down Expand Up @@ -517,21 +517,21 @@ struct ShaderModuleEntryData {
/// Represents the shader resources
struct ResourcesNodes {
ResourceNodeData *pInputInfo;
uint32_t inputInfoCount;
unsigned inputInfoCount;
ResourceNodeData *pOutputInfo;
uint32_t outputInfoCount;
unsigned outputInfoCount;
ResourceNodeData *pUniformBufferInfo;
uint32_t uniformBufferInfoCount;
unsigned uniformBufferInfoCount;
ResourceNodeData *pShaderStorageInfo;
uint32_t shaderStorageInfoCount;
unsigned shaderStorageInfoCount;
ResourceNodeData *pTexturesInfo;
uint32_t textureInfoCount;
unsigned textureInfoCount;
ResourceNodeData *pImagesInfo;
uint32_t imageInfoCount;
unsigned imageInfoCount;
ResourceNodeData *pAtomicCounterInfo;
uint32_t atomicCounterInfoCount;
unsigned atomicCounterInfoCount;
ResourceNodeData *pDefaultUniformInfo;
uint32_t defaultUniformInfoCount;
unsigned defaultUniformInfoCount;
};

/// Represents usage info of a shader module
Expand Down Expand Up @@ -567,6 +567,7 @@ struct ShaderModuleUsage {
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
bool disableDualSource; ///< Whether disable dualSource blend
};

/// Represents common part of shader module data
Expand Down Expand Up @@ -889,33 +890,33 @@ struct SamplerYCbCrConversionMetaData {

/// Represents assistant info for each vertex attribute in uber fetch shader
struct UberFetchShaderAttribInfo {
uint32_t binding : 8; ///< Attribute binding in vertex buffer table
uint32_t perInstance : 1; ///< Whether vertex input rate is per-instance
uint32_t isCurrent : 1; ///< Whether it is a current attribute
uint32_t isPacked : 1; ///< Whether it is a packed format
uint32_t isFixed : 1; ///< Whether it is a fixed format
uint32_t componentSize : 4; ///< Byte size per component
uint32_t componentMask : 4; ///< Component mask of this attribute.
uint32_t isBgra : 1; ///< Whether is BGRA format
uint32_t reserved : 11; ///< reserved bits in DWORD 0
uint32_t offset; ///< Attribute offset
uint32_t instanceDivisor; ///< Reciprocal of instance divisor
uint32_t bufferFormat; ///< Buffer format info. it is a copy of buffer SRD DWORD3.
unsigned binding : 8; ///< Attribute binding in vertex buffer table
unsigned perInstance : 1; ///< Whether vertex input rate is per-instance
unsigned isCurrent : 1; ///< Whether it is a current attribute
unsigned isPacked : 1; ///< Whether it is a packed format
unsigned isFixed : 1; ///< Whether it is a fixed format
unsigned componentSize : 4; ///< Byte size per component
unsigned componentMask : 4; ///< Component mask of this attribute.
unsigned isBgra : 1; ///< Whether is BGRA format
unsigned reserved : 11; ///< reserved bits in DWORD 0
unsigned offset; ///< Attribute offset
unsigned instanceDivisor; ///< Reciprocal of instance divisor
unsigned bufferFormat; ///< Buffer format info. it is a copy of buffer SRD DWORD3.
};

/// Represents the bit field info of struct BilUberFetchShaderAttribInfo
constexpr uint32_t UberFetchShaderAttribMaskBinding = 0x00000FFu;
constexpr uint32_t UberFetchShaderAttribMaskPerInstance = 0x0000100u;
constexpr uint32_t UberFetchShaderAttribMaskIsCurrent = 0x0000200u;
constexpr uint32_t UberFetchShaderAttribMaskIsPacked = 0x0000400u;
constexpr uint32_t UberFetchShaderAttribMaskIsFixed = 0x0000800u;
constexpr uint32_t UberFetchShaderAttribMaskComponentSize = 0x000F000u;
constexpr uint32_t UberFetchShaderAttribShiftComponentSize = 12u;
constexpr uint32_t UberFetchShaderAttribMaskComponent0 = 0x0010000u;
constexpr uint32_t UberFetchShaderAttribMaskComponent1 = 0x0020000u;
constexpr uint32_t UberFetchShaderAttribMaskComponent2 = 0x0040000u;
constexpr uint32_t UberFetchShaderAttribMaskComponent3 = 0x0080000u;
constexpr uint32_t UberFetchShaderAttribMaskIsBgra = 0x0100000u;
constexpr unsigned UberFetchShaderAttribMaskBinding = 0x00000FFu;
constexpr unsigned UberFetchShaderAttribMaskPerInstance = 0x0000100u;
constexpr unsigned UberFetchShaderAttribMaskIsCurrent = 0x0000200u;
constexpr unsigned UberFetchShaderAttribMaskIsPacked = 0x0000400u;
constexpr unsigned UberFetchShaderAttribMaskIsFixed = 0x0000800u;
constexpr unsigned UberFetchShaderAttribMaskComponentSize = 0x000F000u;
constexpr unsigned UberFetchShaderAttribShiftComponentSize = 12u;
constexpr unsigned UberFetchShaderAttribMaskComponent0 = 0x0010000u;
constexpr unsigned UberFetchShaderAttribMaskComponent1 = 0x0020000u;
constexpr unsigned UberFetchShaderAttribMaskComponent2 = 0x0040000u;
constexpr unsigned UberFetchShaderAttribMaskComponent3 = 0x0080000u;
constexpr unsigned UberFetchShaderAttribMaskIsBgra = 0x0100000u;

/// Represents the bit field info of struct BilUberFetchShaderAttribInfo

Expand Down Expand Up @@ -974,7 +975,7 @@ struct BvhShaderResourceDescriptor {
};

// Corresponds to gl_RayFlags* in GLSL_EXT_ray_tracing.txt
enum RayTracingRayFlag : uint32_t {
enum RayTracingRayFlag : unsigned {
RayTracingRayFlagNone = 0x00, // gl_RayFlagsNoneEXT
RayTracingRayFlagForceOpaque = 0x01, // gl_RayFlagsOpaqueEXT
RayTracingRayFlagForceNonOpaque = 0x02, // gl_RayFlagsNoOpaqueEXT
Expand Down Expand Up @@ -1130,8 +1131,8 @@ struct RtState {
};

struct UniformConstantMapEntry {
uint32_t location; ///< Starting location of the uniform constant variable
uint32_t offset; ///< Offset of the uniform constant variable in the final buffer
unsigned location; ///< Starting location of the uniform constant variable
unsigned offset; ///< Offset of the uniform constant variable in the final buffer
};

struct UniformConstantMap {
Expand Down Expand Up @@ -1250,15 +1251,28 @@ struct GraphicsPipelineBuildInfo {
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION < 62
BinaryData shaderLibrary; ///< SPIR-V library binary data
#endif
RtState rtState; ///< Ray tracing state
bool originUpperLeft; ///< Whether origin coordinate of framebuffer is upper-left.
const void *pClientMetadata; ///< Pointer to (optional) client-defined data to be stored inside the ELF
size_t clientMetadataSize; ///< Size (in bytes) of the client-defined data
unsigned numUniformConstantMaps; ///< Number of uniform constant maps
UniformConstantMap **ppUniformMaps; ///< Pointers to array of pointers for the uniform constant map.
ApiXfbOutData apiXfbOutData; ///< Transform feedback data specified by API interface.
bool vbAddressLowBitsKnown; ///< Whether vbAddressLowBits is valid
RtState rtState; ///< Ray tracing state
#if LLPC_CLIENT_INTERFACE_MAJOR_VERSION < 71
bool originUpperLeft; ///< Whether origin coordinate of framebuffer is upper-left.
unsigned numUniformConstantMaps; ///< Number of uniform constant maps
UniformConstantMap **ppUniformMaps; ///< Pointers to array of pointers for the uniform constant map.
ApiXfbOutData apiXfbOutData; ///< Transform feedback data specified by API interface.
bool vbAddressLowBitsKnown; ///< Whether vbAddressLowBits is valid
uint8_t vbAddressLowBits[MaxVertexBindings]; ///< Lowest two bits of vertex buffer addresses
const auto &getGlState() const { return *this; }
#else
struct {
bool originUpperLeft; ///< Whether origin coordinate of framebuffer is upper-left.
unsigned numUniformConstantMaps; ///< Number of uniform constant maps
UniformConstantMap **ppUniformMaps; ///< Pointers to array of pointers for the uniform constant map.
ApiXfbOutData apiXfbOutData; ///< Transform feedback data specified by API interface.
bool vbAddressLowBitsKnown; ///< Whether vbAddressLowBits is valid
uint8_t vbAddressLowBits[MaxVertexBindings]; ///< Lowest two bits of vertex buffer addresses
} glState;
const auto &getGlState() const { return glState; }
#endif
const void *pClientMetadata; ///< Pointer to (optional) client-defined data to be stored inside the ELF
size_t clientMetadataSize; ///< Size (in bytes) of the client-defined data
};

/// Represents info to build a compute pipeline.
Expand Down
13 changes: 10 additions & 3 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
)

llvm_map_components_to_libnames(extra_llvm_libs CompilerUtils Continuations)
llvm_map_components_to_libnames(extra_llvm_libs CompilerUtils Raytracing)
target_link_libraries(LLVMlgc PUBLIC llvm_dialects ${extra_llvm_libs} llpc_version)

### Cached Project Options #############################################################################################
Expand All @@ -65,7 +65,11 @@ set_compiler_options(LLVMlgc ${LLPC_ENABLE_WERROR})

### TableGen for LGC dialect ###########################################################################################

set(LGC_TABLEGEN_EXE $<TARGET_FILE:llvm-dialects-tblgen>)
if (EXISTS ${LLVM_TOOLS_BINARY_PATH}/llvm-dialects-tblgen)
set(LGC_TABLEGEN_EXE ${LLVM_TOOLS_BINARY_PATH}/llvm-dialects-tblgen)
else()
set(LGC_TABLEGEN_EXE $<TARGET_FILE:llvm-dialects-tblgen>)
endif()
set(LGC_TABLEGEN_TARGET llvm-dialects-tblgen)
set(LLVM_TARGET_DEFINITIONS interface/lgc/LgcDialect.td)

Expand Down Expand Up @@ -204,6 +208,9 @@ target_sources(LLVMlgc PRIVATE
util/StartStopTimer.cpp
)

# lgc/interface/lgc
target_sources(LLVMlgc PRIVATE interface/lgc/LgcDialect.td)

add_subdirectory(disassembler)
add_subdirectory(tool/lgc)
add_subdirectory(test)
Expand All @@ -212,4 +219,4 @@ if (LLPC_BUILD_TESTS)
add_subdirectory(unittests)
endif()

target_link_libraries(LLVMlgc PRIVATE LLVMContinuations)
target_link_libraries(LLVMlgc PRIVATE LLVMRaytracing)
Loading
Loading