Created
April 29, 2020 22:32
-
-
Save hugoam/c91adbf496733a78738afd11ee951c00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index 8394d031..86abec2b 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -27,6 +27,13 @@ project( | |
LANGUAGES C CXX | |
) | |
+set(DAWN_LIBRARY_DIR "${Dawn_BINARY_DIR}/lib") | |
+ | |
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${DAWN_LIBRARY_DIR}) | |
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${DAWN_LIBRARY_DIR}) | |
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${DAWN_LIBRARY_DIR}) | |
+set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY ${DAWN_LIBRARY_DIR}) | |
+ | |
set_property(GLOBAL PROPERTY USE_FOLDERS ON) | |
if(NOT CMAKE_BUILD_TYPE) | |
@@ -104,9 +111,9 @@ target_include_directories(dawn_internal_config INTERFACE | |
target_link_libraries(dawn_internal_config INTERFACE dawn_public_config) | |
# Compile definitions for the internal config | |
-if (DAWN_ALWAYS_ASSERT OR $<CONFIG:Debug>) | |
- target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS") | |
-endif() | |
+ | |
+target_compile_definitions(dawn_internal_config INTERFACE $<$<OR:$<CONFIG:Debug>,$<BOOL:${DAWN_ALWAYS_ASSERT}>>:DAWN_ENABLE_ASSERTS>) | |
+ | |
if (DAWN_ENABLE_D3D12) | |
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12") | |
endif() | |
diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp | |
index 0e387863..d7ebf0f7 100644 | |
--- a/examples/SampleUtils.cpp | |
+++ b/examples/SampleUtils.cpp | |
@@ -65,7 +65,9 @@ enum class CmdBufType { | |
// Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on | |
// their respective platforms, and Vulkan is preferred to OpenGL | |
-#if defined(DAWN_ENABLE_BACKEND_D3D12) | |
+#if defined(DAWN_ENABLE_BACKEND_VULKAN) | |
+static wgpu::BackendType backendType = wgpu::BackendType::Vulkan; | |
+#elif defined(DAWN_ENABLE_BACKEND_D3D12) | |
static wgpu::BackendType backendType = wgpu::BackendType::D3D12; | |
#elif defined(DAWN_ENABLE_BACKEND_METAL) | |
static wgpu::BackendType backendType = wgpu::BackendType::Metal; | |
diff --git a/src/common/windows_with_undefs.h b/src/common/windows_with_undefs.h | |
index 381116a0..207be61c 100644 | |
--- a/src/common/windows_with_undefs.h | |
+++ b/src/common/windows_with_undefs.h | |
@@ -27,7 +27,7 @@ | |
// Macros defined for ANSI / Unicode support | |
#undef CreateWindow | |
-#undef GetMessage | |
+//#undef GetMessage | |
// Macros defined to produce compiler intrinsics | |
#undef MemoryBarrier | |
diff --git a/src/dawn/CMakeLists.txt b/src/dawn/CMakeLists.txt | |
index 05173432..d13fced8 100644 | |
--- a/src/dawn/CMakeLists.txt | |
+++ b/src/dawn/CMakeLists.txt | |
@@ -81,5 +81,13 @@ DawnJSONGenerator( | |
) | |
add_library(dawn_proc STATIC ${DAWN_DUMMY_FILE}) | |
+add_library(dawn_proc_shared SHARED ${DAWN_DUMMY_FILE}) | |
target_sources(dawn_proc PRIVATE ${DAWNPROC_GEN_SOURCES}) | |
+target_sources(dawn_proc_shared PRIVATE ${DAWNPROC_GEN_SOURCES}) | |
target_link_libraries(dawn_proc PUBLIC dawn_headers) | |
+target_link_libraries(dawn_proc_shared PUBLIC dawn_headers) | |
+ | |
+target_compile_definitions(dawn_proc_shared | |
+ PRIVATE WGPU_IMPLEMENTATION | |
+ PUBLIC WGPU_SHARED_LIBRARY | |
+) | |
diff --git a/src/dawn_native/CMakeLists.txt b/src/dawn_native/CMakeLists.txt | |
index 9d783255..8289327e 100644 | |
--- a/src/dawn_native/CMakeLists.txt | |
+++ b/src/dawn_native/CMakeLists.txt | |
@@ -19,7 +19,8 @@ DawnJSONGenerator( | |
) | |
add_library(dawn_native STATIC ${DAWN_DUMMY_FILE}) | |
-target_sources(dawn_native PRIVATE | |
+add_library(dawn_native_shared SHARED ${DAWN_DUMMY_FILE}) | |
+set(DAWN_NATIVE_SOURCES | |
"${DAWN_INCLUDE_DIR}/dawn_native/DawnNative.h" | |
"${DAWN_INCLUDE_DIR}/dawn_native/dawn_native_export.h" | |
${DAWN_NATIVE_UTILS_GEN_SOURCES} | |
@@ -135,6 +136,10 @@ target_sources(dawn_native PRIVATE | |
"Toggles.h" | |
"dawn_platform.h" | |
) | |
+ | |
+target_sources(dawn_native PRIVATE ${DAWN_NATIVE_SOURCES}) | |
+target_sources(dawn_native_shared PRIVATE ${DAWN_NATIVE_SOURCES}) | |
+ | |
target_link_libraries(dawn_native | |
PUBLIC dawncpp_headers | |
PRIVATE dawn_common | |
@@ -144,9 +149,31 @@ target_link_libraries(dawn_native | |
spirv-cross-core | |
) | |
+target_link_libraries(dawn_native_shared | |
+ PUBLIC dawncpp_headers | |
+ PRIVATE dawn_common | |
+ dawn_platform | |
+ dawn_internal_config | |
+ shaderc_spvc_shared | |
+ SPIRV-Tools | |
+ spirv-cross-hlsl | |
+ spirv-cross-glsl | |
+ spirv-cross-core | |
+) | |
+ | |
+target_compile_definitions(dawn_native_shared | |
+ PRIVATE DAWN_NATIVE_IMPLEMENTATION | |
+ PUBLIC DAWN_NATIVE_SHARED_LIBRARY | |
+) | |
+ | |
+if (MSVC) | |
+ target_compile_options(dawn_native_shared PRIVATE /wd4251) | |
+endif() | |
+ | |
if (DAWN_USE_X11) | |
find_package(X11 REQUIRED) | |
target_link_libraries(dawn_native PRIVATE ${X11_LIBRARIES}) | |
+ target_link_libraries(dawn_native_shared PRIVATE ${X11_LIBRARIES}) | |
endif() | |
if (WIN32) | |
@@ -154,7 +181,7 @@ if (WIN32) | |
endif() | |
if (DAWN_ENABLE_D3D12) | |
- target_sources(dawn_native PRIVATE | |
+ set(DAWN_NATIVE_D3D12_SOURCES | |
"${DAWN_INCLUDE_DIR}/dawn_native/D3D12Backend.h" | |
"d3d12/AdapterD3D12.cpp" | |
"d3d12/AdapterD3D12.h" | |
@@ -227,11 +254,14 @@ if (DAWN_ENABLE_D3D12) | |
"d3d12/UtilsD3D12.h" | |
"d3d12/d3d12_platform.h" | |
) | |
- target_link_libraries(dawn_native PRIVATE dxguid.lib) | |
+ target_sources(dawn_native PRIVATE ${DAWN_NATIVE_D3D12_SOURCES}) | |
+ target_sources(dawn_native_shared PRIVATE ${DAWN_NATIVE_D3D12_SOURCES}) | |
+ target_link_libraries(dawn_native PRIVATE dxguid.lib dxcompiler.lib) | |
+ target_link_libraries(dawn_native_shared PRIVATE dxguid.lib dxcompiler.lib) | |
endif() | |
if (DAWN_ENABLE_METAL) | |
- target_sources(dawn_native PRIVATE | |
+ set(DAWN_NATIVE_METAL_SOURCES | |
"${DAWN_INCLUDE_DIR}/dawn_native/MetalBackend.h" | |
"Surface_metal.mm" | |
"metal/BackendMTL.h" | |
@@ -270,20 +300,30 @@ if (DAWN_ENABLE_METAL) | |
"metal/UtilsMetal.h" | |
"metal/UtilsMetal.mm" | |
) | |
+ target_sources(dawn_native PRIVATE ${DAWN_NATIVE_METAL_SOURCES}) | |
+ target_sources(dawn_native_shared PRIVATE ${DAWN_NATIVE_METAL_SOURCES}) | |
target_link_libraries(dawn_native PRIVATE | |
"-framework Cocoa" | |
"-framework IOKit" | |
"-framework IOSurface" | |
"-framework QuartzCore" | |
) | |
+ target_link_libraries(dawn_native_shared PRIVATE | |
+ "-framework Cocoa" | |
+ "-framework IOKit" | |
+ "-framework IOSurface" | |
+ "-framework QuartzCore" | |
+ ) | |
endif() | |
if (DAWN_ENABLE_NULL) | |
- target_sources(dawn_native PRIVATE | |
+ set(DAWN_NATIVE_NULL_SOURCES | |
"${DAWN_INCLUDE_DIR}/dawn_native/NullBackend.h" | |
"null/DeviceNull.cpp" | |
"null/DeviceNull.h" | |
) | |
+ target_sources(dawn_native PRIVATE ${DAWN_NATIVE_NULL_SOURCES}) | |
+ target_sources(dawn_native_shared PRIVATE ${DAWN_NATIVE_NULL_SOURCES}) | |
endif() | |
if (DAWN_ENABLE_OPENGL) | |
@@ -297,7 +337,7 @@ if (DAWN_ENABLE_OPENGL) | |
RESULT_VARIABLE "DAWN_NATIVE_OPENGL_AUTOGEN_SOURCES" | |
) | |
- target_sources(dawn_native PRIVATE | |
+ set(DAWN_NATIVE_OPENGL_SOURCES | |
"${DAWN_INCLUDE_DIR}/dawn_native/OpenGLBackend.h" | |
${DAWN_NATIVE_OPENGL_AUTOGEN_SOURCES} | |
"opengl/BackendGL.cpp" | |
@@ -343,12 +383,14 @@ if (DAWN_ENABLE_OPENGL) | |
"opengl/UtilsGL.h" | |
"opengl/opengl_platform.h" | |
) | |
- | |
+ target_sources(dawn_native PRIVATE ${DAWN_NATIVE_OPENGL_SOURCES}) | |
+ target_sources(dawn_native_shared PRIVATE ${DAWN_NATIVE_OPENGL_SOURCES}) | |
target_link_libraries(dawn_native PRIVATE dawn_khronos_platform) | |
+ target_link_libraries(dawn_native_shared PRIVATE dawn_khronos_platform) | |
endif() | |
if (DAWN_ENABLE_VULKAN) | |
- target_sources(dawn_native PRIVATE | |
+ set(DAWN_NATIVE_VULKAN_SOURCES | |
"${DAWN_INCLUDE_DIR}/dawn_native/VulkanBackend.h" | |
"vulkan/AdapterVk.cpp" | |
"vulkan/AdapterVk.h" | |
@@ -409,36 +451,53 @@ if (DAWN_ENABLE_VULKAN) | |
"vulkan/external_memory/MemoryService.h" | |
"vulkan/external_semaphore/SemaphoreService.h" | |
) | |
+ target_sources(dawn_native PRIVATE ${DAWN_NATIVE_VULKAN_SOURCES}) | |
+ target_sources(dawn_native_shared PRIVATE ${DAWN_NATIVE_VULKAN_SOURCES}) | |
target_link_libraries(dawn_native PUBLIC dawn_vulkan_headers) | |
+ target_link_libraries(dawn_native_shared PUBLIC dawn_vulkan_headers) | |
if (UNIX AND NOT APPLE) | |
target_sources(dawn_native PRIVATE | |
"vulkan/external_memory/MemoryServiceOpaqueFD.cpp" | |
"vulkan/external_semaphore/SemaphoreServiceOpaqueFD.cpp" | |
) | |
+ target_sources(dawn_native_shared PRIVATE | |
+ "vulkan/external_memory/MemoryServiceOpaqueFD.cpp" | |
+ "vulkan/external_semaphore/SemaphoreServiceOpaqueFD.cpp" | |
+ ) | |
else() | |
target_sources(dawn_native PRIVATE | |
"vulkan/external_memory/MemoryServiceNull.cpp" | |
"vulkan/external_semaphore/SemaphoreServiceNull.cpp" | |
) | |
+ target_sources(dawn_native_shared PRIVATE | |
+ "vulkan/external_memory/MemoryServiceNull.cpp" | |
+ "vulkan/external_semaphore/SemaphoreServiceNull.cpp" | |
+ ) | |
endif() | |
endif() | |
# TODO how to do the component build in CMake? | |
target_sources(dawn_native PRIVATE "DawnNative.cpp") | |
+target_sources(dawn_native_shared PRIVATE "DawnNative.cpp") | |
if (DAWN_ENABLE_D3D12) | |
target_sources(dawn_native PRIVATE "d3d12/D3D12Backend.cpp") | |
+ target_sources(dawn_native_shared PRIVATE "d3d12/D3D12Backend.cpp") | |
endif() | |
if (DAWN_ENABLE_METAL) | |
target_sources(dawn_native PRIVATE "metal/MetalBackend.mm") | |
+ target_sources(dawn_native_shared PRIVATE "metal/MetalBackend.mm") | |
endif() | |
if (DAWN_ENABLE_NULL) | |
target_sources(dawn_native PRIVATE "null/NullBackend.cpp") | |
+ target_sources(dawn_native_shared PRIVATE "null/NullBackend.cpp") | |
endif() | |
if (DAWN_ENABLE_OPENGL) | |
target_sources(dawn_native PRIVATE "opengl/OpenGLBackend.cpp") | |
+ target_sources(dawn_native_shared PRIVATE "opengl/OpenGLBackend.cpp") | |
endif() | |
if (DAWN_ENABLE_VULKAN) | |
target_sources(dawn_native PRIVATE "vulkan/VulkanBackend.cpp") | |
+ target_sources(dawn_native_shared PRIVATE "vulkan/VulkanBackend.cpp") | |
endif() | |
diff --git a/src/dawn_native/EncodingContext.h b/src/dawn_native/EncodingContext.h | |
index 3142bd09..94dd5a41 100644 | |
--- a/src/dawn_native/EncodingContext.h | |
+++ b/src/dawn_native/EncodingContext.h | |
@@ -23,6 +23,8 @@ | |
#include <string> | |
+#undef GetMessage | |
+ | |
namespace dawn_native { | |
class DeviceBase; | |
diff --git a/src/dawn_native/Format.cpp b/src/dawn_native/Format.cpp | |
index 9c7fa58a..39192f3b 100644 | |
--- a/src/dawn_native/Format.cpp | |
+++ b/src/dawn_native/Format.cpp | |
@@ -130,7 +130,7 @@ namespace dawn_native { | |
}; | |
auto AddDepthStencilFormat = [&AddFormat](wgpu::TextureFormat format, Format::Aspect aspect, | |
- uint32_t byteSize) { | |
+ uint32_t byteSize, Type type) { | |
Format internalFormat; | |
internalFormat.format = format; | |
internalFormat.isRenderable = true; | |
@@ -138,7 +138,7 @@ namespace dawn_native { | |
internalFormat.isSupported = true; | |
internalFormat.supportsStorageUsage = false; | |
internalFormat.aspect = aspect; | |
- internalFormat.type = Type::Other; | |
+ internalFormat.type = type; | |
internalFormat.blockByteSize = byteSize; | |
internalFormat.blockWidth = 1; | |
internalFormat.blockHeight = 1; | |
@@ -229,10 +229,10 @@ namespace dawn_native { | |
AddDepthFormat(wgpu::TextureFormat::Depth32Float, 4, Type::Float); | |
// Packed depth/depth-stencil formats | |
- AddDepthStencilFormat(wgpu::TextureFormat::Depth24Plus, Aspect::Depth, 4); | |
+ AddDepthStencilFormat(wgpu::TextureFormat::Depth24Plus, Aspect::Depth, 4, Type::Other); | |
// TODO(cwallez@chromium.org): It isn't clear if this format should be copyable | |
// because its size isn't well defined, is it 4, 5 or 8? | |
- AddDepthStencilFormat(wgpu::TextureFormat::Depth24PlusStencil8, Aspect::DepthStencil, 4); | |
+ AddDepthStencilFormat(wgpu::TextureFormat::Depth24PlusStencil8, Aspect::DepthStencil, 4, Type::Other); | |
// BC compressed formats | |
bool isBCFormatSupported = device->IsExtensionEnabled(Extension::TextureCompressionBC); | |
diff --git a/src/dawn_native/d3d12/BackendD3D12.cpp b/src/dawn_native/d3d12/BackendD3D12.cpp | |
index eea97206..b70bcb23 100644 | |
--- a/src/dawn_native/d3d12/BackendD3D12.cpp | |
+++ b/src/dawn_native/d3d12/BackendD3D12.cpp | |
@@ -32,7 +32,7 @@ namespace dawn_native { namespace d3d12 { | |
// Enable the debug layer (requires the Graphics Tools "optional feature"). | |
{ | |
- if (enableBackendValidation) { | |
+ if (enableBackendValidation || true) { | |
ComPtr<ID3D12Debug> debugController; | |
if (SUCCEEDED( | |
functions->d3d12GetDebugInterface(IID_PPV_ARGS(&debugController)))) { | |
@@ -68,6 +68,28 @@ namespace dawn_native { namespace d3d12 { | |
return std::move(factory); | |
} | |
+#if USE_DXC | |
+ ResultOrError<CComPtr<IDxcLibrary>> CreateDxcLibrary() { | |
+ CComPtr<IDxcLibrary> library; | |
+ if (FAILED(DxcCreateInstance(CLSID_DxcLibrary, IID_PPV_ARGS(&library)))) { | |
+ return DAWN_INTERNAL_ERROR("Failed to create DXC library"); | |
+ } | |
+ | |
+ ASSERT(library != nullptr); | |
+ return std::move(library); | |
+ } | |
+ | |
+ ResultOrError<CComPtr<IDxcCompiler>> CreateDxcCompiler() { | |
+ CComPtr<IDxcCompiler> compiler; | |
+ if (FAILED(DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&compiler)))) { | |
+ return DAWN_INTERNAL_ERROR("Failed to create DXC compiler"); | |
+ } | |
+ | |
+ ASSERT(compiler != nullptr); | |
+ return std::move(compiler); | |
+ } | |
+#endif | |
+ | |
} // anonymous namespace | |
Backend::Backend(InstanceBase* instance) | |
@@ -84,6 +106,12 @@ namespace dawn_native { namespace d3d12 { | |
CreateFactory(mFunctions.get(), instance->IsBackendValidationEnabled(), | |
instance->IsBeginCaptureOnStartupEnabled())); | |
+#if USE_DXC | |
+ DAWN_TRY_ASSIGN(mDxcLibrary, CreateDxcLibrary()); | |
+ | |
+ DAWN_TRY_ASSIGN(mDxcCompiler, CreateDxcCompiler()); | |
+#endif | |
+ | |
return {}; | |
} | |
@@ -91,6 +119,16 @@ namespace dawn_native { namespace d3d12 { | |
return mFactory; | |
} | |
+#if USE_DXC | |
+ IDxcLibrary* Backend::GetDxcLibrary() const { | |
+ return mDxcLibrary; | |
+ } | |
+ | |
+ IDxcCompiler* Backend::GetDxcCompiler() const { | |
+ return mDxcCompiler; | |
+ } | |
+#endif | |
+ | |
const PlatformFunctions* Backend::GetFunctions() const { | |
return mFunctions.get(); | |
} | |
diff --git a/src/dawn_native/d3d12/BackendD3D12.h b/src/dawn_native/d3d12/BackendD3D12.h | |
index 3161048a..776f1fff 100644 | |
--- a/src/dawn_native/d3d12/BackendD3D12.h | |
+++ b/src/dawn_native/d3d12/BackendD3D12.h | |
@@ -19,6 +19,14 @@ | |
#include "dawn_native/d3d12/d3d12_platform.h" | |
+#define USE_DXC 1 | |
+ | |
+#if USE_DXC | |
+#include <dxcapi.h> | |
+#include <WinUser.h> | |
+#include <atlbase.h> | |
+#endif | |
+ | |
namespace dawn_native { namespace d3d12 { | |
class PlatformFunctions; | |
@@ -30,6 +38,10 @@ namespace dawn_native { namespace d3d12 { | |
MaybeError Initialize(); | |
ComPtr<IDXGIFactory4> GetFactory() const; | |
+#if USE_DXC | |
+ IDxcLibrary* GetDxcLibrary() const; | |
+ IDxcCompiler* GetDxcCompiler() const; | |
+#endif | |
const PlatformFunctions* GetFunctions() const; | |
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override; | |
@@ -39,6 +51,10 @@ namespace dawn_native { namespace d3d12 { | |
// the D3D12 DLLs are unloaded before we are done using them. | |
std::unique_ptr<PlatformFunctions> mFunctions; | |
ComPtr<IDXGIFactory4> mFactory; | |
+#if USE_DXC | |
+ CComPtr<IDxcLibrary> mDxcLibrary; | |
+ CComPtr<IDxcCompiler> mDxcCompiler; | |
+#endif | |
}; | |
}} // namespace dawn_native::d3d12 | |
diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp | |
index 8f09bf94..7cd01dc3 100644 | |
--- a/src/dawn_native/d3d12/DeviceD3D12.cpp | |
+++ b/src/dawn_native/d3d12/DeviceD3D12.cpp | |
@@ -169,6 +169,16 @@ namespace dawn_native { namespace d3d12 { | |
return ToBackend(GetAdapter())->GetBackend()->GetFactory(); | |
} | |
+#if USE_DXC | |
+ IDxcLibrary* Device::GetDxcLibrary() const { | |
+ return ToBackend(GetAdapter())->GetBackend()->GetDxcLibrary(); | |
+ } | |
+ | |
+ IDxcCompiler* Device::GetDxcCompiler() const { | |
+ return ToBackend(GetAdapter())->GetBackend()->GetDxcCompiler(); | |
+ } | |
+#endif | |
+ | |
const PlatformFunctions* Device::GetFunctions() const { | |
return ToBackend(GetAdapter())->GetBackend()->GetFunctions(); | |
} | |
diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h | |
index 615f1fb5..3ffec3aa 100644 | |
--- a/src/dawn_native/d3d12/DeviceD3D12.h | |
+++ b/src/dawn_native/d3d12/DeviceD3D12.h | |
@@ -27,6 +27,12 @@ | |
#include <memory> | |
+#define USE_DXC 1 | |
+ | |
+#if USE_DXC | |
+#include <dxcapi.h> | |
+#endif | |
+ | |
namespace dawn_native { namespace d3d12 { | |
class CommandAllocatorManager; | |
@@ -73,6 +79,10 @@ namespace dawn_native { namespace d3d12 { | |
const PlatformFunctions* GetFunctions() const; | |
ComPtr<IDXGIFactory4> GetFactory() const; | |
+#if USE_DXC | |
+ IDxcLibrary* GetDxcLibrary() const; | |
+ IDxcCompiler* GetDxcCompiler() const; | |
+#endif | |
ResultOrError<CommandRecordingContext*> GetPendingCommandContext(); | |
Serial GetPendingCommandSerial() const override; | |
diff --git a/src/dawn_native/d3d12/PlatformFunctions.cpp b/src/dawn_native/d3d12/PlatformFunctions.cpp | |
index 1e79f88c..73f4bbeb 100644 | |
--- a/src/dawn_native/d3d12/PlatformFunctions.cpp | |
+++ b/src/dawn_native/d3d12/PlatformFunctions.cpp | |
@@ -16,6 +16,12 @@ | |
#include "common/DynamicLib.h" | |
+#define USE_DXC 1 | |
+ | |
+#if USE_DXC | |
+#include <dxcapi.h> | |
+#endif | |
+ | |
namespace dawn_native { namespace d3d12 { | |
PlatformFunctions::PlatformFunctions() { | |
@@ -73,11 +79,18 @@ namespace dawn_native { namespace d3d12 { | |
} | |
MaybeError PlatformFunctions::LoadD3DCompiler() { | |
+#if USE_DXC | |
+ std::string error; | |
+ if (!mD3DCompilerLib.Open("dxcompiler.dll", &error)) { | |
+ return DAWN_INTERNAL_ERROR(error.c_str()); | |
+ } | |
+#else | |
std::string error; | |
if (!mD3DCompilerLib.Open("d3dcompiler_47.dll", &error) || | |
!mD3DCompilerLib.GetProc(&d3dCompile, "D3DCompile", &error)) { | |
return DAWN_INTERNAL_ERROR(error.c_str()); | |
} | |
+#endif | |
return {}; | |
} | |
diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp | |
index 85cd0b72..03806203 100644 | |
--- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp | |
+++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp | |
@@ -26,6 +26,11 @@ | |
#include <d3dcompiler.h> | |
+#if USE_DXC | |
+#include <dxcapi.h> | |
+#include <atlbase.h> | |
+#endif | |
+ | |
namespace dawn_native { namespace d3d12 { | |
namespace { | |
@@ -310,27 +315,24 @@ namespace dawn_native { namespace d3d12 { | |
D3D12_GRAPHICS_PIPELINE_STATE_DESC descriptorD3D12 = {}; | |
+#if USE_DXC | |
+ PerStage<ComPtr<IDxcBlob>> compiledShader; | |
+#else | |
PerStage<ComPtr<ID3DBlob>> compiledShader; | |
- ComPtr<ID3DBlob> errors; | |
+#endif | |
wgpu::ShaderStage renderStages = wgpu::ShaderStage::Vertex | wgpu::ShaderStage::Fragment; | |
for (auto stage : IterateStages(renderStages)) { | |
ShaderModule* module = nullptr; | |
- const char* entryPoint = nullptr; | |
- const char* compileTarget = nullptr; | |
D3D12_SHADER_BYTECODE* shader = nullptr; | |
switch (stage) { | |
case SingleShaderStage::Vertex: | |
module = ToBackend(descriptor->vertexStage.module); | |
- entryPoint = descriptor->vertexStage.entryPoint; | |
shader = &descriptorD3D12.VS; | |
- compileTarget = "vs_5_1"; | |
break; | |
case SingleShaderStage::Fragment: | |
module = ToBackend(descriptor->fragmentStage->module); | |
- entryPoint = descriptor->fragmentStage->entryPoint; | |
shader = &descriptorD3D12.PS; | |
- compileTarget = "ps_5_1"; | |
break; | |
default: | |
UNREACHABLE(); | |
@@ -341,6 +343,136 @@ namespace dawn_native { namespace d3d12 { | |
DAWN_TRY_ASSIGN(hlslSource, module->GetHLSLSource(ToBackend(GetLayout()))); | |
const PlatformFunctions* functions = device->GetFunctions(); | |
+#if USE_DXC | |
+ CComPtr<IDxcLibrary> dxcLibrary = ToBackend(GetDevice())->GetDxcLibrary(); | |
+ CComPtr<IDxcCompiler> dxcCompiler = ToBackend(GetDevice())->GetDxcCompiler(); | |
+ | |
+ auto ConvertStringToWstring = [](const char* str) { | |
+ std::wstring result; | |
+ size_t len = strlen(str); | |
+ if (len == 0) { | |
+ return result; | |
+ } | |
+ int numChars = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, str, | |
+ len, NULL, 0); | |
+ if (numChars) { | |
+ result.resize(numChars); | |
+ MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, str, len, &result[0], | |
+ numChars); | |
+ } | |
+ return result; | |
+ }; | |
+ | |
+ std::wstring entryPoint; | |
+ std::wstring compileTarget; | |
+ switch (stage) { | |
+ case SingleShaderStage::Vertex: | |
+ entryPoint = ConvertStringToWstring(descriptor->vertexStage.entryPoint); | |
+ compileTarget = L"vs_6_0"; | |
+ break; | |
+ case SingleShaderStage::Fragment: | |
+ entryPoint = ConvertStringToWstring(descriptor->fragmentStage->entryPoint); | |
+ compileTarget = L"ps_6_0"; | |
+ break; | |
+ default: | |
+ UNREACHABLE(); | |
+ break; | |
+ } | |
+ | |
+ uint32_t codePage = CP_UTF8; | |
+ CComPtr<IDxcBlobEncoding> sourceBlob; | |
+ if (FAILED(dxcLibrary->CreateBlobWithEncodingOnHeapCopy( | |
+ hlslSource.c_str(), hlslSource.length(), CP_ACP, &sourceBlob))) { | |
+ } | |
+ | |
+ std::vector<LPCWSTR> arguments; | |
+ if (compileFlags & D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY) | |
+ arguments.push_back(L"/Gec"); | |
+ // /Ges Not implemented: | |
+ // if(Flags1 & D3DCOMPILE_ENABLE_STRICTNESS) arguments.push_back(L"/Ges"); | |
+ if (compileFlags & D3DCOMPILE_IEEE_STRICTNESS) | |
+ arguments.push_back(L"/Gis"); | |
+ if (compileFlags & D3DCOMPILE_OPTIMIZATION_LEVEL2) { | |
+ switch (compileFlags & D3DCOMPILE_OPTIMIZATION_LEVEL2) { | |
+ case D3DCOMPILE_OPTIMIZATION_LEVEL0: | |
+ arguments.push_back(L"/O0"); | |
+ break; | |
+ case D3DCOMPILE_OPTIMIZATION_LEVEL2: | |
+ arguments.push_back(L"/O2"); | |
+ break; | |
+ case D3DCOMPILE_OPTIMIZATION_LEVEL3: | |
+ arguments.push_back(L"/O3"); | |
+ break; | |
+ } | |
+ } | |
+ // Currently, /Od turns off too many optimization passes, causing incorrect DXIL to be | |
+ // generated. Re-enable once /Od is implemented properly: | |
+ // if(Flags1 & D3DCOMPILE_SKIP_OPTIMIZATION) arguments.push_back(L"/Od"); | |
+ if (compileFlags & D3DCOMPILE_DEBUG) | |
+ arguments.push_back(L"/Zi"); | |
+ if (compileFlags & D3DCOMPILE_PACK_MATRIX_ROW_MAJOR) | |
+ arguments.push_back(L"/Zpr"); | |
+ if (compileFlags & D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR) | |
+ arguments.push_back(L"/Zpc"); | |
+ if (compileFlags & D3DCOMPILE_AVOID_FLOW_CONTROL) | |
+ arguments.push_back(L"/Gfa"); | |
+ if (compileFlags & D3DCOMPILE_PREFER_FLOW_CONTROL) | |
+ arguments.push_back(L"/Gfp"); | |
+ // We don't implement this: | |
+ // if(Flags1 & D3DCOMPILE_PARTIAL_PRECISION) arguments.push_back(L"/Gpp"); | |
+ if (compileFlags & D3DCOMPILE_RESOURCES_MAY_ALIAS) | |
+ arguments.push_back(L"/res_may_alias"); | |
+ arguments.push_back(L"-HV"); | |
+ arguments.push_back(L"2016"); | |
+ | |
+ CComPtr<IDxcOperationResult> result; | |
+ if (FAILED(dxcCompiler->Compile(sourceBlob, // pSource | |
+ nullptr, // pSourceName | |
+ entryPoint.c_str(), // pEntryPoint | |
+ compileTarget.c_str(), // pTargetProfile | |
+ arguments.data(), | |
+ arguments.size(), // pArguments, argCount | |
+ nullptr, 0, // pDefines, defineCount | |
+ nullptr, // pIncludeHandler | |
+ &result))) // ppResult | |
+ { | |
+ } | |
+ | |
+ HRESULT hr; | |
+ result->GetStatus(&hr); | |
+ MaybeError error = CheckHRESULT(hr, "D3DCompile"); | |
+ if (error.IsError()) { | |
+ if (result) { | |
+ ComPtr<IDxcBlobEncoding> errors; | |
+ if (SUCCEEDED(result->GetErrorBuffer(&errors))) { | |
+ dawn::WarningLog() << reinterpret_cast<char*>(errors->GetBufferPointer()); | |
+ DAWN_TRY(std::move(error)); | |
+ } | |
+ } | |
+ } | |
+ | |
+ ComPtr<IDxcBlob> code; | |
+ result->GetResult(&code); | |
+ | |
+ compiledShader[stage] = code; | |
+#else | |
+ const char* entryPoint = nullptr; | |
+ const char* compileTarget = nullptr; | |
+ switch (stage) { | |
+ case SingleShaderStage::Vertex: | |
+ entryPoint = descriptor->vertexStage.entryPoint; | |
+ compileTarget = "vs_5_1"; | |
+ break; | |
+ case SingleShaderStage::Fragment: | |
+ entryPoint = descriptor->fragmentStage->entryPoint; | |
+ compileTarget = "ps_5_1"; | |
+ break; | |
+ default: | |
+ UNREACHABLE(); | |
+ break; | |
+ } | |
+ | |
+ ComPtr<ID3DBlob> errors; | |
MaybeError error = CheckHRESULT( | |
functions->d3dCompile(hlslSource.c_str(), hlslSource.length(), nullptr, nullptr, | |
nullptr, entryPoint, compileTarget, compileFlags, 0, | |
@@ -350,6 +482,7 @@ namespace dawn_native { namespace d3d12 { | |
dawn::WarningLog() << reinterpret_cast<char*>(errors->GetBufferPointer()); | |
DAWN_TRY(std::move(error)); | |
} | |
+#endif | |
if (shader != nullptr) { | |
shader->pShaderBytecode = compiledShader[stage]->GetBufferPointer(); | |
diff --git a/src/dawn_native/vulkan/VulkanBackend.cpp b/src/dawn_native/vulkan/VulkanBackend.cpp | |
index c1458a00..663d060d 100644 | |
--- a/src/dawn_native/vulkan/VulkanBackend.cpp | |
+++ b/src/dawn_native/vulkan/VulkanBackend.cpp | |
@@ -33,12 +33,23 @@ namespace dawn_native { namespace vulkan { | |
return backendDevice->GetVkInstance(); | |
} | |
+ VkDevice GetDevice(WGPUDevice device) { | |
+ Device* backendDevice = reinterpret_cast<Device*>(device); | |
+ return backendDevice->GetVkDevice(); | |
+ } | |
+ | |
DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetInstanceProcAddr(WGPUDevice device, | |
const char* pName) { | |
Device* backendDevice = reinterpret_cast<Device*>(device); | |
return (*backendDevice->fn.GetInstanceProcAddr)(backendDevice->GetVkInstance(), pName); | |
} | |
+ DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetDeviceProcAddr(WGPUDevice device, | |
+ const char* pName) { | |
+ Device* backendDevice = reinterpret_cast<Device*>(device); | |
+ return (*backendDevice->fn.GetDeviceProcAddr)(backendDevice->GetVkDevice(), pName); | |
+ } | |
+ | |
// Explicitly export this function because it uses the "native" type for surfaces while the | |
// header as seen in this file uses the wrapped type. | |
DAWN_NATIVE_EXPORT DawnSwapChainImplementation | |
diff --git a/src/include/dawn_native/VulkanBackend.h b/src/include/dawn_native/VulkanBackend.h | |
index b144e4ec..f2b98811 100644 | |
--- a/src/include/dawn_native/VulkanBackend.h | |
+++ b/src/include/dawn_native/VulkanBackend.h | |
@@ -24,8 +24,10 @@ | |
namespace dawn_native { namespace vulkan { | |
DAWN_NATIVE_EXPORT VkInstance GetInstance(WGPUDevice device); | |
+ DAWN_NATIVE_EXPORT VkDevice GetDevice(WGPUDevice device); | |
DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetInstanceProcAddr(WGPUDevice device, const char* pName); | |
+ DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetDeviceProcAddr(WGPUDevice device, const char* pName); | |
DAWN_NATIVE_EXPORT DawnSwapChainImplementation | |
CreateNativeSwapChainImpl(WGPUDevice device, ::VkSurfaceKHR surface); | |
diff --git a/src/utils/WGPUHelpers.h b/src/utils/WGPUHelpers.h | |
index 92bd518c..8f28185e 100644 | |
--- a/src/utils/WGPUHelpers.h | |
+++ b/src/utils/WGPUHelpers.h | |
@@ -17,6 +17,7 @@ | |
#include <dawn/webgpu_cpp.h> | |
+#include <vector> | |
#include <array> | |
#include <initializer_list> | |
#include <vector> | |
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt | |
index dbceb4db..aecb3ab0 100644 | |
--- a/third_party/CMakeLists.txt | |
+++ b/third_party/CMakeLists.txt | |
@@ -51,7 +51,7 @@ else() | |
# Change the default value of SHADERC_ENABLE_SHARED_CRT to ON as that's what matches the | |
# CMake defaults better. | |
if(MSVC) | |
- option(SHADERC_ENABLE_SHARED_CRT "Use the shared CRT instead of the static CRT" ON CACHE BOOL "" FORCE) | |
+ #option(SHADERC_ENABLE_SHARED_CRT "Use the shared CRT instead of the static CRT" ON CACHE BOOL "" FORCE) | |
endif() | |
# Let SPVC's CMakeLists.txt deal with configuring SPIRV-Cross |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment