Skip to content

Commit 14a55b7

Browse files
author
Greg Roth
authored
[linux] Enable Reflection on *nix platforms (#4810)
Needed for the impending enabling on *nix platforms * Remove circular dependency from RDAT Dumper A file included by the source that implemented various ToString converters of reflection data to strings itself depended on those declarations, which it only found because of the unique way MSVC processes templates. By moving the definitions and declarations into their own header and source files, everyone gets what they need without ouroborosing. * Create DirectX-Headers submodule Creates the DirectX-Headers submodule and adds the needed defines to allow them to be used. As yet makes no use of these headers * Improve src dir finding error The check for the file stream that is meant to represent the filechecked source file wasn't sufficient to detect a non-existent file. By expanding the error check, it can produce a helpful message. Also initialize the failure code so it isn't random * Enable reflection functionality and testing This flips the switch, removing or repositioning many ifdefs and including previously excluded files in the build. * Actually add the DirectX-Headers submodule * fix *nix build breaks caused while fixing win breaks :P * Respond to feedback -- some of it anyway ;) * simplify cmake file to exclude unneeded src dir * fix cmake (again) * Fix GCC template specialization finickiness What compiler is overly permissive now huh? huh? (or just quick to adopt new language features?) * LPCBYTE isn't a thing Loathe as I am to push one more commit onto this. I don't want to propagate a misconception. I meant to remove this earlier and caught it from one final self-review >:(
1 parent 0a1f7a1 commit 14a55b7

23 files changed

Lines changed: 822 additions & 774 deletions

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "external/effcee"]
1414
path = external/effcee
1515
url = https://github.com/google/effcee
16+
[submodule "external/DirectX-Headers"]
17+
path = external/DirectX-Headers
18+
url = https://github.com/microsoft/DirectX-Headers.git

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,12 @@ add_subdirectory(include/dxc)
662662
# This over-specifies the dependency graph, but since generating these doesn't
663663
# really depend on anything else in the build it is safe.
664664
list(APPEND LLVM_COMMON_DEPENDS HCTGen)
665+
666+
if(EXISTS "${LLVM_MAIN_SRC_DIR}/external")
667+
add_subdirectory(external) # SPIRV change
668+
endif()
669+
include_directories(AFTER ${DIRECTX_HEADER_INCLUDE_DIR}/directx ${DIRECTX_HEADER_INCLUDE_DIR}/wsl/stubs)
670+
665671
# HLSL - Change End
666672

667673
add_subdirectory(lib)
@@ -702,10 +708,6 @@ if(WITH_POLLY)
702708
endif()
703709
endif(WITH_POLLY)
704710

705-
if(EXISTS "${LLVM_MAIN_SRC_DIR}/external")
706-
add_subdirectory(external) # SPIRV change
707-
endif()
708-
709711
if( LLVM_INCLUDE_TOOLS )
710712
add_subdirectory(tools)
711713
endif()

external/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ if (NOT HLSL_ENABLE_DEBUG_ITERATORS)
77
add_definitions(/D_ITERATOR_DEBUG_LEVEL=0)
88
endif (NOT HLSL_ENABLE_DEBUG_ITERATORS)
99

10+
# Need DirectX-Headers module if not on windows
11+
if (NOT WIN32)
12+
if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers")
13+
set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE)
14+
else()
15+
message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers")
16+
endif()
17+
endif (NOT WIN32)
18+
1019
# Enabling SPIR-V codegen requires SPIRV-Headers for spirv.hpp and
1120
# SPIRV-Tools for SPIR-V disassembling functionality.
1221
if (${ENABLE_SPIRV_CODEGEN})

external/DirectX-Headers

Submodule DirectX-Headers added at 980971e
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// //
3+
// DxReflection.h //
4+
// Copyright (C) Microsoft Corporation. All rights reserved. //
5+
// This file is distributed under the University of Illinois Open Source //
6+
// License. See LICENSE.TXT for details. //
7+
// //
8+
// Provides the needed headers and defines for D3D reflection. //
9+
// //
10+
///////////////////////////////////////////////////////////////////////////////
11+
12+
#pragma once
13+
14+
#ifndef _WIN32
15+
// need to disable this as it is voilated by this header
16+
#pragma GCC diagnostic push
17+
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
18+
// Need to instruct non-windows compilers on what an interface is
19+
#define interface struct
20+
#include "d3d12shader.h"
21+
#undef interface
22+
#pragma GCC diagnostic pop
23+
#else
24+
#include <d3d12shader.h>
25+
#endif

include/dxc/Support/WinAdapter.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <vector>
3434
#endif // __cplusplus
3535

36+
#define COM_NO_WINDOWS_H // needed to inform d3d headers that this isn't windows
37+
3638
//===----------------------------------------------------------------------===//
3739
//
3840
// Begin: Macro Definitions
@@ -64,10 +66,12 @@
6466
#endif // __EMULATE_UUID
6567

6668
#define STDMETHODCALLTYPE
67-
#define STDAPI extern "C" HRESULT STDAPICALLTYPE
68-
#define STDAPI_(type) extern "C" type STDAPICALLTYPE
69-
#define STDMETHODIMP HRESULT STDMETHODCALLTYPE
7069
#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
70+
#define STDMETHODIMP STDMETHODIMP_(HRESULT)
71+
#define STDMETHOD_(type,name) virtual STDMETHODIMP_(type) name
72+
#define STDMETHOD(name) STDMETHOD_(HRESULT, name)
73+
#define EXTERN_C extern "C"
74+
7175

7276
#define UNREFERENCED_PARAMETER(P) (void)(P)
7377

@@ -325,6 +329,9 @@
325329
#define _Null_
326330
#define _Notnull_
327331
#define _Maybenull_
332+
#define THIS_
333+
#define THIS
334+
#define PURE = 0
328335

329336
#define _Outptr_result_bytebuffer_(size)
330337

@@ -364,6 +371,7 @@ typedef unsigned int UINT;
364371
typedef unsigned long ULONG;
365372
typedef long long LONGLONG;
366373
typedef long long LONG_PTR;
374+
typedef unsigned long long ULONG_PTR;
367375
typedef unsigned long long ULONGLONG;
368376

369377
typedef uint16_t WORD;
@@ -403,6 +411,7 @@ typedef signed int HRESULT;
403411
//===--------------------- Handle Types -----------------------------------===//
404412

405413
typedef void *HANDLE;
414+
typedef void *RPC_IF_HANDLE;
406415

407416
#define DECLARE_HANDLE(name) \
408417
struct name##__ { \
@@ -610,6 +619,13 @@ template <typename T> inline void **IID_PPV_ARGS_Helper(T **pp) {
610619

611620
#endif // __EMULATE_UUID
612621

622+
// Needed for d3d headers, but fail to create actual interfaces
623+
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
624+
#define DECLSPEC_UUID(x)
625+
#define MIDL_INTERFACE(x) struct DECLSPEC_UUID(x)
626+
#define DECLARE_INTERFACE(iface) struct iface
627+
#define DECLARE_INTERFACE_(iface, parent) DECLARE_INTERFACE(iface) : parent
628+
613629
//===--------------------- COM Interfaces ---------------------------------===//
614630

615631
CROSS_PLATFORM_UUIDOF(IUnknown, "00000000-0000-0000-C000-000000000046")
@@ -666,6 +682,11 @@ struct IStream : public ISequentialStream {
666682
virtual HRESULT Clone(IStream **ppstm) = 0;
667683
};
668684

685+
// These don't need stub implementations as they come from the DirectX Headers
686+
// They still need the __uuidof() though
687+
CROSS_PLATFORM_UUIDOF(ID3D12LibraryReflection, "8E349D19-54DB-4A56-9DC9-119D87BDB804")
688+
CROSS_PLATFORM_UUIDOF(ID3D12ShaderReflection, "5A58797D-A72C-478D-8BA2-EFC6B0EFE88E")
689+
669690
//===--------------------- COM Pointer Types ------------------------------===//
670691

671692
class CAllocator {

include/dxc/Test/D3DReflectionDumper.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,10 @@
1414
#include "dxc/Support/Global.h"
1515
#include "DumpContext.h"
1616
#include "dxc/Support/WinIncludes.h"
17-
#include <d3d12shader.h>
1817

1918
namespace hlsl {
2019
namespace dump {
2120

22-
LPCSTR ToString(D3D_CBUFFER_TYPE CBType);
23-
LPCSTR ToString(D3D_SHADER_INPUT_TYPE Type);
24-
LPCSTR ToString(D3D_RESOURCE_RETURN_TYPE ReturnType);
25-
LPCSTR ToString(D3D_SRV_DIMENSION Dimension);
26-
LPCSTR ToString(D3D_PRIMITIVE_TOPOLOGY GSOutputTopology);
27-
LPCSTR ToString(D3D_PRIMITIVE InputPrimitive);
28-
LPCSTR ToString(D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive);
29-
LPCSTR ToString(D3D_TESSELLATOR_PARTITIONING HSPartitioning);
30-
LPCSTR ToString(D3D_TESSELLATOR_DOMAIN TessellatorDomain);
31-
LPCSTR ToString(D3D_SHADER_VARIABLE_CLASS Class);
32-
LPCSTR ToString(D3D_SHADER_VARIABLE_TYPE Type);
33-
LPCSTR ToString(D3D_SHADER_VARIABLE_FLAGS Flag);
34-
LPCSTR ToString(D3D_SHADER_INPUT_FLAGS Flag);
35-
LPCSTR ToString(D3D_SHADER_CBUFFER_FLAGS Flag);
36-
LPCSTR ToString(D3D_PARAMETER_FLAGS Flag);
37-
LPCSTR ToString(D3D_NAME Name);
38-
LPCSTR ToString(D3D_REGISTER_COMPONENT_TYPE CompTy);
39-
LPCSTR ToString(D3D_MIN_PRECISION MinPrec);
40-
LPCSTR CompMaskToString(unsigned CompMask);
41-
4221
class D3DReflectionDumper : public DumpContext {
4322
private:
4423
bool m_bCheckByName = false;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// //
3+
// D3DReflectionStrings.h //
4+
// Copyright (C) Microsoft Corporation. All rights reserved. //
5+
// This file is distributed under the University of Illinois Open Source //
6+
// License. See LICENSE.TXT for details. //
7+
// //
8+
// Used to convert reflection data types into strings. //
9+
// //
10+
///////////////////////////////////////////////////////////////////////////////
11+
12+
#pragma once
13+
14+
#include "dxc/Support/D3DReflection.h"
15+
#include "dxc/DxilContainer/DxilRuntimeReflection.h"
16+
17+
namespace hlsl {
18+
using namespace RDAT;
19+
namespace dump {
20+
21+
// ToString functions for D3D types
22+
LPCSTR ToString(D3D_CBUFFER_TYPE CBType);
23+
LPCSTR ToString(D3D_SHADER_INPUT_TYPE Type);
24+
LPCSTR ToString(D3D_RESOURCE_RETURN_TYPE ReturnType);
25+
LPCSTR ToString(D3D_SRV_DIMENSION Dimension);
26+
LPCSTR ToString(D3D_PRIMITIVE_TOPOLOGY GSOutputTopology);
27+
LPCSTR ToString(D3D_PRIMITIVE InputPrimitive);
28+
LPCSTR ToString(D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive);
29+
LPCSTR ToString(D3D_TESSELLATOR_PARTITIONING HSPartitioning);
30+
LPCSTR ToString(D3D_TESSELLATOR_DOMAIN TessellatorDomain);
31+
LPCSTR ToString(D3D_SHADER_VARIABLE_CLASS Class);
32+
LPCSTR ToString(D3D_SHADER_VARIABLE_TYPE Type);
33+
LPCSTR ToString(D3D_SHADER_VARIABLE_FLAGS Flag);
34+
LPCSTR ToString(D3D_SHADER_INPUT_FLAGS Flag);
35+
LPCSTR ToString(D3D_SHADER_CBUFFER_FLAGS Flag);
36+
LPCSTR ToString(D3D_PARAMETER_FLAGS Flag);
37+
LPCSTR ToString(D3D_NAME Name);
38+
LPCSTR ToString(D3D_REGISTER_COMPONENT_TYPE CompTy);
39+
LPCSTR ToString(D3D_MIN_PRECISION MinPrec);
40+
LPCSTR CompMaskToString(unsigned CompMask);
41+
42+
// These macros declare the ToString functions for DXC types
43+
#define DEF_RDAT_ENUMS DEF_RDAT_DUMP_DECL
44+
#define DEF_DXIL_ENUMS DEF_RDAT_DUMP_DECL
45+
#include "dxc/DxilContainer/RDAT_Macros.inl"
46+
47+
} // namespace dump
48+
} // namespace hlsl

include/dxc/Test/DumpContext.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
#pragma once
1313

1414
#include "dxc/Support/Global.h"
15+
#include "dxc/Test/D3DReflectionStrings.h"
1516
#include <string>
1617
#include <ostream>
1718
#include <sstream>
1819
#include <iomanip>
1920
#include <unordered_set>
2021

2122
namespace hlsl {
23+
using namespace RDAT;
2224
namespace dump {
2325

2426
template<typename _T>
@@ -45,7 +47,6 @@ class DumpContext {
4547
private:
4648
std::ostream &m_out;
4749
unsigned m_indent = 0;
48-
bool m_bCheckByName = false;
4950
std::unordered_set<size_t> m_visited;
5051

5152
std::ostream &DoIndent() {
@@ -72,10 +73,6 @@ class DumpContext {
7273
std::ostream &Write(std::ostream &out, _T t) {
7374
return out << t;
7475
}
75-
template<>
76-
std::ostream &Write<uint8_t>(std::ostream &out, uint8_t t) {
77-
return out << (unsigned)t;
78-
}
7976
template<typename _T, typename... Args>
8077
std::ostream &Write(std::ostream &out, _T t, Args... args) {
8178
return Write(Write(out, t), args...);
@@ -121,6 +118,11 @@ class DumpContext {
121118
void VisitReset() { m_visited.clear(); }
122119
};
123120

121+
template<>
122+
inline std::ostream &DumpContext::Write<uint8_t>(std::ostream &out, uint8_t t) {
123+
return out << (unsigned)t;
124+
}
125+
124126
// Copied from llvm/ADT/StringExtras.h
125127
inline char hexdigit(unsigned X, bool LowerCase = false) {
126128
const char HexChar = LowerCase ? 'a' : 'A';

include/dxc/Test/DxcTestUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void ParseCommandPartsFromFile(LPCWSTR fileName, std::vector<FileRunCommandPart>
145145
class FileRunTestResult {
146146
public:
147147
std::string ErrorMessage;
148-
int RunResult;
148+
int RunResult = -1;
149149
static FileRunTestResult RunHashTestFromFileCommands(LPCWSTR fileName);
150150
static FileRunTestResult RunFromFileCommands(LPCWSTR fileName,
151151
PluginToolsPaths *pPluginToolsPaths = nullptr,

0 commit comments

Comments
 (0)