Skip to content
Merged
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
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ endif()
if (${ENABLE_SPIRV_CODEGEN})
add_definitions(-DENABLE_SPIRV_CODEGEN)
endif()

# Building dxil2spv off by default while it's in early development.
option(ENABLE_DXIL2SPV "Enables DXIL to SPIR-V translation." OFF)
# SPIRV change ends

include(VersionFromVCS)
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ before_build:
build_script:
- cmd: call utils\hct\hctbuild -%PLATFORM% -%CONFIGURATION% -show-cmake-log -spirvtest
- sh: mkdir build && cd build
- sh: cmake .. -GNinja -C ../cmake/caches/PredefinedParams.cmake -DSPIRV_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS=-Werror -DENABLE_DXIL2SPV=ON
- sh: cmake .. -GNinja -C ../cmake/caches/PredefinedParams.cmake -DSPIRV_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS=-Werror
- sh: ninja

test_script:
Expand All @@ -52,7 +52,6 @@ test_script:
- sh: ./bin/dxc -T ps_6_0 -Fo passthru-ps.spv ../tools/clang/test/CodeGenSPIRV/passthru-ps.hlsl2spv -spirv
- sh: ./bin/clang-spirv-tests --spirv-test-root ../tools/clang/test/CodeGenSPIRV/
- sh: ./bin/clang-hlsl-tests --HlslDataDir $PWD/../tools/clang/test/HLSL/
- sh: ./bin/dxil2spv ../tools/clang/test/Dxil2Spv/passthru-ps.ll

after_test:
# Collect artifacts for Windows
Expand All @@ -73,3 +72,4 @@ notifications:
on_build_success: true
on_build_failure: true
on_build_status_changed: true

4 changes: 0 additions & 4 deletions include/dxc/Test/DxcTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ class FileRunCommandPart {
FileRunCommandResult RunTee(const FileRunCommandResult *Prior);
FileRunCommandResult RunXFail(const FileRunCommandResult *Prior);
FileRunCommandResult RunDxilVer(dxc::DxcDllSupport& DllSupport, const FileRunCommandResult* Prior);
#ifdef ENABLE_DXIL2SPV
FileRunCommandResult RunDxil2Spv(dxc::DxcDllSupport &DllSupport,
const FileRunCommandResult *Prior);
#endif
FileRunCommandResult RunDxcHashTest(dxc::DxcDllSupport &DllSupport);
FileRunCommandResult RunFromPath(const std::string &path, const FileRunCommandResult *Prior);
FileRunCommandResult RunFileCompareText(const FileRunCommandResult *Prior);
Expand Down
30 changes: 1 addition & 29 deletions tools/clang/include/clang/SPIRV/SpirvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class SpirvBuilder {
public:
SpirvBuilder(ASTContext &ac, SpirvContext &c, const SpirvCodeGenOptions &,
FeatureManager &featureMgr);
SpirvBuilder(SpirvContext &c, const SpirvCodeGenOptions &,
FeatureManager &featureMgr);
~SpirvBuilder() = default;

// Forbid copy construction and assignment
Expand All @@ -74,9 +72,6 @@ class SpirvBuilder {
SpirvFunction *createSpirvFunction(QualType returnType, SourceLocation,
llvm::StringRef name, bool isPrecise,
bool isNoInline = false);
SpirvFunction *createSpirvFunction(const SpirvType *returnType,
SourceLocation, llvm::StringRef name,
bool isPrecise, bool isNoInline = false);

/// \brief Begins building a SPIR-V function by allocating a SpirvFunction
/// object. Returns the pointer for the function on success. Returns nullptr
Expand All @@ -87,10 +82,6 @@ class SpirvBuilder {
llvm::StringRef name = "",
bool isPrecise = false, bool isNoInline = false,
SpirvFunction *func = nullptr);
SpirvFunction *beginFunction(const SpirvType *returnType, SourceLocation,
llvm::StringRef name = "",
bool isPrecise = false, bool isNoInline = false,
SpirvFunction *func = nullptr);

/// \brief Creates and registers a function parameter of the given pointer
/// type in the current function and returns its pointer.
Expand All @@ -105,9 +96,6 @@ class SpirvBuilder {
SpirvVariable *addFnVar(QualType valueType, SourceLocation,
llvm::StringRef name = "", bool isPrecise = false,
SpirvInstruction *init = nullptr);
SpirvVariable *addFnVar(const spirv::SpirvType *valueType, SourceLocation,
llvm::StringRef name = "", bool isPrecise = false,
SpirvInstruction *init = nullptr);

/// \brief Ends building of the current function. All basic blocks constructed
/// from the beginning or after ending the previous function will be collected
Expand Down Expand Up @@ -238,9 +226,6 @@ class SpirvBuilder {
SpirvBinaryOp *createBinaryOp(spv::Op op, QualType resultType,
SpirvInstruction *lhs, SpirvInstruction *rhs,
SourceLocation loc, SourceRange range = {});
SpirvBinaryOp *createBinaryOp(spv::Op op, const SpirvType *resultType,
SpirvInstruction *lhs, SpirvInstruction *rhs,
SourceLocation loc, SourceRange range = {});

SpirvSpecConstantBinaryOp *createSpecConstantBinaryOp(spv::Op op,
QualType resultType,
Expand Down Expand Up @@ -620,10 +605,6 @@ class SpirvBuilder {
SpirvVariable *addStageIOVar(QualType type, spv::StorageClass storageClass,
llvm::StringRef name, bool isPrecise,
SourceLocation loc);
SpirvVariable *addStageIOVar(const SpirvType *type,
spv::StorageClass storageClass,
llvm::StringRef name, bool isPrecise,
SourceLocation loc);

/// \brief Adds a stage builtin variable whose value is of the given type.
///
Expand All @@ -633,10 +614,6 @@ class SpirvBuilder {
spv::StorageClass storageClass,
spv::BuiltIn, bool isPrecise,
SourceLocation loc);
SpirvVariable *addStageBuiltinVar(const SpirvType *type,
spv::StorageClass storageClass,
spv::BuiltIn, bool isPrecise,
SourceLocation loc);

/// \brief Adds a module variable. This variable should not have the Function
/// storage class.
Expand Down Expand Up @@ -741,12 +718,8 @@ class SpirvBuilder {
/// and add the context to the list of constants in the module.
SpirvConstant *getConstantInt(QualType type, llvm::APInt value,
bool specConst = false);
SpirvConstant *getConstantInt(const SpirvType *type, llvm::APInt value,
bool specConst = false);
SpirvConstant *getConstantFloat(QualType type, llvm::APFloat value,
bool specConst = false);
SpirvConstant *getConstantFloat(const SpirvType *type, llvm::APFloat value,
bool specConst = false);
SpirvConstant *getConstantBool(bool value, bool specConst = false);
SpirvConstant *
getConstantComposite(QualType compositeType,
Expand All @@ -763,7 +736,6 @@ class SpirvBuilder {

public:
std::vector<uint32_t> takeModule();
std::vector<uint32_t> takeModuleForDxilToSpv();

protected:
/// Only friend classes are allowed to add capability/extension to the module
Expand Down Expand Up @@ -824,7 +796,7 @@ class SpirvBuilder {
SpirvInstruction *var);

private:
ASTContext *astContext;
ASTContext &astContext;
SpirvContext &context; ///< From which we allocate various SPIR-V object
FeatureManager &featureManager;

Expand Down
3 changes: 0 additions & 3 deletions tools/clang/include/clang/SPIRV/SpirvFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class SpirvFunction {
SpirvFunction(QualType astReturnType, SourceLocation,
llvm::StringRef name = "", bool precise = false,
bool noInline = false);
SpirvFunction(const SpirvType *spirvReturnType, SourceLocation,
llvm::StringRef name = "", bool precise = false,
bool noInline = false);

~SpirvFunction();

Expand Down
9 changes: 0 additions & 9 deletions tools/clang/include/clang/SPIRV/SpirvInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ class SpirvInstruction {
// Forbid creating SpirvInstruction directly
SpirvInstruction(Kind kind, spv::Op opcode, QualType astResultType,
SourceLocation loc, SourceRange range = {});
SpirvInstruction(Kind kind, spv::Op opcode, const SpirvType *resultType,
SourceLocation loc, SourceRange range = {});

protected:
const Kind kind;
Expand Down Expand Up @@ -1021,9 +1019,6 @@ class SpirvBinaryOp : public SpirvInstruction {
SpirvBinaryOp(spv::Op opcode, QualType resultType, SourceLocation loc,
SpirvInstruction *op1, SpirvInstruction *op2,
SourceRange range = {});
SpirvBinaryOp(spv::Op opcode, const SpirvType *resultType, SourceLocation loc,
SpirvInstruction *op1, SpirvInstruction *op2,
SourceRange range = {});

DEFINE_RELEASE_MEMORY_FOR_CLASS(SpirvBinaryOp)

Expand Down Expand Up @@ -1157,8 +1152,6 @@ class SpirvConstantInteger : public SpirvConstant {
public:
SpirvConstantInteger(QualType type, llvm::APInt value,
bool isSpecConst = false);
SpirvConstantInteger(const SpirvType *type, llvm::APInt value,
bool isSpecConst = false);

DEFINE_RELEASE_MEMORY_FOR_CLASS(SpirvConstantInteger)

Expand All @@ -1181,8 +1174,6 @@ class SpirvConstantFloat : public SpirvConstant {
public:
SpirvConstantFloat(QualType type, llvm::APFloat value,
bool isSpecConst = false);
SpirvConstantFloat(const SpirvType *type, llvm::APFloat value,
bool isSpecConst = false);

DEFINE_RELEASE_MEMORY_FOR_CLASS(SpirvConstantFloat)

Expand Down
39 changes: 0 additions & 39 deletions tools/clang/include/clang/SPIRV/SpirvUtils.h

This file was deleted.

2 changes: 0 additions & 2 deletions tools/clang/lib/SPIRV/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ add_clang_library(clangSPIRV
InitListHandler.cpp
LiteralTypeVisitor.cpp
LowerTypeVisitor.cpp
SpirvTypeVisitor.cpp
SortDebugInfoVisitor.cpp
NonUniformVisitor.cpp
PreciseVisitor.cpp
Expand All @@ -33,7 +32,6 @@ add_clang_library(clangSPIRV
SpirvType.cpp
SignaturePackingUtil.cpp
String.cpp
SpirvUtils.cpp

LINK_LIBS
clangAST
Expand Down
2 changes: 1 addition & 1 deletion tools/clang/lib/SPIRV/EmitVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void EmitVisitor::emitDebugLine(spv::Op op, const SourceLocation &loc,
}

auto fileId = debugMainFileId;
const auto &sm = astContext->getSourceManager();
const auto &sm = astContext.getSourceManager();
const char *fileName = sm.getPresumedLoc(loc).getFilename();
if (fileName)
fileId = getOrCreateOpStringId(fileName);
Expand Down
19 changes: 9 additions & 10 deletions tools/clang/lib/SPIRV/EmitVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EmitTypeHandler {
};

public:
EmitTypeHandler(ASTContext *astCtx, SpirvContext &spvContext,
EmitTypeHandler(ASTContext &astCtx, SpirvContext &spvContext,
const SpirvCodeGenOptions &opts, FeatureManager &featureMgr,
std::vector<uint32_t> *debugVec,
std::vector<uint32_t> *decVec,
Expand Down Expand Up @@ -145,13 +145,13 @@ class EmitTypeHandler {
template <unsigned N>
DiagnosticBuilder emitError(const char (&message)[N],
SourceLocation loc = {}) {
const auto diagId = astContext->getDiagnostics().getCustomDiagID(
const auto diagId = astContext.getDiagnostics().getCustomDiagID(
clang::DiagnosticsEngine::Error, message);
return astContext->getDiagnostics().Report(loc, diagId);
return astContext.getDiagnostics().Report(loc, diagId);
}

private:
ASTContext *astContext;
ASTContext &astContext;
SpirvContext &context;
FeatureManager featureManager;
std::vector<uint32_t> curTypeInst;
Expand Down Expand Up @@ -198,10 +198,9 @@ class EmitVisitor : public Visitor {
};

public:
EmitVisitor(ASTContext *astCtx, SpirvContext &spvCtx,
EmitVisitor(ASTContext &astCtx, SpirvContext &spvCtx,
const SpirvCodeGenOptions &opts, FeatureManager &featureMgr)
: Visitor(opts, spvCtx), astContext(astCtx), featureManager(featureMgr),
id(0),
: Visitor(opts, spvCtx), astContext(astCtx), featureManager(featureMgr), id(0),
typeHandler(astCtx, spvCtx, opts, featureMgr, &debugVariableBinary,
&annotationsBinary, &typeConstantBinary,
[this]() -> uint32_t { return takeNextId(); }),
Expand Down Expand Up @@ -396,14 +395,14 @@ class EmitVisitor : public Visitor {
template <unsigned N>
DiagnosticBuilder emitError(const char (&message)[N],
SourceLocation loc = {}) {
const auto diagId = astContext->getDiagnostics().getCustomDiagID(
const auto diagId = astContext.getDiagnostics().getCustomDiagID(
clang::DiagnosticsEngine::Error, message);
return astContext->getDiagnostics().Report(loc, diagId);
return astContext.getDiagnostics().Report(loc, diagId);
}

private:
// Object that holds Clang AST nodes.
ASTContext *astContext;
ASTContext &astContext;
// Feature manager.
FeatureManager featureManager;
// The last result-id that's been used so far.
Expand Down
28 changes: 21 additions & 7 deletions tools/clang/lib/SPIRV/LowerTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "clang/AST/HlslTypes.h"
#include "clang/SPIRV/AstTypeProbe.h"
#include "clang/SPIRV/SpirvFunction.h"
#include "clang/SPIRV/SpirvUtils.h"

namespace {
/// Returns the :packoffset() annotation on the given decl. Returns nullptr if
Expand Down Expand Up @@ -118,14 +117,34 @@ bool LowerTypeVisitor::visitInstruction(SpirvInstruction *instr) {
}
break;
}
// Variables and function parameters must have a corresponding HLSL types set.
// Variables and function parameters must have a pointer type.
case spv::Op::OpFunctionParameter:
case spv::Op::OpVariable: {
if (auto *var = dyn_cast<SpirvVariable>(instr)) {
if (var->hasBinding() && var->getHlslUserType().empty()) {
var->setHlslUserType(getHlslResourceTypeName(var->getAstResultType()));
}

auto vkImgFeatures = spvContext.getVkImageFeaturesForSpirvVariable(var);
if (vkImgFeatures.format != spv::ImageFormat::Unknown) {
if (const auto *imageType = dyn_cast<ImageType>(resultType)) {
resultType = spvContext.getImageType(imageType, vkImgFeatures.format);
instr->setResultType(resultType);
}
}
}
const SpirvType *pointerType =
spvContext.getPointerType(resultType, instr->getStorageClass());
instr->setResultType(pointerType);
break;
}
// Access chains must have a pointer type. The storage class for the pointer
// is the same as the storage class of the access base.
case spv::Op::OpAccessChain: {
const auto *pointerType = spvContext.getPointerType(
resultType,
cast<SpirvAccessChain>(instr)->getBase()->getStorageClass());
instr->setResultType(pointerType);
break;
}
// OpImageTexelPointer's result type must be a pointer with image storage
Expand Down Expand Up @@ -157,11 +176,6 @@ bool LowerTypeVisitor::visitInstruction(SpirvInstruction *instr) {
break;
}

// Apply additional SPIR-V type transformations, including ensuring variables
// and function parameters have a pointer type.
SpirvUtils utils(context);
utils.applyResultTypeTransformations(instr);

// The instruction does not have a result-type, so nothing to do.
return true;
}
Expand Down
Loading