Skip to content

Commit

Permalink
Merge pull request #5 from microsoft/master
Browse files Browse the repository at this point in the history
Merge with master
  • Loading branch information
Darkstep79 authored Feb 23, 2021
2 parents 478bb48 + b63b179 commit 2a6c919
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 55 deletions.
3 changes: 3 additions & 0 deletions include/dxc/Support/dxcfilesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "dxc/dxcapi.h"
#include "llvm/Support/MSFileSystem.h"
#include <string>

namespace clang {
class CompilerInstance;
Expand Down Expand Up @@ -46,4 +47,6 @@ DxcArgsFileSystem *
CreateDxcArgsFileSystem(_In_ IDxcBlobUtf8 *pSource, _In_ LPCWSTR pSourceName,
_In_opt_ IDxcIncludeHandler *pIncludeHandler);

void MakeAbsoluteOrCurDirRelativeW(LPCWSTR &Path, std::wstring &PathStorage);

} // namespace dxcutil
8 changes: 8 additions & 0 deletions lib/DXIL/DxilShaderFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
bool hasMulticomponentUAVLoads = false;
bool hasViewportOrRTArrayIndex = false;
bool hasShadingRate = false;
bool hasBarycentrics = false;
bool hasSamplerFeedback = false;
bool hasRaytracingTier1_1 = false;
bool hasAtomicInt64OnTypedResource = false;
Expand Down Expand Up @@ -408,6 +409,9 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
case DXIL::OpCode::GeometryIndex:
hasRaytracingTier1_1 = true;
break;
case DXIL::OpCode::AttributeAtVertex:
hasBarycentrics = true;
break;
case DXIL::OpCode::AtomicBinOp:
case DXIL::OpCode::AtomicCompareExchange:
if (isInt64) {
Expand Down Expand Up @@ -467,6 +471,9 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
case Semantic::Kind::ShadingRate:
hasShadingRate = true;
break;
case Semantic::Kind::Barycentrics:
hasBarycentrics = true;
break;
default:
break;
}
Expand Down Expand Up @@ -531,6 +538,7 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
flag.SetViewID(hasViewID);
flag.SetViewportAndRTArrayIndex(hasViewportOrRTArrayIndex);
flag.SetShadingRate(hasShadingRate);
flag.SetBarycentrics(hasBarycentrics);
flag.SetSamplerFeedback(hasSamplerFeedback);
flag.SetRaytracingTier1_1(hasRaytracingTier1_1);
flag.SetAtomicInt64OnTypedResource(hasAtomicInt64OnTypedResource);
Expand Down
22 changes: 15 additions & 7 deletions lib/HLSL/DxilPreparePasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,13 +1432,20 @@ class DxilValidateWaveSensitivity : public ModulePass {
if (F.isDeclaration())
continue;

SmallVector<CallInst *, 16> localGradientOps;
DenseSet<Instruction *> localGradientArgs;
for (CallInst *CI : gradientOps) {
if (CI->getParent()->getParent() == &F)
localGradientOps.emplace_back(CI);
if (CI->getParent()->getParent() == &F) {
for (Value *V : CI->arg_operands()) {
// TODO: only check operand which used for gradient calculation.
Instruction *vI = dyn_cast<Instruction>(V);
if (!vI)
continue;
localGradientArgs.insert(vI);
}
}
}

if (localGradientOps.empty())
if (localGradientArgs.empty())
continue;

PostDominatorTree PDT;
Expand All @@ -1447,9 +1454,10 @@ class DxilValidateWaveSensitivity : public ModulePass {
WaveSensitivityAnalysis::create(PDT));

WaveVal->Analyze(&F);
for (CallInst *op : localGradientOps) {
if (WaveVal->IsWaveSensitive(op)) {
dxilutil::EmitWarningOnInstruction(op,
for (Instruction *gradArg : localGradientArgs) {
// Check operand of gradient ops, not gradientOps itself.
if (WaveVal->IsWaveSensitive(gradArg)) {
dxilutil::EmitWarningOnInstruction(gradArg,
UniNoWaveSensitiveGradientErrMsg);
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
// get a location. Fix it here by giving it a dummy location so the debug
// info is well-formed.
if (!TheCallDL) {
// If no debug metadata, don't bother trying to find the subprog
if (!getDebugMetadataVersionFromModule(*Fn->getParent()))
return;
if (DISubprogram *Subprogram = getDISubprogram(Fn)) {
TheCallDL = DebugLoc(llvm::DILocation::get(Fn->getContext(), 0, 0, Subprogram));
TheCall->setDebugLoc(TheCallDL);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s

// Make sure no warning when sample is not wave sensitive.
// CHECK-NOT:warning
// CHECK:main
Texture2D<float> tex;
SamplerState s;

float main(float4 a : A) : SV_Target {

float i=WaveReadLaneFirst(a.z);

if (i > 3)
return sin(tex.Sample(s, a.xy));

return 1;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// RUN: %dxilver 1.1 | %dxc -E main -T ps_6_1 %s | FileCheck %s


// CHECK: Note: shader requires additional functionality:
// CHECK-NEXT: Barycentrics

// CHECK: call float @dx.op.attributeAtVertex.f32(i32 137, i32 0, i32 0, i8 0, i8 0)
// CHECK: call float @dx.op.attributeAtVertex.f32(i32 137, i32 0, i32 0, i8 1, i8 0)
// CHECK: call float @dx.op.attributeAtVertex.f32(i32 137, i32 0, i32 0, i8 2, i8 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// RUN: %dxilver 1.6 | %dxc -E main -T ps_6_2 -HV 2018 -enable-16bit-types %s | FileCheck %s


// CHECK: Note: shader requires additional functionality:
// CHECK-NEXT: Barycentrics

// CHECK: call i32 @dx.op.attributeAtVertex.i32(i32 137, i32 0, i32 0, i8 0, i8 0)
// CHECK: call i32 @dx.op.attributeAtVertex.i32(i32 137, i32 0, i32 0, i8 1, i8 0)
// CHECK: call i32 @dx.op.attributeAtVertex.i32(i32 137, i32 0, i32 0, i8 2, i8 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %dxilver 1.1 | %dxc -E main -T ps_6_1 -O0 %s | FileCheck %s

// CHECK: Note: shader requires additional functionality:
// CHECK-NEXT: Barycentrics

// CHECK: call float @dx.op.attributeAtVertex.f32(i32 137, i32 1, i32 0, i8 0, i8 0)
// CHECK: call float @dx.op.attributeAtVertex.f32(i32 137, i32 1, i32 0, i8 1, i8 0)
// CHECK: call float @dx.op.attributeAtVertex.f32(i32 137, i32 1, i32 0, i8 2, i8 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %dxilver 1.1 | %dxc -E main -T ps_6_1 %s | FileCheck %s

// CHECK: Note: shader requires additional functionality:
// CHECK-NEXT: Barycentrics
// CHECK: !"SV_Barycentrics"

float4 main(float3 bary : SV_Barycentrics) : SV_Target
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %dxilver 1.1 | %dxc -E main -T ps_6_1 %s | FileCheck %s

// CHECK: Note: shader requires additional functionality:
// CHECK-NEXT: Barycentrics

// CHECK: ; SV_Barycentrics
// CHECK: ; SV_Barycentrics
// CHECK: ; SV_Barycentrics
Expand Down
7 changes: 4 additions & 3 deletions tools/clang/tools/dxcompiler/dxcfilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ bool IsAbsoluteOrCurDirRelativeW(LPCWSTR Path) {
return FALSE;
}

}

namespace dxcutil {

void MakeAbsoluteOrCurDirRelativeW(LPCWSTR &Path, std::wstring &PathStorage) {
if (IsAbsoluteOrCurDirRelativeW(Path)) {
return;
Expand All @@ -191,9 +195,6 @@ void MakeAbsoluteOrCurDirRelativeW(LPCWSTR &Path, std::wstring &PathStorage) {
}
}

}

namespace dxcutil {
/// File system based on API arguments. Support being added incrementally.
///
/// DxcArgsFileSystem emulates a file system to clang/llvm based on API
Expand Down
11 changes: 10 additions & 1 deletion tools/clang/tools/dxcompiler/dxcpdbutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "dxc/Support/HLSLOptions.h"

#include "dxcshadersourceinfo.h"
#include "dxc/Support/dxcfilesystem.h"

#include <vector>
#include <locale>
Expand Down Expand Up @@ -79,6 +80,8 @@ static HRESULT CopyWstringToBSTR(const std::wstring &str, BSTR *pResult) {
}

static std::wstring NormalizePath(const WCHAR *path) {
std::wstring PathStorage;
dxcutil::MakeAbsoluteOrCurDirRelativeW(path, PathStorage);
std::string FilenameStr8 = Unicode::UTF16ToUTF8StringOrThrow(path);
llvm::SmallString<128> NormalizedPath;
llvm::sys::path::native(FilenameStr8, NormalizedPath);
Expand Down Expand Up @@ -223,7 +226,8 @@ struct PdbRecompilerIncludeHandler : public IDxcIncludeHandler {
return E_POINTER;
*ppIncludeSource = nullptr;

auto it = m_FileMap.find(NormalizePath(pFilename));
std::wstring Filename = NormalizePath(pFilename);
auto it = m_FileMap.find(Filename);
if (it == m_FileMap.end())
return E_FAIL;

Expand Down Expand Up @@ -513,6 +517,11 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
m_ArgPairs.push_back( std::move(newPair) );
}

// Entry point might have been omitted. Set it to main by default.
if (m_EntryPoint.empty()) {
m_EntryPoint = L"main";
}

// Sources
for (unsigned i = 0; i < reader.GetSourcesCount(); i++) {
hlsl::SourceInfoReader::Source source_data = reader.GetSource(i);
Expand Down
97 changes: 97 additions & 0 deletions tools/clang/unittests/HLSL/CompilerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class CompilerTest : public ::testing::Test {
TEST_METHOD(CompileThenAddCustomDebugName)
TEST_METHOD(CompileThenTestPdbUtils)
TEST_METHOD(CompileThenTestPdbUtilsStripped)
TEST_METHOD(CompileThenTestPdbUtilsEmptyEntry)
TEST_METHOD(CompileThenTestPdbUtilsRelativePath)
TEST_METHOD(CompileWithRootSignatureThenStripRootSignature)

TEST_METHOD(CompileWhenIncludeThenLoadInvoked)
Expand Down Expand Up @@ -1534,6 +1536,101 @@ TEST_F(CompilerTest, CompileThenTestPdbUtils) {
TestPdbUtils(/*bSlim*/false, /*bSourceInDebugModule*/false, /*strip*/true); // Full PDB, where source info is stored in its own part, and debug module is present
TestPdbUtils(/*bSlim*/true, /*bSourceInDebugModule*/false, /*strip*/true); // Slim PDB, where source info is stored in its own part, and debug module is NOT present
}

TEST_F(CompilerTest, CompileThenTestPdbUtilsRelativePath) {
std::string main_source = R"x(
#include "helper.h"
cbuffer MyCbuffer : register(b1) {
float4 my_cbuf_foo;
}
[RootSignature("CBV(b1)")]
float4 main() : SV_Target {
return my_cbuf_foo;
}
)x";

CComPtr<IDxcCompiler3> pCompiler;
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler));

DxcBuffer SourceBuf = {};
SourceBuf.Ptr = main_source.c_str();
SourceBuf.Size = main_source.size();
SourceBuf.Encoding = CP_UTF8;

std::vector<const WCHAR *> args;
args.push_back(L"/Tps_6_0");
args.push_back(L"/Zi");
args.push_back(L"/Qsource_only_debug");
args.push_back(L"shaders/Shader.hlsl");

CComPtr<TestIncludeHandler> pInclude;
std::string included_File = "#define ZERO 0";
pInclude = new TestIncludeHandler(m_dllSupport);
pInclude->CallResults.emplace_back(included_File.c_str());

CComPtr<IDxcResult> pResult;
VERIFY_SUCCEEDED(pCompiler->Compile(&SourceBuf, args.data(), args.size(), pInclude, IID_PPV_ARGS(&pResult)));

CComPtr<IDxcBlob> pPdb;
CComPtr<IDxcBlobUtf16> pPdbName;
VERIFY_SUCCEEDED(pResult->GetOutput(DXC_OUT_PDB, IID_PPV_ARGS(&pPdb), &pPdbName));

CComPtr<IDxcPdbUtils> pPdbUtils;
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcPdbUtils, &pPdbUtils));

VERIFY_SUCCEEDED(pPdbUtils->Load(pPdb));

CComPtr<IDxcBlob> pFullPdb;
VERIFY_SUCCEEDED(pPdbUtils->GetFullPDB(&pFullPdb));

VERIFY_SUCCEEDED(pPdbUtils->Load(pFullPdb));
VERIFY_IS_TRUE(pPdbUtils->IsFullPDB());
}


TEST_F(CompilerTest, CompileThenTestPdbUtilsEmptyEntry) {
std::string main_source = R"x(
cbuffer MyCbuffer : register(b1) {
float4 my_cbuf_foo;
}
[RootSignature("CBV(b1)")]
float4 main() : SV_Target {
return my_cbuf_foo;
}
)x";

CComPtr<IDxcCompiler3> pCompiler;
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler));

DxcBuffer SourceBuf = {};
SourceBuf.Ptr = main_source.c_str();
SourceBuf.Size = main_source.size();
SourceBuf.Encoding = CP_UTF8;

std::vector<const WCHAR *> args;
args.push_back(L"/Tps_6_0");
args.push_back(L"/Zi");

CComPtr<IDxcResult> pResult;
VERIFY_SUCCEEDED(pCompiler->Compile(&SourceBuf, args.data(), args.size(), nullptr, IID_PPV_ARGS(&pResult)));

CComPtr<IDxcBlob> pPdb;
CComPtr<IDxcBlobUtf16> pPdbName;
VERIFY_SUCCEEDED(pResult->GetOutput(DXC_OUT_PDB, IID_PPV_ARGS(&pPdb), &pPdbName));

CComPtr<IDxcPdbUtils> pPdbUtils;
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcPdbUtils, &pPdbUtils));

VERIFY_SUCCEEDED(pPdbUtils->Load(pPdb));

CComBSTR pEntryName;
VERIFY_SUCCEEDED(pPdbUtils->GetEntryPoint(&pEntryName));

VERIFY_ARE_EQUAL(pEntryName, L"main");
}

#endif

TEST_F(CompilerTest, CompileWithRootSignatureThenStripRootSignature) {
Expand Down
Loading

0 comments on commit 2a6c919

Please sign in to comment.