7 ms·
OpenGL: Mesh shaders in the current year
- prideout 1y agoWhy is Minecraft mentioned several times in the post?
- wirybeige 1y agoThe post links to this: https://github.com/MCRcortex/nvidium https://github.com/MCRcortex/nvidium nvidium is using GL_NV_mesh_shader which is only available for nVIDIA cards. This mod is the only game/mod I know of that uses mesh shaders & is OpenGL. & so the new gl extension will let users of other vendors use the mod if it gets updated to use the new extension.
- mellinoe 1y agoPresumably because Minecraft is the only application which still uses OpenGL but would use the extension
- doubletwoyou 1y agopretty sure the base minecraft rendering engine is still using opengl, and most of the improvement mods also just use opengl so exposing this extension to them is probably important to a game where its 50 billion simple cubes being rendered
- FrustratedMonky 1y agoIs Minecraft the only thing using OpenGL anymore? What is the current state of OpenGL, I thought it had faded away?
- aj_hackman 1y agoIt's officially deprecated in favor of Vulkan, but it will likely live on for decades to come due to legacy CAD software and a bunch of older games still using it. I don't share the distaste many have for it, it's good to have a cross-platform medium-complexity graphics API for doing the 90% of rendering that isn't cutting-edge AAA gaming.
- m-schuetz 1y agoOpenGL is going to live a long life simply because Vulkan is way more complex and overengineered than it needs to be.
- jsheard 1y agoIt's steadily getting better as they keep walking back aspects which turned out to be needlessly complex, or only needed to be complex for the sake of older hardware that hardly anyone cares about anymore, but yeah there's still a way to go. Those simpler ways of doing things are just grafted onto the side of the existing API surface so just knowing which parts you're supposed to use is a battle in itself. Hopefully they'll eventually do a clean-slate Vulkan 2.0 to tidy up the cruft, but I'm not getting my hopes up.
- m-schuetz 1y agoMight be getting better but just yesterday I dabbled in Vulkan again, digging through the examples from https://github.com/SaschaWillems/Vulkan https://github.com/SaschaWillems/Vulkan, and the complexity is pure insanity. What should be a simple malloc ends up being 40 lines of code, what should be a simple memcpy is another 30 lines of code, and what should be a single-line kernel launch is another 50 lines of bindings, layouts, pipelines, etc.
- flohofwoe 1y agoTbf, a lot of the complexity (also in the official Khronos samples) is caused by insane C++ abstraction layers and 'helper frameworks' on top of the actual Vulkan C API. Just directly talking to the C API in the tutorials/examples instead of custom wrapper code would be a lot more helpful since you'd don't need to sift through the custom abstraction layers (even if it would be slightly more code). E.g. have a look at the code snippets in here and weep in despair ;) https://docs.vulkan.org/tutorial/latest/03_Drawing_a_triangle/00_Setup/03_Physical_devices_and_queue_families.html https://docs.vulkan.org/tutorial/latest/03_Drawing_a_triangl...
- 1y ago
- kbolino 1y agoI don't think any major platform that ever supported OpenGL or OpenGL ES--including desktops, smartphones/tablets, and web browsers--has actually removed it yet. Apple will probably be the first to pull the plug, but they've only aggressively deprecated it so far.
- jhasse 1y agoHow exactly is it aggressiv? I'm selling games using OpenGL on iOS, iPadOS, tvOS and macOS, works with all of their latest hardware. I'm not getting a warning or any sign from them that they will remove support.
- kbolino 1y agoIt was my understanding (which could definitely be wrong) that their OpenGL support is both behind the times--which is impressive since OpenGL has received no major new features AFAIK in the past decade, the topic of this HN post notwithstanding--and won't even get any bugfixes.
- charlotte-fyi 1y agoThe last supported version they ship doesn't support compute, which is a pretty big limitation.
- Sharlin 1y agoIt's super frequently recommended as a starting point for learners because it's high level enough to get something on the screen in ten lines of code but low level enough to teach you the fundamentals of how the rendering pipeline works (even though GL's abstraction is rather anachronistic and differs from how modern GPUs actually work). Vulkan (requiring literally a thousand LoC worth of initialization to render a single triangle) is emphatically not any sort of replacement for that use case (and honestly not for 95% of hobbyist/indie use cases either unless you use a high-level abstraction on top of it). The worst thing about OpenGL is probably the hilariously non-typesafe C API.
- cubefox 1y agoI believe the modern OpenGL replacement would be WebGPU, which is not just made for browsers, and which isn't as low-level as Vulkan or DirectX 12.
- m-schuetz 1y agoAMD, do support for NV_shader_buffer_load next! Shader Buffer Load brought "Buffer Device Address" / pointers to OpenGL/glsl, long before Vulkan was even a thing. It's the best thing since sliced bread, and easily lets you access all your vertex data with pointers, i.e., you don't need to bind any vertex buffers anymore. Also easily lets you draw the entire scene in a single draw call since vertex shaders can just load data from wherever the pointers lead them, e.g., it makes GLSL vertex shaders look like this: uniform Node* u_nodes; void main(){ Node node = u_nodes[gl_DrawID]; vec3 pos = node.position[gl_VertexID]; vec2 uv = node.uv[gl_VertexID]; ... }
- garaetjjte 1y agoYou could do similar thing with SSBO, I think?
- m-schuetz 1y agoThat is for SSBOs. u_nodes is a pointer to an SSBO in this case. That SSBO then has lots of more pointers to various different SSBOs that contain the vertex data.
- garaetjjte 1y agoI'm thinking of declaring array of SSBOs that contain array of data structs. Address would be represented by index of SSBO binding and offset within that buffer. Though that limits maximum number of used SSBOs within drawcall to GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS.
- m-schuetz 1y agoTo my knowledge you can't have an array of SSBOs in OpenGL. You could have one SSBO for everything, but that makes other things very difficult, like how to deal with dynamically growing scenes, loading and unloading models, etc.
- SeriousM 1y agoIt seems to me, as not so 3d savy, that 3d objects and shaders have a similar connection as html structure and css. Nowadays you need a structure of objects yet the layout, color and behavor comes from css. In this regard, 3d scenes offer the elements but shaders can design them much more efficient than a engine ever could. Is that accurate? Btw, can objects modified by shaders signal collisions?
- deleted 1y ago[deleted]
- flohofwoe 1y ago3D scenes (closest thing to the DOM) and materials (closest thing to CSS) are several abstraction layers above what modern 3D APIs provide, this is more 'rendering/game engine' territory. 3D APIs are more on the level of 'draw this list of triangles, and the color of a specific pixel in the triangle is computed like this: (hundreds of lines of pixel shader code)" - but even this is slowly being being replaced by even lower level code which implements completely custom rendering pipelines entirely on the GPU.
- adastra22 1y agoShaders are not layout. I don't think there is an HTML/DOM analogy here that works. But if you had to force one, shaders are more like Javascript. It's a terrible analogy though. Collisions aren't part of a graphics API.
- pjmlp 1y agoThere is, CSS shaders, or Project Houdini. - https://alteredqualia.com/css-shaders/article/ https://alteredqualia.com/css-shaders/article/ - https://developer.mozilla.org/en-US/docs/Web/API/Houdini_APIs https://developer.mozilla.org/en-US/docs/Web/API/Houdini_API...
- flohofwoe 1y ago> Collisions aren't part of a graphics API. You can do occlusion queries though, which is a form of 2D collision detection similar to what home computer sprite hardware provided ;)
- phkahler 1y agoWhy GL_EXT_mesh_shader and not GL_mesh_shader? And why for ES? I thought ES was for less advanced hardware.
- OnionBlender 1y agoEXT is a Khronos naming convention. It means it is a generic extension, intended to be implemented across implementations. https://wikis.khronos.org/opengl/OpenGL_Extension#Extension_Types https://wikis.khronos.org/opengl/OpenGL_Extension#Extension_...
- lights0123 1y agoIt's not for ES, but the same group is responsible for changes to both.
- catapart 1y agoThis sounds pretty cool, but can anyone dumb this down for me? Mesh shaders are good because they are more efficient than the general purpose triangle shaders? Or is this something else entirely?
- flohofwoe 1y agoIt's essentially a replacement for vertex shaders which map more closely to how GPUs are processing big and complex triangle meshes as small packets of vertices in parallel by doing the job of splitting a complex triangle mesh into such small packets of vertices in an offline asset-pipeline job instead of relying too much on 'hardware magic' like vertex caches. AFAIK mesh shaders also get rid of (the ever troublesome) geometry shaders and hull shaders, but don't quote me on that :) By far most traditional triangle rendering use cases should only see minimal performance improvements though, it's very much the definition of 'diminishing returns'. It's definitely more straightforward and 'elegant' though. PS: this is a pretty good introduction I think https://gpuopen.com/learn/mesh_shaders/mesh_shaders-from_vertex_shader_to_mesh_shader/ https://gpuopen.com/learn/mesh_shaders/mesh_shaders-from_ver...
- catapart 1y agoOh, awesome! Yeah, that's a great introduction. Seems like it introduces a new abstraction that allows a single mesh to be mapped to much smaller groups of vertices so you can take advantage of BVHs and stuff like that on a more granular level, right in the shader code. Very cool stuff! Thanks for the info.
- cubefox 1y agoAs far as I understand, mesh shaders allow you to generate arbitrary geometry on the GPU. That wasn't possible with the traditional vertex pipeline, which only allowed specialized mesh transformations like tesselation. For example, hair meshes (lots of small strands) are usually generated on the CPU from some basic parameters (basic hairstyle shape, hair color, strand density, curliness, fuzziness etc) and then the generated mesh (which could be quite large) is loaded onto the GPU. But the GPU could do that itself using mesh shaders, saving a lot of memory bandwidth. Here is a paper about this idea: https://www.cemyuksel.com/research/hairmesh_rendering/Real-Time_Hair_Rendering_with_Hair_Meshes-SIGGRAPH24.pdf https://www.cemyuksel.com/research/hairmesh_rendering/Real-T... However, the main application of mesh shaders currently is more restricted: Meshes are chunked into patches (meshlets), which allows for more fine grained occlusion culling of occluded geometry. Though most these things, I believe, can already be done with compute shaders, although perhaps not as elegantly, or with some overhead.
- zackmorris 1y agoA little bit off topic but: GL_LINES doesn't have a performant analog on lots of other platforms, even Unity. Drawing a line properly requires turning the two endpoint vertices into a quad and optionally adding endcaps which are at least triangular but can be polygons. From my understanding, that requires a geometry shader since we're adding virtual/implicit vertices. Does anyone know if mesh shaders could accomplish the same thing? Also I wish that GL_LINES was open-sourced for other platforms. Maybe it is in the OpenGL spec and I just haven't looked. I've attempted some other techniques like having the fragment shader draw a border around each triangle, but they all have their drawbacks.
- kg 1y agoTo draw lines instead of a geometry shader you can use instancing, since you know how many vertices you need to represent a line segment's bounding box. Have one vertex buffer that just contains N vertices (the actual attribute data doesn't matter, but you can shove UVs or index values in there) and bind it alongside a buffer containing your actual line information (start, end, color, etc). The driver+GPU will replicate the 'line vertex buffer' vertices for every instance in the 'line instance buffer' that you bound. This works for most other regular shapes too, like a relatively tight bounding box for circles if you're drawing a bunch of them.
- m-schuetz 1y agoIn my experience, drawing quads with GL_POINTS in OpenGL was way faster than drawing quads with instancing in DirectX. That was noticable with the DirectX vs. OpenGL backends for WebGL, where switching between the two resulted in widely different performance.
- mandarax8 1y agoI'm not sure exactly what you mean, but you can both output line primitives directly from the mesh shader or output mitered/capped extruded lines via triangles. As far as other platforms, there's VK_EXT_line_rasterization which is a port of opengl line drawing functionality to vulkan.
- 1y ago
- Pannoniae 1y agoWow, very nice ;) OpenGL was a very nice API and even despite its shortcomings, it is quite telling that VK didn't fully replace it 10 years later. Cross-vendor mesh shader support is great - we had NV_mesh_shader for quite a while but it's great that it's also supported on AMD now. It's good for voxel games like this - the shape of the vertex data is fairly fixed and very compressible, mesh shaders can really cut down on the VRAM usage and help reduce overhead. Most minecraft optimisation mods generally try to reduce drawcalls by batching chunks (16x16x16) into bigger regions and use more modern OpenGL to reduce API overhead. This mod does GPU-driven culling for invisible chunk sections (so the hidden chunks aren't rendered but without a roundtrip to the CPU) and also generates the triangles themselves with a mesh shader from the terrain data, which cuts down on the vertex size a lot. (EDIT: I reworded this section because the mod does only a few drawcalls in total so my wording was inaccurate. Sorry!) Sadly, optimising the game is a bit tricky due to several reasons - the first big one is translucency sorting, because there are translucent blocks in the game like stained glass, which have to be properly sorted for the blending to work. (the base game doesn't sort correctly either by default....) The second is that it's quite overengineered, so improving it while also not breaking other mods and accidentally fixing vanilla bugs is quite hard. There are further improvements possible but honestly, this is day and night compared to the vanilla renderer :) For us mere mortals (not working at Unity or Unreal), the complexity is just too much. Vulkan tries to abstract desktop and mobile together, but if you're making an indie game, there's no value for you in that. The GL/GLES split was better because each could evolve to its strengths instead of being chained to a fundamentally different design. The global state in OpenGL is certainly an annoyance, but I do not think that replacing it with fixed pipelines is an improvement, especially considering that most of that state is just a register write in desktop GPUs. Luckily, they eased up on that, but the API is still confusing, the defaults are not sane, and you need vendor-specific advice to know what's usable and what isn't. Ironically, writing Vulkan makes you more vendor-dependent in a sense, because you don't have OpenGL extension hell - you have Vulkan extension hell AND a bunch of incidental complexity around the used formats and layouts and whatnot. On a more positive note, I seriously hope that OpenGL won't be entirely abandoned in the future, it has been a great API so far and it only really has small issues and driver problems but nothing really unfixable.
- 1y ago
- qoez 1y agoMakes me sad this won't ever get to webgl since 'webgl3' is basically not considered anymore (replaced by webgpu)