News for hackers. Stuff that matters.
Re:Zink (OpenGL on Vulkan) performance better than expected by gw on Wednesday September 09, 2020 @03:55PM (#24425211)
It's things like this that make me not worry about sticking with opengl. It's supported everywhere, fast enough for my uses, and is exactly the level of abstraction i want to be at. I completed the vulkan triangle tutorial and i cannot imagine needing all those knobs for the games and other things i make. I'm pretty confident that by the time opengl is no longer natively supported, software layers like this will be stable and fast enough.
Re:Zink (OpenGL on Vulkan) performance better than expected by simias on Wednesday September 09, 2020 @06:27PM (#24426624)
I'm far from an expert in the field but what annoyed me deeply with OpenGL was the implicit global state and, in particular, the fact that it's very difficult and error-prone to make applications that interact with OpenGL from multiple threads.

In a way I find OpenGL too complicated sometimes, some of its abstractions don't really make a whole lot of sense on modern hardware. Having a lower level API can make some code simpler to write, at least in theory. When I use OpenGL I often find myself thinking "I sure hope the driver will manage to understand what I'm trying to do and not end up doing something silly".

Note that my exposure to OpenGL comes mainly from console emulators though, and that's obviously very biased since emulators need to mimic very quirky behaviors of the original hardware, and that often results and very un-idiomatic GL code.

Re:Zink (OpenGL on Vulkan) performance better than expected by moonchild on Wednesday September 09, 2020 @07:25PM (#24427160)
> implicit global state

In 4.x they added DSA[1], which lets you avoid the global state a lot of the time. There's still some, but much less.

I do agree, though, that opengl is somewhat a mess, and vulkan really overwhelming.

1. https://www.khronos.org/opengl/wiki/Direct_State_Access

Re:Zink (OpenGL on Vulkan) performance better than expected by pcwalton on Wednesday September 09, 2020 @07:20PM (#24427108)
> in particular, the fact that it's very difficult and error-prone to make applications that interact with OpenGL from multiple threads.

These days I rarely ever bother with threaded OpenGL, and I stick to one context per thread, using OS surface sharing primitives (DXGI, IOSurface, etc.) to communicate.

Re:Zink (OpenGL on Vulkan) performance better than expected by pmarreck on Wednesday September 09, 2020 @06:45PM (#24426770)
> the implicit global state and, in particular, the fact that it's very difficult and error-prone to make applications that interact with OpenGL from multiple threads

These things are obviously related.

From my work in OO langs, I believe it is possible to wrap OO code in functional code to some degree without rewriting, assuming that global references can be intercepted and resolved to local ones somehow, and that the state reference that encompasses all the globals is an immutable data struct

Re:Zink (OpenGL on Vulkan) performance better than expected by skocznymroczny on Wednesday September 09, 2020 @05:48PM (#24426333)
I like OpenGL, but I really hate the global state. If only there was some concept of state objects that record state, something like:

glBeginState(&stateObj); glEnable(GL_BLEND); glDepthTest(GL_LEQUAL); glEndState(&stateObj);

and then later on you'd do glBindState(&stateObj) to apply it.

I have high hopes for WebGPU though and I am going to migrate my renderer to it soon.

Re:Zink (OpenGL on Vulkan) performance better than expected by moonchild on Wednesday September 09, 2020 @07:37PM (#24427242)
That sounds much worse. That's still global state, just encapsulated global state. Any time you say glBindWhatever(), you're assigning global state. And the state obj should be an opaque handle so you don't end up with stale pointers. Should be glEnable(state, GL_BLEND); glDepthTest(state, GL_LEQUAL);.
Re:Zink (OpenGL on Vulkan) performance better than expected by skitter on Wednesday September 09, 2020 @07:15PM (#24427051)
I recently wrote a tiny game[1] and rendering with WebGPU was reasonably easy as it was mostly clear why/where things were going wrong and there was little state to manage, while WebGL was enough of a hassle that I didn't even manage to get instancing working.

[1]https://specificprotagonist.itch.io/cary

Re:Zink (OpenGL on Vulkan) performance better than expected by pcwalton on Wednesday September 09, 2020 @07:15PM (#24427059)
Something like `glBindState()` would encapsulate the global state, but it wouldn't eliminate it. A better approach would be to pass in the state to the draw command like WebGPU/Metal/Vulkan do, which would also allow the driver to amortize the cost of state validation.
Re:Zink (OpenGL on Vulkan) performance better than expected by gw on Wednesday September 09, 2020 @07:09PM (#24427006)
Webgl doesn't have this problem since it runs those functions on a context object. But yeah i wish there was a way to do that with opengl.
Re:Zink (OpenGL on Vulkan) performance better than expected by pcwalton on Wednesday September 09, 2020 @07:17PM (#24427073)
The problems of global state persist in WebGL, because (1) if you need to save and restore state inside a single context, WebGL provides no help; (2) the driver is unable to amortize validation as the state is not tied to the individual render pass/pipeline descriptors.
Re:Zink (OpenGL on Vulkan) performance better than expected by gw on Wednesday September 09, 2020 @07:36PM (#24427236)
Interesting. When you say "save and restore state", do you mean actually serializing it and loading it later? In what situation would you want to do this? Not doubting that there is one but i haven't heard of this before.
Re:Zink (OpenGL on Vulkan) performance better than expected by pcwalton on Wednesday September 09, 2020 @08:16PM (#24427532)
Typically you use this feature to associate state with an object in your render graph. For example, all of the render state used to render the sky, including shader program, vertex buffers, textures, blend state, etc. can be attached to the sky node in your scene graph. Then you can (basically) have a generic "draw an object in your scene graph" function that just performs the appropriate drawcall with the right state. The performance advantage of this is that the driver can do all the validation once, when you construct the sky object, instead of every frame.
Re:Zink (OpenGL on Vulkan) performance better than expected by ryandrake on Wednesday September 09, 2020 @05:03PM (#24425877)
I've always liked this illustration: Code to draw a triangle in 1. OpenGL 1.x, 2. OpenGL 3+, 3 Vulkan [1].

1: http://sol.gfxile.net/temp/hellotriangle.png

Re:Zink (OpenGL on Vulkan) performance better than expected by gw on Wednesday September 09, 2020 @05:13PM (#24425960)
It is pretty wild, though mine wasn't quite as bad. It ended up clocking in at 650 lines. I guess part of that is because nim doesn't have braces... https://github.com/oakes/vulkan_triangle_nim/blob/master/src...
Re:Zink (OpenGL on Vulkan) performance better than expected by monocasa on Wednesday September 09, 2020 @08:09PM (#24427489)
It's decidedly not optimized for hello world style examples, but it's a lot nicer once you have a non trivial codebase, IMO.
Re:Zink (OpenGL on Vulkan) performance better than expected by gameswithgo on Wednesday September 09, 2020 @06:28PM (#24426634)
supposedly code the draw doom 4 is less with vulkan than opengl though
Re:Zink (OpenGL on Vulkan) performance better than expected by Reelin on Thursday September 10, 2020 @02:23AM (#24429459)
> glfwCreateWindow(..., "The spinning triangle that took 1397 lines of code", ...);

I get it, Vulkan is low level, but still.

Re:Zink (OpenGL on Vulkan) performance better than expected by gameswithgo on Wednesday September 09, 2020 @03:59PM (#24425251)
on top of that more mature "easy mode" wrappers over Vulkan are beginning to exist too.
Re:Zink (OpenGL on Vulkan) performance better than expected by pjmlp on Wednesday September 09, 2020 @04:13PM (#24425386)
They already exist, a checkbox away on a middleware engine, that is how much I want to meddle with it.

Khronos is now driving the Anari effort, because most visualization toolkits could not be bothered to move forward into Vulkan.

https://www.khronos.org/anari

Pity that they decided to just bother with C99 though.

Re:Zink (OpenGL on Vulkan) performance better than expected by johnnycerberus on Wednesday September 09, 2020 @04:54PM (#24425804)
> Pity that they decided to just bother with C99 though.

Isn't this the trend nowadays? I've seen recently that simple languages are trending again, languages like C, Go, Zig, Erlang, Lua. I think we hit the ceiling with mammoths like C++ and Scala.

Re:Zink (OpenGL on Vulkan) performance better than expected by pjmlp on Wednesday September 09, 2020 @05:23PM (#24426060)
Not at all, proprietary graphics APIs provide modern bindings in C++, Objective-C, Swift.
Re:Zink (OpenGL on Vulkan) performance better than expected by amaranth on Wednesday September 09, 2020 @06:19PM (#24426565)
C99 ensures it can be used with basically every other language and can be compiled for almost every platform. Bindings on top of that for other languages would be nice but can be provided by the community too. If it was C++, Rust, Nim, etc you'd have to write it in a way that allows exposing a C API anyway so the only advantage would be for people creating an implementation of the API getting to use a better language internally.
Re:Zink (OpenGL on Vulkan) performance better than expected by pjmlp on Thursday September 10, 2020 @01:28AM (#24429161)
That can be achieved with an IDL that isn't unsafe by default and the cause of endless security bugs.

Then everyone can generate whatever bindings they feel like in an automated way.

Re:Zink (OpenGL on Vulkan) performance better than expected by pantalaimon on Wednesday September 09, 2020 @07:00PM (#24426914)
But why C99 instead of C11?
Re:Zink (OpenGL on Vulkan) performance better than expected by moonchild on Wednesday September 09, 2020 @07:22PM (#24427120)
What features does c11 provide that would be useful?
Re:Zink (OpenGL on Vulkan) performance better than expected by marcthe12 on Wednesday September 09, 2020 @10:59PM (#24428505)
Atomic and Generics. Awkward to use and relatively unknown but c11 introduced them
Re:Zink (OpenGL on Vulkan) performance better than expected by moonchild on Wednesday September 09, 2020 @11:46PM (#24428700)
How do atomics help a high-level graphics API? The implementation can use them, but threading probably shouldn't be part of the interface.

Generics are cool, but auxiliary to any core part of the api since it's not really possible to use them outside of in a macro that wraps over a real function.

Re:Zink (OpenGL on Vulkan) performance better than expected by Reelin on Thursday September 10, 2020 @01:49AM (#24429271)
Can't you (ie the programmer) still use them though? You can write C11 code which freely calls the C99 API. By using C99 the API is compatible with a wider range of compilers and callable from a broader range of languages.

(Also where would the API itself have benefited in any significant way from the use of atomics or generics? Recall that compiler support for atomics is optional in C11.)

Re:Zink (OpenGL on Vulkan) performance better than expected by marcthe12 on Thursday September 10, 2020 @02:12AM (#24429405)
Generic could help but that could be just a wrapper over the main api.
Re:Zink (OpenGL on Vulkan) performance better than expected by bsder on Wednesday September 09, 2020 @11:33PM (#24428654)
Because Microsoft basically won't support C11.
Re:Zink (OpenGL on Vulkan) performance better than expected by pjmlp on Thursday September 10, 2020 @01:30AM (#24429171)
They do via clang, long part of Visual Studio installer (since 2015), Visual C++ as C++ compiler naturally not.

And they aren't the only ones, try to see how much of Apple or Google OS applications you manage to write with C11 alone.

Re:Zink (OpenGL on Vulkan) performance better than expected by marcthe12 on Thursday September 10, 2020 @02:11AM (#24429400)
They recently added it the roadmap though.
Re:Zink (OpenGL on Vulkan) performance better than expected by pjmlp on Thursday September 10, 2020 @05:55AM (#24430644)
Where is this roadmap?

There is no public plan to add to Visual C++ anything more than what ISO C++ requires in terms of C source code and libraries compatibility.

Microsoft has contributed to clang on Windows for those that still want to use C.

Re:Zink (OpenGL on Vulkan) performance better than expected by kevincox on Wednesday September 09, 2020 @04:03PM (#24425303)
They are beginning to exist but it is very unlikely that these will have the stability that OpenGL has. They will likely be more convenient, but if you are building something today that doesn't have very high performance needs sticking to the OpenGL API is probably a good way to ensure that you won't have to migrate to something else for a very, very long time.
Re:Zink (OpenGL on Vulkan) performance better than expected by bsder on Wednesday September 09, 2020 @11:40PM (#24428679)
> if you are building something today that doesn't have very high performance needs sticking to the OpenGL API is probably a good way to ensure that you won't have to migrate to something else for a very, very long time.

That is, in fact, precisely the wrong advice.

Vulkan runs on Windows, Linux, and OS X (via MoltenVk). Nothing else does.

OS X runs OpenGL 3.Ancient and has now dropped OpenGL. OpenGL drivers for Linux tend to be laughably worse than the Vulkan drivers.

All of the major gaming companies have basically said "We have no OpenGL jobs. We have a ton of unfilled Vulkan jobs."

If you aren't using DirectWhatever, Vulkan is going to be the only useful 3D API very shortly.

Re:Zink (OpenGL on Vulkan) performance better than expected by badsectoracula on Thursday September 10, 2020 @12:36AM (#24428929)
OS X runs OpenGL 4.1 and is still available even if deprecated. If you are considering MoltenVK as a viable option then perhaps Zink over MoltenVK would work in the future.

Note that most of the newer OpenGL features are largely about sending stuff faster to the GPU, not enabling new GPU features - you can do a lot of stuff with OpenGL 4.1. IMO if you are struggling for CPU performance with OpenGL then you might be better moving to Vulkan. But if this isn't your bottleneck then there isn't a reason to not stick with OpenGL.

If OpenGL drivers on Linux are "laughably worse" (though in practice i haven't much of a difference) then the solution is to improve those drivers. It'll be better for all the thousands of existing applications too.

Re:Zink (OpenGL on Vulkan) performance better than expected by bsder on Friday September 11, 2020 @06:00PM (#24447796)
> OS X runs OpenGL 4.1 and is still available even if deprecated.

You are correct. I misspoke. I meant to say 4.Ancient since 4.1 is 10 years old now.

> Note that most of the newer OpenGL features are largely about sending stuff faster to the GPU, not enabling new GPU features

For shaders, I certainly find that not true. There are a lot of shader features that got added over 10 years.

And, I believe things even as important as Uniform Buffer Objects are later than 4.1.

OpenGL 4.1 just ... isn't good in this day and age.

> If OpenGL drivers on Linux are "laughably worse" (though in practice i haven't much of a difference) then the solution is to improve those drivers.

I totally disagree. There simply aren't enough people in the Linux ecosystem to maintain those drivers and Vulkan drivers. I'd rather those developers all work on the newer and better API.

Re:Zink (OpenGL on Vulkan) performance better than expected by pjmlp on Thursday September 10, 2020 @02:02AM (#24429338)
Vulkan runs on Windows , only runs outside sandbox model and doesn't support RDP sessions, because ICD OpenGL driver model isn't supported in such scenarios.

ICD OpenGL drivers are also not supported on Windows ARM variants.

Microsoft is driving the effort of OpenGL and related technology on top of DirectX instead.

https://devblogs.microsoft.com/directx/in-the-works-opencl-a...

Also so far there is no Vulkan on PlayStation, and while Switch does support Vulkan/OpenGL 4.5, most titles are either using middleware like Unity (ca 50% of Switch titles) or NVN.

Re:Zink (OpenGL on Vulkan) performance better than expected by for_xyz on Saturday September 12, 2020 @05:48PM (#24456140)
I'm pretty sure I ran vulkan apps via RDP and they worked fine. I think it was also on GTX 960.
Re:Zink (OpenGL on Vulkan) performance better than expected by Reelin on Thursday September 10, 2020 @02:02AM (#24429340)
I think the person you responded to was comparing OpenGL to Vulkan middleware wrappers from the perspective of API usage. From that angle, whether or not OpenGL drivers are provided at all is completely irrelevant. The API itself will presumably remain available, implemented under the hood via Zink (or similar) on top of Vulkan (or DirectX, or Metal, etc). Such an arrangement is likely to be more stable than middleware that can change overnight at the whims of it's developers.
Re:Zink (OpenGL on Vulkan) performance better than expected by abnercoimbre on Thursday September 10, 2020 @03:33AM (#24429844)
As verbose as Vulkan may be, it's a well-designed vanilla C API. Some of the future helper libraries may also be in vanilla C, in which case it's not difficult to version and ensure relative stability.
Re:Zink (OpenGL on Vulkan) performance better than expected by abnercoimbre on Thursday September 10, 2020 @12:01AM (#24428769)
Seconding everything here. It's also worth nothing MoltenVK development was sponsored by Valve (that's how they get Dota 2 on macOS.)
Re:Zink (OpenGL on Vulkan) performance better than expected by nicoburns on Wednesday September 09, 2020 @04:09PM (#24425354)
The other good option that's likely to be supported for a long time is WebGPU.
Re:Zink (OpenGL on Vulkan) performance better than expected by Nullabillity on Wednesday September 09, 2020 @07:18PM (#24427081)
As long as Vulkan itself stays stable, who cares, just pin the version of the wrapper?
Re:Zink (OpenGL on Vulkan) performance better than expected by moron4hire on Wednesday September 09, 2020 @05:55PM (#24426381)
What "stability that OpenGL has"?
Re:Zink (OpenGL on Vulkan) performance better than expected by badsectoracula on Thursday September 10, 2020 @12:28AM (#24428893)
The OpenGL API is standardized and has multiple implementations so it isn't susceptible to some layer/library developer waking up one morning and deciding to break the API to make it "cleaner" or "easier" or whatever.

Hell, even though Khronos tried to do exactly that with the core/compatibility schism, pretty much all existing implementations decided breaking people's code is a stupid move and mostly ignored it (Apple being an exception but Apple hates developers[0] and their OpenGL implementation was always awful - even then, Apple's implementation is still an implementation of a stable API).

In practice it means that your currently working code will remain working in the future and there are good chances that you'll be able to port it in other places with either official or unofficial implementations.

[0] OK, OK, i know, Apple doesn't "hate" developers, they just do not care about them at all and they'd happily break things like a hippo dancing in a glassware shop if they believe that would make their own developers feel better.

Re:Zink (OpenGL on Vulkan) performance better than expected by bitwize on Thursday September 10, 2020 @02:01AM (#24429334)
Multiple implementations suck because implementors rarely aim for full compliance, and now you have to have as many code paths as there are implementations to account for the differences between them. Best to have a single implementation that everybody agrees on -- like the winner of the graphics API wars, Direct3D.
Re:Zink (OpenGL on Vulkan) performance better than expected by imtringued on Thursday September 10, 2020 @04:06AM (#24430003)
I don't know what you are talking about. Direct3D is Windows only. Metal is iOS and Mac only. Vulkan is in theory supported on all platforms but UWP doesn't allow it and Mac requires a compatibility wrapper.

If anything the graphics API war is still going on.

Re:Zink (OpenGL on Vulkan) performance better than expected by pjmlp on Thursday September 10, 2020 @04:38AM (#24430170)
Vulkan is only supported on the Switch, in what concerns game consoles.

And even there one can choose GL 4.5 and NVN as well.

Most native titles end up going with NVN.

Re:Zink (OpenGL on Vulkan) performance better than expected by Reelin on Thursday September 10, 2020 @02:09AM (#24429391)
> Best to have a single implementation that everybody agrees on -- like the winner of the graphics API wars, Direct3D.

Ah yes, D3D, well known for its broad cross platform support! In all seriousness, would a Linux D3D driver even be legal? I have to assume that major legal or technical barriers exist, otherwise why wouldn't a GPU vendor have developed one at some point?

Re:Zink (OpenGL on Vulkan) performance better than expected by Nullabillity on Thursday September 10, 2020 @04:12AM (#24430038)
Mesa actually does support D3D9 natively for AMD (and, sort of, Intel) GPUs via the Gallium Nine project, and there is a branch of Wine that uses it.

But these days that's mostly superseded by DXVK (which implements D3D9 through 11 over Vulkan, kind of like Zink in the OP) and VKD3D (D3D12 over Vulkan).

Re:Zink (OpenGL on Vulkan) performance better than expected by imtringued on Thursday September 10, 2020 @04:07AM (#24430011)
D3D drivers for Linux exist but it's through a compatibility layer. https://github.com/doitsujin/dxvk
Re:Zink (OpenGL on Vulkan) performance better than expected by Reelin on Thursday September 10, 2020 @06:00AM (#24430675)
I don't think a compatibility layer implemented in software is the same as a driver implemented by the vendor that interacts directly with the hardware.
Re:Zink (OpenGL on Vulkan) performance better than expected by jokoon on Thursday September 10, 2020 @02:09AM (#24429385)
Opengl is expensive to support, because drivers can be quite large today.

Vulkan lets dev do things directly.

You could say opengl is one "layer of crap" Carmack was talking about.

I'm still happy to use it though.

Re:Zink (OpenGL on Vulkan) performance better than expected by walkingolof on Thursday September 10, 2020 @03:11AM (#24429731)
With Vulcan, you are more than ever as a indie developer faced with the question: Are you going to do a game or an engine.
Re:Zink (OpenGL on Vulkan) performance better than expected by slezyr on Thursday September 10, 2020 @05:56AM (#24430649)
You simply don't need to touch it.

Use the bgfx.

https://bkaradzic.github.io/bgfx/overview.html

Re:Zink (OpenGL on Vulkan) performance better than expected by esperent on Thursday September 10, 2020 @04:46AM (#24430218)
There are several wrappers for Vulkan that make it easier to work with, like V-EZ. Using one of the is probably the best approach for an indie dev.
Re:Zink (OpenGL on Vulkan) performance better than expected by shakna on Wednesday September 09, 2020 @09:05PM (#24427839)
OpenGL isn't supported everywhere. Apple deprecated OpenGL across all their platforms in June, 2018.
Re:Zink (OpenGL on Vulkan) performance better than expected by shmerl on Wednesday September 09, 2020 @09:34PM (#24428003)
And sabotaged Vulkan support on their systems as well.
Re:Zink (OpenGL on Vulkan) performance better than expected by gw on Wednesday September 09, 2020 @10:02PM (#24428168)
Deprecated, not removed. In fact opengl will still be supported in the new ARM macs.
Re:Zink (OpenGL on Vulkan) performance better than expected by shakna on Thursday September 10, 2020 @12:43AM (#24428967)
Deprecated means not supported, yes?

If you use it, then you'll get no help from the platform on getting it to run. Random parts may begin to break, and the intention is likely an eventual removal.

Re:Zink (OpenGL on Vulkan) performance better than expected by monocasa on Thursday September 10, 2020 @03:00AM (#24429667)
In Apple-speak, 'deprecated' means "we told you so" when/if it gets removed in a few years at a WWDC.