Skip to content

Commit

Permalink
Changed dynamic lookup of D3DCompiler library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolftein committed Feb 13, 2024
1 parent 114f577 commit 1508ec3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 32 deletions.
10 changes: 1 addition & 9 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ IF (WIN32)
LIST(APPEND PROJECT_DEPENDENCIES "XAudio2")
ENDIF ()

## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Dependency (Win32: D3DCompiler) TODO REMOVE
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

IF (WIN32)
LIST(APPEND PROJECT_DEPENDENCIES "d3dcompiler")
ENDIF ()

## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Dependency (EASTL in-drop replacement for STL)
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Expand Down Expand Up @@ -147,7 +139,7 @@ TARGET_INCLUDE_DIRECTORIES(Toml INTERFACE ${external_toml_SOURCE_DIR})
LIST(APPEND PROJECT_DEPENDENCIES "Toml")

## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Dependency (QUILL)
## Dependency (SPDLOG)
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

FetchContent_Declare(External_SPDLOG
Expand Down
74 changes: 51 additions & 23 deletions Source/Private/Content/Pipeline/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ namespace Content
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

#ifdef EA_PLATFORM_WINDOWS

static pD3DCompile GetD3DCompileFunction()
{
static pD3DCompile FunctionPtr = nullptr;

if (FunctionPtr == nullptr)
{
if (const HMODULE Module = ::LoadLibraryW(L"D3DCompiler_47"))
{
FunctionPtr = (pD3DCompile) GetProcAddress(Module, "D3DCompile");
}
}
return FunctionPtr;
}

#endif // EA_PLATFORM_WINDOWS

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

PipelineLoader::PipelineLoader(Graphic::Backend Backend, Graphic::Language Target)
: mBackend { Backend },
mTarget { Target }
Expand Down Expand Up @@ -326,35 +347,42 @@ namespace Content

Ref<const CStr> Profile = kShaderProfiles[CastEnum(mTarget)][CastEnum(Stage)];

const HRESULT Result = D3DCompile(
Code.data(),
Code.size(),
nullptr,
Defines,
nullptr,
Entry.data(),
Profile.data(),
D3DCOMPILE_OPTIMIZATION_LEVEL3,
0,
& Bytecode,
& Error);

Chunk Compilation;

if (SUCCEEDED(Result))
if (const pD3DCompile D3DCompile = GetD3DCompileFunction())
{
Compilation = Chunk(Bytecode->GetBufferSize());
FastCopyMemory(Compilation.GetData(), Bytecode->GetBufferPointer(), Bytecode->GetBufferSize());
Bytecode->Release();
const HRESULT Result = D3DCompile(
Code.data(),
Code.size(),
nullptr,
Defines,
nullptr,
Entry.data(),
Profile.data(),
D3DCOMPILE_OPTIMIZATION_LEVEL3,
0,
& Bytecode,
& Error);

Chunk Compilation;

if (SUCCEEDED(Result))
{
Compilation = Chunk(Bytecode->GetBufferSize());
FastCopyMemory(Compilation.GetData(), Bytecode->GetBufferPointer(), Bytecode->GetBufferSize());
Bytecode->Release();
}
else
{
LOG_ERROR("Failed to compile shader: {}", reinterpret_cast<Ptr<Char>>(Error->GetBufferPointer()));
}

return Compilation;
}
else
{
LOG_ERROR("Failed to compile shader: {}", reinterpret_cast<Ptr<Char>>(Error->GetBufferPointer()));
LOG_ERROR("Can't find D3DCompile function");
}
#endif // EA_PLATFORM_WINDOWS

return Compilation;
#else // EA_PLATFORM_WINDOWS
return Chunk();
#endif // EA_PLATFORM_WINDOWS
}
}
1 change: 1 addition & 0 deletions Source/Private/Content/Pipeline/Loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace Content
// -=(Undocumented)=-
Chunk CompileDXBC(CStr Entry, CStr Code, Ref<Vector<Property>> Properties, Graphic::Stage Stage);


private:

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Expand Down

0 comments on commit 1508ec3

Please sign in to comment.