From 4d95ec9807c00a06ce6548eab1ebc3cf9e46aa9c Mon Sep 17 00:00:00 2001 From: David Huculak Date: Sat, 1 Apr 2023 15:48:45 -0400 Subject: [PATCH 1/4] add dxc error message formatting --- wgpu-hal/src/dx12/shader_compilation.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 6d1b75e426..797813bd44 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -83,6 +83,8 @@ pub(super) fn compile_fxc( mod dxc { use std::path::PathBuf; + use hassle_rs::{DxcBlob, DxcOperationResult}; + // Destructor order should be fine since _dxil and _dxc don't rely on each other. pub(crate) struct DxcContainer { compiler: hassle_rs::DxcCompiler, @@ -176,6 +178,12 @@ mod dxc { &[], ); + let format_error_message = |e: DxcOperationResult| { + e.get_error_buffer() + .and_then(|e| dxc_container.library.get_blob_as_string(&DxcBlob::from(e))) + .unwrap_or_default() + }; + let (result, log_level) = match compiled { Ok(dxc_result) => match dxc_result.get_result() { Ok(dxc_blob) => { @@ -188,7 +196,11 @@ mod dxc { Err(e) => ( Err(crate::PipelineError::Linkage( stage_bit, - format!("DXC validation error: {:?}\n{:?}", e.0, e.1), + format!( + "DXC validation error: {:?}\n{:?}", + format_error_message(e.0), + e.1 + ), )), log::Level::Error, ), @@ -205,7 +217,7 @@ mod dxc { Err(e) => ( Err(crate::PipelineError::Linkage( stage_bit, - format!("DXC compile error: {e:?}"), + format!("DXC compile error: {:?}", format_error_message(e.0)), )), log::Level::Error, ), From f8c4e5506b495b6b6dddc9cf85c41a6a967aa453 Mon Sep 17 00:00:00 2001 From: David Huculak Date: Sat, 1 Apr 2023 15:55:31 -0400 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16d7bb93cd..54453580be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,6 +114,7 @@ By @cwfitzgerald in [#3610](https://github.com/gfx-rs/wgpu/pull/3610). - Improve attachment related errors. By @cwfitzgerald in [#3549](https://github.com/gfx-rs/wgpu/pull/3549) - Make error descriptions all upper case. By @cwfitzgerald in [#3549](https://github.com/gfx-rs/wgpu/pull/3549) - Don't include ANSI terminal color escape sequences in shader module validation error messages. By @jimblandy in [#3591](https://github.com/gfx-rs/wgpu/pull/3591) +- Report error messages from DXC compile. By @Davidster #### WebGPU From 2c980c4d625334df3e5c19660f3f315d8ba8ba52 Mon Sep 17 00:00:00 2001 From: David Huculak Date: Sat, 1 Apr 2023 15:58:40 -0400 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54453580be..94063a973f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,7 +114,7 @@ By @cwfitzgerald in [#3610](https://github.com/gfx-rs/wgpu/pull/3610). - Improve attachment related errors. By @cwfitzgerald in [#3549](https://github.com/gfx-rs/wgpu/pull/3549) - Make error descriptions all upper case. By @cwfitzgerald in [#3549](https://github.com/gfx-rs/wgpu/pull/3549) - Don't include ANSI terminal color escape sequences in shader module validation error messages. By @jimblandy in [#3591](https://github.com/gfx-rs/wgpu/pull/3591) -- Report error messages from DXC compile. By @Davidster +- Report error messages from DXC compile. By @Davidster in [#3632](https://github.com/gfx-rs/wgpu/pull/3632) #### WebGPU From d24d4f04fd4a2559842a03a451b15e95f7a1d700 Mon Sep 17 00:00:00 2001 From: David Huculak Date: Sun, 9 Apr 2023 18:52:05 -0400 Subject: [PATCH 4/4] change closure to private function --- wgpu-hal/src/dx12/shader_compilation.rs | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 797813bd44..9f9be7c409 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -83,8 +83,6 @@ pub(super) fn compile_fxc( mod dxc { use std::path::PathBuf; - use hassle_rs::{DxcBlob, DxcOperationResult}; - // Destructor order should be fine since _dxil and _dxc don't rely on each other. pub(crate) struct DxcContainer { compiler: hassle_rs::DxcCompiler, @@ -178,12 +176,6 @@ mod dxc { &[], ); - let format_error_message = |e: DxcOperationResult| { - e.get_error_buffer() - .and_then(|e| dxc_container.library.get_blob_as_string(&DxcBlob::from(e))) - .unwrap_or_default() - }; - let (result, log_level) = match compiled { Ok(dxc_result) => match dxc_result.get_result() { Ok(dxc_blob) => { @@ -198,7 +190,8 @@ mod dxc { stage_bit, format!( "DXC validation error: {:?}\n{:?}", - format_error_message(e.0), + get_error_string_from_dxc_result(&dxc_container.library, &e.0) + .unwrap_or_default(), e.1 ), )), @@ -217,7 +210,11 @@ mod dxc { Err(e) => ( Err(crate::PipelineError::Linkage( stage_bit, - format!("DXC compile error: {:?}", format_error_message(e.0)), + format!( + "DXC compile error: {:?}", + get_error_string_from_dxc_result(&dxc_container.library, &e.0) + .unwrap_or_default() + ), )), log::Level::Error, ), @@ -252,6 +249,15 @@ mod dxc { } } } + + fn get_error_string_from_dxc_result( + library: &hassle_rs::DxcLibrary, + error: &hassle_rs::DxcOperationResult, + ) -> Result { + error + .get_error_buffer() + .and_then(|error| library.get_blob_as_string(&hassle_rs::DxcBlob::from(error))) + } } // These are stubs for when the `dxc_shader_compiler` feature is disabled.