TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Weep for Graphics Programming

367 pointsby sampsabout 9 years ago

28 comments

heavenlyhashabout 9 years ago
Upvoted simply because -- notwithstanding all of the entirely valid complaints -- this is actually the short, sweet introduction to GL that I would&#x27;ve loved when I first picked it up.<p>All of these things took me some serious time to learn. Partly because of my sheer incredulity at the stringliness of it all. Finding good GL tutorials is hard, after all: &quot;surely&quot;, I thought, &quot;these are just bad examples, and I should keep looking for a better way&quot;.<p>A quick, frank throwdown of &quot;this is the way it is&quot; like this would&#x27;ve gotten me over that hump much faster. Even if it&#x27;s crushing, I&#x27;m filing this link away for &quot;must read&quot; when someone asks me where to get started in GL programming.
评论 #11621709 未加载
评论 #11623322 未加载
评论 #11623278 未加载
评论 #11625070 未加载
评论 #11621886 未加载
kvarkabout 9 years ago
In Rust ecosystem, we&#x27;ve been experimenting with different ways to make CPU-GPU interaction safer when it comes to graphics abstractions.<p>In gfx-rs [1] one defines a Pipeline State Object with a macro, and then all the input&#x2F;output data and resources are just fields in a regular Rust struct [2]. So assignment pretty much works as one expects. All the compatibility checks are done at run (init) time, when the shader programs are linked&#x2F;reflected.<p>In vulkano [3] the Rust structures are generated at compile time by analyzing your SPIR-V code.<p><pre><code> [1] https:&#x2F;&#x2F;github.com&#x2F;gfx-rs&#x2F;gfx [2] https:&#x2F;&#x2F;github.com&#x2F;gfx-rs&#x2F;gfx&#x2F;blob&#x2F;2c00b52568e5e7da3df227d415eab9f55feba5a9&#x2F;examples&#x2F;shadow&#x2F;main.rs#L314 [3] https:&#x2F;&#x2F;github.com&#x2F;tomaka&#x2F;vulkano</code></pre>
评论 #11620852 未加载
评论 #11620634 未加载
评论 #11623344 未加载
Athasabout 9 years ago
I&#x27;m not sure why bytecode is supposed to be significantly better than storing the shaders as strings. Sure, you get rid of a complex parser and can more easily use it as a compiler target, but the core problem remains: the compiler can still not reason across the device boundary. The CPU compiler does not understand what happens on the GPU, and the GPU compiler has no idea what the CPU is going to do do it.<p>Although I&#x27;m not a big fan of CUDA, it does have an advantage in that it combines both worlds in a single language. This <i>does</i> permit optimisations that cross devices boundaries, but I have no idea whether the CUDA compiler does any of this.<p>Apologies for tooting my own horn, buI have been working on a language that can optimise on both sides of the CPU-GPU-boundary: <a href="http:&#x2F;&#x2F;futhark-lang.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;futhark-lang.org&#x2F;</a> (Although it is more high-level and less graphics-oriented than what I think the author is looking for.)
评论 #11620225 未加载
评论 #11623449 未加载
评论 #11620212 未加载
评论 #11621000 未加载
评论 #11620735 未加载
评论 #11626377 未加载
zamalekabout 9 years ago
I spent a lot of time making toy engines with XNA and carried much of its lessons to my toy engines in C++.<p><i>If your asset can be built, then your asset should be built.</i> Content pipelines.<p>&gt; Shaders are Strings<p>If you&#x27;re using Vulkan, compile your shaders to SPIR-V alongside your project. If you&#x27;re using OpenGL you&#x27;re mostly out of luck - but there&#x27;s still no reason to inline the shaders even with the most rudimentary content manager. Possibly do a syntax pass while building your project.<p>&gt; Stringly Typed Binding Boilerplate<p>If you build your assets first then you can generate the boilerplate code with strong bindings (grabbing positions etc. in the ctor, publicly exposed getters&#x2F;setters). I prototyped this in XNA but never really made a full solution.<p>Graphics APIs are zero-assumption APIs - they don&#x27;t care how you retrieve assets. Either write a framework or use an opinionated off-the-shelf engine. Keeping it this abstract allows for any sort of imaginable scenario. For example: in my XNA prototype, the effects (shaders) were deeply aware of my camera system. In the presence of strong bindings I wouldn&#x27;t have been able to do that.<p>Changing the way that the APIs work (to something not heterogeneous) would require Khronos, Microsoft and Apple to define the interaction interface for <i>every single language that can currently use those APIs</i>.<p>It&#x27;s loosely defined like this for a reason - these are low-level APIs. It&#x27;s up to you to make a stronger binding for your language.
评论 #11621511 未加载
评论 #11624875 未加载
junkeabout 9 years ago
Young fool, only now, at the end, do you understand... code is data.<p>CEPL demos: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=2Z4GfOUWEuA&amp;list=PL2VAYZE_4wRKKr5pJzfYD1w4tKCXARs5y" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=2Z4GfOUWEuA&amp;list=PL2VAYZE_4w...</a><p>I get it, there are many good reasons to stick to C++ if you want to ship a game today.
评论 #11624131 未加载
评论 #11619746 未加载
评论 #11622598 未加载
rjmunroabout 9 years ago
I don&#x27;t think the representation of shaders as strings vs bytecode is a problem at the low level. Strings are slightly inefficient, but you could just pretend that they are bytecode, where the bytes are all restricted to the ASCII range.<p>What is required is a language where the compiler can analyse the code and decide what to do on the CPU and what to do on the GPU as part of it&#x27;s optimisation. It could even emit different versions for different CPU &#x2F; GPU combinations or JIT compile on the target machine once it knows what the actual capabilities are (maybe in some cases it makes sense to do more on the CPU if the GPU is less powerful). You could possibly also run more or even all code on the CPU to enable easier debugging.<p>The language could be defined at high enough level that it can be statically analysed and verified, which I think would answer the criticisms in the article.
haxiomicabout 9 years ago
The haxe-language project &#x27;hxsl&#x27; takes a pretty good stab at improving the situation. With hxsl you write your GPU and CPU code in the same language (haxe) and it generates shader strings (in GLSL or AGAL) at compiletime along with CPU code for whatever platform you&#x27;re targeting.<p>There&#x27;s not a lot of documentation around it at the moment but the author explains a little about it in this video <a href="https:&#x2F;&#x2F;youtu.be&#x2F;-WeGME_T9Ew?t=31m49s" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;-WeGME_T9Ew?t=31m49s</a><p>Source code on github <a href="https:&#x2F;&#x2F;github.com&#x2F;ncannasse&#x2F;heaps&#x2F;tree&#x2F;master&#x2F;hxsl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ncannasse&#x2F;heaps&#x2F;tree&#x2F;master&#x2F;hxsl</a>
评论 #11619820 未加载
评论 #11619854 未加载
Negative1about 9 years ago
I think his conclusion is valid; compilers can now handle register assignment and other boilerplate pretty well (Metal does this superbly and SPIR-V seems very good).<p>My only qualm is that he treats these aspects that he deems outdated as unnecessary, which is just not true. For a long time there was no other alternative. Introducing High Level languages for programmable shading was a huge deal and it actually decreased a lot of complexity. In reality it simplified a lot of stuff that was quite difficult before GLSL&#x2F;HLSL came along.<p>He seems to be making some kind of rallying call for change but the next generation is already here. We&#x27;ll have to keep supporting that old approach for a while longer but the problem really has been solved (to some extent).<p>Also, old person rant: &quot;Back in my day, we only had 8 register combiners and 4 blend states. And we liked it!&quot;
kirillkhabout 9 years ago
When writing my first OpenGL code, I was stunned by the amount of boilerplate required. It is so bad it reminds me of COBOL. No one in their right mind would tolerate that monstrosity in a normal CPU program (except, possibly, some hardcore C++ fans).<p>I think in order to solve this, we need three things: 1) Intermediate representation for compiled GPU code. Bytecode mentioned in the article sounds like it. 2) Cross-platform GPU programming support in our programming languages&#x27; standard libraries. 3) Compiler plugins and DSLs that output the IR and link to the library.
评论 #11620100 未加载
评论 #11625075 未加载
评论 #11619889 未加载
kelvin0about 9 years ago
Gets much worse than that, for anyone having shipped AAA games on multiple consoles: 1) Ubershader program files (#ifdef&#x27;s pepper generously everywhere) 2) Each console has it&#x27;s own quirks and gotchas that you try to abstract 3) CPU&#x2F;GPU interface is a nightmare and debugging is as painful as it gets.
评论 #11619575 未加载
Arnsasteabout 9 years ago
He listed some of the downsides of the OpenGL approach to shaders, but he forgot to address the (IMHO) really big advantage: You can use OpenGL in every programming language that is able to call C functions, which is basically every programming language.<p>Somebody in this thread mentioned CUDA, which is great, but it also has the downside that you practically have to use C++ on the CPU side. You also can use e.g. python, but when you do you are back to compiling CUDA code at runtime.<p>Sure, you could argue that we can simply create a new programming language for applications that use the graphics card (Or use C++ like CUDA). The problem with this is that few people would use it just because its a bit easier to do CPU-GPU communication. An there is a second much larger problem: Different graphics API vendors would create different programming languages which makes it much harder for a application to support multiple graphics API as a lot of games do today with DirectX and OpenGL.<p>Perhaps there is another better solution, but I can&#x27;t see it right now.
评论 #11621607 未加载
chongliabout 9 years ago
What we really need is a project to do for GPUs what RISC-V[0] is about to do for CPUs. It&#x27;s high time we as a society broke away from the stranglehold proprietary companies such as Nvidia and Intel have over us. It&#x27;s time for a completely open computing platform for all of us to use to the fullest advantage of society.<p>[0] <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;RISC-V" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;RISC-V</a>
评论 #11621479 未加载
exDM69about 9 years ago
The issues pointed out by OP are mostly gone in the new Vulkan API, which is the new graphics API from Khronos. Shaders are shipped in SPIR-V bytecode binary format and the binding of resources to shader inputs is more memory-oriented.<p>Time to go learn a new API :)
评论 #11619675 未加载
joeld42about 9 years ago
CUDA sounds like the kind of &quot;heterogeneous&quot; model the author is suggesting. Unfortunately it has it&#x27;s own set of problems.<p>I&#x27;m not really sure what kind of API the author wants. Sure, it&#x27;s annoying that data in GPU-land and CPU-land are difficult to get to work together. But that&#x27;s not the API&#x27;s fault, it&#x27;s because they are physically very far removed from each other. They don&#x27;t share memory (and if they did you&#x27;d still have to lock and manage it). You could make an API that made them seem more transparent to the programmer, but then you&#x27;re back to the GL 1.0 mess where you have zero control and the driver does dumb things at random times because it doesn&#x27;t know anything about the program that is executing.
评论 #11621789 未加载
csabahruskaabout 9 years ago
In lambdacube 3d you can program the CPU&#x2F;GPU (OpenGL+GLSL) in one typed language. (<a href="http:&#x2F;&#x2F;lambdacube3d.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;lambdacube3d.com&#x2F;</a>)
_yosefkabout 9 years ago
OpenCL was moving to LLVM IR away from programs-as-source-code-strings at some point. Still, you ought to have a JIT step if you want to be able to ship the same binary to multiple systems with GPUs not compatible at the binary level. And BTW shipping LLVM IR on the CPU would make things better in terms of supporting CPUs with incompatible ISAs... whether that ever overtakes native binaries is a question (it did to an extent, of course, with the JVM and what-not.) Of course you could move the JIT off the client device completely and do it at the App Store - prepare a bunch of binaries for all the devices out there - but still, the developers will have shipped IR.<p>Once you get to shipping IR instead of strings, which is nice I guess in that it should make initialization somewhat faster and the GPU drivers somewhat smaller, I&#x27;m not sure what you&#x27;re going to get from being able to treat a CPU&#x2F;GPU program as a single whole. Typically the stuff running on the GPU or any other sort of accelerator does not call back into the CPU - these are &quot;leaf functions&quot;, optimized as a separate program, pretty much. I guess it&#x27;d be nice to be able to optimize a given call to such a function automatically (&quot;here the CPU passes a constant so let&#x27;s constant-fold all this stuff over here.&quot;) The same effect can be achieved today by creating a GPU wrapper code passing the constants and having the CPU call that, avoiding this doesn&#x27;t sound like a huge deal. Other than that, what big improvement opportunities am I missing due to the CPU compiler not caring what the GPU compiler is doing and what code the GPU is running?<p>(Not a rhetorical question, I expect to be missing something; I work on accelerator design but I haven&#x27;t ever thought very deeply about an integrated CPU+accelerator compiler, except for a high-level language producing code for both the CPU and some accelerators - but this is a different situation, and there you don&#x27;t care what say OpenGL or OpenCL do, you generate both and you&#x27;re the compiler and you use whatever opportunities for program analysis that your higher level language gives you. Here I think the point was that we miss opportunities due to not having a single compiler analyzing our C&#x2F;C++ CPU code and our shader&#x2F;OpenCL&#x2F;... code as a single whole - it&#x27;s this area where I don&#x27;t see a lot of missed opportunities and asking where I&#x27;m wrong.)
评论 #11619902 未加载
评论 #11626264 未加载
xigencyabout 9 years ago
It seems unlikely that any of this will change, because control is in the hands of a relatively few powerful organizations who honestly have no interest in making life easier for software engineers working on graphics programming; and those engineers who do have to put up with it have long since given up or chalk it up to experience; and those developers would probably resist any changes now simply because change requires more work and learning how to do things all over again.<p>The hardware developers (AMD&#x2F;nVidia&#x2F;Intel) have an interest in not changing their device drivers, the software vendors (OpenGL and DirectX) have little interest in redeveloping technology, and the software developers with the most capital, game engine developers, have already found workarounds and hire enough engineers to plug leaks in their lifeboats. The state of tools for game developers is so shoddy as well that trying to retrofit language compilers and shader compilers to work together seems like a drawn out task.<p>It&#x27;s sort of a David and Goliath situation if you think you can change the graphics programming landscape on your own. Plus, we all know how poorly these standards are developed over time.
评论 #11622171 未加载
评论 #11621572 未加载
评论 #11622533 未加载
vanderZwanabout 9 years ago
Would Halide[0] be what he&#x27;s looking for? It&#x27;s a DSL, sure, but one that is embedded in C++, so you can at least program your whole pipeline in place, giving you a good grasp of the flow of the program(s).<p>[0] <a href="http:&#x2F;&#x2F;halide-lang.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;halide-lang.org&#x2F;</a>
评论 #11619637 未加载
ixtliabout 9 years ago
Very well written. I get the sense that the reason we&#x27;re all here now is that historically the people who use these APIs as client programmers have been somewhat bad at explaining what they want.
评论 #11622640 未加载
IvanK_netabout 9 years ago
I did not find anything interesting or useful in this article.<p>Author just says, that OpenGL and &quot;shaders as strings&quot; are bad, without explaining why. Then author speaks about some mysterious &quot;Heterogeneity&quot; without specifying what it means.<p>&quot;We need programming models that let us write one program that spans multiple execution contexts&quot; - what does it mean? How should that model look like, how should it be different? It is like saying &quot;cars with 4 wheels are bad, cars with different number of wheels would be better&quot;.
评论 #11619922 未加载
评论 #11619938 未加载
DonHopkinsabout 9 years ago
DreemGL [1] [2] addresses these problems by compiling JavaScript code into shaders.<p>&quot;DreemGL is an open-source multi-screen prototyping framework for mediated environments, with a visual editor and shader styling for webGL and DALi runtimes written in JavaScript.&quot; [3]<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;dreemproject&#x2F;dreemgl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dreemproject&#x2F;dreemgl</a><p>[2] <a href="http:&#x2F;&#x2F;docs.dreemproject.org&#x2F;docs&#x2F;api&#x2F;index.html#!&#x2F;guide&#x2F;dreem_in_10_part1" rel="nofollow">http:&#x2F;&#x2F;docs.dreemproject.org&#x2F;docs&#x2F;api&#x2F;index.html#!&#x2F;guide&#x2F;dre...</a><p>[3] <a href="https:&#x2F;&#x2F;dreemproject.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dreemproject.org&#x2F;</a>
评论 #11624621 未加载
rawnlqabout 9 years ago
One interesting library for building shaders is: <a href="http:&#x2F;&#x2F;acko.net&#x2F;blog&#x2F;shadergraph-2&#x2F;" rel="nofollow">http:&#x2F;&#x2F;acko.net&#x2F;blog&#x2F;shadergraph-2&#x2F;</a> or <a href="https:&#x2F;&#x2F;github.com&#x2F;unconed&#x2F;shadergraph" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;unconed&#x2F;shadergraph</a><p>Made by the guy behind MathBox.
robbiesabout 9 years ago
I think the author has good intentions (don&#x27;t we all), but I don&#x27;t think he understands enough about graphics programming to make some of the proclamations&#x2F;requests in the article. Not that I blame him...it&#x27;s hard to get an understanding of GPU programming outside the scope of a game dev or IHV.<p>&gt; To define an object’s appearance in a 3D scene, real-time graphics applications use shaders... Eh, the shaders are just a part of the GPU pipeline that transforms your vertices, textures, and shaders into something interesting on the screen.<p>This is already oversimplifying what GPUs are trying to do for the base case of graphics.<p>&gt; the interface between the CPU and GPU code is needlessly dynamic, so you can’t reason statically about the whole, heterogeneous program.<p>Ok, so what is the proposed solution here? You have a variety of IHVs (NV, AMD, Intel, ImgTec, ARM, Samsung, Qualcomm, etc). Each vendor has a set of active architectures that each have their own ISA. And even then, there are sub-archs that likely require different accommodations in ISA generation depending on the sub-rev.<p>So in the author&#x27;s view of just the shader code, you already have the large problem of unifying the varieties of ISA under some...homogenous ISA, like an x86. That&#x27;s a non-trivial problem. What&#x27;s the motivation here? How will you get vendors to comply?<p>I think right now, SPIR-V, OpenCL, and CUDA aren&#x27;t doing a _bad_ job in trying to create a common programming model where you can target multiple hardware revs with some intermediate representation, but until all the vendors team up and agree on an ISA, I don&#x27;t see how to fix this.<p><i>On top of that</i>, that isn&#x27;t even really the only important bit of programming that happens on GPUs. GPUs primarily operate on command buffers, of which, there is nary a mention of in the article. So even if we address the shader cores inside the GPU, what about a common model for programming command buffers directly? Good luck getting vendors to unify on that. Vulkan&#x2F;DX12&#x2F;Metal are good (even great) efforts in exposing the command buffer model. You couldn&#x27;t even _see_ this stuff in OpenGL and pre-DX12 (though there were display lists and deferred contexts, which kinda exposed the command buffer programming model).<p>&gt; To use those parameters, the host program’s first step is to look up location handles for each variable...<p>Ok, I don&#x27;t blame the author for complaining about this model, but this is an introductory complaint. You can bind shader inputs to &#x27;registers&#x27;, which map to API slots. So with some planning, you don&#x27;t need to query location handles if you specify them in the shader in advance. I think this functionality existed in Shader Model 1.0, though I can&#x27;t find any old example code for it (2001?).<p>That being said, I certainly don&#x27;t blame the author for not knowing this, as I think this is a common mistake made by introductory graphics programmers, because the educational resources are poor. I don&#x27;t think I ever learned it in school...only in the industry was this exposed to me, to my great joy. Though I am certain many smarter engineers figured it out unprompted.<p>&gt; OpenGL’s programming model espouses the simplistic view that heterogeneous software should comprise multiple, loosely coupled, independent programs.<p>Eh, I don&#x27;t think I want a common programming model across CPUs and GPUs. They are fundamentally different machines, and I don&#x27;t think it makes sense to try to lump them together. I don&#x27;t think we just assume that we can use the same programming methodologies for a single vs multi-threaded program. I know that plenty tried, but I thought the best method of addressing the differences was education and tools. I&#x27;d advocate that most effective way that GPU programming will become more accessible will be education and tools. I have hope that the current architecture of the modern &#x27;explicit&#x27; API will facilitate that movement.
评论 #11623251 未加载
评论 #11624001 未加载
onetimePeteabout 9 years ago
Coding for a GPU is basically embedded programming - and the jit step is needed to avoid platform adaption costs.
scrumperabout 9 years ago
Slightly OT, but the literate presentation was nice. Any particular tool or technique you used for that?<p>Thanks
评论 #11623474 未加载
评论 #11623478 未加载
评论 #11623481 未加载
cosmicexplorerabout 9 years ago
I think this what OpenACC (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;OpenACC" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;OpenACC</a>) was created to do; its support is pretty iffy right now, though.
评论 #11619763 未加载
tdsamardzhievabout 9 years ago
Can somebody with Direct3D-experience give opinion if it&#x27;s any better?
评论 #11619859 未加载
sklogicabout 9 years ago
Source code or IR or whatever else would always be needed, I&#x27;m afraid, with a late (and, likely, unpredictable) compilation. Passing an image of a different format may trigger a dynamic shader (or OpenCL kernel) recompilation on some GPUs, for example.