D3D12: Add HLSL compiler version to key
BUG=dawn:529 Change-Id: I84d8edc6022564cda084a0f0de384a4e15e0e1a1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/35480 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com>
This commit is contained in:
parent
346fa226df
commit
f600666866
|
@ -128,6 +128,16 @@ namespace dawn_native { namespace d3d12 {
|
||||||
return mDxcCompiler.Get();
|
return mDxcCompiler.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultOrError<IDxcValidator*> Backend::GetOrCreateDxcValidator() {
|
||||||
|
if (mDxcValidator == nullptr) {
|
||||||
|
DAWN_TRY(CheckHRESULT(
|
||||||
|
mFunctions->dxcCreateInstance(CLSID_DxcValidator, IID_PPV_ARGS(&mDxcValidator)),
|
||||||
|
"DXC create validator"));
|
||||||
|
ASSERT(mDxcValidator != nullptr);
|
||||||
|
}
|
||||||
|
return mDxcValidator.Get();
|
||||||
|
}
|
||||||
|
|
||||||
const PlatformFunctions* Backend::GetFunctions() const {
|
const PlatformFunctions* Backend::GetFunctions() const {
|
||||||
return mFunctions.get();
|
return mFunctions.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
ComPtr<IDXGIFactory4> GetFactory() const;
|
ComPtr<IDXGIFactory4> GetFactory() const;
|
||||||
ResultOrError<IDxcLibrary*> GetOrCreateDxcLibrary();
|
ResultOrError<IDxcLibrary*> GetOrCreateDxcLibrary();
|
||||||
ResultOrError<IDxcCompiler*> GetOrCreateDxcCompiler();
|
ResultOrError<IDxcCompiler*> GetOrCreateDxcCompiler();
|
||||||
|
ResultOrError<IDxcValidator*> GetOrCreateDxcValidator();
|
||||||
const PlatformFunctions* GetFunctions() const;
|
const PlatformFunctions* GetFunctions() const;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override;
|
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override;
|
||||||
|
@ -45,6 +46,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
ComPtr<IDXGIFactory4> mFactory;
|
ComPtr<IDXGIFactory4> mFactory;
|
||||||
ComPtr<IDxcLibrary> mDxcLibrary;
|
ComPtr<IDxcLibrary> mDxcLibrary;
|
||||||
ComPtr<IDxcCompiler> mDxcCompiler;
|
ComPtr<IDxcCompiler> mDxcCompiler;
|
||||||
|
ComPtr<IDxcValidator> mDxcValidator;
|
||||||
};
|
};
|
||||||
|
|
||||||
}} // namespace dawn_native::d3d12
|
}} // namespace dawn_native::d3d12
|
||||||
|
|
|
@ -218,6 +218,10 @@ namespace dawn_native { namespace d3d12 {
|
||||||
return ToBackend(GetAdapter())->GetBackend()->GetOrCreateDxcCompiler();
|
return ToBackend(GetAdapter())->GetBackend()->GetOrCreateDxcCompiler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultOrError<IDxcValidator*> Device::GetOrCreateDxcValidator() const {
|
||||||
|
return ToBackend(GetAdapter())->GetBackend()->GetOrCreateDxcValidator();
|
||||||
|
}
|
||||||
|
|
||||||
const PlatformFunctions* Device::GetFunctions() const {
|
const PlatformFunctions* Device::GetFunctions() const {
|
||||||
return ToBackend(GetAdapter())->GetBackend()->GetFunctions();
|
return ToBackend(GetAdapter())->GetBackend()->GetFunctions();
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
ComPtr<IDXGIFactory4> GetFactory() const;
|
ComPtr<IDXGIFactory4> GetFactory() const;
|
||||||
ResultOrError<IDxcLibrary*> GetOrCreateDxcLibrary() const;
|
ResultOrError<IDxcLibrary*> GetOrCreateDxcLibrary() const;
|
||||||
ResultOrError<IDxcCompiler*> GetOrCreateDxcCompiler() const;
|
ResultOrError<IDxcCompiler*> GetOrCreateDxcCompiler() const;
|
||||||
|
ResultOrError<IDxcValidator*> GetOrCreateDxcValidator() const;
|
||||||
|
|
||||||
ResultOrError<CommandRecordingContext*> GetPendingCommandContext();
|
ResultOrError<CommandRecordingContext*> GetPendingCommandContext();
|
||||||
|
|
||||||
|
|
|
@ -319,9 +319,12 @@ namespace dawn_native { namespace d3d12 {
|
||||||
// layout. The pipeline layout is only required if we key from WGSL: two different pipeline
|
// layout. The pipeline layout is only required if we key from WGSL: two different pipeline
|
||||||
// layouts could be used to produce different shader blobs and the wrong shader blob could
|
// layouts could be used to produce different shader blobs and the wrong shader blob could
|
||||||
// be loaded since the pipeline layout was missing from the key.
|
// be loaded since the pipeline layout was missing from the key.
|
||||||
|
// The compiler flags or version used could also produce different HLSL source. HLSL key
|
||||||
|
// needs both to ensure the shader cache key is unique to the HLSL source.
|
||||||
// TODO(dawn:549): Consider keying from WGSL and serialize the pipeline layout it used.
|
// TODO(dawn:549): Consider keying from WGSL and serialize the pipeline layout it used.
|
||||||
const PersistentCacheKey& shaderCacheKey =
|
PersistentCacheKey shaderCacheKey;
|
||||||
CreateHLSLKey(entryPointName, stage, hlslSource, compileFlags);
|
DAWN_TRY_ASSIGN(shaderCacheKey,
|
||||||
|
CreateHLSLKey(entryPointName, stage, hlslSource, compileFlags));
|
||||||
|
|
||||||
CompiledShader compiledShader = {};
|
CompiledShader compiledShader = {};
|
||||||
DAWN_TRY_ASSIGN(compiledShader.cachedShader,
|
DAWN_TRY_ASSIGN(compiledShader.cachedShader,
|
||||||
|
@ -357,7 +360,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentCacheKey ShaderModule::CreateHLSLKey(const char* entryPointName,
|
ResultOrError<PersistentCacheKey> ShaderModule::CreateHLSLKey(const char* entryPointName,
|
||||||
SingleShaderStage stage,
|
SingleShaderStage stage,
|
||||||
const std::string& hlslSource,
|
const std::string& hlslSource,
|
||||||
uint32_t compileFlags) const {
|
uint32_t compileFlags) const {
|
||||||
|
@ -383,7 +386,15 @@ namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
stream << compileFlags;
|
stream << compileFlags;
|
||||||
|
|
||||||
// TODO(dawn:549): add the HLSL compiler version for good measure.
|
// Add the HLSL compiler version for good measure.
|
||||||
|
// Prepend the compiler name to ensure the version is always unique.
|
||||||
|
if (GetDevice()->IsToggleEnabled(Toggle::UseDXC)) {
|
||||||
|
uint64_t dxCompilerVersion;
|
||||||
|
DAWN_TRY_ASSIGN(dxCompilerVersion, GetDXCompilerVersion());
|
||||||
|
stream << "DXC" << dxCompilerVersion;
|
||||||
|
} else {
|
||||||
|
stream << "FXC" << GetD3DCompilerVersion();
|
||||||
|
}
|
||||||
|
|
||||||
// If the source contains multiple entry points, ensure they are cached seperately
|
// If the source contains multiple entry points, ensure they are cached seperately
|
||||||
// per stage since DX shader code can only be compiled per stage using the same
|
// per stage since DX shader code can only be compiled per stage using the same
|
||||||
|
@ -394,4 +405,24 @@ namespace dawn_native { namespace d3d12 {
|
||||||
return PersistentCacheKey(std::istreambuf_iterator<char>{stream},
|
return PersistentCacheKey(std::istreambuf_iterator<char>{stream},
|
||||||
std::istreambuf_iterator<char>{});
|
std::istreambuf_iterator<char>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultOrError<uint64_t> ShaderModule::GetDXCompilerVersion() const {
|
||||||
|
ComPtr<IDxcValidator> dxcValidator;
|
||||||
|
DAWN_TRY_ASSIGN(dxcValidator, ToBackend(GetDevice())->GetOrCreateDxcValidator());
|
||||||
|
|
||||||
|
ComPtr<IDxcVersionInfo> versionInfo;
|
||||||
|
DAWN_TRY(CheckHRESULT(dxcValidator.As(&versionInfo),
|
||||||
|
"D3D12 QueryInterface IDxcValidator to IDxcVersionInfo"));
|
||||||
|
|
||||||
|
uint32_t compilerMajor, compilerMinor;
|
||||||
|
DAWN_TRY(CheckHRESULT(versionInfo->GetVersion(&compilerMajor, &compilerMinor),
|
||||||
|
"IDxcVersionInfo::GetVersion"));
|
||||||
|
|
||||||
|
// Pack both into a single version number.
|
||||||
|
return (uint64_t(compilerMajor) << uint64_t(32)) + compilerMinor;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t ShaderModule::GetD3DCompilerVersion() const {
|
||||||
|
return D3D_COMPILER_VERSION;
|
||||||
|
}
|
||||||
}} // namespace dawn_native::d3d12
|
}} // namespace dawn_native::d3d12
|
||||||
|
|
|
@ -59,11 +59,14 @@ namespace dawn_native { namespace d3d12 {
|
||||||
SingleShaderStage stage,
|
SingleShaderStage stage,
|
||||||
PipelineLayout* layout) const;
|
PipelineLayout* layout) const;
|
||||||
|
|
||||||
PersistentCacheKey CreateHLSLKey(const char* entryPointName,
|
ResultOrError<PersistentCacheKey> CreateHLSLKey(const char* entryPointName,
|
||||||
SingleShaderStage stage,
|
SingleShaderStage stage,
|
||||||
const std::string& hlslSource,
|
const std::string& hlslSource,
|
||||||
uint32_t compileFlags) const;
|
uint32_t compileFlags) const;
|
||||||
|
|
||||||
|
ResultOrError<uint64_t> GetDXCompilerVersion() const;
|
||||||
|
uint64_t GetD3DCompilerVersion() const;
|
||||||
|
|
||||||
#ifdef DAWN_ENABLE_WGSL
|
#ifdef DAWN_ENABLE_WGSL
|
||||||
std::unique_ptr<tint::ast::Module> mTintModule;
|
std::unique_ptr<tint::ast::Module> mTintModule;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue