Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example do not work, out of the box #1

Open
Rusty-Weasel opened this issue Dec 14, 2023 · 13 comments
Open

Example do not work, out of the box #1

Rusty-Weasel opened this issue Dec 14, 2023 · 13 comments

Comments

@Rusty-Weasel
Copy link

First of all, thanks for doing this, egui with vulkan could be a nice thing.

Just tried if it work out of the box, but something wrong
image

any idea?

@MatchaChoco010
Copy link
Owner

First of all, thanks for trying the example so quickly!

Please make sure that you are using the latest version of Vulkan SDK in your environment and that you have installed it correctly.

In the example, I use a validation layer called VK_LAYER_KHRONOS_validation, which basically exists in Vulkan.

If the Vulkan SDK is not too old and it does not work, you should check if the installation is done correctly.
Is %VULKAN_SDK% in your PATH set correctly?

@Rusty-Weasel
Copy link
Author

Okay tested it, just downloaded latest tar ball and extract to folder + set the following envs (just as test by hand):

envs:

  • export VULKAN_SDK=/PATH/TO/vulkansdk/1.3.268.0/x86_64/
  • export VK_LAYER_PATH=$VULKAN_SDK/etc/vulkan/explicit_layer.d
  • export LD_LIBRARY_PATH=$VULKAN_SDK/lib:$LD_LIBRARY_PATH

Examples:

  • egui_ash_simple = works

image

  • egui_ash_vulkan = fail by another error (try to look later at it)
  • images = works
  • multi_viewports = fail by another error (try to look later at it)
  • native_image = works
  • scene_view = fail by another error (try to look later at it)
  • tiles = fail by another error (try to look later at it)

the other error is mostly the same:
thread 'main' panicked at /.cargo/registry/src/index.crates.io-6f17d22bba15001f/bytemuck-1.14.0/src/internal.rs:32:3:
cast_slice>TargetAlignmentGreaterAndInputNotAligned

so far to the moment :-)

@MatchaChoco010
Copy link
Owner

I am using bytemuck in examples to convert the shader spv from &[u8] to &[u32].
https://github.com/MatchaChoco010/egui-ash/blob/main/examples/egui_ash_vulkan/renderer.rs#L469-L478

This conversion should not fail because spv should be aligned by 4 bytes, but it appears that the conversion to &[u32] fails because the input spv &[u8] is not aligned to a length that is a multiple of 4.

Are /examples/egui_ash_vulkan/shaders/spv/vert.spv and /examples/egui_ash_vulkan/shaders/spv/frag.spv in multiple of 4 byte size?
They should be 1528bytes and 860bytes respectively.
If these bytes are wrong, the git clone of spv is probably not working.

@Rusty-Weasel
Copy link
Author

yes they are
image

@MatchaChoco010
Copy link
Owner

Thanks for the confirmation!
Hmmm, why isn't it working?

The only two places in example egui_ash_vulkan that use bytemuck are in the shader loading.

I think the problem is that either include_bytes! is not reading bytes correctly, or there is something wrong with bytemuck::cast_slice...

For example, what would happen to assert if you edited L469-L488 as follows and ran it?
https://github.com/MatchaChoco010/egui-ash/blob/main/examples/egui_ash_vulkan/renderer.rs#L469-L488

let vertex_shader_module = {
    let bytes: &[u8] = include_bytes!("./shaders/spv/vert.spv");
    assert!(bytes.len() % 4 == 0);
    let words: &[u32] = bytemuck::cast_slice(bytes);
    let shader_module_create_info = vk::ShaderModuleCreateInfo::builder().code(words);
    unsafe {
        device
            .create_shader_module(&shader_module_create_info, None)
            .expect("Failed to create shader module")
    }
};
let fragment_shader_module = {
    let bytes: &[u8] = include_bytes!("./shaders/spv/frag.spv");
    assert!(bytes.len() % 4 == 0);
    let words: &[u32] = bytemuck::cast_slice(bytes);
    let shader_module_create_info = vk::ShaderModuleCreateInfo::builder().code(words);
    unsafe {
        device
            .create_shader_module(&shader_module_create_info, None)
            .expect("Failed to create shader module")
    }
};

If assert fails, then something is wrong with include_bytes.
Otherwise, there is something wrong with the cast_slice of bytemuck...

@Rusty-Weasel
Copy link
Author

image

tested -> same as before

@MatchaChoco010
Copy link
Owner

Okay, I looked it up, and it seems that alignment was a different concept than length.
cast_slice will fail if the address of the first byte in the array is not divisible by 4.

I made a code to try to cast to an array of &[u32] normally without using bytemuck.
Could you try the fix-shader-import branch?
https://github.com/MatchaChoco010/egui-ash/tree/fix-shader-import

@Rusty-Weasel
Copy link
Author

image

image

@MatchaChoco010
Copy link
Owner

The image appears to use the main branch?
Could you try fix-shader-import instead of the main branch?

@tyrypyrking
Copy link

I had the same issue, and the branch fixed it for me in "tiles" example.
P.S. thank you for this amazing repo, it's exactly what I was looking for.

@Rusty-Weasel
Copy link
Author

The image appears to use the main branch? Could you try fix-shader-import instead of the main branch?

no, it is a seperate clone directly from fix-shade-import branch

@MatchaChoco010
Copy link
Owner

Hmm, the fix-shader-import branch should not be using cast_slice in bytemuck directly.
Is something in the dependent library causing an error with the cast_slice it uses internally?

@GoWeasel If you don't mind, could you try showing backtrace with RUST_BACKTRACE=1?

@MatchaChoco010
Copy link
Owner

Today I published 0.2.0 with some fixes and some API changes.
It also includes the contents of the fix-shader-import branch.

If you want, you can try the latest on the main branch and show me the backtrace with RUST_BACKTRACE=1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants