vsg-dev / VulkanSceneGraph

Vulkan & C++17 based Scene Graph Project
http://www.vulkanscenegraph.org
MIT License
1.32k stars 212 forks source link

ShaderStage::create does not work #293

Closed 16uhrpasing closed 3 years ago

16uhrpasing commented 3 years ago

Hi,

I'm using the VulkanSDK 1.2.176.1 and the latest version of VSG. If I compile my shaders with the glslangValidator and use them via vsg::ShaderStage::read, everything works fine. If I use the exact same source code as a const char * via ShaderStage::create, the program breaks.

Reproduce in vsgdraw from vsgExamples:

const auto vertShader = R"(

version 450

layout(push_constant) uniform PushConstants { mat4 projection; mat4 modelview; } pc;

layout(location = 0) in vec3 inPosition; layout(location = 0) out vec3 fragColor; layout(location = 1) in vec3 inColor; layout(location = 1) out vec2 fragTexCoord; layout(location = 2) in vec2 inTexCoord;

void main() { gl_Position = (pc.projection pc.modelview) vec4(inPosition, 1.0); fragColor = inColor; fragTexCoord = inTexCoord; } )";

const auto fragShader = R"(

version 450

layout(binding = 0) uniform sampler2D texSampler;

layout(location = 0) out vec4 outColor; layout(location = 1) in vec2 fragTexCoord; layout(location = 0) in vec3 fragColor;

void main() { outColor = texture(texSampler, fragTexCoord)*vec4(fragColor,1.0f); } )";

replace the "//load shaders" ShaderStage::read call with auto vertexShader = vsg::ShaderStage::create(VK_SHADER_STAGE_VERTEX_BIT, "main", vertShader); auto fragmentShader = vsg::ShaderStage::create(VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragShader);

-> vsg::Exception at memory location XYZ

compile the exact same source with glslangValidator to the .spv format and use in ShaderStage::create -> works

robertosfield commented 3 years ago

Could you provide a full .cpp that recreates the problem, copying pasting parts of possible example that recreates a problems is really prone to deviation between the copy and pasting and what you have, so the results I might get could well diverge and won't have any means of checking what you fully mean,

Also could you provide a stack trace, and details of your OS & hardware.

16uhrpasing commented 3 years ago

Sorry for the delay, here are the tests I did with the corresponding stack traces and a README. shader error VSG.zip

robertosfield commented 3 years ago

Thanks for the zip file. I have begun investigating. The insource version works for me - I'm using Linux, latest VSG/vsgXchange master, NVidia drivers and VulkanSDK 1.2.162.0, but it creates a Vulkan debug error, running the vsgdraw I see that it's also generating a Vulkan debug error, but I this Vulkan debug error looks unrelated to the issue you're seeing so I'll follow that one up separately. The error is:

UNASSIGNED-CoreValidation-DrawState-InvalidRenderArea(ERROR / SPEC): msgNum: 1149387633 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidRe nderArea ] Object 0: handle = 0x90000000009, type = VK_OBJECT_TYPE_RENDER_PASS; | MessageID = 0x44824371 | Cannot execute a render pass with renderArea not within the bound of the framebuffer. RenderArea: x 0, y 0, width 1280, height 1024. Framebuffer: width 1280, height 1016. Objects: 1

I think this particular error is due to the Window manager resizing the window after it's been created, and the state setup not handling this resize. I will just need to strep through the vsgdraw code to see what needs to be update - this example used to run without Vulkan debug errors so it might be recent VukanSDK are just a bit tighter.

The vsgonv/source.cpp version crashes for me, initially via an exception due to the shader files not being found, then once I fixed the path issue a seg fault in the NVidia driver. My track trace looks like:

0 0x00007fffedf2acf2 in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glvkspirv.so.465.27

1 0x00007fffedf73540 in _nv008nvvm () from

/lib/x86_64-linux-gnu/libnvidia-glvkspirv.so.465.27

2 0x00007ffff5a1bc8f in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glcore.so.465.27

3 0x00007ffff5a1cd3f in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glcore.so.465.27

4 0x00007ffff5a30480 in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glcore.so.465.27

5 0x00007ffff5a30e56 in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glcore.so.465.27

6 0x00007ffff5a1e1bb in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glcore.so.465.27

7 0x00007ffff5a27283 in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glcore.so.465.27

8 0x00007ffff5a2bbc5 in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glcore.so.465.27

9 0x00007ffff5a2bd1b in ?? () from

/lib/x86_64-linux-gnu/libnvidia-glcore.so.465.27

10 0x0000555555607ef6 in

vsg::GraphicsPipeline::Implementation::Implementation(vsg::Context&, vsg::Device, vsg::RenderPass, vsg::PipelineLayout*, std::v ector<vsg::ref_ptr, std::allocator<vsg::ref_ptr > > const&, std::vector<vsg::ref_ptr, std:: allocator<vsg::ref_ptr > > const&, unsigned int) ()

11 0x0000555555608f3c in vsg::GraphicsPipeline::compile(vsg::Context&) ()

12 0x00005555555fde71 in vsg::StateGroup::compile(vsg::Context&) ()

13 0x000055555566ed82 in vsg::CompileTraversal::apply(vsg::StateGroup&) ()

14 0x000055555566ffc0 in vsg::CompileTraversal::apply(vsg::View&) ()

15 0x000055555563bde0 in vsg::View::accept(vsg::Visitor&) ()

16 0x0000555555671344 in vsg::CompileTraversal::apply(vsg::RenderGraph&)

()

17 0x0000555555670e8f in vsg::CompileTraversal::apply(vsg::CommandGraph&)

()

18 0x000055555562f487 in vsg::Viewer::compile(vsg::BufferPreferences) ()

19 0x00005555555ebbbb in main ()

I don't have Windows so can't review the stack trace included in your .zip file, could you post an ascii version of the stack trace?

When I run with -d to get the Vulkan debug layer I see:

UNASSIGNED-CoreValidation-Shader-InconsistentSpirv(ERROR / SPEC): msgNum: 7060244 - Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x556615807328, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: Invalid opcode: 4352 Objects: 1 [0] 0x556615807328, type: 3, name: NULL

When I run vsgconv on the vert.vert and vert.frag myself and then use the resulting .spv the same application runs correctly, and I just see the same Vulkan debug error as seen with vsgdraw and above.

Could you try VulkanSDK 1.162.0 to see if that works for you? I will update to the latest VulkanSDK and see if that has an influence on my results.

robertosfield commented 3 years ago

I have updated to VulkanSDK 1.176.1 and recompiled the VSG/vsgXchange and recreated the vert.spv and frag.spv files and they work fine. The .spv you supplied that had been created by your vsgoonv do still fail with the Vulkan debug error:

UNASSIGNED-CoreValidation-Shader-InconsistentSpirv(ERROR / SPEC): msgNum: 7060244 - Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x557d09711068, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: Invalid opcode: 4352 Objects: 1 [0] 0x557d09711068, type: 3, name: NULL

What is the commit # you are using for the VSG and vsgXchange?

Could you try updating VSG and vsgXchange to their respective masters?

Apart from the vsgdraw Vulkan debug error I don't have anything else I can investigate as all the suggested tests are working OK.

16uhrpasing commented 3 years ago

I updated everything to the respective masters and rebuilt it completely - the vsgconv SPIRV's and the inline shader work perfectly now. I'm assuming that I previously didn't link the glslang library correctly in the VSG Cmake configuration.

Edit: Thank you very much for this awesome piece of software and the awesome support.

robertosfield commented 3 years ago

I did make some improvements of the glslang integration to handle custom SPRIV and glsl versioning, perhaps you were using a VSG rev that predated this.

On Sun, 18 Jul 2021 at 17:47, 16uhrpasing @.***> wrote:

Closed #293 https://github.com/vsg-dev/VulkanSceneGraph/issues/293.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vsg-dev/VulkanSceneGraph/issues/293#event-5035213697, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKEGUHXB6Z6G7UB54BEXALTYMASHANCNFSM475BNR7Q .