3 ms·
Not 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
by flohofwoe 3y ago
Not 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.