gfx-rs / gfx-ocean

Compute based ocean simulation with gfx_hal :ocean:
116 stars 7 forks source link

Program crashes on startup #8

Closed hlavaatch closed 6 years ago

hlavaatch commented 6 years ago

you seem to be calling vkCreateWin32SurfaceKHR() without enabling VK_KHR_surface

Runningtarget\debug\ocean.exe` Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x00000000) assuming VK_API_VERSION_1_1.

ERROR:: [ParameterValidation] Object: 0x0 | Attemped to call vkCreateWin32SurfaceKHR() but its required extension VK_KHR_surface has not been enabled

thread 'main' panicked at 'Unable to load surface functions: ["\"vkDestroySurfaceKHR\"", "\"vkGetPhysicalDeviceSurfaceSupportKHR\"", "\"vkGetPhysicalDeviceSurfaceCapabilitiesKHR\"", "\"vkGetPhysicalDeviceSurfaceFormatsKHR\"", "\"vkGetPhysicalDeviceSurfacePresentModesKHR\""]', libcore\result.rs:945:5 note: Run with RUST_BACKTRACE=1 for a backtrace. ERROR:: [DebugReport] Object: 0x278a46b0a40 | Debug Report callbacks not removed before DestroyInstance ERROR:: [DebugReport] Object: 0x278a46b0a40 | Debug Report callbacks not removed before DestroyInstance ERROR:: [DebugReport] Object: 0x278a46b0a40 | Debug Report callbacks not removed before DestroyInstance ERROR:: [DebugReport] Object: 0x278a46b0a40 | Debug Report callbacks not removed before DestroyInstance error: process didn't exit successfully: target\debug\ocean.exe (exit code: 101)`

msiglreith commented 6 years ago

Thanks for the report. We are internally setting all surface extensions in gfx-rs on instance creation. I assume it will be filtered out somewhere due to the mishandling of the apiVersion on the loader side.

Can you post your system information? (gpu and driver) I'll try to reproduce it locally.

hlavaatch commented 6 years ago

Win10, Radeon R9 280X, radeon driver 18.3.4 (vulkan driver 2.0.18), vulkan sdk/runtime 1.1.70

vulkaninfo.txt

hlavaatch commented 6 years ago
stack backtrace:
   0: std::sys::windows::backtrace::unwind_backtrace
             at C:\projects\rust\src\libstd\sys\windows\backtrace\mod.rs:65
   1: std::sys_common::backtrace::_print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:71
   2: std::sys_common::backtrace::print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:59
   3: std::panicking::default_hook::{{closure}}
             at C:\projects\rust\src\libstd\panicking.rs:207
   4: std::panicking::default_hook
             at C:\projects\rust\src\libstd\panicking.rs:223
   5: std::panicking::rust_panic_with_hook
             at C:\projects\rust\src\libstd\panicking.rs:402
   6: std::panicking::begin_panic_fmt
             at C:\projects\rust\src\libstd\panicking.rs:349
   7: std::panicking::rust_begin_panic
             at C:\projects\rust\src\libstd\panicking.rs:325
   8: core::panicking::panic_fmt
             at C:\projects\rust\src\libcore\panicking.rs:72
   9: core::result::unwrap_failed<alloc::vec::Vec<str*>>
             at C:\projects\rust\src\libcore\macros.rs:26
  10: core::result::Result<ash::extensions::surface::Surface, alloc::vec::Vec<str*>>::expect<ash::extensions::surface::Surface,alloc::vec::Vec<str*>>
             at C:\projects\rust\src\libcore\result.rs:809
  11: gfx_backend_vulkan::Instance::create_surface_from_vk_surface_khr
             at C:\Users\hlavac\.cargo\git\checkouts\gfx-e86e7f3ebdbc4218\e70dec4\src\backend\vulkan\src\window.rs:276
  12: gfx_backend_vulkan::Instance::create_surface_from_hwnd
             at C:\Users\hlavac\.cargo\git\checkouts\gfx-e86e7f3ebdbc4218\e70dec4\src\backend\vulkan\src\window.rs:228
  13: gfx_backend_vulkan::Instance::create_surface
             at C:\Users\hlavac\.cargo\git\checkouts\gfx-e86e7f3ebdbc4218\e70dec4\src\backend\vulkan\src\window.rs:267
  14: ocean::main
             at .\src\main.rs:116
  15: std::rt::lang_start::{{closure}}<()>
             at C:\projects\rust\src\libstd\rt.rs:74
  16: std::rt::lang_start_internal::{{closure}}
             at C:\projects\rust\src\libstd\rt.rs:59
  17: std::panicking::try::do_call<closure,i32>
             at C:\projects\rust\src\libstd\panicking.rs:306
  18: panic_unwind::__rust_maybe_catch_panic
             at C:\projects\rust\src\libpanic_unwind\lib.rs:102
  19: std::panicking::try
             at C:\projects\rust\src\libstd\panicking.rs:285
  20: std::panic::catch_unwind
             at C:\projects\rust\src\libstd\panic.rs:361
  21: std::rt::lang_start_internal
             at C:\projects\rust\src\libstd\rt.rs:58
  22: std::rt::lang_start<()>
             at C:\projects\rust\src\libstd\rt.rs:74
  23: main
  24: invoke_main
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  25: __scrt_common_main_seh
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283
  26: BaseThreadInitThunk
  27: RtlUserThreadStart
msiglreith commented 6 years ago

Hm, updated my drivers and VulkanSDK (Win10, r7 360 (18.3.4) with VulkanSDK 1.1.70.1) and it works for me here. I get the same warning

Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x00000000) assuming VK_API_VERSION_1_1.

but not the parameter validation for the win32 surface feature.

I'll update to the latest gfx version which should help with debugging I hope.

hlavaatch commented 6 years ago

I have debugged and fixed two problems in gfx/backend/vulkan/src/lib.rs :

For the (harmless, but potentially problematic) unspecified API version warning: There is a vk_make_version! macro in ash::vk that can be used to properly initialize vk::ApplicationInfo.api_version:

#[macro_use(vk_make_version)]
extern crate ash;

. . .

impl Instance {
    pub fn create(name: &str, version: u32) -> Self {

. . .

    let app_info = vk::ApplicationInfo {

. . .

     api_version: vk_make_version!(1,0,0),
 };

Second and fatal problem is the "VK_KHR_surface" is missing from the list of enabled extensions thanks to some dodgy code filtering the SURFACE_EXTENSIONS against instance extensions.

I have changed it to this and now it works:

        // Check our xtensions against the available extensions
        let extensions = SURFACE_EXTENSIONS
            .iter()
            .chain(EXTENSIONS.iter())
            .filter_map(|&ext| {
                instance_extensions
                    .iter()
                    .find(|inst_ext| unsafe {
                        CStr::from_ptr(inst_ext.extension_name.as_ptr()).to_str().unwrap() == ext   //<---HERE!
                    })
                    .map(|_| ext)
                    .or_else(|| {
                        warn!("Unable to find extension: {}", ext);
                        None
                    })
            })
            .collect::<Vec<&str>>();
hlavaatch commented 6 years ago

The crash has been fixed in upstream, new gfx version helps. [https://github.com/gfx-rs/gfx/commit/63a5c8698d7957f8099fa91dce9158a2259b6e7b]

msiglreith commented 6 years ago

Oh, right I remember that extension issue again. Thanks for debugging! It has been fixed upstream already but the version used in gfx_ocean was quite outdated. Could you try again the latest gfx_ocean master and confirm if it's working?

hlavaatch commented 6 years ago

Confirmed, latest master does not crash anymore thanks to the updated gfx. There is some mess with shadres

ERROR:<unknown>: [SC] Object: 0x0 | SPIR-V module not valid: MemoryBarrier: Vulkan specification requires Memory Semantics to have one of the following bits set: Acquire, Release, AcquireRelease or SequentiallyConsistent

and some compilation warnings

warning: unused `std::result::Result` which must be used
   --> src/main.rs:208:9
    |
208 |         file.read_to_string(&mut shader);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: #[warn(unused_must_use)] on by default

warning: unused `std::result::Result` which must be used
   --> src/main.rs:221:9
    |
221 |         file.read_to_string(&mut shader);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

but that is outside of the scope of this issue. Closing the crash issue as fixed :)