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

[linux] Enable Reflection on *nix platforms #4810

Merged
merged 13 commits into from
Nov 24, 2022
Merged
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "external/effcee"]
path = external/effcee
url = https://github.com/google/effcee
[submodule "external/DirectX-Headers"]
path = external/DirectX-Headers
url = https://github.com/microsoft/DirectX-Headers.git
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,12 @@ add_subdirectory(include/dxc)
# This over-specifies the dependency graph, but since generating these doesn't
# really depend on anything else in the build it is safe.
list(APPEND LLVM_COMMON_DEPENDS HCTGen)

if(EXISTS "${LLVM_MAIN_SRC_DIR}/external")
add_subdirectory(external) # SPIRV change
endif()
include_directories(AFTER ${DIRECTX_HEADER_INCLUDE_DIR}/directx ${DIRECTX_HEADER_INCLUDE_DIR}/wsl/stubs)

# HLSL - Change End

add_subdirectory(lib)
Expand Down Expand Up @@ -702,10 +708,6 @@ if(WITH_POLLY)
endif()
endif(WITH_POLLY)

if(EXISTS "${LLVM_MAIN_SRC_DIR}/external")
add_subdirectory(external) # SPIRV change
endif()

if( LLVM_INCLUDE_TOOLS )
add_subdirectory(tools)
endif()
Expand Down
9 changes: 9 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ if (NOT HLSL_ENABLE_DEBUG_ITERATORS)
add_definitions(/D_ITERATOR_DEBUG_LEVEL=0)
endif (NOT HLSL_ENABLE_DEBUG_ITERATORS)

# Need DirectX-Headers module if not on windows
if (NOT WIN32)
if (IS_DIRECTORY "${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers")
set(DIRECTX_HEADER_INCLUDE_DIR ${DXC_EXTERNAL_ROOT_DIR}/DirectX-Headers/include PARENT_SCOPE)
else()
message(FATAL_ERROR "DirectX-Headers was not found - required for reflection support on *nix see https://github.com/microsoft/DirectX-Headers")
endif()
endif (NOT WIN32)

# Enabling SPIR-V codegen requires SPIRV-Headers for spirv.hpp and
# SPIRV-Tools for SPIR-V disassembling functionality.
if (${ENABLE_SPIRV_CODEGEN})
Expand Down
1 change: 1 addition & 0 deletions external/DirectX-Headers
Submodule DirectX-Headers added at 980971
25 changes: 25 additions & 0 deletions include/dxc/Support/D3DReflection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
///////////////////////////////////////////////////////////////////////////////
// //
// DxReflection.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides the needed headers and defines for D3D reflection. //
// //
///////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef _WIN32
// need to disable this as it is voilated by this header
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// need to disable this as it is voilated by this header
// need to disable this as it is violated by this header

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
Comment on lines +15 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pow2clk Didn't we disable this warning altogether as discussed in #3793 (review), or is it now enabled by default on newer compilers (since I only commented out, instead of leaving an unconditional -Wnon-virtual-dtor)?

// Need to instruct non-windows compilers on what an interface is
#define interface struct
#include "d3d12shader.h"
#undef interface
#pragma GCC diagnostic pop
#else
#include <d3d12shader.h>
#endif
27 changes: 24 additions & 3 deletions include/dxc/Support/WinAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <vector>
#endif // __cplusplus

#define COM_NO_WINDOWS_H // needed to inform d3d headers that this isn't windows

//===----------------------------------------------------------------------===//
//
// Begin: Macro Definitions
Expand Down Expand Up @@ -64,10 +66,12 @@
#endif // __EMULATE_UUID

#define STDMETHODCALLTYPE
#define STDAPI extern "C" HRESULT STDAPICALLTYPE
#define STDAPI_(type) extern "C" type STDAPICALLTYPE
#define STDMETHODIMP HRESULT STDMETHODCALLTYPE
#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
#define STDMETHODIMP STDMETHODIMP_(HRESULT)
#define STDMETHOD_(type,name) virtual STDMETHODIMP_(type) name
#define STDMETHOD(name) STDMETHOD_(HRESULT, name)
#define EXTERN_C extern "C"


#define UNREFERENCED_PARAMETER(P) (void)(P)

Expand Down Expand Up @@ -325,6 +329,9 @@
#define _Null_
#define _Notnull_
#define _Maybenull_
#define THIS_
#define THIS
#define PURE = 0

#define _Outptr_result_bytebuffer_(size)

Expand Down Expand Up @@ -364,6 +371,7 @@ typedef unsigned int UINT;
typedef unsigned long ULONG;
typedef long long LONGLONG;
typedef long long LONG_PTR;
typedef unsigned long long ULONG_PTR;
typedef unsigned long long ULONGLONG;

typedef uint16_t WORD;
Expand Down Expand Up @@ -403,6 +411,7 @@ typedef signed int HRESULT;
//===--------------------- Handle Types -----------------------------------===//

typedef void *HANDLE;
typedef void *RPC_IF_HANDLE;

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

#endif // __EMULATE_UUID

// Needed for d3d headers, but fail to create actual interfaces
#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 } }
#define DECLSPEC_UUID(x)
#define MIDL_INTERFACE(x) struct DECLSPEC_UUID(x)
#define DECLARE_INTERFACE(iface) struct iface
#define DECLARE_INTERFACE_(iface, parent) DECLARE_INTERFACE(iface) : parent

//===--------------------- COM Interfaces ---------------------------------===//

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

// These don't need stub implementations as they come from the DirectX Headers
// They still need the __uuidof() though
CROSS_PLATFORM_UUIDOF(ID3D12LibraryReflection, "8E349D19-54DB-4A56-9DC9-119D87BDB804")
CROSS_PLATFORM_UUIDOF(ID3D12ShaderReflection, "5A58797D-A72C-478D-8BA2-EFC6B0EFE88E")

//===--------------------- COM Pointer Types ------------------------------===//

class CAllocator {
Expand Down
21 changes: 0 additions & 21 deletions include/dxc/Test/D3DReflectionDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,10 @@
#include "dxc/Support/Global.h"
#include "DumpContext.h"
#include "dxc/Support/WinIncludes.h"
#include <d3d12shader.h>

namespace hlsl {
namespace dump {

LPCSTR ToString(D3D_CBUFFER_TYPE CBType);
LPCSTR ToString(D3D_SHADER_INPUT_TYPE Type);
LPCSTR ToString(D3D_RESOURCE_RETURN_TYPE ReturnType);
LPCSTR ToString(D3D_SRV_DIMENSION Dimension);
LPCSTR ToString(D3D_PRIMITIVE_TOPOLOGY GSOutputTopology);
LPCSTR ToString(D3D_PRIMITIVE InputPrimitive);
LPCSTR ToString(D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive);
LPCSTR ToString(D3D_TESSELLATOR_PARTITIONING HSPartitioning);
LPCSTR ToString(D3D_TESSELLATOR_DOMAIN TessellatorDomain);
LPCSTR ToString(D3D_SHADER_VARIABLE_CLASS Class);
LPCSTR ToString(D3D_SHADER_VARIABLE_TYPE Type);
LPCSTR ToString(D3D_SHADER_VARIABLE_FLAGS Flag);
LPCSTR ToString(D3D_SHADER_INPUT_FLAGS Flag);
LPCSTR ToString(D3D_SHADER_CBUFFER_FLAGS Flag);
LPCSTR ToString(D3D_PARAMETER_FLAGS Flag);
LPCSTR ToString(D3D_NAME Name);
LPCSTR ToString(D3D_REGISTER_COMPONENT_TYPE CompTy);
LPCSTR ToString(D3D_MIN_PRECISION MinPrec);
LPCSTR CompMaskToString(unsigned CompMask);

class D3DReflectionDumper : public DumpContext {
private:
bool m_bCheckByName = false;
Expand Down
48 changes: 48 additions & 0 deletions include/dxc/Test/D3DReflectionStrings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
///////////////////////////////////////////////////////////////////////////////
// //
// D3DReflectionStrings.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Used to convert reflection data types into strings. //
// //
///////////////////////////////////////////////////////////////////////////////

#pragma once

#include "dxc/Support/D3DReflection.h"
#include "dxc/DxilContainer/DxilRuntimeReflection.h"

namespace hlsl {
using namespace RDAT;
namespace dump {

// ToString functions for D3D types
LPCSTR ToString(D3D_CBUFFER_TYPE CBType);
LPCSTR ToString(D3D_SHADER_INPUT_TYPE Type);
LPCSTR ToString(D3D_RESOURCE_RETURN_TYPE ReturnType);
LPCSTR ToString(D3D_SRV_DIMENSION Dimension);
LPCSTR ToString(D3D_PRIMITIVE_TOPOLOGY GSOutputTopology);
LPCSTR ToString(D3D_PRIMITIVE InputPrimitive);
LPCSTR ToString(D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive);
LPCSTR ToString(D3D_TESSELLATOR_PARTITIONING HSPartitioning);
LPCSTR ToString(D3D_TESSELLATOR_DOMAIN TessellatorDomain);
LPCSTR ToString(D3D_SHADER_VARIABLE_CLASS Class);
LPCSTR ToString(D3D_SHADER_VARIABLE_TYPE Type);
LPCSTR ToString(D3D_SHADER_VARIABLE_FLAGS Flag);
LPCSTR ToString(D3D_SHADER_INPUT_FLAGS Flag);
LPCSTR ToString(D3D_SHADER_CBUFFER_FLAGS Flag);
LPCSTR ToString(D3D_PARAMETER_FLAGS Flag);
LPCSTR ToString(D3D_NAME Name);
LPCSTR ToString(D3D_REGISTER_COMPONENT_TYPE CompTy);
LPCSTR ToString(D3D_MIN_PRECISION MinPrec);
LPCSTR CompMaskToString(unsigned CompMask);

// These macros declare the ToString functions for DXC types
#define DEF_RDAT_ENUMS DEF_RDAT_DUMP_DECL
#define DEF_DXIL_ENUMS DEF_RDAT_DUMP_DECL
#include "dxc/DxilContainer/RDAT_Macros.inl"

} // namespace dump
} // namespace hlsl
12 changes: 7 additions & 5 deletions include/dxc/Test/DumpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
#pragma once

#include "dxc/Support/Global.h"
#include "dxc/Test/D3DReflectionStrings.h"
#include <string>
#include <ostream>
#include <sstream>
#include <iomanip>
#include <unordered_set>

namespace hlsl {
using namespace RDAT;
namespace dump {

template<typename _T>
Expand All @@ -45,7 +47,6 @@ class DumpContext {
private:
std::ostream &m_out;
unsigned m_indent = 0;
bool m_bCheckByName = false;
std::unordered_set<size_t> m_visited;

std::ostream &DoIndent() {
Expand All @@ -72,10 +73,6 @@ class DumpContext {
std::ostream &Write(std::ostream &out, _T t) {
return out << t;
}
template<>
std::ostream &Write<uint8_t>(std::ostream &out, uint8_t t) {
return out << (unsigned)t;
}
template<typename _T, typename... Args>
std::ostream &Write(std::ostream &out, _T t, Args... args) {
return Write(Write(out, t), args...);
Expand Down Expand Up @@ -121,6 +118,11 @@ class DumpContext {
void VisitReset() { m_visited.clear(); }
};

template<>
inline std::ostream &DumpContext::Write<uint8_t>(std::ostream &out, uint8_t t) {
return out << (unsigned)t;
}

// Copied from llvm/ADT/StringExtras.h
inline char hexdigit(unsigned X, bool LowerCase = false) {
const char HexChar = LowerCase ? 'a' : 'A';
Expand Down
2 changes: 1 addition & 1 deletion include/dxc/Test/DxcTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void ParseCommandPartsFromFile(LPCWSTR fileName, std::vector<FileRunCommandPart>
class FileRunTestResult {
public:
std::string ErrorMessage;
int RunResult;
int RunResult = -1;
static FileRunTestResult RunHashTestFromFileCommands(LPCWSTR fileName);
static FileRunTestResult RunFromFileCommands(LPCWSTR fileName,
PluginToolsPaths *pPluginToolsPaths = nullptr,
Expand Down
2 changes: 1 addition & 1 deletion include/dxc/Test/HlslTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ inline std::vector<std::string> GetRunLines(const LPCWSTR name) {
#else
std::ifstream infile((CW2A(path.c_str())));
#endif
if (infile.bad()) {
if (infile.fail() || infile.bad()) {
std::wstring errMsg(L"Unable to read file ");
errMsg += path;
WEX::Logging::Log::Error(errMsg.c_str());
Expand Down
6 changes: 0 additions & 6 deletions include/dxc/Test/RDATDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "DumpContext.h"
#include "dxc/Support/WinIncludes.h"
#include "dxc/DxilContainer/DxilRuntimeReflection.h"

namespace hlsl {
using namespace RDAT;
Expand Down Expand Up @@ -97,10 +96,5 @@ template<typename _T>
void DumpValueArray(DumpContext &d, const char *memberName,
const char *typeName, const void *valueArray,
unsigned arraySize);

#define DEF_RDAT_ENUMS DEF_RDAT_DUMP_DECL
#define DEF_DXIL_ENUMS DEF_RDAT_DUMP_DECL
#include "dxc/DxilContainer/RDAT_Macros.inl"

} // namespace dump
} // namespace hlsl
2 changes: 1 addition & 1 deletion include/dxc/Test/WEXAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#define VERIFY_WIN32_BOOL_SUCCEEDED_2(expr, msg) EXPECT_TRUE(expr) << msg
#define VERIFY_WIN32_BOOL_SUCCEEDED(...) MACRO_N(VERIFY_WIN32_BOOL_SUCCEEDED_, __VA_ARGS__)

#define VERIFY_FAIL ADD_FAILURE
#define VERIFY_FAIL(...) ADD_FAILURE() << __VA_ARGS__ ""

#define TEST_CLASS_SETUP(method) \
bool method(); \
Expand Down
Loading