Recently I've switched from FXC to DXC to compile shader model 6.0. It compiles well without errors (and runs well) but I can't debug shaders because on my netbook PIX says "failed to load PDB file", and on my main laptop PIX can't even start analysis and it shows the error "Timing Data Error".
What am I missing? The compilation generates PDB files (I can see them in the folder with the .exe) but PIX can't find them for some reason. I compile shaders like this:
// Create compiler and utils.
CComPtr<IDxcUtils> pUtils;
CComPtr<IDxcCompiler3> pCompiler;
DxcCreateInstance(CLSID_DxcUtils, IID_PPV_ARGS(&pUtils));
DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&pCompiler));
// Create default include handler.
CComPtr<IDxcIncludeHandler> pIncludeHandler;
pUtils->CreateDefaultIncludeHandler(&pIncludeHandler);
std::vector<LPCWSTR> vArgs;
vArgs.push_back(sPathToShader.c_str());
vArgs.push_back(L"-E");
vArgs.push_back(sShaderEntryPoint.c_str());
vArgs.push_back(L"-T");
vArgs.push_back(sShaderModel.c_str());
vArgs.push_back(DXC_ARG_DEBUG);
vArgs.push_back(DXC_ARG_SKIP_OPTIMIZATIONS);
// Open source file.
CComPtr<IDxcBlobEncoding> pSource = nullptr;
pUtils->LoadFile(sPathToShader.c_str(), nullptr, &pSource);
DxcBuffer Source;
Source.Ptr = pSource->GetBufferPointer();
Source.Size = pSource->GetBufferSize();
Source.Encoding = DXC_CP_ACP;
// Compile it with specified arguments.
CComPtr<IDxcResult> pResults;
pCompiler->Compile(
&Source,
vArgs.data(),
vArgs.size(),
pIncludeHandler,
IID_PPV_ARGS(&pResults)
);
// Print errors if present.
CComPtr<IDxcBlobUtf8> pErrors = nullptr;
pResults->GetOutput(DXC_OUT_ERRORS, IID_PPV_ARGS(&pErrors), nullptr);
if (pErrors != nullptr && pErrors->GetStringLength() != 0)
{
OutputDebugStringA(pErrors->GetStringPointer());
}
// Quit if the compilation failed.
HRESULT hrStatus;
pResults->GetStatus(&hrStatus);
if (FAILED(hrStatus))
{
return;
}
// Save shader binary.
CComPtr<IDxcBlob> pShader = nullptr;
CComPtr<IDxcBlobUtf16> pShaderName = nullptr;
pResults->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&pShader), &pShaderName);
if (pShader == nullptr)
{
return;
}
// Save pdb.
CComPtr<IDxcBlob> pPDB = nullptr;
CComPtr<IDxcBlobUtf16> pPDBName = nullptr;
pResults->GetOutput(DXC_OUT_PDB, IID_PPV_ARGS(&pPDB), &pPDBName);
{
FILE* fp = NULL;
_wfopen_s(&fp, pPDBName->GetStringPointer(), L"wb");
fwrite(pPDB->GetBufferPointer(), pPDB->GetBufferSize(), 1, fp);
fclose(fp);
}