D3D: Move all the functions about DXC from DeviceD3D to DeviceD3D12
This patch moves all the function calls about DXC from DeviceD3D to
DeviceD3D12 so that DXC can only be used in D3D12 backend.
This patch also removes device->GetDxcValidator() as it is not used
in Dawn.
Bug: dawn:1705
Change-Id: I6c1bad52d8e25988a80dfff9acb6dd84d2fd5327
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/155342
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn/native/d3d/DeviceD3D.cpp b/src/dawn/native/d3d/DeviceD3D.cpp
index 1f50bf3..3f80955 100644
--- a/src/dawn/native/d3d/DeviceD3D.cpp
+++ b/src/dawn/native/d3d/DeviceD3D.cpp
@@ -62,18 +62,6 @@
return ToBackend(GetPhysicalDevice())->GetBackend()->GetFactory();
}
-ComPtr<IDxcLibrary> Device::GetDxcLibrary() const {
- return ToBackend(GetPhysicalDevice())->GetBackend()->GetDxcLibrary();
-}
-
-ComPtr<IDxcCompiler3> Device::GetDxcCompiler() const {
- return ToBackend(GetPhysicalDevice())->GetBackend()->GetDxcCompiler();
-}
-
-ComPtr<IDxcValidator> Device::GetDxcValidator() const {
- return ToBackend(GetPhysicalDevice())->GetBackend()->GetDxcValidator();
-}
-
HANDLE Device::GetFenceHandle() const {
return mFenceHandle;
}
diff --git a/src/dawn/native/d3d/DeviceD3D.h b/src/dawn/native/d3d/DeviceD3D.h
index c8ebbb3..cd80705 100644
--- a/src/dawn/native/d3d/DeviceD3D.h
+++ b/src/dawn/native/d3d/DeviceD3D.h
@@ -42,13 +42,6 @@
const PlatformFunctions* GetFunctions() const;
ComPtr<IDXGIFactory4> GetFactory() const;
- // Those DXC methods are needed by d3d::ShaderModule
- // TODO(penghuang): remove them when related code is refactored to
- // d3d12::ShaderModule.
- ComPtr<IDxcLibrary> GetDxcLibrary() const;
- ComPtr<IDxcCompiler3> GetDxcCompiler() const;
- ComPtr<IDxcValidator> GetDxcValidator() const;
-
HANDLE GetFenceHandle() const;
std::unique_ptr<ExternalImageDXGIImpl> CreateExternalImageDXGIImpl(
diff --git a/src/dawn/native/d3d/ShaderUtils.cpp b/src/dawn/native/d3d/ShaderUtils.cpp
index d2dea95..3b5481d 100644
--- a/src/dawn/native/d3d/ShaderUtils.cpp
+++ b/src/dawn/native/d3d/ShaderUtils.cpp
@@ -264,6 +264,8 @@
return {};
}
+} // anonymous namespace
+
std::string CompileFlagsToString(uint32_t compileFlags) {
struct Flag {
uint32_t value;
@@ -326,8 +328,6 @@
return result;
}
-} // anonymous namespace
-
ResultOrError<CompiledShader> CompileShader(d3d::D3DCompilationRequest r) {
CompiledShader compiledShader;
bool shouldDumpShader = r.hlsl.dumpShaders;
@@ -363,9 +363,9 @@
return compiledShader;
}
-void DumpCompiledShader(Device* device,
- const CompiledShader& compiledShader,
- uint32_t compileFlags) {
+void DumpFXCCompiledShader(Device* device,
+ const CompiledShader& compiledShader,
+ uint32_t compileFlags) {
std::ostringstream dumpedMsg;
// The HLSL may be empty if compilation failed.
if (!compiledShader.hlslSource.empty()) {
@@ -373,43 +373,23 @@
<< compiledShader.hlslSource << std::endl;
}
- // The blob may be empty if FXC/DXC compilation failed.
+ // The blob may be empty if FXC compilation failed.
const Blob& shaderBlob = compiledShader.shaderBlob;
if (!shaderBlob.Empty()) {
- if (device->IsToggleEnabled(Toggle::UseDXC)) {
- dumpedMsg << "/* DXC compile flags */ " << std::endl
- << CompileFlagsToString(compileFlags) << std::endl;
- dumpedMsg << "/* Dumped disassembled DXIL */" << std::endl;
- ComPtr<IDxcBlobEncoding> disassembly;
- DxcBuffer dxcBuffer;
- dxcBuffer.Encoding = DXC_CP_UTF8;
- dxcBuffer.Ptr = shaderBlob.Data();
- dxcBuffer.Size = shaderBlob.Size();
- if (FAILED(device->GetDxcCompiler()->Disassemble(&dxcBuffer,
- IID_PPV_ARGS(&disassembly)))) {
- dumpedMsg << "DXC disassemble failed" << std::endl;
- } else {
- dumpedMsg << std::string_view(
- static_cast<const char*>(disassembly->GetBufferPointer()),
- disassembly->GetBufferSize());
- }
+ dumpedMsg << "/* FXC compile flags */ " << std::endl
+ << CompileFlagsToString(compileFlags) << std::endl;
+ dumpedMsg << "/* Dumped disassembled DXBC */" << std::endl;
+ ComPtr<ID3DBlob> disassembly;
+ UINT flags =
+ // Some literals are printed as floats with precision(6) which is not enough
+ // precision for values very close to 0, so always print literals as hex values.
+ D3D_DISASM_PRINT_HEX_LITERALS;
+ if (FAILED(device->GetFunctions()->d3dDisassemble(shaderBlob.Data(), shaderBlob.Size(),
+ flags, nullptr, &disassembly))) {
+ dumpedMsg << "D3D disassemble failed" << std::endl;
} else {
- dumpedMsg << "/* FXC compile flags */ " << std::endl
- << CompileFlagsToString(compileFlags) << std::endl;
- dumpedMsg << "/* Dumped disassembled DXBC */" << std::endl;
- ComPtr<ID3DBlob> disassembly;
- UINT flags =
- // Some literals are printed as floats with precision(6) which is not enough
- // precision for values very close to 0, so always print literals as hex values.
- D3D_DISASM_PRINT_HEX_LITERALS;
- if (FAILED(device->GetFunctions()->d3dDisassemble(shaderBlob.Data(), shaderBlob.Size(),
- flags, nullptr, &disassembly))) {
- dumpedMsg << "D3D disassemble failed" << std::endl;
- } else {
- dumpedMsg << std::string_view(
- static_cast<const char*>(disassembly->GetBufferPointer()),
- disassembly->GetBufferSize());
- }
+ dumpedMsg << std::string_view(static_cast<const char*>(disassembly->GetBufferPointer()),
+ disassembly->GetBufferSize());
}
}
diff --git a/src/dawn/native/d3d/ShaderUtils.h b/src/dawn/native/d3d/ShaderUtils.h
index 4070663..0b5abb2 100644
--- a/src/dawn/native/d3d/ShaderUtils.h
+++ b/src/dawn/native/d3d/ShaderUtils.h
@@ -39,11 +39,13 @@
DAWN_SERIALIZABLE(struct, CompiledShader, COMPILED_SHADER_MEMBERS){};
#undef COMPILED_SHADER_MEMBERS
+std::string CompileFlagsToString(uint32_t compileFlags);
+
ResultOrError<CompiledShader> CompileShader(d3d::D3DCompilationRequest r);
-void DumpCompiledShader(Device* device,
- const CompiledShader& compiledShader,
- uint32_t compileFlags);
+void DumpFXCCompiledShader(Device* device,
+ const CompiledShader& compiledShader,
+ uint32_t compileFlags);
} // namespace dawn::native::d3d
diff --git a/src/dawn/native/d3d11/ShaderModuleD3D11.cpp b/src/dawn/native/d3d11/ShaderModuleD3D11.cpp
index 40a354d..0bd8450 100644
--- a/src/dawn/native/d3d11/ShaderModuleD3D11.cpp
+++ b/src/dawn/native/d3d11/ShaderModuleD3D11.cpp
@@ -192,7 +192,7 @@
}();
if (device->IsToggleEnabled(Toggle::DumpShaders)) {
- d3d::DumpCompiledShader(device, *compiledShader, compileFlags);
+ d3d::DumpFXCCompiledShader(device, *compiledShader, compileFlags);
}
if (compileError.IsError()) {
diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp
index af836c4..7da08d2 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/DeviceD3D12.cpp
@@ -856,4 +856,12 @@
return DeviceBase::GetBufferCopyOffsetAlignmentForDepthStencil();
}
+ComPtr<IDxcLibrary> Device::GetDxcLibrary() const {
+ return ToBackend(GetPhysicalDevice())->GetBackend()->GetDxcLibrary();
+}
+
+ComPtr<IDxcCompiler3> Device::GetDxcCompiler() const {
+ return ToBackend(GetPhysicalDevice())->GetBackend()->GetDxcCompiler();
+}
+
} // namespace dawn::native::d3d12
diff --git a/src/dawn/native/d3d12/DeviceD3D12.h b/src/dawn/native/d3d12/DeviceD3D12.h
index b430700..2072ad5 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.h
+++ b/src/dawn/native/d3d12/DeviceD3D12.h
@@ -172,6 +172,10 @@
ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials();
MaybeError WaitForIdleForDestruction();
+ // Those DXC methods are needed by d3d12::ShaderModule
+ ComPtr<IDxcLibrary> GetDxcLibrary() const;
+ ComPtr<IDxcCompiler3> GetDxcCompiler() const;
+
private:
using Base = d3d::Device;
diff --git a/src/dawn/native/d3d12/ShaderModuleD3D12.cpp b/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
index 4209427..74f99f4 100644
--- a/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
+++ b/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
@@ -40,6 +40,44 @@
namespace dawn::native::d3d12 {
+namespace {
+
+void DumpDXCCompiledShader(Device* device,
+ const dawn::native::d3d::CompiledShader& compiledShader,
+ uint32_t compileFlags) {
+ std::ostringstream dumpedMsg;
+ // The HLSL may be empty if compilation failed.
+ if (!compiledShader.hlslSource.empty()) {
+ dumpedMsg << "/* Dumped generated HLSL */" << std::endl
+ << compiledShader.hlslSource << std::endl;
+ }
+
+ // The blob may be empty if DXC compilation failed.
+ const Blob& shaderBlob = compiledShader.shaderBlob;
+ if (!shaderBlob.Empty()) {
+ dumpedMsg << "/* DXC compile flags */ " << std::endl
+ << dawn::native::d3d::CompileFlagsToString(compileFlags) << std::endl;
+ dumpedMsg << "/* Dumped disassembled DXIL */" << std::endl;
+ ComPtr<IDxcBlobEncoding> disassembly;
+ DxcBuffer dxcBuffer;
+ dxcBuffer.Encoding = DXC_CP_UTF8;
+ dxcBuffer.Ptr = shaderBlob.Data();
+ dxcBuffer.Size = shaderBlob.Size();
+ if (FAILED(device->GetDxcCompiler()->Disassemble(&dxcBuffer, IID_PPV_ARGS(&disassembly)))) {
+ dumpedMsg << "DXC disassemble failed" << std::endl;
+ } else {
+ dumpedMsg << std::string_view(static_cast<const char*>(disassembly->GetBufferPointer()),
+ disassembly->GetBufferSize());
+ }
+ }
+
+ std::string logMessage = dumpedMsg.str();
+ if (!logMessage.empty()) {
+ device->EmitLog(WGPULoggingType_Info, logMessage.c_str());
+ }
+}
+} // namespace
+
// static
ResultOrError<Ref<ShaderModule>> ShaderModule::Create(
Device* device,
@@ -243,7 +281,11 @@
}();
if (device->IsToggleEnabled(Toggle::DumpShaders)) {
- d3d::DumpCompiledShader(device, *compiledShader, compileFlags);
+ if (device->IsToggleEnabled(Toggle::UseDXC)) {
+ DumpDXCCompiledShader(device, *compiledShader, compileFlags);
+ } else {
+ d3d::DumpFXCCompiledShader(device, *compiledShader, compileFlags);
+ }
}
if (compileError.IsError()) {