NulError in logger when getting a DX12 compile error
so I have been running known bad shaders (infinite loops) and came across a really unexpected error dump when using D3D12 as backend.
It took me 3 days to go through the naga translation etc, but I have no recreated this issue in wgpu-native. It will happen with backend forced to Dx12 and not on Vulkan (using the snippet from #337). ref branch
here is the loop that naga translated into wgsl (I removed some of the placeholder vars). I think this is also a bad translation - but I am not too sure. it's an issue to file elsewhere too.
var i: i32 = 0i;
loop {
if !((i < 100i)) {
break;
}
{
a = (a - 0.005f);
}
continuing {
b = (b + 0.1f);
}
}
If run with DX12 you get a panic emitted from https://github.com/gfx-rs/wgpu-native/blob/3e18e3d3e5fd433053875464447c36d980625f0b/src/logging.rs#L43
the full output and stacktrace:
[wgpu] [warn] Naga generated shader for "fs_main" at Fragment:
struct NagaConstants {
int first_vertex;
int first_instance;
uint other;
};
ConstantBuffer<NagaConstants> _NagaConstants: register(b0);
float4 vs_main(uint in_vertex_index : SV_VertexID) : SV_Position
{
float x = float((int((_NagaConstants.first_vertex + in_vertex_index)) - 1));
float y = float(((int(((_NagaConstants.first_vertex + in_vertex_index) & 1u)) * 2) - 1));
return float4(x, y, 0.0, 1.0);
}
float4 fs_main() : SV_Target0
{
float a = 1.0;
float b = 0.0;
int i = 0;
bool loop_init = true;
while(true) {
if (!loop_init) {
float _e13 = b;
b = (_e13 + 0.1);
}
loop_init = false;
int _e6 = i;
if (!((_e6 < 100))) {
break;
}
{
float _e10 = a;
a = (_e10 - 0.005);
}
}
float _e16 = b;
float _e17 = a;
return float4(1.0, _e16, _e17, 1.0);
}
thread '<unnamed>' panicked at src\logging.rs:43:43:
called `Result::unwrap()` on an `Err` value: NulError(264, [68, 101, 118, 105, 99, 101, 58, 58, 99, 114, 101, 97, 116, 101, 95, 114, 101, 110, 100, 101, 114, 95, 112, 105, 112, 101, 108, 105, 110, 101, 32, 101, 114, 114, 111, 114, 58, 32, 73, 110, 116, 101, 114, 110, 97, 108, 32, 101, 114, 114, 111, 114, 32, 105, 110, 32, 83, 104, 97, 100, 101, 114, 83, 116, 97, 103, 101, 115, 40, 70, 82, 65, 71, 77, 69, 78, 84, 41, 32, 115, 104, 97, 100, 101, 114, 58, 32, 70, 88, 67, 32, 68, 51, 68, 67, 111, 109, 112, 105, 108, 101, 32, 101, 114, 114, 111, 114, 32, 40, 48, 120, 56, 48, 48, 48, 52, 48, 48, 53, 41, 58, 32, 68, 58, 92, 68, 111, 107, 117, 109, 101, 110, 116, 101, 92, 85, 110, 105, 95, 79, 70, 70, 76, 73, 78, 69, 92, 83, 111, 83, 101, 50, 48, 50, 52, 92, 119, 103, 112, 117, 45, 110, 97, 116, 105, 118, 101, 92, 101, 120, 97, 109,
112, 108, 101, 115, 92, 116, 114, 105, 97, 110, 103, 108, 101, 92, 115, 104, 97, 100, 101, 114, 46, 119, 103, 115, 108, 40, 50, 50, 44, 49, 49, 45, 49, 52, 41, 58, 32, 101, 114, 114, 111, 114, 32, 88, 51, 54, 57, 54, 58, 32, 105, 110, 102, 105, 110, 105, 116, 101, 32, 108, 111,
111, 112, 32, 100, 101, 116, 101, 99, 116, 101, 100, 32, 45, 32, 108, 111, 111, 112, 32, 110, 101, 118, 101, 114, 32, 101, 120, 105, 116, 115, 10, 0])
stack backtrace:
0: 0x7ff7652fecad - std::backtrace_rs::backtrace::dbghelp64::trace
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
1: 0x7ff7652fecad - std::backtrace_rs::backtrace::trace_unsynchronized
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
2: 0x7ff7652fecad - std::sys_common::backtrace::_print_fmt
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\sys_common\backtrace.rs:68
3: 0x7ff7652fecad - std::sys_common::backtrace::_print::impl$0::fmt
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\sys_common\backtrace.rs:44
4: 0x7ff764f1f369 - core::fmt::rt::Argument::fmt
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\fmt\rt.rs:165
5: 0x7ff764f1f369 - core::fmt::write
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\fmt\mod.rs:1168
6: 0x7ff7652f50c1 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\io\mod.rs:1835
7: 0x7ff7652fea86 - std::sys_common::backtrace::print
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\sys_common\backtrace.rs:34
8: 0x7ff765301c68 - std::panicking::default_hook::closure$1
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:271
9: 0x7ff765301916 - std::panicking::default_hook
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:298
10: 0x7ff765302268 - std::panicking::rust_panic_with_hook
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:795
11: 0x7ff765302127 - std::panicking::begin_panic_handler::closure$0
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:664
12: 0x7ff7652ff61f - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\sys_common\backtrace.rs:171
13: 0x7ff765301dd8 - std::panicking::begin_panic_handler
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:652
14: 0x7ff766015e94 - core::panicking::panic_fmt
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\panicking.rs:72
15: 0x7ff766016460 - core::result::unwrap_failed
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\result.rs:1679
16: 0x7ff764f06754 - enum2$<core::result::Result<alloc::ffi::c_str::CString,alloc::ffi::c_str::NulError> >::unwrap
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\core\src\result.rs:1102
17: 0x7ff764f06754 - wgpu_native::logging::impl$0::log
at D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\src\logging.rs:43
18: 0x7ff764f3e662 - log::__private_api::log_impl
at C:\Users\Jan\.cargo\registry\src\index.crates.io-6f17d22bba15001f\log-0.4.22\src\__private_api.rs:61
19: 0x7ff764f3f42a - log::__private_api::log<tuple$<> >
at C:\Users\Jan\.cargo\registry\src\index.crates.io-6f17d22bba15001f\log-0.4.22\src\__private_api.rs:72
20: 0x7ff76509253d - wgpu_core::global::Global::device_create_render_pipeline<wgpu_hal::dx12::Api>
at C:\Users\Jan\.cargo\git\checkouts\wgpu-53e70f8674b08dd4\5c5c8b1\wgpu-core\src\device\global.rs:1567
21: 0x7ff764ef5c32 - wgpu_native::wgpuDeviceCreateRenderPipeline
at D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\src\lib.rs:2287
22: 0x7ff764ed1644 - main
at D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\examples\triangle\main.c:220
23: 0x7ff766013b69 - invoke_main
at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
24: 0x7ff766013ca2 - __scrt_common_main_seh
at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
25: 0x7ff766013d2e - __scrt_common_main
at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:330
26: 0x7ff766013d4e - mainCRTStartup
at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:16
27: 0x7ffe3a787374 - BaseThreadInitThunk
28: 0x7ffe3bc3cc91 - RtlUserThreadStart
make: *** [Makefile:144: run-example-triangle] Error 3
if you decode the error message you get
Device::create_render_pipeline error: Internal error in ShaderStages(FRAGMENT) shader: FXC D3DCompile error (0x80004005): D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\examples\triangle\shader.wgsl(22,11-14): error X3696: infinite loop detected - loop never exits
Which I guess is an FXC issue (since it works in vulkan) - but that is an issue to file elsewhere. The problem here is how there is seemingly a nullbyte at the end but the bound is wrong? I am not quite sure but it might be an easy fix.
checked this again in v24 and D3D12 variant still panics, with an error pop up even (from the D3D compiler). I wonder why it's clearly a validation error yet still an uncaptured error and this panic happens?
the full output and stacktrace:
[wgpu] [error] Naga generated shader for "fs_main" at Fragment:
struct NagaConstants {
int first_vertex;
int first_instance;
uint other;
};
ConstantBuffer<NagaConstants> _NagaConstants: register(b0);
float4 vs_main(uint in_vertex_index : SV_VertexID) : SV_Position
{
float x = float((int((_NagaConstants.first_vertex + in_vertex_index)) - 1));
float y = float(((int(((_NagaConstants.first_vertex + in_vertex_index) & 1u)) * 2) - 1));
return float4(x, y, 0.0, 1.0);
}
float4 fs_main() : SV_Target0
{
float a = 1.0;
float b = 0.0;
int i = 0;
bool loop_init = true;
while(true) {
if (!loop_init) {
float _e13 = b;
b = (_e13 + 0.1);
}
loop_init = false;
int _e6 = i;
if (!((_e6 < 100))) {
break;
}
{
float _e10 = a;
a = (_e10 - 0.005);
}
}
float _e16 = b;
float _e17 = a;
return float4(1.0, _e16, _e17, 1.0);
}
[wgpu] [error] Shader translation error for stage ShaderStages(FRAGMENT): FXC D3DCompile error (Unbekannter Fehler (0x80004005)): D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\examples\triangle\shader.wgsl(22,11-14): error X3696: infinite loop detected - loop never exits
[wgpu] [error] Please report it to https://github.com/gfx-rs/wgpu
[wgpu] [warn] Handling wgpu uncaptured errors as fatal by default
thread '<unnamed>' panicked at src\lib.rs:417:5:
wgpu uncaptured error:
Validation Error
Caused by:
In wgpuDeviceCreateRenderPipeline, label = 'render_pipeline'
Internal error in ShaderStages(FRAGMENT) shader: FXC D3DCompile error (Unbekannter Fehler (0x80004005)): D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\examples\triangle\shader.wgsl(22,11-14): error X3696: infinite loop detected - loop never exits
stack backtrace:
0: 0x7ff6c2b7e3bd - std::backtrace_rs::backtrace::dbghelp64::trace
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
1: 0x7ff6c2b7e3bd - std::backtrace_rs::backtrace::trace_unsynchronized
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
2: 0x7ff6c2b7e3bd - std::sys_common::backtrace::_print_fmt
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\sys_common\backtrace.rs:68
3: 0x7ff6c2b7e3bd - std::sys_common::backtrace::_print::impl$0::fmt
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\sys_common\backtrace.rs:44
4: 0x7ff6c2784c89 - core::fmt::rt::Argument::fmt
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\fmt\rt.rs:165
5: 0x7ff6c2784c89 - core::fmt::write
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\fmt\mod.rs:1168
6: 0x7ff6c2b747d1 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\io\mod.rs:1835
7: 0x7ff6c2b7e196 - std::sys_common::backtrace::print
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\sys_common\backtrace.rs:34
8: 0x7ff6c2b81378 - std::panicking::default_hook::closure$1
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:271
9: 0x7ff6c2b81026 - std::panicking::default_hook
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:298
10: 0x7ff6c2b81978 - std::panicking::rust_panic_with_hook
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:795
11: 0x7ff6c2b81837 - std::panicking::begin_panic_handler::closure$0
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:664
12: 0x7ff6c2b7ed2f - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\sys_common\backtrace.rs:171
13: 0x7ff6c2b814e8 - std::panicking::begin_panic_handler
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:652
14: 0x7ff6c35d40b4 - core::panicking::panic_fmt
at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\panicking.rs:72
15: 0x7ff6c2743e4b - wgpu_native::default_uncaptured_error_handler
at D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\src\lib.rs:417
16: 0x7ff6c2744684 - wgpu_native::ErrorSinkRaw::handle_error
at D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\src\lib.rs:551
17: 0x7ff6c27ad663 - wgpu_native::handle_error<enum2$<wgpu_core::pipeline::CreateRenderPipelineError> >
at D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\src\lib.rs:632
18: 0x7ff6c274e767 - wgpu_native::wgpuDeviceCreateRenderPipeline
at D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\src\lib.rs:2304
19: 0x7ff6c2731765 - main
at D:\Dokumente\Uni_OFFLINE\SoSe2024\wgpu-native\examples\triangle\main.c:229
20: 0x7ff6c35d1d89 - invoke_main
at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
21: 0x7ff6c35d1ec2 - __scrt_common_main_seh
at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
22: 0x7ff6c35d1f4e - __scrt_common_main
at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:330
23: 0x7ff6c35d1f6e - mainCRTStartup
at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:16
24: 0x7ff932017374 - BaseThreadInitThunk
25: 0x7ff93351cc91 - RtlUserThreadStart
[wgpu] [warn] Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting.
[wgpu] [warn] Live Producer at 0x000001D848922A58, Refcount: 23.
[wgpu] [warn] Live Object at 0x000001D84FE32F50, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D8532EE8F0, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D853077950, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D8543D2D00, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D853DB8120, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D84F4C4000, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D8549185A0, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D84F4C44C0, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D854913A10, Refcount: 2.
[wgpu] [warn] Live Object at 0x000001D84F4C4260, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D84F4C2AA0, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D854773620, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D852AF5400, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D850F64910, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D850F64DB0, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D850F654A0, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D853DC5210, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D8532F6180, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D8510CF220, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D84F4C2F60, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D8522560F0, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D851725050, Refcount: 2.
[wgpu] [warn] Live Object at 0x000001D85412E680, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D84FE93420, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D854BACBB0, Refcount: 1.
[wgpu] [warn] Live Object at 0x000001D84DDA6F70, Refcount: 0.
[wgpu] [warn] Live Object at 0x000001D84FE33490, Refcount: 1.
[wgpu] [warn] Live Object : 27
make: *** [Makefile:187: run-example-triangle] Error 3
I have seen that v25 will improve some translation issues regarding infinite loops, so will revisit this once they release and native is caught up.
is actually not an issue since v24 the above was unrelated. Fixed with the whole WGPUStringView thing