Skip to content

Commit

Permalink
Replace "\\" with "/" in the include handler because DXC 1.8.2405.17 …
Browse files Browse the repository at this point in the history
…will preprocess include directives before passing them to the include handler. This change undoes that preprocessing
  • Loading branch information
KStocky committed Jun 2, 2024
1 parent 39ddd89 commit ecf1f61
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/ShaderTestFramework/Private/D3D12/Shader/IncludeHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
#include "D3D12/Shader/IncludeHandler.h"

#include <filesystem>
#include <fstream>
#include <sstream>

namespace fs = std::filesystem;

namespace
{
fs::path SanitizePath(LPCWSTR InPath)
{
if (InPath[0] == L'.')
{
InPath += 1;
}

if (InPath[1] == L'/')
{
InPath += 1;
}

std::wstring tempPath = InPath;

for (auto offset = tempPath.find_first_of(L'\\'); offset != std::wstring::npos; offset = tempPath.find_first_of(L'\\', offset + 1))
{
tempPath[offset] = L'/';
}

return fs::path{ std::move(tempPath) };
}
}

IncludeHandler::IncludeHandler(VirtualShaderDirectoryMappingManager InManager, ComPtr<IDxcUtils> InUtils)
: m_DirectoryMappings(std::move(InManager))
, m_Utils(std::move(InUtils))
Expand Down Expand Up @@ -48,23 +74,15 @@ ULONG IncludeHandler::Release()

HRESULT IncludeHandler::LoadSource(LPCWSTR pFilename, IDxcBlob** ppIncludeSource)
{
namespace fs = std::filesystem;

if ((pFilename[0] == L'.') && (pFilename[1] == L'/'))
{
pFilename += 2;
}

const auto realPath = [this, pFilename]()
const auto realPath = [this, path = SanitizePath(pFilename)]()
{
std::wstring fileName = pFilename;

if (auto result = m_DirectoryMappings.Map(std::filesystem::path{ fileName }); result.has_value())
if (auto result = m_DirectoryMappings.Map(path); result.has_value())
{
return result.value();
}

return fs::path{ fileName };
return path;
}();

if (!fs::exists(realPath))
Expand Down

0 comments on commit ecf1f61

Please sign in to comment.