Skip to content

Commit

Permalink
Move dxil.dll to DXC repo. (#6866)
Browse files Browse the repository at this point in the history
Build dxil.dll in DXC repo.
It will shares same validator code with dxcompiler.dll.

Fixes #6769
  • Loading branch information
python3kgae authored Sep 5, 2024
1 parent 72f306c commit 9e039e2
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/clang/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ endif()
set(CLANG_TEST_DEPS dxc dxa dxopt dxl dxv dxr dxcompiler clang-tblgen llvm-config opt FileCheck count not ClangUnitTests)
if (WIN32)
list(APPEND CLANG_TEST_DEPS
dxc_batch ExecHLSLTests
dxc_batch ExecHLSLTests dxildll
)
else()
list(APPEND CLANG_TEST_DEPS
dxildll
)
endif()
add_custom_target(clang-test-depends DEPENDS ${CLANG_TEST_DEPS})
Expand Down
1 change: 1 addition & 0 deletions tools/clang/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_subdirectory(dxcompiler)
add_subdirectory(dxclib)
add_subdirectory(dxc)
add_subdirectory(dxcvalidator)
add_subdirectory(dxildll)
add_subdirectory(dxa)
add_subdirectory(dxopt)
add_subdirectory(dxl)
Expand Down
2 changes: 2 additions & 0 deletions tools/clang/tools/dxcvalidator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set( LLVM_LINK_COMPONENTS
DxilContainer
DxilHash
DxilValidation
DxilRootSignature
HLSL # for gcc link error on AreDxilResourcesDense and DxilSignatureAllocator which are used in DxilValidation
Option # option library
Support # just for assert and raw streams
)
Expand Down
86 changes: 86 additions & 0 deletions tools/clang/tools/dxildll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (C) Microsoft Corporation. All rights reserved.
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.

set(SHARED_LIBRARY TRUE)

set(DXCComponents
LLVMBitWriter
LLVMDxcSupport
LLVMDXIL
LLVMDxilContainer
LLVMDxilHash
LLVMDxilRootSignature
LLVMDxilValidation
LLVMHLSL # for AreDxilResourcesDense and DxilSignatureAllocator which are used in DxilValidation
LLVMMSSupport
LLVMSupport
LLVMTransformUtils
LLVMAnalysis
LLVMDxcBindingTable
LLVMipa
)

foreach(C ${DXCComponents})
if (WIN32)
list(APPEND DXCLibs ${C})
list(APPEND DXCDependencies ${C})
else()
list(APPEND DXCLibs ${C})
list(APPEND DXCDependencies ${C})
endif()
endforeach(C ${DXCComponents})

include_directories(
${LLVM_SOURCE_DIR}/tools/clang/tools/dxcvalidator
${LLVM_BINARY_DIR}/projects/include
)

set(sources
dxildll.cpp
dxildll.def
dxcvalidator.cpp
)

if (WIN32)
add_clang_library(dxildll SHARED ${sources})
list(APPEND DXCLibs
kernel32.lib
atls.lib
advapi32.lib
ole32.lib)
else()
add_clang_library(dxildll SHARED ${sources})
endif()

target_link_libraries(dxildll PRIVATE
${DXCLibs}
clangBasic # for clang::getGitCommitHash.
dxcvalidator
)

if (WIN32)
add_dependencies(dxildll
${DXCDependencies}
DxcEtw
DxcRuntimeEtw
)
else()
add_dependencies(dxildll
${DXCDependencies}
)
endif()

if (WIN32)
get_target_property(sources dxildll SOURCES)

list(APPEND sources dxildll.rc)
set_target_properties(${target_name} PROPERTIES SOURCES "${sources}")

set_property(SOURCE dxildll.rc PROPERTY COMPILE_DEFINITIONS "INCLUDE_HLSL_VERSION_FILE=1")
set_property(SOURCE dxildll.rc PROPERTY COMPILE_OPTIONS "/I" "${HLSL_VERSION_LOCATION}" "/I" "${LLVM_MAIN_SRC_DIR}")
endif()

set_target_properties(dxildll
PROPERTIES
OUTPUT_NAME "dxil"
)
140 changes: 140 additions & 0 deletions tools/clang/tools/dxildll/dxcvalidator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
///////////////////////////////////////////////////////////////////////////////
// //
// dxcvalidator.cpp //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Implements the DirectX Validator object, including hashing support. //
// //
///////////////////////////////////////////////////////////////////////////////

#include "dxcvalidator.h"

#include "dxc/Support/WinIncludes.h"

#include "dxc/Support/Global.h"
#include "dxc/Support/microcom.h"
#include "dxc/dxcapi.h"

#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
#include "clang/Basic/Version.h"
#endif // SUPPORT_QUERY_GIT_COMMIT_INFO

using namespace llvm;
using namespace hlsl;

class DxcValidator : public IDxcValidator2,
#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
public IDxcVersionInfo2
#else
public IDxcVersionInfo
#endif // SUPPORT_QUERY_GIT_COMMIT_INFO
{
private:
DXC_MICROCOM_TM_REF_FIELDS()

public:
DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL()
DXC_MICROCOM_TM_CTOR(DxcValidator)

HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
void **ppvObject) override {

return DoBasicQueryInterface<IDxcValidator, IDxcValidator2,
IDxcVersionInfo>(this, iid, ppvObject);
}

HRESULT STDMETHODCALLTYPE Validate(
IDxcBlob *pShader, // Shader to validate.
UINT32 Flags, // Validation flags.
IDxcOperationResult *
*ppResult // Validation output status, buffer, and errors
) override;

// IDxcValidator2
HRESULT STDMETHODCALLTYPE ValidateWithDebug(
IDxcBlob *pShader, // Shader to validate.
UINT32 Flags, // Validation flags.
DxcBuffer *pDebugModule, // Debug module bitcode to provide line numbers
IDxcOperationResult *
*ppResult // Validation output status, buffer, and errors
) override;

// IDxcVersionInfo
HRESULT STDMETHODCALLTYPE GetVersion(UINT32 *pMajor, UINT32 *pMinor) override;
HRESULT STDMETHODCALLTYPE GetFlags(UINT32 *pFlags) override;

#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
// IDxcVersionInfo2
HRESULT STDMETHODCALLTYPE GetCommitInfo(UINT32 *pCommitCount,
char **pCommitHash) override;
#endif
};

// Compile a single entry point to the target shader model
HRESULT STDMETHODCALLTYPE DxcValidator::Validate(
IDxcBlob *pShader, // Shader to validate.
UINT32 Flags, // Validation flags.
IDxcOperationResult *
*ppResult // Validation output status, buffer, and errors
) {
return hlsl::validateWithDebug(pShader, Flags, nullptr, ppResult);
}

HRESULT STDMETHODCALLTYPE DxcValidator::ValidateWithDebug(
IDxcBlob *pShader, // Shader to validate.
UINT32 Flags, // Validation flags.
DxcBuffer *pOptDebugBitcode, // Optional debug module bitcode to provide
// line numbers
IDxcOperationResult *
*ppResult // Validation output status, buffer, and errors
) {
return hlsl::validateWithDebug(pShader, Flags, pOptDebugBitcode, ppResult);
}

HRESULT STDMETHODCALLTYPE DxcValidator::GetVersion(UINT32 *pMajor,
UINT32 *pMinor) {
return hlsl::getValidationVersion(pMajor, pMinor);
}

#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
HRESULT STDMETHODCALLTYPE DxcValidator::GetCommitInfo(UINT32 *pCommitCount,
char **pCommitHash) {
if (pCommitCount == nullptr || pCommitHash == nullptr)
return E_INVALIDARG;

char *const hash = (char *)CoTaskMemAlloc(
8 + 1); // 8 is guaranteed by utils/GetCommitInfo.py
if (hash == nullptr)
return E_OUTOFMEMORY;
std::strcpy(hash, clang::getGitCommitHash());

*pCommitHash = hash;
*pCommitCount = clang::getGitCommitCount();

return S_OK;
}
#endif // SUPPORT_QUERY_GIT_COMMIT_INFO

HRESULT STDMETHODCALLTYPE DxcValidator::GetFlags(UINT32 *pFlags) {
DxcThreadMalloc TM(m_pMalloc);
if (pFlags == nullptr)
return E_INVALIDARG;
*pFlags = DxcVersionInfoFlags_None;
#ifdef _DEBUG
*pFlags |= DxcVersionInfoFlags_Debug;
#endif
return S_OK;
}

HRESULT CreateDxcValidator(REFIID riid, LPVOID *ppv) {
try {
CComPtr<DxcValidator> result(
DxcValidator::Alloc(DxcGetThreadMallocNoRef()));
if (result.p == nullptr)
return E_OUTOFMEMORY;
return result.p->QueryInterface(riid, ppv);
}
CATCH_CPP_RETURN_HRESULT();
}
Loading

0 comments on commit 9e039e2

Please sign in to comment.