From c00163ba0925a7de0936a0b0c8385e1986ae5a4c Mon Sep 17 00:00:00 2001 From: "Li, Hao" Date: Fri, 3 Apr 2020 08:34:38 +0000 Subject: [PATCH] Return error instead of crash if compile shader failed on D3D12 Bug: dawn:347 Change-Id: Id5cc8c9c7c3acf5daa6f17fd3235b584dd52d522 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/18720 Commit-Queue: Hao Li Reviewed-by: Austin Eng --- src/dawn_native/d3d12/RenderPipelineD3D12.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp index 830860be8e..28df6de4c1 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp @@ -15,6 +15,7 @@ #include "dawn_native/d3d12/RenderPipelineD3D12.h" #include "common/Assert.h" +#include "common/Log.h" #include "dawn_native/d3d12/D3D12Error.h" #include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/PipelineLayoutD3D12.h" @@ -341,11 +342,14 @@ namespace dawn_native { namespace d3d12 { DAWN_TRY_ASSIGN(hlslSource, module->GetHLSLSource(ToBackend(GetLayout()))); const PlatformFunctions* functions = device->GetFunctions(); - if (FAILED(functions->d3dCompile(hlslSource.c_str(), hlslSource.length(), nullptr, - nullptr, nullptr, entryPoint, compileTarget, - compileFlags, 0, &compiledShader[stage], &errors))) { - printf("%s\n", reinterpret_cast(errors->GetBufferPointer())); - ASSERT(false); + MaybeError error = CheckHRESULT( + functions->d3dCompile(hlslSource.c_str(), hlslSource.length(), nullptr, nullptr, + nullptr, entryPoint, compileTarget, compileFlags, 0, + &compiledShader[stage], &errors), + "D3DCompile"); + if (error.IsError()) { + dawn::WarningLog() << reinterpret_cast(errors->GetBufferPointer()); + DAWN_TRY(std::move(error)); } if (shader != nullptr) {