Vulkan: for beginners?

[QUOTE=cheery;31106]It’s a C API to where you can feed in a custom allocator. Sure the programmer probably needs to know what he is doing.

It’s also taken by bunch of other systems. It’s one of the mechanisms used in erlang to achieve fault tolerance. In C -case: If you give the API garbage, it either renders garbage or crashes. That’s something that cannot be avoided with C programs. Still you’re not intentionally constructing traps to produce flanging pointers or corrupted memory.

Also the stuff will stay within the process boundaries. It’ll be still unacceptable for an userspace process to cause kernel panics, even if coded by a newbie.

I don’t think Vulkan will be the kind of API you describe it will be. It’ll require you to consider things you would have to consider with C anyway. It also doesn’t make it unnecessarily difficult to implement things such as WebVulkan. On the contrary it’ll be simpler than it was with WebGL.[/QUOTE]

I doubt we’ll ever see “WebVulkan”. It’s just a severe mismatch. Vulkan is about performance by sacrificing input validation and error reporting. That doesn’t jive with downloadable executable content that take full command of your GPU. Besides Vulkan enable multithreading, this is in stark contrast to javascript, an inherently single threaded language. So I think WebGL wil stay WebGL.

[QUOTE=cheery;31106]I don’t know what we’re exactly getting yet. From the slides I understood that Vulkan actually removes lot more than it introduces. Overall it’d seem that there will be very few API functions. More information is passed up in buffers rather than explicit function calls. This may actually mean more robustness in non-C/C++ -software.

I saw the SPIR-V paper and thought that the designers are quite competent. They’ve taken every measure to not add in unnecessary complexity. And the slides seem quite good too. Before doing any stupid conclusions I need to see more. This far I’m staying optimistic.[/QUOTE]

[QUOTE=Alfonse Reinheart;31418]
(on having to think about memory transitions / what kind of access is legal)

No you don’t. If you render to a texture, then read from it, all OpenGL requires is that you stop rendering to it before you try to read from it. That is, you bind a new FBO (or remove the texture from the current one). Conceptually, you’re not thinking about a memory state transition; you’re just following the rule about not reading from a render target (which is a conceptually dubious prospect). Mantle requires that you do a memory state transition as well as no longer rendering to the texture.

I think you’re confusing SSBO’s incoherent, asynchonous operations with the usual coherent, synchronous OpenGL operations. Most of OpenGL operates in a coherent, synchronous way; the API takes care of things behind your back. If you upload data to a buffer, you don’t have to issue a barrier or wait for a while before using that buffer for vertex data. OpenGL takes care of any synchronization or cache clearing between the upload and the usage.[/QUOTE]

You don’t have to care if you don’t care about performance, or blindly copy a solution without thinking about it. I don’t see how either of those belong in low-level GPU programming.

If I, as a programmer, have no idea about the dependencies in the calculations I’m issuing, I’d expect horrible stalls to occur. This is comparable to doing CPU programming that keeps running into the same lock, and then complaining that it’s no faster than a single-threaded version. This kind of solution shouldn’t be using threading in the first place. Similarly, this kind of solution in graphics programming should be using a higher-level graphics API, not a driver-level API.

I can’t say I have used the memory states, so I’ll have to see how it goes. But IMO, there should be only two cases:

[ul]
[li]I know what my program is doing. If something is wrong, I just have to go through the intended control flow and check that all transitions, fences, etc. are in place.
[/li][li]I don’t understand the dependencies in my program’s calculations. In other words, I have no idea what I’m doing, but I want a low-level API to make sense of it.
[/li][/ul]

If I’m clueless, but looking for a standard solution, why not use a ready-made engine? If, though, I’m clueless while writing a new solver, that thing is not going to work anyway. :stuck_out_tongue:

[QUOTE=Vandroiy;31437]You don’t have to care if you don’t care about performance, or blindly copy a solution without thinking about it. I don’t see how either of those belong in low-level GPU programming.

If I, as a programmer, have no idea about the dependencies in the calculations I’m issuing, I’d expect horrible stalls to occur. This is comparable to doing CPU programming that keeps running into the same lock, and then complaining that it’s no faster than a single-threaded version. This kind of solution shouldn’t be using threading in the first place. Similarly, this kind of solution in graphics programming should be using a higher-level graphics API, not a driver-level API.

I can’t say I have used the memory states, so I’ll have to see how it goes. But IMO, there should be only two cases:

[ul]
[li]I know what my program is doing. If something is wrong, I just have to go through the intended control flow and check that all transitions, fences, etc. are in place.[/li][li]I don’t understand the dependencies in my program’s calculations. In other words, I have no idea what I’m doing, but I want a low-level API to make sense of it.[/li][/ul]

If I’m clueless, but looking for a standard solution, why not use a ready-made engine? If, though, I’m clueless while writing a new solver, that thing is not going to work anyway. :p[/QUOTE]

I think vulkan will be more for graphics APIs trying to get good performance more than for programmers to work with directly.

for example to do shadow mapping you need a target depth map for each light and render to it. Then you need to feed that into a render (letting vulkan know to switch it from renderable to readable).

I expect that you will be able to just let a graphics engine know the view/projection of the lights and let it schedule the forward renders for the light passes. Using a pool of shadow textures a separate render to shadowmap queue (or the shadow and forward pass in a single command buffer)

[QUOTE=Ident_;31435]Wasn’t it to some part the CAD-related companies and developers who kept Khronos from significantly changing OpenGL in version 3.X (more OO etc)? Seems like some CAD people like gloptus would also love to retain immediate mode from OpenGL 1.2, or what was it that made 1.2 special to you? I at least do not understand this viewpoint at all, 1.2 was pretty terrible, did you ever try to do FBO related stuff cross-platform in that version? A pure mess and waste of time. In OpenGL 3 we got FBOs as core and do not have to worry about such things. FBOs, vaos, etc. are pretty common usage in most projects and I find it annoying having to work with the uncertainty about these features given in the old versions. Even OpenGL 2.X suffers from these same issues. Also let us not forget about performance, which, for non-trivial rendering, has way higher prospects in the latest OpenGL versions than in 1.2. And this is, after all, what OpenGL exists for: being able to render in real-time or interactive frame rates (or at least cutting some months of time that your render-farms require for rendering :wink: )

Like Alfonse said, if you do not care about performance and only care about simplicity and are trying to do very ordianry things that do not require specific features, then graphics engines are the right thing to use.[/QUOTE]

My point is calling something a “graphics API” when it’s close to driver-level and requires good knowledge of hardware working internals then it should not be called an API.

You and Alfonse are confusing an API with grphics Engines based on how high/low level the API is.

All I’m saying you may be making the driver developer life easier but not the API user. You want to make facilitate driver development and make more stable drivers, then provide a base-implementation (driver like) you Khronos define it and let OpenGL implementor work on top of this driver-level layer. Could be “Vulkan”? Well…the you implement it and show me where I can download a working SDK for Windows or Linux. :wink: Other than this I don’t believe we will see anything “Vulkan”. Like it or not this is reality we learned from “Khronos” and how they headed with OpenGL.

There are different levels of “caring about performance”. Nobody would call OpenGL slow, despite the fact that it handles this stuff for you. It’s just slower than Vulkan could be. Furthermore, it doesn’t matter if OpenGL or you the user has to handle this; what makes your application fast or slow on this point depends on the user’s awareness of these kinds of problems.

For example, if you render to a texture and then read from it in the next rendering command, you will induce a pipeline stall. However, you can work around that by adding some other processing between the write and read that doesn’t need to read from the texture. Both of these are just as true for Vulkan as OpenGL.

The only difference is that Vulkan as an API makes it clear that read-after-write may involve a pipeline stall, since you have to explicitly put the synchronization there. But in both APIs, you can take actions to reduce/avoid the stall. And it’s the same action in both cases. Also, in both APIs you have to think about what you’re doing, since reading from and writing to the same image will result in undefined behavior.

And OpenGL won’t even error due to that.

OpenGL is useful because it’s low-enough level that you’re dealing with hardware constructs and concepts directly. But it’s high-enough level that you aren’t dealing with hardware minutiae directly. You do your stuff at a level of concepts: FBOs, textures, etc. You say you’re using one FBO, then another. Whatever minutiae the driver has to do to make that work is irrelevant to you; you just want it to work.

That’s not to say that OpenGL’s synchronous model is good for performance. It’s merely a higher-level abstraction, designed to make the API easier to use without being so high-level that it stops you from touching hardware constructs. Which means that it sacrifices some performance for safety and user sanity. Removing the synchronous, in-order execution model is really about 90% of what makes Vulkan work, what makes its performance possible.

It’s also about 90% of what makes Vulkan hard to learn.

So why do you think that a “driver-level API” is appropriate for a beginning graphics programmer to learn? Remember: that’s what we’re talking about here.

[QUOTE=Vandroiy;31437]I can’t say I have used the memory states, so I’ll have to see how it goes. But IMO, there should be only two cases:

[ul]
[li]I know what my program is doing. If something is wrong, I just have to go through the intended control flow and check that all transitions, fences, etc. are in place.
[/li][li]I don’t understand the dependencies in my program’s calculations. In other words, I have no idea what I’m doing, but I want a low-level API to make sense of it.
[/li][/ul][/quote]

You say “go through the intended control flow and check that all transitions, fences, etc. are in place” as though such a process is trivial. That’s like saying, “why use smart pointers? If I get a memory leak, I’ll just go through my program’s ‘intended control flow’ (because everything always happens exactly as I ‘intended’ it) to find every memory allocation and make sure it gets freed when its not in use.”

It is exactly this process which will make Vulkan hard to use. First, you have to know what “all transitions, fences, etc” actually are and do. And second, you have to make sure to call them when you need them.

In OpenGL, you just change FBOs and bind the texture to a sampler. It’s much simpler and thus much less error prone.

Remember: we’re talking about beginners here. Not experts. Not people who are good at remembering to do something they just learned about 2 days ago.

Oh please. We all know what “API” means; it’s a pretty clear definition. And we know what “graphics” is. Therefore, an “API” designed for “graphics” work is a “graphics API”.

It may be lower-level than prior graphics APIs. But it’s still higher-level than, for example, GLide, and nobody had any problems calling that a “graphics API”.

So please cease your semantics shell gaming right now. Vulkan is a graphics API. So is Ogre3D. So is OpenGL. The difference is which level they operate at.

It remains unclear at present exactly how much “good knowledge of hardware working internals” is required to use Vulkan. Oh sure, you have to know when to swap memory states or whatever Vulkan requires. But those rules are defined by Vulkan, not the particular hardware.

That is, you don’t issue a “AMD_memory_barrier” or an “NVIDIA_memory_state_transition”. You issue a Vulkan memory state transition. And you do so when Vulkan tells you that you have to. So using the Vulkan API doesn’t require reading up on every possible piece of hardware.

Now granted, effective (ie: maximum performance) use of Vulkan will probably require significant hardware knowledge. But that’s true of OpenGL too; there are lots of hardware-specific optimizations one can make under OpenGL.

… Are you paying attention to anything other than your own posts? You are posting in a thread that is all about examining how hard using the API will be.

We all know that Vulkan makes the API user’s life harder.

Look, I know that Valve is involved and therefore it’s reasonable to doubt when this will come out. But given the fact that we have actually seen live Vulkan implementations on actual hardware, your doubts seem to rest on rather dubious foundations.

And who’s fault was that, Mr. “us CAD developers?”

It seems to me that, now that Khronos kicked “us CAD developers” to the curb, there’s every chance for it to succeed :wink:

I’m not against any success of a new good working API. But my guess if Vulkan is meant to target game developers need from performance to low-level control then they definitely will be using DirectX 12. :wink: Are not they? now? instead of OpenGL?

Unless they want to use most mobile platforms. Or anything not-Windows. Game development doesn’t begin and end with Win32.

I would also remind you that Valve, EA, Unity, Epic, are all game developers, and they are all on-board with Vulkan.

I’m not saying that Vulkan is guaranteed to succeed. But these pesky facts keep getting in the way of your assumptions of why it’s doomed to fail.

[QUOTE=Alfonse Reinheart;31443]Unless they want to use most mobile platforms. Or anything not-Windows. Game development doesn’t begin and end with Win32.

I would also remind you that Valve, EA, Unity, Epic, are all game developers, and they are all on-board with Vulkan.

I’m not saying that Vulkan is guaranteed to succeed. But these pesky facts keep getting in the way of your assumptions of why it’s doomed to fail.[/QUOTE]

It often doesnt matter how good a technology is as much as it matters how many relevant supporters it gets and how big the usership becomes (for whatever reason - can simply be the price for example). Some examples: Betamax, Dreamcast, HDDvD. Bluray in the end won vs HD DvD because the company support shifted entirely towards it. I wouldn’t say any of the two technoliges was significantly better. The same is true for Vulkan and Direct3D 12 (and has been for previous Direct3D and OpenGL versions in the past - they are pretty much equivalent in features, OpenGL only having a benefit in regards to cross-platform availability). If the big game companies will adopt Vulkan, then also hobbyists will. Indie developers (if they dont just use OpenGL) will probably stick with Vulkan since they often target minor platforms.

From another thread:

[QUOTE=Salabar;37645]That’s how I see this.
Lesson 1:
Goal: to understand a general framework of Vulkan. It’s alright to use vkFinish-like functions and not explain them in depth, since it is not really important for now. Helper functions will be used for context initialization and shader compilation.

Initialize Vulkan runtime and a GPU.
Create a compute queue, allocate a memory page in Host-accessible device memory. Create a shader that fills a buffer with thread_ids.
Create a huge command buffer which will make all of manipulations required in this sample.
Dispatch it.
Map the buffer into host memory, printf it.
Clean up job.

Homework: alter the shader in such way it writes thread_id squared instead.[/quote]

Hmm. If I’m a beginning graphics programmer, and the first chapter I read doesn’t involve making something even remotely like a picture, with some form of color on it, I might be put off. At the very least, it should produce some kind of picture that can be viewed. Ideally, it would draw to an actual window.

I don’t think that it would be too much to make it deliver colors rather than thread_ids. The colors could be derived from the “thread_id”. This could be done via a table in the shader that converts (truncated) IDs to colors. This would also help get the programmer used to the idea that shader code writing isn’t that much different from non-shader writing, since a constant array is something that they should be familiar with from C/C++.

Yes, images are a bit more complex (using Mantle as a guide). But that’s mainly due to uploading; simply allocating memory and assigning it to an image isn’t that difficult. Without the uploading process, it could be pretty rudimentary.

Also, this would give the user more room to play around with, in terms of what they can change and modify. They can play with different colors and see the results.

The downside to this whole apporach (one I didn’t realize before), is that to do what you’ve suggested, you have to deal with descriptor sets/layouts. Since that’s how you’re writing your output data, whether an image or a buffer, there still has to be at least a cursory examination of this concept. That’s still quite a lot for them to deal with. Not as much as doing the full rendering pipeline, but it’s still there.

[QUOTE=Salabar;37645]Lesson 2:
Goal: In depth explanation on how resource attachment works.
Create a shader:
DrawEllipse(int4 offset_and_radiuses, int3 color, int3_buffer output_image){
if point (thread_id.x, thread_id.y) is in ellipse (offset_and_radiuses)
output_image[thread_id] = color;
}

Final application will let user to type indefinite number of circles to draw. After each draw, it maps the resulting image into host memory and saves it into BMP or another elementary image format.
Homework: create a shader for drawing of rectangles, learn to switch between different shaders.[/quote]

Lesson 1 covered resource attachment already, since you needed that to write data. This would be covering reading data from the shader, which also necessitates the ability for the user to write such data.

[QUOTE=Salabar;37645]Lesson 3:
In depth synchronization.

Move image buffer into unmappable area. Explain why it is important.
Create another queue. Use it to issue DMA mechanism instead of mapping as in previous lesson.
Use fences so DMA-queue stalls until draw-queue in done drawing and vice-versa. Explain why explicit synch is bad.

Homework:
Remove all vkFinish calls using fences.
Play with different heaps, try using fences to test the application perfomance when different memory areas are used.[/quote]

I’d suggest focusing instead on multiple Compute operations, chaning into one another. That would segue much better into a discussion of the rendering pipeline. For example if Lesson 2 was about drawing some number of circles based on input buffers, make Lesson 3 creating those input buffers, then executing the lesson 2 operation on it.

That would require talking a lot about synchronization, changing compute shaders, and the like. You could even introduce atomic counters if Vulkan has such things.

Ideally, it would draw to an actual window.

The problem is, how do you do this without using a ton of useless libraries? I guess, the tutorial could be shipped with simple button1 Qt project that will read something from file :slight_smile:

The downside to this whole apporach (one I didn’t realize before), is that to do what you’ve suggested, you have to deal with descriptor sets/layouts.

I think the first lesson should give a general understandment of how you interact with GPU. It was the hardest thing for me in blue triangles sample from Red Book. Things like this are important, but not until you know what the heck shader\queue is. “This stuff describes the way data is fed to a shader program. It will be explained in the lesson 2 on a more complex example”. I believe this is basically how VBOs were talked about in the first Red Book chapter.

VBOsVAOs

Of course.

… at some point, such an introductory work is going to have to draw to a window, no matter how many “useless libraries” you might need to do so. For one to not do so would be unacceptable in the eyes of most beginning graphics programmers.

Windows are not optional.

Also, who decides what libraries are “useless”? Even things like GLFW and FreeGLUT are useful to many programmers, not merely those just starting out. And even that’s ignoring the presence of WIS.

My point was that the goal of starting with compute was to lower the number of concepts you need to understand initially to be able to function. And having to talk about descriptor sets/layouts isn’t lowering it, relative to starting with a rendering example. I was simply saying that, while the number of concepts is lower than the rendering pipeline case, it still requires quite a bit.

[QUOTE=Alfonse Reinheart;37651]… at some point, such an introductory work is going to have to draw to a window, no matter how many “useless libraries” you might need to do so. For one to not do so would be unacceptable in the eyes of most beginning graphics programmers.

Windows are not optional.

Also, who decides what libraries are “useless”? Even things like GLFW and FreeGLUT are useful to many programmers, not merely those just starting out. And even that’s ignoring the presence of WIS.[/QUOTE]
I was referring to drawing some image on a window in the very first lesson (when starting with compute shaders). You can generate a texture on Vulkan and use, say OpenCV to show it to user, but it distracts from actual graphics. And it will increase the “fun” user will experience when trying to link his program.

Yes. So was I. As I said, this is not optional; this is what your userbase expects, and with good reason. If the first actual code they see cannot do something as “simple” as display a window and draw stuff in it, then that suggests that the rest will not be much better. Oh sure, we all know that creating a window is not simple at all. But that’s what graphics is to most people, and they are not wrong to think that way.

Remember: you’re already fighting an uphill battle when lesson 1 isn’t even using the rendering pipeline. Arbitrarily subverting expectations like that is not going to win over your userbase.

… I want to make sure I read that right. You’re saying that drawing stuff to the screen “distracts from actual graphics.”

I don’t think you’re going to find a lot of people who will agree that graphics needs a lot less drawing stuff to the screen.

Also, why would you suggest using OpenCV of all things? That’s a computer vision library, not a GUI display system. Why would you not use Vulkan to display it, since it has a windows system interface built-in? Oh, you still need platform specific code to create and manage a window. But Vulkan has the tools to display to that window built-in.

Any beginner instructional material worth using will, as part of that download, include whatever ancillary software one would need to build a program. For Vulkan, it would naturally include a copy of the relevant Vulkan SDK. Which the user will have to link with to begin using Vulkan at all. Having to link to something else that’s included with the download will be no more difficult than that.

I get the idea; you want to make it as easy as possible for people to download, compile, and execute the code. That’s great. But don’t try to optimize for idiots. Especially if doing so leaves out critical steps that your target audience needs to know.

I can see a shadertoy like setup where it’s just a compute shader generating a texture that gets pushed to the screen for lesson 2 (lesson 1 being creating the window in the first place).

then in lesson 3 you use use a buffer to provide input for something that changes in time or in response to the mouse position. This introduces data transfer from application to GPU and barriers.

in lesson 4 you can then start with the graphics pipeline setup to put a triangle on screen in lesson 5.

[QUOTE=Alfonse Reinheart;37653]Yes. So was I. As I said, this is not optional; this is what your userbase expects, and with good reason. If the first actual code they see cannot do something as “simple” as display a window and draw stuff in it, then that suggests that the rest will not be much better. Oh sure, we all know that creating a window is not simple at all. But that’s what graphics is to most people, and they are not wrong to think that way.

Remember: you’re already fighting an uphill battle when lesson 1 isn’t even using the rendering pipeline. Arbitrarily subverting expectations like that is not going to win over your userbase.[/QUOTE]

You’re probably right. On another hand, if one cannot bear a couple of lessons with nothing but “boring” console output, will he even have a discipline to write anything of use, while using driver-level © API? But we’ll see. With a requirement to work everywhere, Vulkan will not become any simpler than Mantle, so chances are, I will be the one who will need such tutorial, rather than one to write it.

But naive and bright-eyed hopefuls will be looking for beginner tutorials soon after vulkan hits. If you can’t deliver a window showing something in the first 2 lessons you are going to lose them.

Well, there is that. I certainly don’t advocate trying to jump into the deep end as a beginning graphics programmer. But if you’re going to serve those people, then you need to understand what they’re looking for.

You won’t need such a tutorial, as you’re already well-versed in the graphics pipeline, computer, GPUs, synchronization, etc. What you need is something like the Mantle programming guide, something that says “this is how the things you already know work in Vulkan”.

Beginning graphics programmers need to learn a lot more.

It is beyond me why I should wait for the Vulkan API if Direct3D 12 is already out there and does everything already. And then I would have to learn everything all over again because Khronos decided to rename everything that vaguely reminded me of D3D 12. And just now I have been testing some hot Direct3D 12 features, turns out nVidia has buggy drivers. Hopefully there won’t be buggy driver implementations when Vulkan rolls out.

DX12 and Vulkan are essentially Mantle. I hope that I can do everything equally or even easier on Vulkan as I am currently doing on DX12. Step up your game tho, please.