cmake/dxc: Add DAWN_DXC_DISABLE_ASSERTS_DEBUG

And make it work exactly like GN arg `dawn_dxc_disable_asserts_debug`,
that is, enable assertions by default in debug builds, but allow the
option to disable them in cases where we get false positives.

Change-Id: I28c370b780c18854f0e3d1a0503439f8aaebe54b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/183962
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 429ed22..fd45f25 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -196,6 +196,7 @@
 option_if_not_defined(DAWN_USE_GLFW "Enable compilation of the GLFW windowing utils" ${DAWN_SUPPORTS_GLFW_FOR_WINDOWING})
 option_if_not_defined(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI})
 option_if_not_defined(DAWN_USE_BUILT_DXC "Enable building and using DXC by the D3D12 backend" OFF)
+option_if_not_defined(DAWN_DXC_DISABLE_ASSERTS_DEBUG "Disable asserts in DXC in debug builds" OFF)
 option_if_not_defined(DAWN_TARGET_MACOS "Manually link Apple core frameworks" ${TARGET_MACOS})
 
 option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
@@ -333,6 +334,7 @@
 message(STATUS "Dawn build GLFW support: ${DAWN_USE_GLFW}")
 message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}")
 message(STATUS "Dawn build and use DXC: ${DAWN_USE_BUILT_DXC}")
+message(STATUS "Dawn disable DXC asserts in debug builds: ${DAWN_DXC_DISABLE_ASSERTS_DEBUG}")
 
 message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
 message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 8f3e3ae..8771e41 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -194,8 +194,11 @@
     # not visible from our build dir. We don't need this validation, so just disable it.
     set(CLANG_FORMAT_EXE "" CACHE STRING "" FORCE)
 
-    # DXC sometimes asserts on valid HLSL, so disable all assertions.
-    set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "" FORCE)
+    if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT DAWN_DXC_DISABLE_ASSERTS_DEBUG)
+        set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "" FORCE)
+    else()
+        set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "" FORCE)
+    endif()
 
     # Override RPATH so that it points to current dir (exe path). This allows both executable and
     # shared library to be in the same location, which we set below. Note that DXC places places