alaingalvan / alainxyz-comments

๐Ÿ”ฎ Utterances powered comments for the Alain.xyz blog.
https://alain.xyz/blog
MIT License
2 stars 0 forks source link

blog/comparison-of-modern-graphics-apis #4

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

A Comparison of Modern Graphics APIs

Alain Galvรกn is an Engineer @ Marmoset.co, here's his personal portfolio focused on ๐Ÿ›† Computer Graphics, ๐ŸŽจ Art & ๐ŸŽน๐ŸŽธ Audio Design/Engineering.

https://alain.xyz/

rams3s commented 4 years ago

Thank you for the article.

You might want to add fences support in Metal (MTLFence)

Cryru commented 4 years ago

Fences are also supported in OpenGL (glFenceSync)

alaingalvan commented 4 years ago

Thanks @Cryru and @rams3s for pointing those out! ๐Ÿ˜

I've gone ahead and updated the post with those examples of fences in OpenGL and Metal. ๐Ÿ‘

NightCreature commented 4 years ago

HLSL is row major by default https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-matrix. Since MS has done away with math libraries mostly and leaves this up to the developer it doesnt really care as long as you specify it to the shader compiler.

redorav commented 4 years ago

Great post! I started creating an Excel to do exactly this between APIs, and this is very helpful.

One thing you may want to mention is fxc/dxc and its new relationship to Vulkan. At work we rarely use the "built-in" compiler but defer to the exes for shader compilation.

I'd also like to point out that on Metal, command buffers are created from command queues, so implicitly they have this behavior where you need to submit the command buffers to the queues they were created from. This makes some sense since queues can have different types such as Graphics, Compute or Copy and you're not allowed to submit say graphics command buffers to compute queues.

There's also an issue in texture alignment that says vk:Semaphore

alaingalvan commented 4 years ago

Thanks @redorav , I've gone ahead and updated that section with more information on texture spaces! Also, feel free to share your notes whenever you feel there's ready it's good to have more discussions on graphics API abstractions.

@NightCreature, you're right, it's probably not worth discussing matrix alignments in general, so I've removed that section from the post.

palver123 commented 3 years ago

Great article! One question for the command pool part: what is MTLQueue? Isn't it supposed to be MTLCommandQueue?

alaingalvan commented 3 years ago

Yes! I've gone ahead and corrected that, thanks @palver123!

haasn commented 3 years ago

Your description for fences and semaphores is backwards. Semaphores are purely on-GPU resources that allow the GPU to wait on itself. Fences are for signalling command completion back to the host.

alaingalvan commented 3 years ago

Thanks @haasn you're right! I've rewritten the section on synchronization primitives to be more accurate and included some more citations in the post.

JiayinCao commented 3 years ago

Nice post. I would like to point out a confusing part in this blog

Send your list of command buffers to your command queue and present your swapchain,
waiting for a signal from your GPU that you've finished rendering the current back
buffer so you can continue your application.

Given the context around this section, it looks like you are talking about the host program. While modern graphics APIs are mostly executed in an asynchronized manner. Certainly, it won't block the CPU during presentation. Technically speaking, we can wait for the GPU to finish the frame rendering before starting next frame rendering. But this will end up in total sequential execution model, meaning either CPU or GPU is working at one point, they will never run at the same time. Either CPU is waiting for the GPU to finish, or GPU is starving because of waiting for commands to come in. This kind of waiting will potentially improve the input latency at the cost of very inefficient rendering. Last gen graphics APIs will silently caches three frames commands under the hood. Modern graphics APIs makes it explicit, while lots of game devs tend to stay the same by having three frames going on at the same time. Even for VR games, where input latency is very important, almost no one waits the GPU to finish before triggering the next frame if I'm not wrong, but they do reduce that three frames to one frame for better input latency.

Andreyogld3d commented 3 years ago

Alain Galvan, Thank you for the article! I have some suggestions:

Section Shader Compiler

Vulkan #include "glslang/Include/revision.h" Right now should prefer HLSL for Vulkan, to improve porting to anothers API/Platform like as Direct3D12/Play Station 4/XBox One, see https://www.khronos.org/blog/hlsl-first-class-vulkan-shading-language

DirectX 12 #include

The legacy D3DCompiler doesn't support Shader Model 6.x, the last supporting shader model is 5.1 https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/specifying-compiler-targets

Direct3D12 can support new Shader Model 6.x, so should use DXC Compiler https://github.com/microsoft/DirectXShaderCompiler.

Section Frame Backings

Direct3D12 has no Window Surface

Section Barriers

Direct3D12 uses ID3D12GraphicsCommandList::ResourceBarrier, but not ID3D12Fence

Section Semaphore

Direct3D12 has no semaphores (like as Vulkan VkSemaphore) at all

alaingalvan commented 2 years ago

Alrighty, I revised the post with the following:

  1. I made it clearer that using shader compilers like DirectXShaderCompiler is the way to approach compiling shaders moving forward, rather tahn using the bundled compiler for DirectX 11/12.

  2. Corrected some of the errata regarding:

    • Window Surfaces
    • Barriers
    • Frame Buffers
    • Semaphores
  3. Made the asynchronous nature of the command buffers clearer in the post, this is to address Jiayin's earlier comment.

Thanks everyone! ๐Ÿ˜

stalkerg commented 2 years ago

I suppose OpenGL has some sort of queue and command buffer by this https://www.khronos.org/opengl/wiki/Sync_Object it's a little indirect but I can't say it's N/A.

stalkerg commented 2 years ago

For command list we have at least this extension https://www.khronos.org/registry/OpenGL/extensions/NV/NV_command_list.txt in OpenGL.

Wumpf commented 1 year ago

Nice article and thanks for keeping it up to date!

Small error I found: WebGPU and Vulcan texture coordinate system is actually oriented like DX, i.e. origin is top left. It's really only OpenGL which is the odd one out where the first texel in memory is addressed with (0, 1) instead of (0, 0)

Sources WebGPU https://www.w3.org/TR/webgpu/#coordinate-systems https://github.com/gfx-rs/wgpu#coordinate-systems

Sources Vulkan https://github.com/gfx-rs/gfx/tree/master/src/backend/vulkan https://jdelezenne.github.io/Codex/Game/Texture.html

LeeTeng2001 commented 1 year ago

Hi, I have a question, whta do you use to create those cute picture?

alaingalvan commented 1 year ago

Hi, I have a question, what do you use to create those cute pictures?

Those images were created using Marmoset Hexels and Affinity Designer.

bipul-mohanto commented 1 year ago

hi @alaingalvan, I am a big fan of your posts. This is a nice overview of different graphics APIs. However, I did not see any mention of NVIDIA OptiX API. That is also a very popular API in the production industry.