Skip to content

Commit 2eb641d

Browse files
authored
Enable build for dxa/dxl/dxopt/dxr/dxv on linux (microsoft#4895)
* Enable build for dxa/dxl/dxopt/dxr/dxv on linux * Add CComBSTR and enable PdbUtils, Rewriter and recompile.
1 parent 2b67226 commit 2eb641d

31 files changed

+448
-168
lines changed

docs/DxcOnUnix.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ The following targets are currently disabled for non-Windows platforms and this
3939
is an area where further contributions can be made:
4040

4141
* d3dcomp
42-
* dxa
43-
* dxopt
44-
* dxl
45-
* dxr
46-
* dxv
4742
* dxlib-sample
4843

4944
Moreover, since the HLSL CodeGen tests were originally written with Windows in

include/dxc/Support/WinAdapter.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#define ERROR_NOT_CAPABLE EPERM
123123
#define ERROR_NOT_FOUND ENOTSUP
124124
#define ERROR_UNHANDLED_EXCEPTION EBADF
125+
#define ERROR_BROKEN_PIPE EPIPE
125126

126127
// Used by HRESULT <--> WIN32 error code conversion
127128
#define SEVERITY_ERROR 1
@@ -1039,8 +1040,60 @@ class CHandle {
10391040
HANDLE m_h;
10401041
};
10411042

1043+
1044+
/////////////////////////////////////////////////////////////////////////////
1045+
// CComBSTR
1046+
1047+
class CComBSTR
1048+
{
1049+
public:
1050+
BSTR m_str;
1051+
CComBSTR() : m_str(nullptr) {};
1052+
CComBSTR(_In_ int nSize, LPCWSTR sz);
1053+
~CComBSTR() throw() {
1054+
SysFreeString(m_str);
1055+
}
1056+
1057+
operator BSTR() const throw()
1058+
{
1059+
return m_str;
1060+
}
1061+
1062+
bool operator==(_In_ const CComBSTR& bstrSrc) const throw();
1063+
1064+
BSTR* operator&() throw()
1065+
{
1066+
return &m_str;
1067+
}
1068+
1069+
BSTR Detach() throw()
1070+
{
1071+
BSTR s = m_str;
1072+
m_str = NULL;
1073+
return s;
1074+
}
1075+
1076+
};
1077+
1078+
10421079
#endif // __cplusplus
10431080

10441081
#endif // _WIN32
10451082

1083+
#ifdef __cplusplus
1084+
1085+
#include <string>
1086+
#include <vector>
1087+
//===--------- Convert argv to wchar ----------------===//
1088+
class WArgV {
1089+
std::vector<std::wstring> WStringVector;
1090+
std::vector<const wchar_t *> WCharPtrVector;
1091+
1092+
public:
1093+
WArgV(int argc, const char **argv);
1094+
WArgV(int argc, const wchar_t **argv);
1095+
const wchar_t **argv() { return WCharPtrVector.data();}
1096+
};
1097+
#endif
1098+
10461099
#endif // LLVM_SUPPORT_WIN_ADAPTER_H

include/dxc/Support/WinFunctions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#ifndef LLVM_SUPPORT_WINFUNCTIONS_H
1616
#define LLVM_SUPPORT_WINFUNCTIONS_H
1717

18-
#ifndef _WIN32
19-
2018
#include "dxc/Support/WinAdapter.h"
2119

20+
#ifndef _WIN32
21+
2222
HRESULT StringCchCopyEx(LPSTR pszDest, size_t cchDest, LPCSTR pszSrc,
2323
LPSTR *ppszDestEnd, size_t *pcchRemaining, DWORD dwFlags);
2424
HRESULT StringCchPrintfA(char *dst, size_t dstSize, const char *format, ...);

lib/DxcSupport/WinAdapter.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10+
#include "dxc/Support/WinIncludes.h"
11+
#include "dxc/Support/WinFunctions.h"
12+
#include "assert.h"
1013
#ifndef _WIN32
1114

12-
#include "dxc/Support/WinAdapter.h"
13-
#include "dxc/Support/WinFunctions.h"
15+
#include "dxc/Support/Unicode.h"
1416

1517
//===--------------------------- CAllocator -------------------------------===//
1618

@@ -75,4 +77,47 @@ CHandle::CHandle(HANDLE h) { m_h = h; }
7577
CHandle::~CHandle() { CloseHandle(m_h); }
7678
CHandle::operator HANDLE() const throw() { return m_h; }
7779

80+
// CComBSTR
81+
CComBSTR::CComBSTR(_In_ int nSize, LPCWSTR sz) {
82+
if (nSize < 0) {
83+
throw std::invalid_argument("CComBSTR must have size >= 0");
84+
}
85+
86+
if (nSize == 0) {
87+
m_str = NULL;
88+
} else {
89+
m_str = SysAllocStringLen(sz, nSize);
90+
if (!*this) {
91+
std::runtime_error("out of memory");
92+
}
93+
}
94+
}
95+
96+
bool CComBSTR::operator==(_In_ const CComBSTR &bstrSrc) const throw() {
97+
return wcscmp(m_str, bstrSrc.m_str) == 0;
98+
}
99+
78100
#endif
101+
102+
//===--------------------------- WArgV -------------------------------===//
103+
WArgV::WArgV(int argc, const char **argv)
104+
: WStringVector(argc), WCharPtrVector(argc) {
105+
for (int i = 0; i < argc; ++i) {
106+
std::string S(argv[i]);
107+
const int wideLength = ::MultiByteToWideChar(
108+
CP_UTF8, MB_ERR_INVALID_CHARS, S.data(), S.size(), nullptr, 0);
109+
assert(wideLength > 0 &&
110+
"else it should have failed during size calculation");
111+
WStringVector[i].resize(wideLength);
112+
::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, S.data(), S.size(),
113+
&(WStringVector[i])[0], WStringVector[i].size());
114+
WCharPtrVector[i] = WStringVector[i].data();
115+
}
116+
}
117+
118+
WArgV::WArgV(int argc, const wchar_t **argv)
119+
: WCharPtrVector(argc) {
120+
for (int i = 0; i < argc; ++i) {
121+
WCharPtrVector[i] = argv[i];
122+
}
123+
}

tools/clang/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ endif()
6969

7070
# HLSL Change Begin
7171
# Explicitly overriding check-clang dependencies for HLSL
72-
set(CLANG_TEST_DEPS dxc dxcompiler clang-tblgen llvm-config opt FileCheck count not ClangUnitTests)
72+
set(CLANG_TEST_DEPS dxc dxa dxopt dxl dxv dxr dxcompiler clang-tblgen llvm-config opt FileCheck count not ClangUnitTests)
7373
add_custom_target(clang-test-depends DEPENDS ${CLANG_TEST_DEPS})
7474
set_target_properties(clang-test-depends PROPERTIES FOLDER "Clang tests")
7575
# HLSL Change End
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int f2(int g)
2+
{
3+
return g*42;
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Verify that we can find an include header in the original directory
2+
#include "inc2.hlsli"
3+
4+
int f1(int g)
5+
{
6+
return f2(g);
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
// Make sure same cbuffer decalred in different lib works.
4+
5+
cbuffer A {
6+
float a;
7+
float v;
8+
}
9+
10+
Texture2D tex;
11+
SamplerState samp;
12+
13+
export float GetV() {
14+
return v + tex.Load(uint3(a, v, a)).y;
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Verify that we can successfully process an include
2+
#include "include/inc1.hlsli"
3+
4+
int g;
5+
static int g_unused;
6+
7+
#ifndef semantic
8+
#define semantic SV_Target
9+
#endif
10+
#ifdef DX12
11+
#define RS "CBV(b0)"
12+
[RootSignature ( RS )]
13+
#endif
14+
15+
float4 main() : semantic
16+
{
17+
#ifdef check_warning
18+
int x = 3;
19+
x;
20+
#endif
21+
return f1(g);
22+
}

tools/clang/test/DXC/dxa_tests.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
// RUN: %dxc %S/Inputs/smoke.hlsl /D "semantic = SV_Position" /T vs_6_0 /Zi /Qembed_debug /DDX12 /Fo %t.dxa.cso
3+
4+
// RUN: %dxa %t.dxa.cso -listfiles | FileCheck %s --check-prefix=FILES
5+
// FILES:smoke.hlsl
6+
7+
// RUN: %dxa %t.dxa.cso -listparts | FileCheck %s --check-prefix=PARTS
8+
// PARTS-DAG:DXIL
9+
// PARTS-DAG:ILDB
10+
// PARTS-DAG:RTS0
11+
// PARTS-DAG:PSV0
12+
// PARTS-DAG:STAT
13+
// PARTS-DAG:ILDN
14+
// PARTS-DAG:HASH
15+
// PARTS-DAG:ISG1
16+
// PARTS-DAG:OSG1
17+
18+
19+
// RUN: %dxa %t.dxa.cso -extractpart dbgmodule -o %t.dxa.cso.dbgmodule
20+
21+
// RUN: %dxa %t.dxa.cso.dbgmodule -listfiles | FileCheck %s --check-prefix=DBG_FILES
22+
// DBG_FILES:smoke.hlsl
23+
24+
// RUN: %dxa %t.dxa.cso.dbgmodule -extractfile=* | FileCheck %s --check-prefix=EXTRACT_FILE
25+
// EXTRACT_FILE:float4 main()
26+
27+
28+
// RUN: %dxa %t.dxa.cso -extractpart module -o %t.dxa.cso.plain.bc
29+
// RUN: %dxa %t.dxa.cso.plain.bc -o %t.rebuilt-container.cso
30+
// RUN: %dxc -dumpbin %t.rebuilt-container.cso | FileCheck %s --check-prefix=REBUILD
31+
32+
// RUN: %dxc -dumpbin %t.dxa.cso -Fc %t.dxa.ll
33+
// RUN: %dxa %t.dxa.ll -o %t.rebuilt-container2.cso
34+
// RUN: %dxc -dumpbin %t.rebuilt-container2.cso | FileCheck %s --check-prefix=REBUILD
35+
36+
// REBUILD:define void @main()

tools/clang/test/DXC/dxopt_test.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Smoke test for dxopt command line
2+
// RUN: %dxc /Odump -Tps_6_0 %S/Inputs/smoke.hlsl > %t.opt.passes.txt
3+
4+
// RUN: echo -print-module:test >> %t.opt.passes.txt
5+
6+
// RUN: %dxc -T ps_6_0 %S/Inputs/smoke.hlsl -fcgl -Fc %t.smoke.hl.ll
7+
// RUN: FileCheck --input-file=%t.smoke.hl.ll %s --check-prefix=HL_LL
8+
9+
// Make sure hl.ll not empty.
10+
// HL_LL:{{.+}}
11+
12+
// RUN: %dxopt -pf %t.opt.passes.txt -o=%t.smoke.opt.bc %t.smoke.hl.ll | FileCheck %s --check-prefix=OPT_PRN
13+
14+
// OPT_PRN:MODULE-PRINT
15+
16+
// RUN: %dxc -dumpbin %t.smoke.opt.bc | FileCheck %s --check-prefix=OPT_BC
17+
18+
// Make sure OPT_BC not empty.
19+
// OPT_BC:{{.+}}

tools/clang/test/DXC/dxr_test.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Basic Rewriter Smoke Test
2+
// RUN: %dxr -remove-unused-globals %S/Inputs/smoke.hlsl -Emain | FileCheck %s --check-prefix=DXR
3+
4+
// DXR:int f2(int g)
5+
// DXR-not:g_unused

tools/clang/test/DXC/lib_entry4.hlsl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Smoke test for dxl command line
2+
// RUN: %dxc /T lib_6_x %s -Fo %t.lib_entry4.dxbc
3+
// RUN: %dxc /T lib_6_x %S/Inputs/lib_res_match.hlsl -Fo %t.lib_res_match.dxbc
4+
// RUN: %dxl -T ps_6_0 "%t.lib_entry4.dxbc;%t.lib_res_match.dxbc" -Fo %t.res_match_entry.dxbc
5+
// RUN: %dxc -dumpbin %t.res_match_entry.dxbc | FileCheck %s
6+
7+
// CHECK:; cbuffer A
8+
// CHECK-NEXT:; {
9+
// CHECK-NEXT:;
10+
// CHECK-NEXT:[8 x i8] (type annotation not present)
11+
// CHECK-NEXT:;
12+
// CHECK-NEXT:; }
13+
14+
// Make sure same cbuffer decalred in different lib works.
15+
16+
17+
cbuffer A {
18+
float a;
19+
float v;
20+
}
21+
22+
Texture2D tex;
23+
SamplerState samp;
24+
25+
float GetV();
26+
27+
[shader("pixel")]
28+
float4 main() : SV_Target
29+
{
30+
return tex.Sample(samp, float2(a, GetV()));
31+
}

tools/clang/test/DXC/recompile.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
// Embed Debug, Recompile
3+
// RUN: %dxc /T ps_6_0 %S/Inputs/smoke.hlsl /Zi /Qembed_debug /Fo %t.recompile.cso
4+
// RUN: %dxc -dumpbin %t.recompile.cso | FileCheck %s --check-prefix=RECOMPILE_EMBED_DEBUG
5+
// RECOMPILE_EMBED_DEBUG:DICompileUnit
6+
7+
// RUN: %dxc /T ps_6_0 %S/Inputs/smoke.hlsl /Zi /Qembed_debug /Fo %t.recompile.cc.cso /Cc /Ni /No /Lx
8+
// RUN: %dxc -dumpbin %t.recompile.cc.cso | FileCheck %s --check-prefix=RECOMPILE_CC_EMBED_DEBUG
9+
// RECOMPILE_CC_EMBED_DEBUG:DICompileUnit
10+
// RUN: %dxc %t.recompile.cc.cso /recompile
11+
// RUN: %dxc %t.recompile.cc.cso /recompile /T ps_6_0 /E main
12+
13+
// Strip Debug, Recompile PDB
14+
// RUN: %dxc /T ps_6_0 %S/Inputs/smoke.hlsl /Zi /Fd %t.recompiled.pdb
15+
// RUN: %dxc -dumpbin %t.recompiled.pdb | FileCheck %s --check-prefix=RECOMPILE_PDB
16+
// RECOMPILE_PDB:DICompileUnit
17+
// RUN: %dxc %t.recompiled.pdb /recompile > %t.recompiled.pdb.ll
18+
// RUN: %dxc %t.recompiled.pdb /recompile /T ps_6_0 /E main
19+
20+
// Command-line Defines, Recompile
21+
// RUN: %dxc %S/Inputs/smoke.hlsl /D "semantic = SV_Position" /T vs_6_0 /Zi /Qembed_debug /DDX12 /Fo %t.define.cso
22+
// RUN: %dxc %t.define.cso /recompile

tools/clang/test/lit.cfg

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ else:
4444
config.test_format = lit.formats.ShTest(execute_external)
4545

4646
# suffixes: A list of file extensions to treat as test files.
47-
config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap', '.hlsl']
47+
config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.S', '.modulemap', '.hlsl', '.test']
4848

4949
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
5050
# subdirectories contain auxiliary inputs for various tests in their parent
@@ -269,6 +269,24 @@ config.substitutions.append( ('%itanium_abi_triple', makeItaniumABITriple(config
269269
config.substitutions.append( ('%ms_abi_triple', makeMSABITriple(config.target_triple)) )
270270
config.substitutions.append( ('%dxc', lit.util.which('dxc', llvm_tools_dir)) )
271271

272+
config.substitutions.append( ('%dxv',
273+
lit.util.which('dxv', llvm_tools_dir)) )
274+
275+
config.substitutions.append( ('%dxa',
276+
lit.util.which('dxa', llvm_tools_dir)) )
277+
278+
config.substitutions.append( ('%dxopt',
279+
lit.util.which('dxopt', llvm_tools_dir)) )
280+
281+
config.substitutions.append( ('%dxr',
282+
lit.util.which('dxr', llvm_tools_dir)) )
283+
284+
config.substitutions.append( ('%listparts',
285+
str(lit.util.which('dxa', llvm_tools_dir)) + ' -listparts ' ))
286+
287+
config.substitutions.append( ('%dxl',
288+
lit.util.which('dxl', llvm_tools_dir)) )
289+
272290
# The host triple might not be set, at least if we're compiling clang from
273291
# an already installed llvm.
274292
if config.host_triple and config.host_triple != '@LLVM_HOST_TRIPLE@':

tools/clang/test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ config.clang_examples = @ENABLE_CLANG_EXAMPLES@
2020
config.enable_shared = @ENABLE_SHARED@
2121
config.enable_backtrace = "@ENABLE_BACKTRACES@"
2222
config.host_arch = "@HOST_ARCH@"
23+
config.spirv = "@ENABLE_SPIRV_CODEGEN@" =="ON"
2324

2425
# Support substitution of the tools and libs dirs with user parameters. This is
2526
# used when we can't determine the tool dir at configuration time.

0 commit comments

Comments
 (0)