5 ms·
Can anyone recommend a good self-contained "hello triangle" example with SDL2 + Vulkan? Just yesterday I was trying to start a project, and I tried building the
by ForkMeOnTinder 3y ago
Can anyone recommend a good self-contained "hello triangle" example with SDL2 + Vulkan? Just yesterday I was trying to start a project, and I tried building the top 4 example repos on github but couldn't get any of them to compile without errors.
- flohofwoe 3y agoNot SDL2, but GLFW has something like that under the tests/ directory: https://github.com/glfw/glfw/blob/master/tests/triangle-vulkan.c https://github.com/glfw/glfw/blob/master/tests/triangle-vulk... (yes it's over 2kloc for a triangle - that's Vulkan for you ;) but at least it's all in one file readable from top to bottom instead of being spread over a dozen obscure "helper classes")
- nightpool 3y agoAh, yes, one readable file, top to bottom https://i.ibb.co/qdjct5K/Screenshot-20231011-095306.png https://i.ibb.co/qdjct5K/Screenshot-20231011-095306.png
- flohofwoe 3y agoThat's SPIRV shader bytecode. Does Vulkan actually come with an integrated shader compiler these days? Otherwise there's not much one can do for a standalone sample like that.
- Chabsff 3y ago"integrated" in the sense that the SDK comes with a compiler, but it's not integrated in the same sense as OpenGL where the compiler is part of the driver. If you can compile that code, then you necessarily have the compiler at hand. You can't make a simple single code file example though. The build system has to get involved somehow. FWIW, I think this is a good thing. Any non-trivial 3D project is going to involve some kind of asset baking sooner or later, which makes the barrier of entry to that negligible. At the same time, driver-driven compilation is just too convenient and sticky. That's a bad combination.
- pharrington 3y agoSPIR-V is an intermediate bytecode format. That bytecode is the data that you use in the Vulkan API, and under the hood your graphics drivers compile that bytecode into the device-specific native shader binary that runs on the graphics hardware. Vulkan doesn't come with any tools to generate that bytecode though. Foreign shader language (like HLSL, GLSL, etc) to SPIR-V compilers exist, and various graphics toolchains can generate SPIR-V. https://github.com/KhronosGroup/SPIRV-Tools https://github.com/KhronosGroup/SPIRV-Tools does have tools to validate and optimize bytecode. edit: i lied apparently - the SPIRV-Tools does have an assembler that translates text such as the "Corresponding SPIR-V" at https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_example https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.htm... to bytecode. However, that's not something you'd want to write manually, especially if you're used to something like GLSL.
- MayeulC 3y ago> yes it's over 2kloc for a triangle - that's Vulkan for you My understanding is that VK_EXT_shader_object should make such examples simpler? https://www.khronos.org/blog/you-can-use-vulkan-without-pipelines-today https://www.khronos.org/blog/you-can-use-vulkan-without-pipe...
- tedunangst 3y agoIs all of it necessary, or is some of it extra verbose for the sake of being explicit? If you leave this blank do you get nothing? .components = { .r = VK_COMPONENT_SWIZZLE_R, .g = VK_COMPONENT_SWIZZLE_G, .b = VK_COMPONENT_SWIZZLE_B, .a = VK_COMPONENT_SWIZZLE_A, },
- hmry 3y agoNicely spotted actually, in that specific case leaving it blank will get you the exact same result. That's because the enum has VK_COMPONENT_SWIZZLE_IDENTITY = 0, and setting everything to IDENTITY is defined to result in exactly what you expect. (r = r, g = g, ...). You can read the spec here if you want to: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkComponentSwizzle.html https://registry.khronos.org/vulkan/specs/1.3-extensions/man... Most things in Vulkan have reasonable defaults, fortunately. Still, it's best to code with the spec open on another monitor.
- ozarker 3y agoThis one's been around a long time. I used it when I started with Vulkan back around 2017/18? It uses glfw but I used sdl2 with it when I went through it. You'll just need to read some sdl2 documentation to get the window hooked up. https://vulkan-tutorial.com/ https://vulkan-tutorial.com/
- andrewmcwatters 3y agohttps://github.com/Planimeter/game-engine-3d/blob/main/src/graphics_vulkan.cpp https://github.com/Planimeter/game-engine-3d/blob/main/src/g... Try reading the above implementation. It’s a Hello, Triangle with SDL. Should compile out of the box on Windows.